diff --git a/app/src/main/assets/items.db b/app/src/main/assets/items.db index 37e07ad..1d8bd5b 100644 Binary files a/app/src/main/assets/items.db and b/app/src/main/assets/items.db differ diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/components/ItemElement.kt b/app/src/main/java/com/github/nacabaro/vbhelper/components/ItemElement.kt index 68ff3a0..1a2783e 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/components/ItemElement.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/components/ItemElement.kt @@ -1,8 +1,5 @@ package com.github.nacabaro.vbhelper.components -import android.graphics.drawable.Icon -import android.util.EventLogTags.Description -import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -21,8 +18,6 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview @@ -30,8 +25,8 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.DialogProperties import com.github.nacabaro.vbhelper.R -import com.github.nacabaro.vbhelper.di.VBHelper import com.github.nacabaro.vbhelper.ui.theme.VBHelperTheme +import kotlin.math.absoluteValue @Composable fun ItemElement( @@ -167,15 +162,24 @@ fun getIconResource(index: Int): Int { 1 -> R.drawable.baseline_agility_24 2 -> R.drawable.baseline_attack_24 3 -> R.drawable.baseline_shield_24 + 4 -> R.drawable.baseline_trophy_24 + 5 -> R.drawable.baseline_arrow_up_24 + 6 -> R.drawable.baseline_timer_24 + 7 -> R.drawable.baseline_rank_24 else -> R.drawable.baseline_question_mark_24 } } fun getLengthResource(index: Int): Int { - return when (index) { - 1 -> R.drawable.baseline_15_min_timer - 2 -> R.drawable.baseline_30_min_timer - 3 -> R.drawable.baseline_60_min_timer + return when (index.absoluteValue) { + 15 -> R.drawable.baseline_15_min_timer + 30 -> R.drawable.baseline_30_min_timer + 60 -> R.drawable.baseline_60_min_timer + 300 -> R.drawable.baseline_5_hour_timer + 600 -> R.drawable.baseline_10_hour_timer + 720 -> R.drawable.baseline_12_hour_timer + 1440 -> R.drawable.baseline_24_hour_timer + 6000 -> R.drawable.baseline_reset_24 else -> R.drawable.baseline_question_mark_24 } } diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/daos/ItemDao.kt b/app/src/main/java/com/github/nacabaro/vbhelper/daos/ItemDao.kt index db9c90e..7eaa1bf 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/daos/ItemDao.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/daos/ItemDao.kt @@ -2,7 +2,6 @@ package com.github.nacabaro.vbhelper.daos import androidx.room.Dao import androidx.room.Query -import com.github.nacabaro.vbhelper.domain.items.Items import com.github.nacabaro.vbhelper.dtos.ItemDtos @Dao @@ -11,6 +10,7 @@ interface ItemDao { SELECT Items.*, UserItems.quantity FROM Items LEFT JOIN UserItems ON Items.id = UserItems.itemId + ORDER BY Items.itemIcon ASC """) suspend fun getAllItems(): List @@ -20,4 +20,18 @@ interface ItemDao { JOIN UserItems ON Items.id = UserItems.itemId """) suspend fun getAllUserItems(): List + + @Query(""" + UPDATE UserItems + SET quantity = quantity - 1 + WHERE itemId = :itemId + """) + fun useItem(itemId: Long) + + @Query(""" + UPDATE UserItems + SET quantity = quantity - :itemAmount + WHERE itemId = :itemId + """) + suspend fun purchaseItem(itemId: Long, itemAmount: Int) } \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/daos/UserCharacterDao.kt b/app/src/main/java/com/github/nacabaro/vbhelper/daos/UserCharacterDao.kt index 90975cb..0dbea43 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/daos/UserCharacterDao.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/daos/UserCharacterDao.kt @@ -4,6 +4,7 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query +import androidx.room.Upsert import com.github.nacabaro.vbhelper.domain.device_data.UserCharacter import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData import com.github.nacabaro.vbhelper.domain.device_data.TransformationHistory @@ -17,6 +18,12 @@ interface UserCharacterDao { @Insert fun insertBECharacterData(characterData: BECharacterData) + @Upsert + fun updateCharacter(character: UserCharacter) + + @Upsert + fun updateBECharacterData(characterData: BECharacterData) + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertTransformationHistory(vararg transformationHistory: TransformationHistory) diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/BECharacterData.kt b/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/BECharacterData.kt index 82c3a36..c3b69c1 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/BECharacterData.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/BECharacterData.kt @@ -20,7 +20,7 @@ data class BECharacterData ( val trainingHp: Int, val trainingAp: Int, val trainingBp: Int, - val remainingTrainingTimeInMinutes: Int, + var remainingTrainingTimeInMinutes: Int, val itemEffectMentalStateValue: Int, val itemEffectMentalStateMinutesRemaining: Int, val itemEffectActivityLevelValue: Int, @@ -32,9 +32,9 @@ data class BECharacterData ( val abilityBranch: Int, val abilityReset: Int, val rank: Int, - val itemType: Int, - val itemMultiplier: Int, - val itemRemainingTime: Int, + var itemType: Int, + var itemMultiplier: Int, + var itemRemainingTime: Int, val otp0: String, val otp1: String, val minorVersion: Int, diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/items/Items.kt b/app/src/main/java/com/github/nacabaro/vbhelper/domain/items/Items.kt index 2452f85..934d303 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/domain/items/Items.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/items/Items.kt @@ -1,6 +1,5 @@ package com.github.nacabaro.vbhelper.domain.items -import android.content.Intent import androidx.room.Entity import androidx.room.PrimaryKey @@ -10,6 +9,6 @@ data class Items( val name: String, val description: String, val itemIcon: Int, - val lengthIcon: Int, + val itemLength: Int, val price: Int ) diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/dtos/ItemDtos.kt b/app/src/main/java/com/github/nacabaro/vbhelper/dtos/ItemDtos.kt index 64cedb8..8e296e8 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/dtos/ItemDtos.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/dtos/ItemDtos.kt @@ -1,6 +1,5 @@ package com.github.nacabaro.vbhelper.dtos -import androidx.room.PrimaryKey object ItemDtos { data class ItemsWithQuantities ( @@ -8,7 +7,7 @@ object ItemDtos { val name: String, val description: String, val itemIcon: Int, - val lengthIcon: Int, + val itemLength: Int, val price: Int, val quantity: Int, ) diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/navigation/AppNavigation.kt b/app/src/main/java/com/github/nacabaro/vbhelper/navigation/AppNavigation.kt index c0b044b..acf7d0a 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/navigation/AppNavigation.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/navigation/AppNavigation.kt @@ -11,13 +11,12 @@ import com.github.nacabaro.vbhelper.screens.BattlesScreen import com.github.nacabaro.vbhelper.screens.DexScreen import com.github.nacabaro.vbhelper.screens.DiMScreen import com.github.nacabaro.vbhelper.screens.homeScreens.HomeScreen -import com.github.nacabaro.vbhelper.screens.ItemsScreen +import com.github.nacabaro.vbhelper.screens.itemsScreen.ItemsScreen import com.github.nacabaro.vbhelper.screens.scanScreen.ScanScreen import com.github.nacabaro.vbhelper.screens.scanScreen.ScanScreenControllerImpl import com.github.nacabaro.vbhelper.screens.settingsScreen.SettingsScreen import com.github.nacabaro.vbhelper.screens.SpriteViewer import com.github.nacabaro.vbhelper.screens.StorageScreen -import com.github.nacabaro.vbhelper.screens.itemsScreen.MyItems import com.github.nacabaro.vbhelper.screens.settingsScreen.SettingsScreenControllerImpl data class AppNavigationHandlers( diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/ItemsScreen.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsScreen.kt similarity index 85% rename from app/src/main/java/com/github/nacabaro/vbhelper/screens/ItemsScreen.kt rename to app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsScreen.kt index 2ef81b5..8bbcbc3 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/ItemsScreen.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsScreen.kt @@ -1,9 +1,7 @@ -package com.github.nacabaro.vbhelper.screens +package com.github.nacabaro.vbhelper.screens.itemsScreen import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material3.Scaffold @@ -16,12 +14,9 @@ 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.navigation.NavController import com.github.nacabaro.vbhelper.components.TopBanner import com.github.nacabaro.vbhelper.navigation.NavigationItems -import com.github.nacabaro.vbhelper.screens.itemsScreen.ItemsStore -import com.github.nacabaro.vbhelper.screens.itemsScreen.MyItems @Composable fun ItemsScreen( diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsScreenController.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsScreenController.kt new file mode 100644 index 0000000..de3c2d1 --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsScreenController.kt @@ -0,0 +1,7 @@ +package com.github.nacabaro.vbhelper.screens.itemsScreen + +import com.github.nacabaro.vbhelper.domain.items.Items + +interface ItemsScreenController { + suspend fun applyItem(item: Items, characterId: Long) +} \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsScreenControllerImpl.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsScreenControllerImpl.kt new file mode 100644 index 0000000..0b02122 --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsScreenControllerImpl.kt @@ -0,0 +1,84 @@ +package com.github.nacabaro.vbhelper.screens.itemsScreen + +import com.github.nacabaro.vbhelper.database.AppDatabase +import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData +import com.github.nacabaro.vbhelper.domain.device_data.VBCharacterData +import com.github.nacabaro.vbhelper.domain.items.Items +import com.github.nacabaro.vbhelper.utils.DeviceType + +class ItemsScreenControllerImpl ( + private val database: AppDatabase +): ItemsScreenController { + private enum class ItemTypes(val id: Int) { + PPTraining(1), + HPTraining(2), + APTraining(3), + BPTraining(4), + AllTraining(5), + EvoTimer(6), + LimitTimer(7), + Vitals(8) + } + + override suspend fun applyItem(item: Items, characterId: Long) { + var characterData = database.userCharacterDao().getCharacter(characterId) + var beCharacterData: BECharacterData + var vbCharacterData: VBCharacterData + if (characterData.characterType == DeviceType.BEDevice) { + beCharacterData = database.userCharacterDao().getBeData(characterId) + } else { + TODO("Not implemented") + //vbCharacterData = database.userCharacterDao().getVbData(characterId) + } + + if (item.itemIcon in 1 .. 5 && characterData.characterType == DeviceType.BEDevice) { + beCharacterData.itemType = item.itemIcon + beCharacterData.itemMultiplier = 3 + beCharacterData.itemRemainingTime = item.itemLength + + database + .userCharacterDao() + .updateBECharacterData(beCharacterData) + + } else if (item.itemIcon == ItemTypes.EvoTimer.id) { + characterData.transformationCountdown = item.itemLength + if (characterData.transformationCountdown < 0) { + characterData.transformationCountdown = 0 + } + + database + .userCharacterDao() + .updateCharacter(characterData) + + } else if (item.itemIcon == ItemTypes.LimitTimer.id) { + beCharacterData.remainingTrainingTimeInMinutes = item.itemLength + if (beCharacterData.remainingTrainingTimeInMinutes > 6000) { + beCharacterData.remainingTrainingTimeInMinutes = 6000 + } + + database + .userCharacterDao() + .updateBECharacterData(beCharacterData) + + } else if (item.itemIcon == ItemTypes.Vitals.id) { + characterData.vitalPoints = item.itemLength + if (characterData.vitalPoints < 0) { + characterData.vitalPoints = 0 + } else if (characterData.vitalPoints > 9999) { + characterData.vitalPoints = 9999 + } + + database + .userCharacterDao() + .updateCharacter(characterData) + } + + consumeItem(item.id) + } + + private fun consumeItem(itemId: Long) { + database + .itemDao() + .useItem(itemId) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsStore.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsStore.kt index d205f8f..faea09d 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsStore.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsStore.kt @@ -51,7 +51,7 @@ fun ItemsStore( items(myItems.value) { index -> ItemElement( itemIcon = getIconResource(index.itemIcon), - lengthIcon = getLengthResource(index.lengthIcon), + lengthIcon = getLengthResource(index.itemLength), modifier = Modifier .padding(8.dp), onClick = { @@ -65,7 +65,7 @@ fun ItemsStore( name = myItems.value[selectedElementIndex!!].name, description = myItems.value[selectedElementIndex!!].description, itemIcon = getIconResource(myItems.value[selectedElementIndex!!].itemIcon), - lengthIcon = getLengthResource(myItems.value[selectedElementIndex!!].lengthIcon), + lengthIcon = getLengthResource(myItems.value[selectedElementIndex!!].itemLength), amount = myItems.value[selectedElementIndex!!].quantity, onClickUse = { }, onClickCancel = { showDialog = false } diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/MyItems.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/MyItems.kt index 2a6f0cb..f9e678b 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/MyItems.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/MyItems.kt @@ -1,11 +1,9 @@ package com.github.nacabaro.vbhelper.screens.itemsScreen -import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.items -import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -17,10 +15,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp import androidx.navigation.NavController -import com.github.nacabaro.vbhelper.R import com.github.nacabaro.vbhelper.components.ItemDialog import com.github.nacabaro.vbhelper.components.ItemElement -import com.github.nacabaro.vbhelper.components.TopBanner import com.github.nacabaro.vbhelper.components.getIconResource import com.github.nacabaro.vbhelper.components.getLengthResource import com.github.nacabaro.vbhelper.di.VBHelper @@ -55,7 +51,7 @@ fun MyItems( items(myItems.value) { index -> ItemElement( itemIcon = getIconResource(index.itemIcon), - lengthIcon = getLengthResource(index.lengthIcon), + lengthIcon = getLengthResource(index.itemLength), modifier = Modifier .padding(8.dp), onClick = { @@ -69,7 +65,7 @@ fun MyItems( name = myItems.value[selectedElementIndex!!].name, description = myItems.value[selectedElementIndex!!].description, itemIcon = getIconResource(myItems.value[selectedElementIndex!!].itemIcon), - lengthIcon = getLengthResource(myItems.value[selectedElementIndex!!].lengthIcon), + lengthIcon = getLengthResource(myItems.value[selectedElementIndex!!].itemLength), amount = myItems.value[selectedElementIndex!!].quantity, onClickUse = { }, onClickCancel = { showDialog = false } diff --git a/app/src/main/res/drawable/baseline_10_hour_timer.xml b/app/src/main/res/drawable/baseline_10_hour_timer.xml new file mode 100644 index 0000000..b0e95af --- /dev/null +++ b/app/src/main/res/drawable/baseline_10_hour_timer.xml @@ -0,0 +1,21 @@ + + + + + + diff --git a/app/src/main/res/drawable/baseline_12_hour_timer.xml b/app/src/main/res/drawable/baseline_12_hour_timer.xml new file mode 100644 index 0000000..c94c7ca --- /dev/null +++ b/app/src/main/res/drawable/baseline_12_hour_timer.xml @@ -0,0 +1,24 @@ + + + + + + diff --git a/app/src/main/res/drawable/baseline_24_hour_timer.xml b/app/src/main/res/drawable/baseline_24_hour_timer.xml new file mode 100644 index 0000000..327f067 --- /dev/null +++ b/app/src/main/res/drawable/baseline_24_hour_timer.xml @@ -0,0 +1,24 @@ + + + + + + diff --git a/app/src/main/res/drawable/baseline_5_hour_timer.xml b/app/src/main/res/drawable/baseline_5_hour_timer.xml new file mode 100644 index 0000000..695d1f7 --- /dev/null +++ b/app/src/main/res/drawable/baseline_5_hour_timer.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable/baseline_arrow_up_24.xml b/app/src/main/res/drawable/baseline_arrow_up_24.xml new file mode 100644 index 0000000..54cb31c --- /dev/null +++ b/app/src/main/res/drawable/baseline_arrow_up_24.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/baseline_reset_24.xml b/app/src/main/res/drawable/baseline_reset_24.xml new file mode 100644 index 0000000..5b1a1ab --- /dev/null +++ b/app/src/main/res/drawable/baseline_reset_24.xml @@ -0,0 +1,9 @@ + + + diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2186327..505e807 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,18 +1,18 @@ [versions] agp = "8.7.3" -datastore = "1.1.1" +datastore = "1.1.2" kotlin = "2.0.0" coreKtx = "1.15.0" junit = "4.13.2" junitVersion = "1.2.1" espressoCore = "3.6.1" lifecycleRuntimeKtx = "2.8.7" -activityCompose = "1.9.3" -composeBom = "2024.04.01" +activityCompose = "1.10.0" +composeBom = "2025.01.00" protobufGradlePlugin = "0.9.4" protobufJavalite = "4.27.0" roomRuntime = "2.6.1" -vbNfcReader = "0.1.0" +vbNfcReader = "0.2.0-SNAPSHOT" dimReader = "2.1.0" [libraries]