Skip to content

Commit

Permalink
Convert auth package to kotlin (#5966)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
psh authored Nov 28, 2024
1 parent 2380230 commit 0c969c3
Show file tree
Hide file tree
Showing 25 changed files with 752 additions and 964 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PasteSensitiveTextInputEditTextTest {
@Before
fun setup() {
context = ApplicationProvider.getApplicationContext()
textView = PasteSensitiveTextInputEditText(context)
textView = PasteSensitiveTextInputEditText(context!!)
}

// this test has no real value, just % for test code coverage
Expand Down
44 changes: 0 additions & 44 deletions app/src/main/java/fr/free/nrw/commons/auth/AccountUtil.java

This file was deleted.

24 changes: 24 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/auth/AccountUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.free.nrw.commons.auth

import android.accounts.Account
import android.accounts.AccountManager
import android.content.Context
import androidx.annotation.VisibleForTesting
import fr.free.nrw.commons.BuildConfig.ACCOUNT_TYPE
import timber.log.Timber

const val AUTH_TOKEN_TYPE: String = "CommonsAndroid"

fun getUserName(context: Context): String? {
return account(context)?.name
}

@VisibleForTesting
fun account(context: Context): Account? = try {
val accountManager = AccountManager.get(context)
val accounts = accountManager.getAccountsByType(ACCOUNT_TYPE)
if (accounts.isNotEmpty()) accounts[0] else null
} catch (e: SecurityException) {
Timber.e(e)
null
}
Loading

0 comments on commit 0c969c3

Please sign in to comment.