Skip to content

Commit

Permalink
Depend removeAccount() method on mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Dzieniak committed Nov 12, 2019
1 parent 6bdacb7 commit 08fd9cb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ abstract class ${schemeClassName}(context: Context) :
</#list>
}

override fun removeAccount(name: String): Completable =
override fun removeAccount(<#if schemaMode == "multiple">name: String</#if>): Completable =
super
.removeAccount(name)
.removeAccount(<#if schemaMode == "multiple">name</#if>)
.andThen(clearSubjects())

private fun clearSubjects(): Completable =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,4 @@ abstract class BaseAccountScheme(private val context: Context) {
manager.addAccountExplicitly(account, password, null)
}
.subscribeOn(Schedulers.io())

/**
* Removes account associated with given email.
*/
open fun removeAccount(name: String): Completable =
Completable
.fromAction {

// Retrieve account.
val account = manager
.getAccountsByType(provideAuthenticator())
.first { it.name == name }

// Remove account.
@Suppress("DEPRECATION")
manager.removeAccount(account, null, null)
}
.subscribeOn(Schedulers.io())
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package co.windly.ktxaccount.runtime.scheme

import android.accounts.Account
import android.content.Context
import io.reactivex.Completable
import io.reactivex.schedulers.Schedulers

/**
* This scheme assumes MULTIPLE accounts for given authenticator can exist.
Expand Down Expand Up @@ -41,5 +43,23 @@ abstract class MultipleAccountScheme(context: Context) : BaseAccountScheme(conte
.firstOrNull { it.name == name }
}

/**
* Removes account associated with given email.
*/
open fun removeAccount(name: String): Completable =
Completable
.fromAction {

// Retrieve account.
val account = manager
.getAccountsByType(provideAuthenticator())
.first { it.name == name }

// Remove account.
@Suppress("DEPRECATION")
manager.removeAccount(account, null, null)
}
.subscribeOn(Schedulers.io())

//endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package co.windly.ktxaccount.runtime.scheme
import android.accounts.Account
import android.content.Context
import io.reactivex.Completable
import io.reactivex.schedulers.Schedulers

/**
* This scheme assumes ONE and ONLY account for given authenticator will ever exist.
Expand All @@ -28,6 +29,12 @@ abstract class SingleAccountScheme(context: Context) : BaseAccountScheme(context
clearExistingAccounts()
.andThen(super.saveAccount(name, password))

/**
* Removes account associated with given email.
*/
open fun removeAccount(): Completable =
clearExistingAccounts()

/**
* Retrieves an account associated with provided authenticator and identified by
* given name.
Expand Down Expand Up @@ -71,6 +78,7 @@ abstract class SingleAccountScheme(context: Context) : BaseAccountScheme(context
manager.removeAccount(it, null, null)
}
}
.subscribeOn(Schedulers.io())

//endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class MainActivity : Activity() {

// Remove account.
manager
.removeAccount(name)
.removeAccount()
.subscribe(
::handleRemoveAccountSuccess,
::handleRemoveAccountError
Expand Down

0 comments on commit 08fd9cb

Please sign in to comment.