Add initial account creation path
This commit is contained in:
parent
0942dbe053
commit
ad0ffe55c9
@ -1,5 +1,6 @@
|
||||
package com.readrops.app.compose
|
||||
|
||||
import com.readrops.app.compose.account.AccountViewModel
|
||||
import com.readrops.app.compose.feeds.FeedViewModel
|
||||
import com.readrops.app.compose.repositories.BaseRepository
|
||||
import com.readrops.app.compose.repositories.LocalRSSRepository
|
||||
@ -15,6 +16,8 @@ val composeAppModule = module {
|
||||
|
||||
viewModel { FeedViewModel(get(), get()) }
|
||||
|
||||
viewModel { AccountViewModel(get()) }
|
||||
|
||||
// repositories
|
||||
|
||||
single<BaseRepository> { LocalRSSRepository(get(), get(), Account(id = 1, isCurrentAccount = true, accountType = AccountType.LOCAL)) }
|
||||
|
@ -17,11 +17,14 @@ import cafe.adriel.voyager.navigator.Navigator
|
||||
import cafe.adriel.voyager.navigator.tab.TabNavigator
|
||||
import cafe.adriel.voyager.transitions.FadeTransition
|
||||
import cafe.adriel.voyager.transitions.SlideTransition
|
||||
import com.readrops.app.compose.account.AccountSelectionScreen
|
||||
import com.readrops.app.compose.account.AccountTab
|
||||
import com.readrops.app.compose.account.AccountViewModel
|
||||
import com.readrops.app.compose.feeds.FeedTab
|
||||
import com.readrops.app.compose.home.HomeScreen
|
||||
import com.readrops.app.compose.more.MoreTab
|
||||
import com.readrops.app.compose.timelime.TimelineTab
|
||||
import org.koin.androidx.viewmodel.ext.android.getViewModel
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
@ -29,10 +32,13 @@ class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val viewModel = getViewModel<AccountViewModel>()
|
||||
val accountExists = viewModel.accountExists()
|
||||
|
||||
setContent {
|
||||
ReadropsTheme {
|
||||
Navigator(
|
||||
screen = HomeScreen()
|
||||
screen = if (accountExists) HomeScreen() else AccountSelectionScreen()
|
||||
) { navigator ->
|
||||
FadeTransition(navigator)
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.readrops.app.compose.account
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import cafe.adriel.voyager.androidx.AndroidScreen
|
||||
|
||||
class AccountSelectionScreen : AndroidScreen() {
|
||||
|
||||
@Composable
|
||||
override fun Content() {
|
||||
Column {
|
||||
Text(text = "account selection")
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.readrops.app.compose.account
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.readrops.db.Database
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
class AccountViewModel(
|
||||
private val database: Database,
|
||||
) : ViewModel() {
|
||||
|
||||
fun accountExists(): Boolean {
|
||||
val accountCount = runBlocking {
|
||||
database.newAccountDao().selectAccountCount()
|
||||
}
|
||||
|
||||
return accountCount > 0
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import com.readrops.db.dao.*
|
||||
import com.readrops.db.dao.newdao.NewAccountDao
|
||||
import com.readrops.db.dao.newdao.NewFeedDao
|
||||
import com.readrops.db.dao.newdao.NewItemDao
|
||||
import com.readrops.db.entities.*
|
||||
@ -32,4 +33,6 @@ abstract class Database : RoomDatabase() {
|
||||
abstract fun newFeedDao(): NewFeedDao
|
||||
|
||||
abstract fun newItemDao(): NewItemDao
|
||||
|
||||
abstract fun newAccountDao(): NewAccountDao
|
||||
}
|
12
db/src/main/java/com/readrops/db/dao/newdao/NewAccountDao.kt
Normal file
12
db/src/main/java/com/readrops/db/dao/newdao/NewAccountDao.kt
Normal file
@ -0,0 +1,12 @@
|
||||
package com.readrops.db.dao.newdao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Query
|
||||
|
||||
@Dao
|
||||
interface NewAccountDao {
|
||||
|
||||
@Query("Select Count(*) From Account")
|
||||
suspend fun selectAccountCount(): Int
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user