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