AccountProvider: Migrate to object

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-08-05 10:09:29 +08:00
parent 038331f8e2
commit 7d083e3749
3 changed files with 5 additions and 9 deletions

View File

@@ -21,15 +21,12 @@ package com.aurora.store.data.providers
import android.content.Context
import com.aurora.Constants
import com.aurora.store.data.SingletonHolder
import com.aurora.store.data.model.AccountType
import com.aurora.store.util.Preferences
class AccountProvider private constructor(var context: Context) {
object AccountProvider {
companion object : SingletonHolder<AccountProvider, Context>(::AccountProvider)
fun getAccountType(): AccountType {
fun getAccountType(context: Context): AccountType {
val rawType = Preferences.getString(context, Constants.ACCOUNT_TYPE)
return when (rawType) {
"GOOGLE" -> AccountType.GOOGLE
@@ -37,7 +34,7 @@ class AccountProvider private constructor(var context: Context) {
}
}
fun logout() {
fun logout(context: Context) {
Preferences.putBoolean(context, Constants.ACCOUNT_SIGNED_IN, false)
Preferences.putString(context, Constants.ACCOUNT_EMAIL_PLAIN, "")
Preferences.putString(context, Constants.ACCOUNT_AAS_PLAIN, "")

View File

@@ -23,7 +23,7 @@ class LogoutDialog: DialogFragment() {
}
private fun logout() {
AccountProvider.with(requireContext()).logout()
AccountProvider.logout(requireContext())
UpdateWorker.cancelAutomatedCheck(requireContext())
findNavController().navigate(LogoutDialogDirections.actionLogoutDialogToSplashFragment())
}

View File

@@ -166,8 +166,7 @@ class AuthViewModel @Inject constructor(
liveData.postValue(AuthState.Valid)
} else {
//Generate and validate new auth
val type = AccountProvider.with(context).getAccountType()
when (type) {
when (AccountProvider.getAccountType(context)) {
AccountType.GOOGLE -> {
val email = Preferences.getString(
context,