-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
25 changed files
with
752 additions
and
964 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
app/src/main/java/fr/free/nrw/commons/auth/AccountUtil.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.