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 android.content.Context
import com.aurora.Constants import com.aurora.Constants
import com.aurora.store.data.SingletonHolder
import com.aurora.store.data.model.AccountType import com.aurora.store.data.model.AccountType
import com.aurora.store.util.Preferences import com.aurora.store.util.Preferences
class AccountProvider private constructor(var context: Context) { object AccountProvider {
companion object : SingletonHolder<AccountProvider, Context>(::AccountProvider) fun getAccountType(context: Context): AccountType {
fun getAccountType(): AccountType {
val rawType = Preferences.getString(context, Constants.ACCOUNT_TYPE) val rawType = Preferences.getString(context, Constants.ACCOUNT_TYPE)
return when (rawType) { return when (rawType) {
"GOOGLE" -> AccountType.GOOGLE "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.putBoolean(context, Constants.ACCOUNT_SIGNED_IN, false)
Preferences.putString(context, Constants.ACCOUNT_EMAIL_PLAIN, "") Preferences.putString(context, Constants.ACCOUNT_EMAIL_PLAIN, "")
Preferences.putString(context, Constants.ACCOUNT_AAS_PLAIN, "") Preferences.putString(context, Constants.ACCOUNT_AAS_PLAIN, "")

View File

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

View File

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