|
@@ -7,12 +7,9 @@ import androidx.activity.compose.setContent
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
import androidx.compose.material3.Surface
|
|
import androidx.compose.material3.Surface
|
|
|
-import androidx.compose.runtime.remember
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.core.view.WindowCompat
|
|
import androidx.core.view.WindowCompat
|
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.launch
|
|
|
-import org.sirekanyan.outline.api.OutlineApi
|
|
|
|
|
-import org.sirekanyan.outline.db.rememberApiUrlDao
|
|
|
|
|
import org.sirekanyan.outline.ui.AddServerContent
|
|
import org.sirekanyan.outline.ui.AddServerContent
|
|
|
import org.sirekanyan.outline.ui.DeleteKeyContent
|
|
import org.sirekanyan.outline.ui.DeleteKeyContent
|
|
|
import org.sirekanyan.outline.ui.DeleteServerContent
|
|
import org.sirekanyan.outline.ui.DeleteServerContent
|
|
@@ -24,22 +21,20 @@ class MainActivity : ComponentActivity() {
|
|
|
super.onCreate(savedInstanceState)
|
|
super.onCreate(savedInstanceState)
|
|
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
|
|
setContent {
|
|
setContent {
|
|
|
- val api = remember { OutlineApi() }
|
|
|
|
|
- val dao = rememberApiUrlDao()
|
|
|
|
|
- val state = rememberMainState(api)
|
|
|
|
|
|
|
+ val state = rememberMainState()
|
|
|
OutlineTheme {
|
|
OutlineTheme {
|
|
|
Surface(Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
|
|
Surface(Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
|
|
|
BackHandler(state.drawer.isOpen) {
|
|
BackHandler(state.drawer.isOpen) {
|
|
|
state.closeDrawer()
|
|
state.closeDrawer()
|
|
|
}
|
|
}
|
|
|
- MainContent(api, dao, state)
|
|
|
|
|
|
|
+ MainContent(state)
|
|
|
state.dialog?.let { dialog ->
|
|
state.dialog?.let { dialog ->
|
|
|
BackHandler(state.dialog != null) {
|
|
BackHandler(state.dialog != null) {
|
|
|
state.dialog = null
|
|
state.dialog = null
|
|
|
}
|
|
}
|
|
|
when (dialog) {
|
|
when (dialog) {
|
|
|
- is AddServerDialog -> Surface { AddServerContent(dao, state) }
|
|
|
|
|
- is EditKeyDialog -> Surface { EditKeyContent(api, state, dialog) }
|
|
|
|
|
|
|
+ is AddServerDialog -> Surface { AddServerContent(state) }
|
|
|
|
|
+ is EditKeyDialog -> Surface { EditKeyContent(state, dialog) }
|
|
|
is DeleteKeyDialog -> {
|
|
is DeleteKeyDialog -> {
|
|
|
val (apiUrl, key) = dialog
|
|
val (apiUrl, key) = dialog
|
|
|
DeleteKeyContent(
|
|
DeleteKeyContent(
|
|
@@ -48,7 +43,7 @@ class MainActivity : ComponentActivity() {
|
|
|
onConfirm = {
|
|
onConfirm = {
|
|
|
state.scope.launch {
|
|
state.scope.launch {
|
|
|
state.deletingKey = key
|
|
state.deletingKey = key
|
|
|
- api.deleteAccessKey(apiUrl, key.accessKey.id)
|
|
|
|
|
|
|
+ state.api.deleteAccessKey(apiUrl, key.accessKey.id)
|
|
|
state.refreshCurrentKeys(showLoading = false)
|
|
state.refreshCurrentKeys(showLoading = false)
|
|
|
}.invokeOnCompletion {
|
|
}.invokeOnCompletion {
|
|
|
state.deletingKey = null
|
|
state.deletingKey = null
|
|
@@ -63,7 +58,7 @@ class MainActivity : ComponentActivity() {
|
|
|
onDismiss = { state.dialog = null },
|
|
onDismiss = { state.dialog = null },
|
|
|
onConfirm = {
|
|
onConfirm = {
|
|
|
state.scope.launch {
|
|
state.scope.launch {
|
|
|
- dao.deleteUrl(apiUrl.id)
|
|
|
|
|
|
|
+ state.dao.deleteUrl(apiUrl.id)
|
|
|
}
|
|
}
|
|
|
state.page = HelloPage
|
|
state.page = HelloPage
|
|
|
state.openDrawer()
|
|
state.openDrawer()
|