mirror of
https://github.com/nacabaro/vbhelper.git
synced 2026-01-27 16:05:32 +00:00
Compare commits
5 Commits
6cce33c5f6
...
37076a9bf0
| Author | SHA1 | Date | |
|---|---|---|---|
| 37076a9bf0 | |||
| 8c99046edb | |||
| c990a495b7 | |||
| 0e61723db1 | |||
| 8815907563 |
@ -15,7 +15,7 @@ android {
|
||||
minSdk = 28
|
||||
targetSdk = 35
|
||||
versionCode = 1
|
||||
versionName = "Alpha 0.6.2"
|
||||
versionName = "Alpha 0.6.3"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
@ -43,6 +43,7 @@ import androidx.compose.ui.res.stringResource
|
||||
fun CharacterEntry(
|
||||
icon: BitmapData,
|
||||
modifier: Modifier = Modifier,
|
||||
cardIcon: BitmapData? = null,
|
||||
obscure: Boolean = false,
|
||||
disabled: Boolean = false,
|
||||
shape: Shape = MaterialTheme.shapes.medium,
|
||||
@ -55,6 +56,7 @@ fun CharacterEntry(
|
||||
val bitmap = remember (icon.bitmap) {
|
||||
if(obscure) icon.getObscuredBitmap() else icon.getBitmap()
|
||||
}
|
||||
val iconSizeMultiplier = 3
|
||||
val imageBitmap = remember(bitmap) { bitmap.asImageBitmap() }
|
||||
val density: Float = LocalContext.current.resources.displayMetrics.density
|
||||
val dpSize = (icon.width * multiplier / density).dp
|
||||
@ -86,7 +88,24 @@ fun CharacterEntry(
|
||||
},
|
||||
modifier = Modifier
|
||||
.size(dpSize)
|
||||
.align(Alignment.BottomCenter)
|
||||
)
|
||||
|
||||
if (cardIcon != null) {
|
||||
val bitmap = remember (icon.bitmap) { cardIcon.getBitmap() }
|
||||
val iconBitmap = remember(bitmap) { bitmap.asImageBitmap() }
|
||||
val dpSize = (icon.width * iconSizeMultiplier /density).dp
|
||||
|
||||
Image(
|
||||
bitmap = iconBitmap,
|
||||
contentDescription = "Card icon",
|
||||
filterQuality = FilterQuality.None,
|
||||
modifier = Modifier
|
||||
.size(dpSize)
|
||||
.align(Alignment.BottomEnd)
|
||||
.padding(8.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -133,7 +152,8 @@ fun ItemDisplay(
|
||||
fun SpecialMissionsEntry(
|
||||
specialMission: SpecialMissions,
|
||||
modifier: Modifier = Modifier,
|
||||
onClickCard: () -> Unit = { },
|
||||
onClickMission: (Long) -> Unit = { },
|
||||
onClickCollect: (Long) -> Unit = { }
|
||||
) {
|
||||
val textValue = when (specialMission.missionType) {
|
||||
SpecialMission.Type.NONE -> stringResource(R.string.special_mission_none)
|
||||
@ -200,10 +220,12 @@ fun SpecialMissionsEntry(
|
||||
Card(
|
||||
modifier = modifier,
|
||||
shape = androidx.compose.material.MaterialTheme.shapes.small,
|
||||
onClick = if (specialMission.status == SpecialMission.Status.COMPLETED || specialMission.status == SpecialMission.Status.FAILED) {
|
||||
onClickCard
|
||||
onClick = if (specialMission.status == SpecialMission.Status.COMPLETED) {
|
||||
{ onClickCollect(specialMission.id) }
|
||||
} else if (specialMission.status == SpecialMission.Status.UNAVAILABLE) {
|
||||
{ }
|
||||
} else {
|
||||
{ }
|
||||
{ onClickMission(specialMission.id) }
|
||||
},
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = color
|
||||
|
||||
@ -5,6 +5,7 @@ import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.github.nacabaro.vbhelper.domain.card.Card
|
||||
import com.github.nacabaro.vbhelper.dtos.CardDtos
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
@ -34,4 +35,15 @@ interface CardDao {
|
||||
|
||||
@Query("DELETE FROM Card WHERE id = :id")
|
||||
suspend fun deleteCard(id: Long)
|
||||
|
||||
@Query("""
|
||||
SELECT
|
||||
c.logo as cardIcon,
|
||||
c.logoWidth as cardIconWidth,
|
||||
c.logoHeight as cardIconHeight
|
||||
FROM Card c
|
||||
JOIN CardCharacter cc ON cc.cardId = c.id
|
||||
WHERE cc.id = :charaId
|
||||
""")
|
||||
fun getCardIconByCharaId(charaId: Long): Flow<CardDtos.CardIcon>
|
||||
}
|
||||
@ -2,6 +2,8 @@ package com.github.nacabaro.vbhelper.daos
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Query
|
||||
import com.github.nacabaro.vbhelper.domain.device_data.SpecialMissions
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface SpecialMissionDao {
|
||||
@ -12,4 +14,11 @@ interface SpecialMissionDao {
|
||||
WHERE id = :id
|
||||
""")
|
||||
suspend fun clearSpecialMission(id: Long)
|
||||
|
||||
@Query("""
|
||||
SELECT *
|
||||
FROM SpecialMissions
|
||||
WHERE id = :id
|
||||
""")
|
||||
fun getSpecialMission(id: Long): Flow<SpecialMissions>
|
||||
}
|
||||
@ -53,7 +53,7 @@ interface UserCharacterDao {
|
||||
WHERE monId = :monId
|
||||
"""
|
||||
)
|
||||
suspend fun getTransformationHistory(monId: Long): List<CharacterDtos.TransformationHistory>?
|
||||
fun getTransformationHistory(monId: Long): Flow<List<CharacterDtos.TransformationHistory>>
|
||||
|
||||
@Query(
|
||||
"""
|
||||
@ -110,13 +110,13 @@ interface UserCharacterDao {
|
||||
suspend fun getCharacter(id: Long): UserCharacter
|
||||
|
||||
@Query("SELECT * FROM BECharacterData WHERE id = :id")
|
||||
suspend fun getBeData(id: Long): BECharacterData
|
||||
fun getBeData(id: Long): Flow<BECharacterData>
|
||||
|
||||
@Query("SELECT * FROM VBCharacterData WHERE id = :id")
|
||||
suspend fun getVbData(id: Long): VBCharacterData
|
||||
fun getVbData(id: Long): Flow<VBCharacterData>
|
||||
|
||||
@Query("SELECT * FROM SpecialMissions WHERE characterId = :id")
|
||||
suspend fun getSpecialMissions(id: Long): List<SpecialMissions>
|
||||
fun getSpecialMissions(id: Long): Flow<List<SpecialMissions>>
|
||||
|
||||
@Query(
|
||||
"""
|
||||
@ -143,7 +143,7 @@ interface UserCharacterDao {
|
||||
LIMIT 1
|
||||
"""
|
||||
)
|
||||
suspend fun getActiveCharacter(): CharacterDtos.CharacterWithSprites?
|
||||
fun getActiveCharacter(): Flow<CharacterDtos.CharacterWithSprites?>
|
||||
|
||||
@Query("DELETE FROM UserCharacter WHERE id = :id")
|
||||
fun deleteCharacterById(id: Long)
|
||||
|
||||
@ -24,4 +24,10 @@ object CardDtos {
|
||||
val characterHp: Int,
|
||||
val steps: Int,
|
||||
)
|
||||
|
||||
data class CardIcon (
|
||||
val cardIcon: ByteArray,
|
||||
val cardIconWidth: Int,
|
||||
val cardIconHeight: Int
|
||||
)
|
||||
}
|
||||
@ -1,13 +1,12 @@
|
||||
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.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
@ -99,20 +98,14 @@ fun AppNavigation(
|
||||
composable(NavigationItems.Scan.route) {
|
||||
val characterIdString = it.arguments?.getString("characterId")
|
||||
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
|
||||
}
|
||||
}
|
||||
val characterData by storageRepository.getActiveCharacter().collectAsState(null)
|
||||
if (characterData != null) {
|
||||
characterId = characterData!!.id
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
@ -28,9 +29,7 @@ import com.github.nacabaro.vbhelper.components.TopBanner
|
||||
import com.github.nacabaro.vbhelper.di.VBHelper
|
||||
import com.github.nacabaro.vbhelper.utils.DeviceType
|
||||
import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData
|
||||
import com.github.nacabaro.vbhelper.domain.device_data.SpecialMissions
|
||||
import com.github.nacabaro.vbhelper.domain.device_data.VBCharacterData
|
||||
import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
||||
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||
import com.github.nacabaro.vbhelper.navigation.NavigationItems
|
||||
import com.github.nacabaro.vbhelper.screens.homeScreens.screens.BEBEmHomeScreen
|
||||
@ -38,9 +37,12 @@ import com.github.nacabaro.vbhelper.screens.homeScreens.screens.BEDiMHomeScreen
|
||||
import com.github.nacabaro.vbhelper.screens.homeScreens.screens.VBDiMHomeScreen
|
||||
import com.github.nacabaro.vbhelper.screens.itemsScreen.ObtainedItemDialog
|
||||
import com.github.nacabaro.vbhelper.source.StorageRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import com.github.nacabaro.vbhelper.R
|
||||
import com.github.nacabaro.vbhelper.dtos.CardDtos
|
||||
import com.github.nacabaro.vbhelper.source.CardRepository
|
||||
import com.github.nacabaro.vbhelper.utils.BitmapData
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlin.collections.emptyList
|
||||
|
||||
@Composable
|
||||
fun HomeScreen(
|
||||
@ -49,30 +51,60 @@ fun HomeScreen(
|
||||
) {
|
||||
val application = LocalContext.current.applicationContext as VBHelper
|
||||
val storageRepository = StorageRepository(application.container.db)
|
||||
val activeMon = remember { mutableStateOf<CharacterDtos.CharacterWithSprites?>(null) }
|
||||
val transformationHistory = remember { mutableStateOf<List<CharacterDtos.TransformationHistory>?>(null) }
|
||||
val beData = remember { mutableStateOf<BECharacterData?>(null) }
|
||||
val vbData = remember { mutableStateOf<VBCharacterData?>(null) }
|
||||
val vbSpecialMissions = remember { mutableStateOf<List<SpecialMissions>>(emptyList()) }
|
||||
val cardRepository = CardRepository(application.container.db)
|
||||
|
||||
val activeMon by storageRepository
|
||||
.getActiveCharacter()
|
||||
.collectAsState(initial = null)
|
||||
|
||||
val cardIconData by (
|
||||
activeMon
|
||||
?.let { chara ->
|
||||
cardRepository.getCardIconByCharaId(chara.charId)
|
||||
}
|
||||
?: flowOf<CardDtos.CardIcon?>(null)
|
||||
).collectAsState(initial = null)
|
||||
|
||||
val transformationHistory by (
|
||||
activeMon
|
||||
?.let { chara ->
|
||||
storageRepository.getTransformationHistory(chara.id)
|
||||
}
|
||||
?: flowOf(emptyList())
|
||||
).collectAsState(initial = emptyList())
|
||||
|
||||
val vbSpecialMissions by (
|
||||
activeMon
|
||||
?.takeIf { it.characterType == DeviceType.VBDevice }
|
||||
?.let { chara ->
|
||||
storageRepository.getSpecialMissions(chara.id)
|
||||
}
|
||||
?: flowOf(emptyList())
|
||||
).collectAsState(initial = emptyList())
|
||||
|
||||
val vbData by (
|
||||
activeMon
|
||||
?.takeIf { it.characterType == DeviceType.VBDevice }
|
||||
?.let { chara ->
|
||||
storageRepository.getCharacterVbData(chara.id)
|
||||
}
|
||||
?: flowOf<VBCharacterData?>(null)
|
||||
).collectAsState(initial = null)
|
||||
|
||||
val beData by (
|
||||
activeMon
|
||||
?.takeIf { it.characterType == DeviceType.BEDevice }
|
||||
?.let { chara ->
|
||||
storageRepository.getCharacterBeData(chara.id)
|
||||
}
|
||||
?: flowOf<BECharacterData?>(null)
|
||||
).collectAsState(initial = null)
|
||||
|
||||
var adventureMissionsFinished by rememberSaveable { mutableStateOf(false) }
|
||||
var betaWarning by rememberSaveable { mutableStateOf(true) }
|
||||
var collectedItem by remember { mutableStateOf<ItemDtos.PurchasedItem?>(null) }
|
||||
var collectedCurrency by remember { mutableStateOf<Int?>(null) }
|
||||
|
||||
LaunchedEffect(storageRepository, activeMon, collectedItem) {
|
||||
withContext(Dispatchers.IO) {
|
||||
activeMon.value = storageRepository.getActiveCharacter()
|
||||
if (activeMon.value != null && activeMon.value!!.characterType == DeviceType.BEDevice) {
|
||||
beData.value = storageRepository.getCharacterBeData(activeMon.value!!.id)
|
||||
transformationHistory.value = storageRepository.getTransformationHistory(activeMon.value!!.id)
|
||||
} else if (activeMon.value != null && activeMon.value!!.characterType == DeviceType.VBDevice) {
|
||||
vbData.value = storageRepository.getCharacterVbData(activeMon.value!!.id)
|
||||
vbSpecialMissions.value = storageRepository.getSpecialMissions(activeMon.value!!.id)
|
||||
transformationHistory.value = storageRepository.getTransformationHistory(activeMon.value!!.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(true) {
|
||||
homeScreenController
|
||||
.didAdventureMissionsFinish {
|
||||
@ -93,7 +125,7 @@ fun HomeScreen(
|
||||
)
|
||||
}
|
||||
) { contentPadding ->
|
||||
if (activeMon.value == null || (beData.value == null && vbData.value == null) || transformationHistory.value == null) {
|
||||
if (activeMon == null || (beData == null && vbData == null) || cardIconData == null || transformationHistory.isEmpty()) {
|
||||
Column (
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
@ -104,32 +136,41 @@ fun HomeScreen(
|
||||
Text(text = stringResource(R.string.adventure_empty_state))
|
||||
}
|
||||
} else {
|
||||
if (activeMon.value!!.isBemCard) {
|
||||
val cardIcon = BitmapData(
|
||||
bitmap = cardIconData!!.cardIcon,
|
||||
width = cardIconData!!.cardIconWidth,
|
||||
height = cardIconData!!.cardIconHeight
|
||||
)
|
||||
|
||||
if (activeMon!!.isBemCard && beData != null) {
|
||||
BEBEmHomeScreen(
|
||||
activeMon = activeMon.value!!,
|
||||
beData = beData.value!!,
|
||||
transformationHistory = transformationHistory.value!!,
|
||||
contentPadding = contentPadding
|
||||
)
|
||||
} else if (!activeMon.value!!.isBemCard && activeMon.value!!.characterType == DeviceType.BEDevice) {
|
||||
BEDiMHomeScreen(
|
||||
activeMon = activeMon.value!!,
|
||||
beData = beData.value!!,
|
||||
transformationHistory = transformationHistory.value!!,
|
||||
contentPadding = contentPadding
|
||||
)
|
||||
} else {
|
||||
VBDiMHomeScreen(
|
||||
activeMon = activeMon.value!!,
|
||||
vbData = vbData.value!!,
|
||||
transformationHistory = transformationHistory.value!!,
|
||||
activeMon = activeMon!!,
|
||||
beData = beData!!,
|
||||
transformationHistory = transformationHistory,
|
||||
contentPadding = contentPadding,
|
||||
specialMissions = vbSpecialMissions.value,
|
||||
cardIcon = cardIcon
|
||||
)
|
||||
} else if (!activeMon!!.isBemCard && activeMon!!.characterType == DeviceType.BEDevice && beData != null) {
|
||||
BEDiMHomeScreen(
|
||||
activeMon = activeMon!!,
|
||||
beData = beData!!,
|
||||
transformationHistory = transformationHistory,
|
||||
contentPadding = contentPadding,
|
||||
cardIcon = cardIcon
|
||||
)
|
||||
} else if (vbData != null) {
|
||||
VBDiMHomeScreen(
|
||||
activeMon = activeMon!!,
|
||||
vbData = vbData!!,
|
||||
transformationHistory = transformationHistory,
|
||||
contentPadding = contentPadding,
|
||||
specialMissions = vbSpecialMissions,
|
||||
homeScreenController = homeScreenController,
|
||||
onClickCollect = { item, currency ->
|
||||
collectedItem = item
|
||||
collectedCurrency = currency
|
||||
}
|
||||
},
|
||||
cardIcon = cardIcon
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
package com.github.nacabaro.vbhelper.screens.homeScreens
|
||||
|
||||
import com.github.cfogrady.vbnfc.vb.SpecialMission
|
||||
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||
|
||||
interface HomeScreenController {
|
||||
fun didAdventureMissionsFinish(onCompletion: (Boolean) -> Unit)
|
||||
fun clearSpecialMission(missionId: Long, missionCompletion: SpecialMission.Status, onCleared: (ItemDtos.PurchasedItem?, Int?) -> Unit)
|
||||
fun clearSpecialMission(missionId: Long, onCleared: (ItemDtos.PurchasedItem?, Int?) -> Unit)
|
||||
}
|
||||
@ -33,13 +33,18 @@ class HomeScreenControllerImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override fun clearSpecialMission(missionId: Long, missionCompletion: SpecialMission.Status, onCleared: (ItemDtos.PurchasedItem?, Int?) -> Unit) {
|
||||
override fun clearSpecialMission(missionId: Long, onCleared: (ItemDtos.PurchasedItem?, Int?) -> Unit) {
|
||||
componentActivity.lifecycleScope.launch {
|
||||
val missionStatus = database
|
||||
.specialMissionDao()
|
||||
.getSpecialMission(missionId)
|
||||
.first()
|
||||
|
||||
database
|
||||
.specialMissionDao()
|
||||
.clearSpecialMission(missionId)
|
||||
|
||||
if (missionCompletion == SpecialMission.Status.COMPLETED) {
|
||||
if (missionStatus.status == SpecialMission.Status.COMPLETED) {
|
||||
val randomItem = database
|
||||
.itemDao()
|
||||
.getAllItems()
|
||||
@ -73,7 +78,6 @@ class HomeScreenControllerImpl(
|
||||
} else {
|
||||
onCleared(null, null)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package com.github.nacabaro.vbhelper.screens.homeScreens.dialogs
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import com.github.nacabaro.vbhelper.R
|
||||
|
||||
@Composable
|
||||
fun DeleteSpecialMissionDialog(
|
||||
onClickDismiss: () -> Unit,
|
||||
onClickDelete: () -> Unit
|
||||
) {
|
||||
Dialog(
|
||||
onDismissRequest = onClickDismiss
|
||||
) {
|
||||
Card {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.home_special_mission_delete_main),
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(8.dp))
|
||||
Row {
|
||||
Button(
|
||||
onClick = onClickDismiss,
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
) {
|
||||
Text(text = stringResource(R.string.home_special_mission_delete_dismiss))
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onClickDelete,
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
) {
|
||||
Text(text = stringResource(R.string.home_special_mission_delete_remove))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -26,6 +26,7 @@ import java.util.Locale
|
||||
fun BEBEmHomeScreen(
|
||||
activeMon: CharacterDtos.CharacterWithSprites,
|
||||
beData: BECharacterData,
|
||||
cardIcon: BitmapData,
|
||||
transformationHistory: List<CharacterDtos.TransformationHistory>,
|
||||
contentPadding: PaddingValues
|
||||
) {
|
||||
@ -46,6 +47,7 @@ fun BEBEmHomeScreen(
|
||||
),
|
||||
multiplier = 8,
|
||||
shape = androidx.compose.material.MaterialTheme.shapes.small,
|
||||
cardIcon = cardIcon,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.aspectRatio(1f)
|
||||
|
||||
@ -26,6 +26,7 @@ import kotlin.text.format
|
||||
@Composable
|
||||
fun BEDiMHomeScreen(
|
||||
activeMon: CharacterDtos.CharacterWithSprites,
|
||||
cardIcon: BitmapData,
|
||||
beData: BECharacterData,
|
||||
transformationHistory: List<CharacterDtos.TransformationHistory>,
|
||||
contentPadding: PaddingValues
|
||||
@ -45,6 +46,7 @@ fun BEDiMHomeScreen(
|
||||
width = activeMon.spriteWidth,
|
||||
height = activeMon.spriteHeight
|
||||
),
|
||||
cardIcon = cardIcon,
|
||||
multiplier = 8,
|
||||
shape = androidx.compose.material.MaterialTheme.shapes.small,
|
||||
modifier = Modifier
|
||||
|
||||
@ -10,6 +10,10 @@ import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
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.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
@ -26,11 +30,13 @@ import com.github.nacabaro.vbhelper.screens.homeScreens.HomeScreenControllerImpl
|
||||
import com.github.nacabaro.vbhelper.utils.BitmapData
|
||||
import java.util.Locale
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.github.nacabaro.vbhelper.screens.homeScreens.dialogs.DeleteSpecialMissionDialog
|
||||
|
||||
|
||||
@Composable
|
||||
fun VBDiMHomeScreen(
|
||||
activeMon: CharacterDtos.CharacterWithSprites,
|
||||
cardIcon: BitmapData,
|
||||
vbData: VBCharacterData,
|
||||
specialMissions: List<SpecialMissions>,
|
||||
homeScreenController: HomeScreenControllerImpl,
|
||||
@ -38,6 +44,8 @@ fun VBDiMHomeScreen(
|
||||
contentPadding: PaddingValues,
|
||||
onClickCollect: (ItemDtos.PurchasedItem?, Int?) -> Unit
|
||||
) {
|
||||
var selectedSpecialMissionId by remember { mutableStateOf<Long>(-1) }
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(top = contentPadding.calculateTopPadding())
|
||||
@ -53,6 +61,7 @@ fun VBDiMHomeScreen(
|
||||
width = activeMon.spriteWidth,
|
||||
height = activeMon.spriteHeight
|
||||
),
|
||||
cardIcon = cardIcon,
|
||||
multiplier = 8,
|
||||
shape = androidx.compose.material.MaterialTheme.shapes.small,
|
||||
modifier = Modifier
|
||||
@ -181,11 +190,28 @@ fun VBDiMHomeScreen(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(8.dp),
|
||||
) {
|
||||
homeScreenController
|
||||
.clearSpecialMission(mission.id, mission.status, onClickCollect)
|
||||
}
|
||||
onClickMission = { missionId ->
|
||||
selectedSpecialMissionId = missionId
|
||||
},
|
||||
onClickCollect = {
|
||||
homeScreenController
|
||||
.clearSpecialMission(selectedSpecialMissionId, onClickCollect)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedSpecialMissionId.toInt() != -1) {
|
||||
DeleteSpecialMissionDialog(
|
||||
onClickDismiss = {
|
||||
selectedSpecialMissionId = -1
|
||||
},
|
||||
onClickDelete = {
|
||||
homeScreenController
|
||||
.clearSpecialMission(selectedSpecialMissionId, onClickCollect)
|
||||
selectedSpecialMissionId = -1
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,8 @@ import com.github.nacabaro.vbhelper.domain.device_data.VBCharacterData
|
||||
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||
import com.github.nacabaro.vbhelper.utils.DeviceType
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@ -52,9 +54,16 @@ class ItemsScreenControllerImpl (
|
||||
var vbCharacterData: VBCharacterData? = null
|
||||
|
||||
if (characterData.characterType == DeviceType.BEDevice) {
|
||||
beCharacterData = database.userCharacterDao().getBeData(characterId)
|
||||
beCharacterData = database
|
||||
.userCharacterDao()
|
||||
.getBeData(characterId)
|
||||
.firstOrNull()
|
||||
|
||||
} else if (characterData.characterType == DeviceType.VBDevice) {
|
||||
vbCharacterData = database.userCharacterDao().getVbData(characterId)
|
||||
vbCharacterData = database
|
||||
.userCharacterDao()
|
||||
.getVbData(characterId)
|
||||
.firstOrNull()
|
||||
}
|
||||
|
||||
if (
|
||||
@ -153,33 +162,35 @@ class ItemsScreenControllerImpl (
|
||||
ItemTypes.Win4.id -> 4
|
||||
else -> 0
|
||||
}
|
||||
|
||||
val specialMissionSlot = when (itemIcon) {
|
||||
ItemTypes.Step8k.id -> 0
|
||||
ItemTypes.Step4k.id -> 0
|
||||
ItemTypes.Vitals1000.id -> 1
|
||||
ItemTypes.Vitals250.id -> 1
|
||||
ItemTypes.Battle20.id -> 2
|
||||
ItemTypes.Battle5.id -> 2
|
||||
ItemTypes.Win10.id -> 3
|
||||
ItemTypes.Win4.id -> 3
|
||||
else -> 0
|
||||
}
|
||||
|
||||
val availableSpecialMissions = database
|
||||
.userCharacterDao()
|
||||
.getSpecialMissions(characterId)
|
||||
.first()
|
||||
|
||||
var firstUnavailableMissionSlot: Long = 0
|
||||
var watchId = 0
|
||||
|
||||
for ((index, mission) in availableSpecialMissions.withIndex()) {
|
||||
if (
|
||||
mission.status == SpecialMission.Status.UNAVAILABLE
|
||||
) {
|
||||
firstUnavailableMissionSlot = mission.id
|
||||
watchId = index + 1
|
||||
}
|
||||
}
|
||||
|
||||
val newSpecialMission = SpecialMissions(
|
||||
id = firstUnavailableMissionSlot,
|
||||
characterId = characterId,
|
||||
missionType = specialMissionType,
|
||||
var newSpecialMission = availableSpecialMissions[specialMissionSlot]
|
||||
newSpecialMission = SpecialMissions(
|
||||
id = newSpecialMission.id,
|
||||
characterId = newSpecialMission.characterId,
|
||||
goal = specialMissionGoal,
|
||||
timeLimitInMinutes = itemLength,
|
||||
watchId = watchId,
|
||||
status = SpecialMission.Status.AVAILABLE,
|
||||
watchId = newSpecialMission.watchId,
|
||||
progress = 0,
|
||||
timeElapsedInMinutes = 0
|
||||
status = SpecialMission.Status.AVAILABLE,
|
||||
timeElapsedInMinutes = 0,
|
||||
timeLimitInMinutes = itemLength,
|
||||
missionType = specialMissionType
|
||||
)
|
||||
|
||||
database
|
||||
|
||||
@ -55,6 +55,7 @@ class ToNfcConverter(
|
||||
val vbData = database
|
||||
.userCharacterDao()
|
||||
.getVbData(characterId)
|
||||
.first()
|
||||
|
||||
val paddedTransformationArray = generateTransformationHistory(characterId, 9)
|
||||
|
||||
@ -116,6 +117,7 @@ class ToNfcConverter(
|
||||
val specialMissions = database
|
||||
.userCharacterDao()
|
||||
.getSpecialMissions(characterId)
|
||||
.first()
|
||||
|
||||
val watchSpecialMissions = specialMissions.map {
|
||||
SpecialMission(
|
||||
@ -175,6 +177,7 @@ class ToNfcConverter(
|
||||
val beData = database
|
||||
.userCharacterDao()
|
||||
.getBeData(characterId)
|
||||
.first()
|
||||
|
||||
val paddedTransformationArray = generateTransformationHistory(characterId)
|
||||
|
||||
@ -237,7 +240,8 @@ class ToNfcConverter(
|
||||
): Array<NfcCharacter.Transformation> {
|
||||
val transformationHistory = database
|
||||
.userCharacterDao()
|
||||
.getTransformationHistory(characterId)!!
|
||||
.getTransformationHistory(characterId)
|
||||
.first()
|
||||
.map {
|
||||
val date = Date(it.transformationDate)
|
||||
val calendar = android.icu.util.GregorianCalendar(TimeZone.getTimeZone("UTC"))
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
package com.github.nacabaro.vbhelper.source
|
||||
|
||||
import com.github.nacabaro.vbhelper.database.AppDatabase
|
||||
import com.github.nacabaro.vbhelper.dtos.CardDtos
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class CardRepository (
|
||||
private val db: AppDatabase
|
||||
) {
|
||||
fun getCardIconByCharaId(charaId: Long): Flow<CardDtos.CardIcon> {
|
||||
return db
|
||||
.cardDao()
|
||||
.getCardIconByCharaId(charaId = charaId)
|
||||
}
|
||||
}
|
||||
@ -19,19 +19,19 @@ class StorageRepository (
|
||||
return db.userCharacterDao().getCharacterWithSprites(id)
|
||||
}
|
||||
|
||||
suspend fun getCharacterBeData(id: Long): BECharacterData {
|
||||
fun getCharacterBeData(id: Long): Flow<BECharacterData> {
|
||||
return db.userCharacterDao().getBeData(id)
|
||||
}
|
||||
|
||||
suspend fun getTransformationHistory(characterId: Long): List<CharacterDtos.TransformationHistory>? {
|
||||
fun getTransformationHistory(characterId: Long): Flow<List<CharacterDtos.TransformationHistory>> {
|
||||
return db.userCharacterDao().getTransformationHistory(characterId)
|
||||
}
|
||||
|
||||
suspend fun getCharacterVbData(id: Long): VBCharacterData {
|
||||
fun getCharacterVbData(id: Long): Flow<VBCharacterData> {
|
||||
return db.userCharacterDao().getVbData(id)
|
||||
}
|
||||
|
||||
suspend fun getSpecialMissions(id: Long): List<SpecialMissions> {
|
||||
fun getSpecialMissions(id: Long): Flow<List<SpecialMissions>> {
|
||||
return db.userCharacterDao().getSpecialMissions(id)
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ class StorageRepository (
|
||||
return db.itemDao().getItem(id)
|
||||
}
|
||||
|
||||
suspend fun getActiveCharacter(): CharacterDtos.CharacterWithSprites? {
|
||||
fun getActiveCharacter(): Flow<CharacterDtos.CharacterWithSprites?> {
|
||||
return db.userCharacterDao().getActiveCharacter()
|
||||
}
|
||||
|
||||
|
||||
@ -222,5 +222,8 @@
|
||||
<string name="special_mission_wins_progress">Won %1$d battles</string>
|
||||
<string name="special_mission_vitals_progress">Earned %1$d vitals</string>
|
||||
<string name="special_mission_icon_content_description">Special mission icon</string>
|
||||
<string name="home_special_mission_delete_main">Are you sure you want to delete this special mission with this progress?</string>
|
||||
<string name="home_special_mission_delete_dismiss">Dismiss</string>
|
||||
<string name="home_special_mission_delete_remove">Remove</string>
|
||||
|
||||
</resources>
|
||||
@ -1,5 +1,5 @@
|
||||
[versions]
|
||||
agp = "8.13.1"
|
||||
agp = "8.13.2"
|
||||
datastore = "1.1.2"
|
||||
kotlin = "2.0.0"
|
||||
coreKtx = "1.15.0"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user