Skip to content

Commit 0c969c3

Browse files
authored
Convert auth package to kotlin (#5966)
* Convert SessionManager to kotlin along with other small fixes * Convert WikiAccountAuthenticator to kotlin * Migrate WikiAccountAuthenticatorService to kotlin * Converted AccountUtil to kotlin * Convert SignupActivity to kotlin * Convert LoginActivity to kotlin * Merge from main
1 parent 2380230 commit 0c969c3

25 files changed

+752
-964
lines changed

app/src/androidTest/java/fr/free/nrw/commons/ui/PasteSensitiveTextInputEditTextTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PasteSensitiveTextInputEditTextTest {
1717
@Before
1818
fun setup() {
1919
context = ApplicationProvider.getApplicationContext()
20-
textView = PasteSensitiveTextInputEditText(context)
20+
textView = PasteSensitiveTextInputEditText(context!!)
2121
}
2222

2323
// this test has no real value, just % for test code coverage

app/src/main/java/fr/free/nrw/commons/auth/AccountUtil.java

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package fr.free.nrw.commons.auth
2+
3+
import android.accounts.Account
4+
import android.accounts.AccountManager
5+
import android.content.Context
6+
import androidx.annotation.VisibleForTesting
7+
import fr.free.nrw.commons.BuildConfig.ACCOUNT_TYPE
8+
import timber.log.Timber
9+
10+
const val AUTH_TOKEN_TYPE: String = "CommonsAndroid"
11+
12+
fun getUserName(context: Context): String? {
13+
return account(context)?.name
14+
}
15+
16+
@VisibleForTesting
17+
fun account(context: Context): Account? = try {
18+
val accountManager = AccountManager.get(context)
19+
val accounts = accountManager.getAccountsByType(ACCOUNT_TYPE)
20+
if (accounts.isNotEmpty()) accounts[0] else null
21+
} catch (e: SecurityException) {
22+
Timber.e(e)
23+
null
24+
}

0 commit comments

Comments
 (0)