🐛 Fixes auth activity doesn't load URL and token
This commit is contained in:
@@ -87,8 +87,14 @@ class AuthActivity : ComponentActivity() {
|
||||
return regex.matches(serverUrl)
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
serverUrl = apiDataHolder.serverUrl
|
||||
token = apiDataHolder.token
|
||||
isServerUrlOk = prefs.getBoolean(context.getString(R.string.server_url_okay_key), false)
|
||||
isTokenOk = prefs.getBoolean(context.getString(R.string.token_okay_key), false)
|
||||
}
|
||||
|
||||
LaunchedEffect(serverUrl) {
|
||||
println("SERVER URL CHANGED")
|
||||
apiDataHolder.serverUrl = serverUrl
|
||||
prefs.edit {
|
||||
putString(
|
||||
@@ -107,7 +113,8 @@ class AuthActivity : ComponentActivity() {
|
||||
|
||||
isServerUrlOk = try {
|
||||
API.doesServerRespond()
|
||||
} catch (_: Exception) {
|
||||
} catch (e: Exception) {
|
||||
Log.e("AuthActivity", "Checking server response failed", e)
|
||||
false
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,11 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.rememberDrawerState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@@ -41,6 +45,8 @@ import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
class MainActivity : ComponentActivity() {
|
||||
private var reload: (() -> Unit)? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
@@ -58,6 +64,11 @@ class MainActivity : ComponentActivity() {
|
||||
val apiDataHolder = APIDataHolder.getInstance()
|
||||
apiDataHolder.initializeFromPrefs(context, prefs)
|
||||
|
||||
// TODO: fix reloading UI
|
||||
var uiNeedsReload by remember { mutableStateOf(false) }
|
||||
reload = fun() { uiNeedsReload = true }
|
||||
|
||||
if (!uiNeedsReload) {
|
||||
ModalNavigationDrawer(
|
||||
drawerState = drawerState,
|
||||
drawerContent = {
|
||||
@@ -158,11 +169,15 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
uiNeedsReload = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
this.reload?.run {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user