Fix creating a local account in AccountTab
This commit is contained in:
parent
45c2de4459
commit
9c95e0d63c
@ -23,6 +23,7 @@ import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.core.component.get
|
||||
|
||||
class AccountScreenModel(
|
||||
private val database: Database,
|
||||
@ -165,6 +166,19 @@ class AccountScreenModel(
|
||||
database.accountDao().updateCurrentAccount(account.id)
|
||||
}
|
||||
}
|
||||
|
||||
fun createLocalAccount() {
|
||||
val context = get<Context>()
|
||||
val account = Account(
|
||||
accountName = context.getString(AccountType.LOCAL.typeName),
|
||||
accountType = AccountType.LOCAL,
|
||||
isCurrentAccount = true
|
||||
)
|
||||
|
||||
screenModelScope.launch(dispatcher) {
|
||||
database.accountDao().insert(account)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Stable
|
||||
|
@ -60,6 +60,7 @@ import com.readrops.app.util.theme.MediumSpacer
|
||||
import com.readrops.app.util.theme.VeryShortSpacer
|
||||
import com.readrops.app.util.theme.spacing
|
||||
import com.readrops.db.entities.account.Account
|
||||
import com.readrops.db.entities.account.AccountType
|
||||
|
||||
object AccountTab : Tab {
|
||||
|
||||
@ -179,11 +180,21 @@ object AccountTab : Tab {
|
||||
onValidate = { accountType ->
|
||||
screenModel.closeDialog()
|
||||
|
||||
val account = Account(
|
||||
accountType = accountType,
|
||||
accountName = context.resources.getString(accountType.typeName)
|
||||
)
|
||||
navigator.push(AccountCredentialsScreen(account, AccountCredentialsScreenMode.NEW_CREDENTIALS))
|
||||
if (accountType == AccountType.LOCAL) {
|
||||
screenModel.createLocalAccount()
|
||||
} else {
|
||||
val account = Account(
|
||||
accountType = accountType,
|
||||
accountName = context.resources.getString(accountType.typeName)
|
||||
)
|
||||
navigator.push(
|
||||
AccountCredentialsScreen(
|
||||
account,
|
||||
AccountCredentialsScreenMode.NEW_CREDENTIALS
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -83,7 +83,6 @@ class AccountCredentialsScreenModel(
|
||||
|
||||
if (mode == AccountCredentialsScreenMode.NEW_CREDENTIALS) {
|
||||
newAccount.id = database.accountDao().insert(newAccount).toInt()
|
||||
database.accountDao().updateCurrentAccount(newAccount.id)
|
||||
|
||||
get<SharedPreferences>().edit()
|
||||
.putString(newAccount.loginKey, newAccount.login)
|
||||
|
@ -21,14 +21,9 @@ fun AccountSelectionDialog(
|
||||
icon = painterResource(id = R.drawable.ic_add_account),
|
||||
onDismiss = onDismiss
|
||||
) {
|
||||
AccountType.values().forEach { type ->
|
||||
AccountType.entries.forEach { type ->
|
||||
SelectableImageText(
|
||||
image = painterResource(
|
||||
id = if (type != AccountType.LOCAL)
|
||||
type.iconRes
|
||||
else
|
||||
R.drawable.ic_rss_feed_grey
|
||||
),
|
||||
image = adaptiveIconPainterResource(id = type.iconRes),
|
||||
text = stringResource(id = type.typeName),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
spacing = MaterialTheme.spacing.mediumSpacing,
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.readrops.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import com.readrops.db.entities.account.Account
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@ -8,6 +9,15 @@ import kotlinx.coroutines.flow.Flow
|
||||
@Dao
|
||||
interface AccountDao : BaseDao<Account> {
|
||||
|
||||
override suspend fun insert(entity: Account): Long {
|
||||
val id = insertAccount(entity)
|
||||
updateCurrentAccount(id.toInt())
|
||||
return id
|
||||
}
|
||||
|
||||
@Insert
|
||||
suspend fun insertAccount(entity: Account): Long
|
||||
|
||||
@Query("Select * From Account")
|
||||
fun selectAllAccounts(): Flow<List<Account>>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user