|
@@ -1,13 +1,16 @@
|
|
|
package org.sirekanyan.outline
|
|
package org.sirekanyan.outline
|
|
|
|
|
|
|
|
|
|
+import android.os.Parcelable
|
|
|
import androidx.compose.material3.DrawerState
|
|
import androidx.compose.material3.DrawerState
|
|
|
import androidx.compose.material3.DrawerValue
|
|
import androidx.compose.material3.DrawerValue
|
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
+import androidx.compose.runtime.MutableState
|
|
|
import androidx.compose.runtime.derivedStateOf
|
|
import androidx.compose.runtime.derivedStateOf
|
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.getValue
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.runtime.remember
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
|
|
|
+import androidx.compose.runtime.saveable.rememberSaveable
|
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.runtime.setValue
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
|
@@ -18,6 +21,8 @@ import kotlinx.coroutines.flow.map
|
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.plus
|
|
import kotlinx.coroutines.plus
|
|
|
import kotlinx.coroutines.withContext
|
|
import kotlinx.coroutines.withContext
|
|
|
|
|
+import kotlinx.parcelize.IgnoredOnParcel
|
|
|
|
|
+import kotlinx.parcelize.Parcelize
|
|
|
import org.sirekanyan.outline.api.OutlineApi
|
|
import org.sirekanyan.outline.api.OutlineApi
|
|
|
import org.sirekanyan.outline.api.model.Key
|
|
import org.sirekanyan.outline.api.model.Key
|
|
|
import org.sirekanyan.outline.db.KeyDao
|
|
import org.sirekanyan.outline.db.KeyDao
|
|
@@ -63,16 +68,20 @@ fun rememberMainState(): MainState {
|
|
|
}
|
|
}
|
|
|
val supervisor = remember { SupervisorJob() }
|
|
val supervisor = remember { SupervisorJob() }
|
|
|
val search = rememberSearchState()
|
|
val search = rememberSearchState()
|
|
|
|
|
+ val page = rememberSaveable { mutableStateOf<Page>(HelloPage) }
|
|
|
|
|
+ val dialog = rememberSaveable { mutableStateOf<Dialog?>(null) }
|
|
|
val api = remember { OutlineApi() }
|
|
val api = remember { OutlineApi() }
|
|
|
val dao = rememberServerDao()
|
|
val dao = rememberServerDao()
|
|
|
val prefs = rememberKeyValueDao()
|
|
val prefs = rememberKeyValueDao()
|
|
|
val cache = rememberKeyDao()
|
|
val cache = rememberKeyDao()
|
|
|
- return remember { MainState(scope + supervisor, search, api, dao, prefs, cache) }
|
|
|
|
|
|
|
+ return remember { MainState(scope + supervisor, search, page, dialog, api, dao, prefs, cache) }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
class MainState(
|
|
class MainState(
|
|
|
val scope: CoroutineScope,
|
|
val scope: CoroutineScope,
|
|
|
val search: SearchState,
|
|
val search: SearchState,
|
|
|
|
|
+ pageState: MutableState<Page>,
|
|
|
|
|
+ dialogState: MutableState<Dialog?>,
|
|
|
val api: OutlineApi,
|
|
val api: OutlineApi,
|
|
|
val dao: ServerDao,
|
|
val dao: ServerDao,
|
|
|
private val prefs: KeyValueDao,
|
|
private val prefs: KeyValueDao,
|
|
@@ -83,8 +92,8 @@ class MainState(
|
|
|
val keys = KeyRepository(api, cache)
|
|
val keys = KeyRepository(api, cache)
|
|
|
val drawer = DrawerState(DrawerValue.Closed)
|
|
val drawer = DrawerState(DrawerValue.Closed)
|
|
|
val drawerDisabled by derivedStateOf { search.isOpened && drawer.isClosed }
|
|
val drawerDisabled by derivedStateOf { search.isOpened && drawer.isClosed }
|
|
|
- var page by mutableStateOf<Page>(HelloPage)
|
|
|
|
|
- var dialog by mutableStateOf<Dialog?>(null)
|
|
|
|
|
|
|
+ var page by pageState
|
|
|
|
|
+ var dialog by dialogState
|
|
|
val selectedPage by derivedStateOf { page as? SelectedPage }
|
|
val selectedPage by derivedStateOf { page as? SelectedPage }
|
|
|
var selectedKey by mutableStateOf<Key?>(null)
|
|
var selectedKey by mutableStateOf<Key?>(null)
|
|
|
val isFabVisible by derivedStateOf { (page as? SelectedPage)?.keys is KeysIdleState }
|
|
val isFabVisible by derivedStateOf { (page as? SelectedPage)?.keys is KeysIdleState }
|
|
@@ -143,15 +152,18 @@ class MainState(
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-sealed class Page
|
|
|
|
|
|
|
+@Parcelize
|
|
|
|
|
+sealed class Page : Parcelable
|
|
|
|
|
|
|
|
data object HelloPage : Page()
|
|
data object HelloPage : Page()
|
|
|
|
|
|
|
|
data class SelectedPage(val server: ServerEntity) : Page() {
|
|
data class SelectedPage(val server: ServerEntity) : Page() {
|
|
|
|
|
+ @IgnoredOnParcel
|
|
|
var keys by mutableStateOf<KeysState>(KeysIdleState)
|
|
var keys by mutableStateOf<KeysState>(KeysIdleState)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-sealed class Dialog
|
|
|
|
|
|
|
+@Parcelize
|
|
|
|
|
+sealed class Dialog : Parcelable
|
|
|
|
|
|
|
|
data object AddServerDialog : Dialog()
|
|
data object AddServerDialog : Dialog()
|
|
|
|
|
|