mirror of
https://github.com/nacabaro/vbhelper.git
synced 2026-01-27 16:05:32 +00:00
Last minute bug related to sending the active character from the main screen.
This commit is contained in:
parent
ac05dfc541
commit
36c3e25fd3
@ -1,15 +1,23 @@
|
||||
package com.github.nacabaro.vbhelper.navigation
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.github.nacabaro.vbhelper.di.VBHelper
|
||||
import com.github.nacabaro.vbhelper.screens.BattlesScreen
|
||||
import com.github.nacabaro.vbhelper.screens.DexScreen
|
||||
import com.github.nacabaro.vbhelper.screens.DiMScreen
|
||||
@ -29,6 +37,7 @@ import com.github.nacabaro.vbhelper.screens.adventureScreen.AdventureScreenContr
|
||||
import com.github.nacabaro.vbhelper.screens.settingsScreen.CreditsScreen
|
||||
import com.github.nacabaro.vbhelper.screens.spriteViewer.SpriteViewerControllerImpl
|
||||
import com.github.nacabaro.vbhelper.screens.storageScreen.StorageScreenControllerImpl
|
||||
import com.github.nacabaro.vbhelper.source.StorageRepository
|
||||
|
||||
data class AppNavigationHandlers(
|
||||
val settingsScreenController: SettingsScreenControllerImpl,
|
||||
@ -86,12 +95,29 @@ fun AppNavigation(
|
||||
}
|
||||
composable(NavigationItems.Scan.route) {
|
||||
val characterIdString = it.arguments?.getString("characterId")
|
||||
val characterId = characterIdString?.toLongOrNull()
|
||||
var characterId by remember { mutableStateOf(characterIdString?.toLongOrNull()) }
|
||||
Log.d("ScanScreen", "characterId: $characterId")
|
||||
val launchedFromHomeScreen = (characterIdString?.toLongOrNull() == null)
|
||||
|
||||
if (characterId == null) {
|
||||
val context = LocalContext.current.applicationContext as VBHelper
|
||||
val storageRepository = StorageRepository(context.container.db)
|
||||
|
||||
LaunchedEffect(characterId) {
|
||||
if (characterId == null) {
|
||||
val characterData = storageRepository.getActiveCharacter()
|
||||
if (characterData != null) {
|
||||
characterId = characterData.id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ScanScreen(
|
||||
navController = navController,
|
||||
scanScreenController = applicationNavigationHandlers.scanScreenController,
|
||||
characterId = characterId
|
||||
characterId = characterId,
|
||||
launchedFromHomeScreen = launchedFromHomeScreen
|
||||
)
|
||||
}
|
||||
composable(NavigationItems.Dex.route) {
|
||||
|
||||
@ -45,25 +45,14 @@ fun ScanScreen(
|
||||
navController: NavController,
|
||||
characterId: Long?,
|
||||
scanScreenController: ScanScreenController,
|
||||
launchedFromHomeScreen: Boolean
|
||||
) {
|
||||
val secrets by scanScreenController.secretsFlow.collectAsState(null)
|
||||
var readingScreen by remember { mutableStateOf(false) }
|
||||
var writingScreen by remember { mutableStateOf(false) }
|
||||
var isDoneReadingCharacter by remember { mutableStateOf(false) }
|
||||
var isDoneSendingCard by remember { mutableStateOf(false) }
|
||||
var isDoneWritingCharacter by remember { mutableStateOf(false) }
|
||||
|
||||
val application = LocalContext.current.applicationContext as VBHelper
|
||||
val storageRepository = StorageRepository(application.container.db)
|
||||
var nfcCharacter by remember { mutableStateOf<NfcCharacter?>(null) }
|
||||
|
||||
/*
|
||||
This is in the case there is an active character,
|
||||
that way active characters are quicker to send.
|
||||
*/
|
||||
var selectedCharacterId by remember { mutableStateOf<Long?>(null) }
|
||||
selectedCharacterId = characterId
|
||||
|
||||
val context = LocalContext.current
|
||||
|
||||
LaunchedEffect(storageRepository) {
|
||||
@ -75,19 +64,17 @@ fun ScanScreen(
|
||||
an active character.
|
||||
*/
|
||||
if (characterId != null && nfcCharacter == null) {
|
||||
selectedCharacterId = characterId
|
||||
nfcCharacter = scanScreenController.characterToNfc(selectedCharacterId!!)
|
||||
}
|
||||
else if (characterId == null && nfcCharacter == null) {
|
||||
val activeCharacter = storageRepository.getActiveCharacter()
|
||||
if (activeCharacter != null) {
|
||||
selectedCharacterId = activeCharacter.id
|
||||
nfcCharacter = scanScreenController.characterToNfc(selectedCharacterId!!)
|
||||
}
|
||||
nfcCharacter = scanScreenController.characterToNfc(characterId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var readingScreen by remember { mutableStateOf(false) }
|
||||
var writingScreen by remember { mutableStateOf(false) }
|
||||
var isDoneReadingCharacter by remember { mutableStateOf(false) }
|
||||
var isDoneSendingCard by remember { mutableStateOf(false) }
|
||||
var isDoneWritingCharacter by remember { mutableStateOf(false) }
|
||||
|
||||
DisposableEffect(readingScreen) {
|
||||
if(readingScreen) {
|
||||
scanScreenController.registerActivityLifecycleListener(
|
||||
@ -171,7 +158,7 @@ fun ScanScreen(
|
||||
LaunchedEffect(storageRepository) {
|
||||
withContext(Dispatchers.IO) {
|
||||
storageRepository
|
||||
.deleteCharacter(selectedCharacterId!!)
|
||||
.deleteCharacter(characterId!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -197,7 +184,7 @@ fun ScanScreen(
|
||||
} else {
|
||||
ChooseConnectOption(
|
||||
onClickRead = when {
|
||||
selectedCharacterId != null -> null
|
||||
!launchedFromHomeScreen -> null
|
||||
else -> {
|
||||
{
|
||||
if(secrets == null) {
|
||||
@ -310,6 +297,7 @@ fun ScanScreenPreview() {
|
||||
override fun characterFromNfc(nfcCharacter: NfcCharacter): String { return "" }
|
||||
override suspend fun characterToNfc(characterId: Long): NfcCharacter? { return null }
|
||||
},
|
||||
characterId = null
|
||||
characterId = null,
|
||||
launchedFromHomeScreen = false
|
||||
)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user