From c0a67e382ba6a158a82edd32cca0c3da83a5f15f Mon Sep 17 00:00:00 2001 From: Nacho Date: Sat, 18 Jan 2025 23:44:38 +0100 Subject: [PATCH 1/7] Things items related - Added a MyItems screen - Added an ItemElement placeholder - Included database with all the items in the app (not final) - Also included some demo items As of now items don't do anything, i'm still making the UI --- app/src/main/assets/items.db | Bin 0 -> 16384 bytes .../vbhelper/components/ItemElement.kt | 63 ++++++++++++++++++ .../github/nacabaro/vbhelper/daos/ItemDao.kt | 19 ++++++ .../nacabaro/vbhelper/database/AppDatabase.kt | 8 ++- .../vbhelper/di/DefaultAppContainer.kt | 4 +- .../nacabaro/vbhelper/domain/items/Items.kt | 15 +++++ .../vbhelper/domain/items/UserItems.kt | 20 ++++++ .../github/nacabaro/vbhelper/dtos/ItemDtos.kt | 15 +++++ .../vbhelper/navigation/AppNavigation.kt | 3 +- .../vbhelper/screens/itemsScreen/MyItems.kt | 61 +++++++++++++++++ .../vbhelper/source/ItemsRepository.kt | 17 +++++ .../res/drawable/baseline_15_min_timer.xml | 15 +++++ .../res/drawable/baseline_30_min_timer.xml | 15 +++++ .../res/drawable/baseline_60_min_timer.xml | 15 +++++ .../main/res/drawable/baseline_shield_24.xml | 9 +++ 15 files changed, 276 insertions(+), 3 deletions(-) create mode 100644 app/src/main/assets/items.db create mode 100644 app/src/main/java/com/github/nacabaro/vbhelper/components/ItemElement.kt create mode 100644 app/src/main/java/com/github/nacabaro/vbhelper/daos/ItemDao.kt create mode 100644 app/src/main/java/com/github/nacabaro/vbhelper/domain/items/Items.kt create mode 100644 app/src/main/java/com/github/nacabaro/vbhelper/domain/items/UserItems.kt create mode 100644 app/src/main/java/com/github/nacabaro/vbhelper/dtos/ItemDtos.kt create mode 100644 app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/MyItems.kt create mode 100644 app/src/main/java/com/github/nacabaro/vbhelper/source/ItemsRepository.kt create mode 100644 app/src/main/res/drawable/baseline_15_min_timer.xml create mode 100644 app/src/main/res/drawable/baseline_30_min_timer.xml create mode 100644 app/src/main/res/drawable/baseline_60_min_timer.xml create mode 100644 app/src/main/res/drawable/baseline_shield_24.xml diff --git a/app/src/main/assets/items.db b/app/src/main/assets/items.db new file mode 100644 index 0000000000000000000000000000000000000000..9064ecf8cdccc050f63d947f4e79964cbd469f11 GIT binary patch literal 16384 zcmeI%F>ljA6bJA-J0&EGQJ5Z7%(dyYnBo!LTQ*eks7IBmMI_~%sP~j}F=0Re0uX=z1Rwwb2tWV=5P$$V z)#PGreVv}|h0fb!cYovtdgu;D^9#9Uan0t;)|v)q^V_UmW@3mhxq;qix@q%mZn0fU zf2~;utj!OY*|C|qZx|2bh406XA9~@(`O<87t7CC}+l(KqCrKO3;#=I}W{Y=OTvOfa zH(1AHo7~`{qL$WeX`8&<5N-Un0hgx=7-sgu;0yp5JH=hof-BM6^E+qF6XvR2Tm`S+Z&zx}%0nKdT<$|Eyw^qKYV$ zn%7n&qDw0hB^kG;*|cl3iRiLyQk3mhPHh_*t-RWjRf(2FE{(OE+Opa5YD;C4M7DMz z%63I3v)S@Gna(DX$#H3=g(f_CmVPbrHkzzTHcBRKX`1Zs9%Pf{?K723A`|g`{jX2z z9U6<37T*1AU3p@uy2wNkb;;^aqF$=M#DoC>2tWV=5P$##AOHafKmY;|fWVCxD9AFQ om4YPBcM4RT%Qt>Y*Z>3|009U<00Izz00bZa0SG_<0!syc1KT%WApigX literal 0 HcmV?d00001 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 new file mode 100644 index 0000000..6557be2 --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/components/ItemElement.kt @@ -0,0 +1,63 @@ +package com.github.nacabaro.vbhelper.components + +import android.graphics.drawable.Icon +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material3.Card +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.dp +import com.github.nacabaro.vbhelper.R + +@Composable +fun ItemElement( + itemIcon: Int, + lengthIcon: Int, + modifier: Modifier = Modifier, + onClick: (() -> Unit) = { } +) { + val iconResource = when (itemIcon) { + 1 -> R.drawable.baseline_agility_24 + 2 -> R.drawable.baseline_attack_24 + 3 -> R.drawable.baseline_shield_24 + else -> R.drawable.baseline_question_mark_24 + } + + val lengthResource = when (lengthIcon) { + 1 -> R.drawable.baseline_15_min_timer + 2 -> R.drawable.baseline_30_min_timer + 3 -> R.drawable.baseline_60_min_timer + else -> R.drawable.baseline_question_mark_24 + } + + Card ( + onClick = onClick, + modifier = modifier + .aspectRatio(1f) + ) { + Box(modifier = Modifier.fillMaxSize()) { + // Background image (full size) + Image( + painter = painterResource(id = iconResource), + contentDescription = null, + contentScale = ContentScale.Crop, + modifier = Modifier.fillMaxSize() + ) + Image( + painter = painterResource(id = lengthResource), + contentDescription = null, + modifier = Modifier + .size(100.dp) // Set the size of the overlay image + .align(Alignment.TopEnd) // Align to the top end (top-right corner) + .padding(16.dp) // Add some padding from the edges + ) + } + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..2c4cad0 --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/daos/ItemDao.kt @@ -0,0 +1,19 @@ +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 +interface ItemDao { + @Query("SELECT * FROM Items") + suspend fun getAllItems(): List + + @Query(""" + SELECT Items.*, UserItems.quantity + FROM Items + JOIN UserItems ON Items.id = UserItems.itemId + """) + suspend fun getAllUserItems(): List +} \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/database/AppDatabase.kt b/app/src/main/java/com/github/nacabaro/vbhelper/database/AppDatabase.kt index 25501a5..7bc9f56 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/database/AppDatabase.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/database/AppDatabase.kt @@ -5,6 +5,7 @@ import androidx.room.RoomDatabase import com.github.nacabaro.vbhelper.daos.CharacterDao import com.github.nacabaro.vbhelper.daos.DexDao import com.github.nacabaro.vbhelper.daos.DiMDao +import com.github.nacabaro.vbhelper.daos.ItemDao import com.github.nacabaro.vbhelper.daos.UserCharacterDao import com.github.nacabaro.vbhelper.domain.characters.Character import com.github.nacabaro.vbhelper.domain.characters.Card @@ -13,6 +14,8 @@ import com.github.nacabaro.vbhelper.domain.characters.Dex import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData import com.github.nacabaro.vbhelper.domain.device_data.TransformationHistory import com.github.nacabaro.vbhelper.domain.device_data.UserCharacter +import com.github.nacabaro.vbhelper.domain.items.Items +import com.github.nacabaro.vbhelper.domain.items.UserItems @Database( version = 1, @@ -23,7 +26,9 @@ import com.github.nacabaro.vbhelper.domain.device_data.UserCharacter UserCharacter::class, BECharacterData::class, TransformationHistory::class, - Dex::class + Dex::class, + Items::class, + UserItems::class ] ) abstract class AppDatabase : RoomDatabase() { @@ -31,4 +36,5 @@ abstract class AppDatabase : RoomDatabase() { abstract fun characterDao(): CharacterDao abstract fun userCharacterDao(): UserCharacterDao abstract fun dexDao(): DexDao + abstract fun itemDao(): ItemDao } \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/di/DefaultAppContainer.kt b/app/src/main/java/com/github/nacabaro/vbhelper/di/DefaultAppContainer.kt index e84819e..4724bc6 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/di/DefaultAppContainer.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/di/DefaultAppContainer.kt @@ -22,7 +22,9 @@ class DefaultAppContainer(private val context: Context) : AppContainer { context = context, klass = AppDatabase::class.java, "internalDb" - ).build() + ) + .createFromAsset("items.db") + .build() } override val dataStoreSecretsRepository = DataStoreSecretsRepository(context.secretsStore) 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 new file mode 100644 index 0000000..2452f85 --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/items/Items.kt @@ -0,0 +1,15 @@ +package com.github.nacabaro.vbhelper.domain.items + +import android.content.Intent +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity +data class Items( + @PrimaryKey val id: Long, + val name: String, + val description: String, + val itemIcon: Int, + val lengthIcon: Int, + val price: Int +) diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/items/UserItems.kt b/app/src/main/java/com/github/nacabaro/vbhelper/domain/items/UserItems.kt new file mode 100644 index 0000000..5c98774 --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/items/UserItems.kt @@ -0,0 +1,20 @@ +package com.github.nacabaro.vbhelper.domain.items + +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey + +@Entity( + foreignKeys = [ + ForeignKey( + entity = Items::class, + parentColumns = ["id"], + childColumns = ["itemId"], + onDelete = ForeignKey.CASCADE + ) + ] +) +data class UserItems( + @PrimaryKey val itemId: Long, + val quantity: 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 new file mode 100644 index 0000000..64cedb8 --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/dtos/ItemDtos.kt @@ -0,0 +1,15 @@ +package com.github.nacabaro.vbhelper.dtos + +import androidx.room.PrimaryKey + +object ItemDtos { + data class ItemsWithQuantities ( + val id: Long, + val name: String, + val description: String, + val itemIcon: Int, + val lengthIcon: Int, + val price: Int, + val quantity: Int, + ) +} \ No newline at end of file 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 5d417b1..be70f03 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 @@ -17,6 +17,7 @@ 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( @@ -92,7 +93,7 @@ fun AppNavigation( } } composable(NavigationItems.Items.route) { - ItemsScreen( + MyItems( navController = navController ) } 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 new file mode 100644 index 0000000..b3d0bad --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/MyItems.kt @@ -0,0 +1,61 @@ +package com.github.nacabaro.vbhelper.screens.itemsScreen + +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 +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +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.components.ItemElement +import com.github.nacabaro.vbhelper.components.TopBanner +import com.github.nacabaro.vbhelper.di.VBHelper +import com.github.nacabaro.vbhelper.dtos.ItemDtos +import com.github.nacabaro.vbhelper.source.ItemsRepository +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +@Composable +fun MyItems( + navController: NavController, +) { + val application = LocalContext.current.applicationContext as VBHelper + val itemsRepository = ItemsRepository(application.container.db) + val myItems = remember { mutableStateOf(emptyList()) } + + LaunchedEffect(itemsRepository) { + withContext(Dispatchers.IO) { + myItems.value = itemsRepository.getUserItems() + } + } + + Scaffold ( + topBar = { TopBanner("Available items") } + ) { contentPadding -> + if (myItems.value.isEmpty()) { + Text("No items") + } else { + LazyVerticalGrid( + columns = GridCells.Fixed(3), + contentPadding = contentPadding + ) { + items(myItems.value) { index -> + ItemElement( + itemIcon = index.itemIcon, + lengthIcon = index.lengthIcon, + modifier = Modifier + .padding(8.dp), + onClick = { } + ) + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/source/ItemsRepository.kt b/app/src/main/java/com/github/nacabaro/vbhelper/source/ItemsRepository.kt new file mode 100644 index 0000000..553994c --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/source/ItemsRepository.kt @@ -0,0 +1,17 @@ +package com.github.nacabaro.vbhelper.source + +import com.github.nacabaro.vbhelper.database.AppDatabase +import com.github.nacabaro.vbhelper.domain.items.Items +import com.github.nacabaro.vbhelper.dtos.ItemDtos + +class ItemsRepository( + private val db: AppDatabase +) { + suspend fun getAllItems(): List { + return db.itemDao().getAllItems() + } + + suspend fun getUserItems(): List { + return db.itemDao().getAllUserItems() + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/baseline_15_min_timer.xml b/app/src/main/res/drawable/baseline_15_min_timer.xml new file mode 100644 index 0000000..e6dcd6e --- /dev/null +++ b/app/src/main/res/drawable/baseline_15_min_timer.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/drawable/baseline_30_min_timer.xml b/app/src/main/res/drawable/baseline_30_min_timer.xml new file mode 100644 index 0000000..e84db54 --- /dev/null +++ b/app/src/main/res/drawable/baseline_30_min_timer.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/drawable/baseline_60_min_timer.xml b/app/src/main/res/drawable/baseline_60_min_timer.xml new file mode 100644 index 0000000..092fd19 --- /dev/null +++ b/app/src/main/res/drawable/baseline_60_min_timer.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/drawable/baseline_shield_24.xml b/app/src/main/res/drawable/baseline_shield_24.xml new file mode 100644 index 0000000..4554dcb --- /dev/null +++ b/app/src/main/res/drawable/baseline_shield_24.xml @@ -0,0 +1,9 @@ + + + From 305b776b5207800a4b109bbfca1704d6ab2bb426 Mon Sep 17 00:00:00 2001 From: Nacho Date: Sun, 19 Jan 2025 13:41:50 +0100 Subject: [PATCH 2/7] Things - Added items store and a way to switch between the store and your items - Added an items dialog, click on it to see details of the item (description, amount) and use it - Added items store, it lists all the items available --- app/src/main/assets/items.db | Bin 16384 -> 16384 bytes .../vbhelper/components/ItemElement.kt | 184 +++++++++++++++--- .../github/nacabaro/vbhelper/daos/ItemDao.kt | 8 +- .../vbhelper/navigation/AppNavigation.kt | 2 +- .../vbhelper/navigation/NavigationItems.kt | 2 + .../nacabaro/vbhelper/screens/ItemsScreen.kt | 57 +++++- .../vbhelper/screens/StorageScreen.kt | 2 +- .../screens/itemsScreen/ItemsStore.kt | 77 ++++++++ .../vbhelper/screens/itemsScreen/MyItems.kt | 54 +++-- .../vbhelper/source/ItemsRepository.kt | 2 +- .../main/res/drawable/baseline_shield_24.xml | 8 +- 11 files changed, 343 insertions(+), 53 deletions(-) create mode 100644 app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsStore.kt diff --git a/app/src/main/assets/items.db b/app/src/main/assets/items.db index 9064ecf8cdccc050f63d947f4e79964cbd469f11..37e07adc584bbff9ba83851f8d5b6f7e09a51b54 100644 GIT binary patch delta 744 zcmZo@U~Fh$oFL68Fj2;tQD9@jLVj(YJO&}Iy)67&_?q~oc@+6fc%Sk7<(yC~Wb*O!^$bx6at(G32}&(aEh$zgDN4-D z%gjqx$jQvjEKx{GOwLv)$yYEmFi^pr~Le4ps#?kDWydqZ-M+b`K^o?FAL)YZ!VB#PN3$=`{ZRA113L^ z5ueN_&&|uiFwL6Yp0B(+$RiQyODc?J#!ATZ};XE1aG zy1>shB18ca7P=7IgHlsUlY!v?mPx8qfQW(&U}k01@!^I!9b^N~F)=gz@?nMQcLcjIT26zL2_ypak0Z!GlcVJ%K)#7&VwlFC z$sh=FEF75g0mI%F&DDlRkg!L0H%y#`m05v-!J8Rsixb!uUa&2E-XNpV?BK^@hmi?( RJ7D6htSlQgZtLVihJRt8R<9gO^2_+|Lc^EL6A@IK?&!8?Q3Yh&X) z9xiWob_VN2PDUn=$rGeyC*PKrm~11<$HJe<;5xC;ZZH2EITSYA1a$x-q^VJ4`sBUm^Z XEX>W$#4wG4fx&BHqx Unit) = { } ) { - val iconResource = when (itemIcon) { - 1 -> R.drawable.baseline_agility_24 - 2 -> R.drawable.baseline_attack_24 - 3 -> R.drawable.baseline_shield_24 - else -> R.drawable.baseline_question_mark_24 - } - - val lengthResource = when (lengthIcon) { - 1 -> R.drawable.baseline_15_min_timer - 2 -> R.drawable.baseline_30_min_timer - 3 -> R.drawable.baseline_60_min_timer - else -> R.drawable.baseline_question_mark_24 - } - Card ( onClick = onClick, modifier = modifier @@ -44,20 +47,151 @@ fun ItemElement( ) { Box(modifier = Modifier.fillMaxSize()) { // Background image (full size) - Image( - painter = painterResource(id = iconResource), - contentDescription = null, - contentScale = ContentScale.Crop, - modifier = Modifier.fillMaxSize() - ) - Image( - painter = painterResource(id = lengthResource), + Icon( + painter = painterResource(id = itemIcon), contentDescription = null, modifier = Modifier - .size(100.dp) // Set the size of the overlay image - .align(Alignment.TopEnd) // Align to the top end (top-right corner) - .padding(16.dp) // Add some padding from the edges + .size(96.dp) + .align(Alignment.Center) + ) + Icon( + painter = painterResource(id = lengthIcon), + contentDescription = null, + tint = MaterialTheme.colorScheme.surfaceTint, + modifier = Modifier + .size(48.dp) // Set the size of the overlay image + .padding(4.dp + ) + .align(Alignment.TopStart) // Align to the top end (top-right corner) ) } } +} + +@Composable +fun ItemDialog( + name: String, + description: String, + itemIcon: Int, + lengthIcon: Int, + amount: Int, + onClickUse: () -> Unit, + onClickCancel: () -> Unit +) { + Dialog( + onDismissRequest = onClickCancel, + properties = DialogProperties( + dismissOnBackPress = true, + dismissOnClickOutside = true + ) + ) { + Card ( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp) + ) { + Column ( + modifier = Modifier + .padding(16.dp) + ) { + Row { + Box(modifier = Modifier) { + // Background image (full size) + Icon( + painter = painterResource(id = itemIcon), + contentDescription = null, + modifier = Modifier + .size(96.dp) + .align(Alignment.Center) + ) + Icon( + painter = painterResource(id = lengthIcon), + contentDescription = null, + tint = MaterialTheme.colorScheme.outline, + modifier = Modifier + .size(64.dp) // Set the size of the overlay image + .align(Alignment.BottomEnd) // Align to the top end (top-right corner) + ) + } + Column ( + modifier = Modifier + .padding(16.dp) + ) { + Text( + fontSize = MaterialTheme.typography.titleLarge.fontSize, + text = name, + modifier = Modifier + .fillMaxWidth() + ) + } + } + Text( + textAlign = TextAlign.Center, + fontSize = MaterialTheme.typography.bodyMedium.fontSize, + fontFamily = MaterialTheme.typography.bodyMedium.fontFamily, + text = description + ) + Text( + textAlign = TextAlign.Center, + fontSize = MaterialTheme.typography.bodySmall.fontSize, + fontFamily = MaterialTheme.typography.bodySmall.fontFamily, + text = "You have $amount of this item", + modifier = Modifier + .fillMaxWidth() + .padding(16.dp) + ) + Row ( + horizontalArrangement = Arrangement.Center, + modifier = Modifier + .fillMaxWidth() + ) { + Button( + onClick = onClickUse + ) { + Text("Use item") + } + Spacer(modifier = Modifier.size(8.dp)) + Button( + onClick = onClickCancel + ) { + Text("Cancel") + } + } + } + } + } +} + +fun getIconResource(index: Int): Int { + return when (index) { + 1 -> R.drawable.baseline_agility_24 + 2 -> R.drawable.baseline_attack_24 + 3 -> R.drawable.baseline_shield_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 + else -> R.drawable.baseline_question_mark_24 + } +} + +@Composable +@Preview(showBackground = true) +fun PreviewItemDialog() { + VBHelperTheme { + ItemDialog( + name = "AP Training x3 (60 min)", + description = "Boosts AP during training (for 60 minutes)", + itemIcon = R.drawable.baseline_attack_24, + lengthIcon = R.drawable.baseline_60_min_timer, + onClickUse = { }, + onClickCancel = { }, + amount = 19 + ) + } } \ No newline at end of file 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 2c4cad0..db9c90e 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 @@ -7,8 +7,12 @@ import com.github.nacabaro.vbhelper.dtos.ItemDtos @Dao interface ItemDao { - @Query("SELECT * FROM Items") - suspend fun getAllItems(): List + @Query(""" + SELECT Items.*, UserItems.quantity + FROM Items + LEFT JOIN UserItems ON Items.id = UserItems.itemId + """) + suspend fun getAllItems(): List @Query(""" SELECT Items.*, UserItems.quantity 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 be70f03..c0b044b 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 @@ -93,7 +93,7 @@ fun AppNavigation( } } composable(NavigationItems.Items.route) { - MyItems( + ItemsScreen( navController = navController ) } diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/navigation/NavigationItems.kt b/app/src/main/java/com/github/nacabaro/vbhelper/navigation/NavigationItems.kt index bc0bd38..ee831b0 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/navigation/NavigationItems.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/navigation/NavigationItems.kt @@ -16,4 +16,6 @@ sealed class NavigationItems ( object Viewer : NavigationItems("Viewer", R.drawable.baseline_image_24, "Viewer") object CardView : NavigationItems("Card/{cardId}", R.drawable.baseline_image_24, "Card") object Items : NavigationItems("Items", R.drawable.baseline_data_24, "Items") + object MyItems : NavigationItems("MyItems", R.drawable.baseline_data_24, "My items") + object ItemsStore : NavigationItems("ItemsStore", R.drawable.baseline_data_24, "Items store") } \ No newline at end of file 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.kt index 76b9532..2ef81b5 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/ItemsScreen.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/ItemsScreen.kt @@ -1,12 +1,65 @@ package com.github.nacabaro.vbhelper.screens +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 +import androidx.compose.material3.Tab +import androidx.compose.material3.TabRow 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.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( - navController: NavController + navController: NavController, ) { - Text(text = "Items") + var selectedTabItem by remember { mutableStateOf(0) } + val items = listOf( + NavigationItems.MyItems, + NavigationItems.ItemsStore + ) + Scaffold( + topBar = { + Column { + TopBanner("Items") + TabRow( + selectedTabIndex = selectedTabItem, + modifier = Modifier + ) { + items.forEachIndexed { index, item -> + Tab( + text = { Text(item.label) }, + selected = selectedTabItem == index, + onClick = { selectedTabItem = index } + ) + } + } + } + } + ) { contentPadding -> + Box( + modifier = Modifier + .fillMaxWidth() + .padding(top = contentPadding.calculateTopPadding()) + ) { + when (selectedTabItem) { + 0 -> MyItems(navController) + 1 -> ItemsStore(navController) + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/StorageScreen.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/StorageScreen.kt index 597fca0..533b131 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/StorageScreen.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/StorageScreen.kt @@ -66,7 +66,7 @@ fun StorageScreen( } Scaffold ( - topBar = { TopBanner(text = "My Digimon") } + topBar = { TopBanner(text = "My characters") } ) { contentPadding -> if (monList.value.isEmpty()) { Column ( 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 new file mode 100644 index 0000000..d205f8f --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsStore.kt @@ -0,0 +1,77 @@ +package com.github.nacabaro.vbhelper.screens.itemsScreen + +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.Text +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.compose.ui.unit.dp +import androidx.navigation.NavController +import com.github.nacabaro.vbhelper.components.ItemDialog +import com.github.nacabaro.vbhelper.components.ItemElement +import com.github.nacabaro.vbhelper.components.getIconResource +import com.github.nacabaro.vbhelper.components.getLengthResource +import com.github.nacabaro.vbhelper.di.VBHelper +import com.github.nacabaro.vbhelper.dtos.ItemDtos +import com.github.nacabaro.vbhelper.source.ItemsRepository +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +@Composable +fun ItemsStore( + navController: NavController +) { + val application = LocalContext.current.applicationContext as VBHelper + val itemsRepository = ItemsRepository(application.container.db) + val myItems = remember { mutableStateOf(emptyList()) } + var showDialog by remember { mutableStateOf(false) } + var selectedElementIndex by remember { mutableStateOf(null) } + + LaunchedEffect(itemsRepository) { + withContext(Dispatchers.IO) { + myItems.value = itemsRepository.getAllItems() + } + } + + if (myItems.value.isEmpty()) { + Text("No items") + } else { + LazyVerticalGrid( + columns = GridCells.Fixed(3), + modifier = Modifier + ) { + items(myItems.value) { index -> + ItemElement( + itemIcon = getIconResource(index.itemIcon), + lengthIcon = getLengthResource(index.lengthIcon), + modifier = Modifier + .padding(8.dp), + onClick = { + showDialog = true + selectedElementIndex = myItems.value.indexOf(index) + } + ) + + if (showDialog && selectedElementIndex != null) { + ItemDialog( + name = myItems.value[selectedElementIndex!!].name, + description = myItems.value[selectedElementIndex!!].description, + itemIcon = getIconResource(myItems.value[selectedElementIndex!!].itemIcon), + lengthIcon = getLengthResource(myItems.value[selectedElementIndex!!].lengthIcon), + amount = myItems.value[selectedElementIndex!!].quantity, + onClickUse = { }, + onClickCancel = { showDialog = false } + ) + } + } + } + } +} \ No newline at end of file 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 b3d0bad..2a6f0cb 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,5 +1,6 @@ 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 @@ -8,14 +9,20 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.Text 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.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 import com.github.nacabaro.vbhelper.dtos.ItemDtos import com.github.nacabaro.vbhelper.source.ItemsRepository @@ -29,6 +36,8 @@ fun MyItems( val application = LocalContext.current.applicationContext as VBHelper val itemsRepository = ItemsRepository(application.container.db) val myItems = remember { mutableStateOf(emptyList()) } + var showDialog by remember { mutableStateOf(false) } + var selectedElementIndex by remember { mutableStateOf(null) } LaunchedEffect(itemsRepository) { withContext(Dispatchers.IO) { @@ -36,23 +45,34 @@ fun MyItems( } } - Scaffold ( - topBar = { TopBanner("Available items") } - ) { contentPadding -> - if (myItems.value.isEmpty()) { - Text("No items") - } else { - LazyVerticalGrid( - columns = GridCells.Fixed(3), - contentPadding = contentPadding - ) { - items(myItems.value) { index -> - ItemElement( - itemIcon = index.itemIcon, - lengthIcon = index.lengthIcon, - modifier = Modifier - .padding(8.dp), - onClick = { } + if (myItems.value.isEmpty()) { + Text("No items") + } else { + LazyVerticalGrid( + columns = GridCells.Fixed(3), + modifier = Modifier + ) { + items(myItems.value) { index -> + ItemElement( + itemIcon = getIconResource(index.itemIcon), + lengthIcon = getLengthResource(index.lengthIcon), + modifier = Modifier + .padding(8.dp), + onClick = { + showDialog = true + selectedElementIndex = myItems.value.indexOf(index) + } + ) + + if (showDialog && selectedElementIndex != null) { + ItemDialog( + name = myItems.value[selectedElementIndex!!].name, + description = myItems.value[selectedElementIndex!!].description, + itemIcon = getIconResource(myItems.value[selectedElementIndex!!].itemIcon), + lengthIcon = getLengthResource(myItems.value[selectedElementIndex!!].lengthIcon), + amount = myItems.value[selectedElementIndex!!].quantity, + onClickUse = { }, + onClickCancel = { showDialog = false } ) } } diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/source/ItemsRepository.kt b/app/src/main/java/com/github/nacabaro/vbhelper/source/ItemsRepository.kt index 553994c..8d6d705 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/source/ItemsRepository.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/source/ItemsRepository.kt @@ -7,7 +7,7 @@ import com.github.nacabaro.vbhelper.dtos.ItemDtos class ItemsRepository( private val db: AppDatabase ) { - suspend fun getAllItems(): List { + suspend fun getAllItems(): List { return db.itemDao().getAllItems() } diff --git a/app/src/main/res/drawable/baseline_shield_24.xml b/app/src/main/res/drawable/baseline_shield_24.xml index 4554dcb..8e3b2ca 100644 --- a/app/src/main/res/drawable/baseline_shield_24.xml +++ b/app/src/main/res/drawable/baseline_shield_24.xml @@ -1,9 +1,9 @@ + android:viewportWidth="960" + android:viewportHeight="960"> + android:pathData="M480,880q-139,-35 -229.5,-159.5T160,444v-244l320,-120 320,120v244q0,152 -90.5,276.5T480,880ZM480,796q104,-33 172,-132t68,-220v-189l-240,-90 -240,90v189q0,121 68,220t172,132ZM480,480Z" + android:fillColor="#000000"/> From f3740d4816c2c0f8c0ff2511f81b0c72bb58b185 Mon Sep 17 00:00:00 2001 From: Nacho Date: Mon, 20 Jan 2025 00:06:42 +0100 Subject: [PATCH 3/7] Here comes the train (with more things) - Updated available items - Created ItemsScreenController - Moved the ItemsScreen to keep code organized --- app/src/main/assets/items.db | Bin 16384 -> 16384 bytes .../vbhelper/components/ItemElement.kt | 24 ++--- .../github/nacabaro/vbhelper/daos/ItemDao.kt | 16 +++- .../vbhelper/daos/UserCharacterDao.kt | 7 ++ .../domain/device_data/BECharacterData.kt | 8 +- .../nacabaro/vbhelper/domain/items/Items.kt | 3 +- .../github/nacabaro/vbhelper/dtos/ItemDtos.kt | 3 +- .../vbhelper/navigation/AppNavigation.kt | 3 +- .../screens/{ => itemsScreen}/ItemsScreen.kt | 7 +- .../itemsScreen/ItemsScreenController.kt | 7 ++ .../itemsScreen/ItemsScreenControllerImpl.kt | 84 ++++++++++++++++++ .../screens/itemsScreen/ItemsStore.kt | 4 +- .../vbhelper/screens/itemsScreen/MyItems.kt | 8 +- .../res/drawable/baseline_10_hour_timer.xml | 21 +++++ .../res/drawable/baseline_12_hour_timer.xml | 24 +++++ .../res/drawable/baseline_24_hour_timer.xml | 24 +++++ .../res/drawable/baseline_5_hour_timer.xml | 17 ++++ .../res/drawable/baseline_arrow_up_24.xml | 9 ++ .../main/res/drawable/baseline_reset_24.xml | 9 ++ gradle/libs.versions.toml | 8 +- 20 files changed, 247 insertions(+), 39 deletions(-) rename app/src/main/java/com/github/nacabaro/vbhelper/screens/{ => itemsScreen}/ItemsScreen.kt (85%) create mode 100644 app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsScreenController.kt create mode 100644 app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ItemsScreenControllerImpl.kt create mode 100644 app/src/main/res/drawable/baseline_10_hour_timer.xml create mode 100644 app/src/main/res/drawable/baseline_12_hour_timer.xml create mode 100644 app/src/main/res/drawable/baseline_24_hour_timer.xml create mode 100644 app/src/main/res/drawable/baseline_5_hour_timer.xml create mode 100644 app/src/main/res/drawable/baseline_arrow_up_24.xml create mode 100644 app/src/main/res/drawable/baseline_reset_24.xml diff --git a/app/src/main/assets/items.db b/app/src/main/assets/items.db index 37e07adc584bbff9ba83851f8d5b6f7e09a51b54..1d8bd5b34c578abd5e87d10244c8694121abe234 100644 GIT binary patch delta 848 zcmZva%}*0S7{+I|+b-Qtkdm5iyNs(LfDLv<1YY8CFvJplj! zO^PA~Ny)Y7Xm0?FNB9Ik*4z)T=Ms!bA2tF-2rkiOdq3 z)t3faBM-4dZ(;06g5WvozAX6PgFgQ-%|4ahNUP$$xGieJflwEc>^%RHzwdWgpMRJi z5Jc`f_kvsDP{aM%B_<^XOx}f%N)!sn!E7WH%e7ABoL#a@YZWy3aHEW_#!%5NZ8=tD zD9*s$q;LxQB8LV#K-$<}h=kPHZy;H7Z;DCr6r4~(7dpVB{}L4jG))#a!a@8))_f8T z>a!3Zk?VfH#z>&f{{mw*S7UDUG2r|%h4(^NBEd}`_f8KmV0?jslxd`mEOP9kRYn)J z7+#Xq07+Qi*eX}3MIX~O-OGTnI}|qLYdnnlsKtphM3|(o+dslISG@G=@oxMmJnGx? z!l=o&hj}Jzbex8}_*FQiC^TqFA<#?y>&Z3IbKK^uGU7dqc|8cHA}JWhPanHN3fur#rOI-QSyMgN&T@B NZEN}1q9qE{e*>FU*OveQ delta 678 zcmZWnO>YuG7@nD3cIhs&3vJ9+!DN&}Yb01h4G~xxXg3yi!3Js4#)CoF*p1~QfHpBE zf+ijjG70f$`~g;@2QPT>(4!ZBfG7VzZ;fBO3wo$;GV{*7&-3JY-^}!Su-AjbV89Om zU}p>3Ss6uQ3w{u-LM)X4!UG_m#REKe5B(ub2lxmcjryOT^lOk;6a_w8>Q?UVo4Kx8 z@3&^FMFl681H~ zyf9(q57JXP=(`}T;_tqn_$AJZUwwz-bKgVhoBT-33O|I&yZ%Vv)p;I-Z$rA2Tn+J@ z_;Dk^gZMUt$jB9PWzx0kW}94&t!s$?Gh~p&fcB zm6sS64t0SC$;uo=TePuuo*pE^9u|ysmcB|TG@q8Jm|mo2fN@ zF&-E(L|REri3bUn$RQS-=)9{xR2_YoVc?K%s(H>i7+%^>EA&vkiWo$%qz#DZ<8(nn zwt++rRC%48b3Llb}`r 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] From 3e41f822732d1feab9be288a1f05570900d56fa9 Mon Sep 17 00:00:00 2001 From: Nacho Date: Mon, 20 Jan 2025 00:29:07 +0100 Subject: [PATCH 4/7] Forgot to push the updated db --- app/src/main/assets/items.db | Bin 16384 -> 16384 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/app/src/main/assets/items.db b/app/src/main/assets/items.db index 1d8bd5b34c578abd5e87d10244c8694121abe234..8ab0d217a7dcbe8b1a0762cf2606bb4813c5e8e4 100644 GIT binary patch delta 799 zcmZo@U~Fh$oFL68I#I@%QFLR%5`8;a4kd1`OZ=PoQ}~7W>iG;g?(k0I_23HNImlDO zS;ED}sl}tl%g6nOdpUOkw*u!Cu6exw`JQpCc;Xp^88Co>7|?;X2>Y}_ zF7eDuE=o--M)49zocRUNP7gk?sR~xQysQkryt%+G;A9GzoM$gPx!g*{kzpExfjF9} zpa8*UDoC932+-dQ3_gr-zkp2Qwv(9LZ^gsR#4v5Lg0(Fp`{X!lHz2vx+673yvbJPo zo2+7Ep~S|h!~29m1jA$AJaC7Bf~MR`V)8s29v;RC-rR5rYdeTUfgKMM!>`GFw&p-X z-E4hXSr{kya7=Er6Q8`^)`*>%aRT322I+~8;zkA%XdVN)AFIbe;=&!k6foJ)&YO{C za;=>&J2S&Cpfe>WI*OWUNwPC2nj(VT*D=B=Kff3y#R0|C`8ha`_^`kO2IOE+zyKW# V447Y&6YTwgW^b_fWoBlW1^{O^%P;@{ delta 367 zcmZo@U~Fh$oFL68GEv5vQDkGn5`8^UPAwL$dHkFBQ~1vE)$%kSkvz8~G zvxJL{Q;SE9myi1m_j2w8ZiS7FKR709S-P{bGfwc}ovdRiF}crDmz|wq8rN$EkBN;g zOdfn-Q3WeqUUr6GK3wb!)`^UaOaYVg>}4mB7 z0-62ON@B9KB@a+yvZ0+fBlF~1J6~=lhF{(+5M`64?48*degVyQo7m_!ImI5NW`n&i IGZVu!0AoT}RR910 From b4a73031e7eb8cfc240dfefe1277eca35ae052d3 Mon Sep 17 00:00:00 2001 From: Nacho Date: Mon, 20 Jan 2025 14:45:28 +0100 Subject: [PATCH 5/7] Working items - Click on use item > then choose the mon you want to apply the item to --- .../github/nacabaro/vbhelper/MainActivity.kt | 12 +- .../vbhelper/components/ItemElement.kt | 1 + .../github/nacabaro/vbhelper/daos/ItemDao.kt | 8 + .../vbhelper/navigation/AppNavigation.kt | 14 ++ .../vbhelper/navigation/NavigationItems.kt | 1 + .../vbhelper/screens/StorageScreen.kt | 2 - .../itemsScreen/ChooseCharacterScreen.kt | 90 +++++++++++ .../itemsScreen/ItemsScreenController.kt | 3 +- .../itemsScreen/ItemsScreenControllerImpl.kt | 143 +++++++++++------- .../vbhelper/screens/itemsScreen/MyItems.kt | 26 +++- 10 files changed, 238 insertions(+), 62 deletions(-) create mode 100644 app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ChooseCharacterScreen.kt diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/MainActivity.kt b/app/src/main/java/com/github/nacabaro/vbhelper/MainActivity.kt index 569662b..eaa7d0e 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/MainActivity.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/MainActivity.kt @@ -24,6 +24,7 @@ import com.github.nacabaro.vbhelper.domain.characters.Character import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData import com.github.nacabaro.vbhelper.domain.device_data.UserCharacter import com.github.nacabaro.vbhelper.navigation.AppNavigationHandlers +import com.github.nacabaro.vbhelper.screens.itemsScreen.ItemsScreenControllerImpl import com.github.nacabaro.vbhelper.screens.scanScreen.ScanScreenControllerImpl import com.github.nacabaro.vbhelper.screens.settingsScreen.SettingsScreenControllerImpl import com.github.nacabaro.vbhelper.ui.theme.VBHelperTheme @@ -63,12 +64,17 @@ class MainActivity : ComponentActivity() { this::unregisterActivityLifecycleListener ) val settingsScreenController = SettingsScreenControllerImpl(this) + val itemsScreenController = ItemsScreenControllerImpl(this) super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { VBHelperTheme { - MainApplication(scanScreenController, settingsScreenController) + MainApplication( + scanScreenController = scanScreenController, + settingsScreenController = settingsScreenController, + itemsScreenController = itemsScreenController + ) } } Log.i("MainActivity", "Activity onCreated") @@ -189,13 +195,15 @@ class MainActivity : ComponentActivity() { @Composable private fun MainApplication( scanScreenController: ScanScreenControllerImpl, - settingsScreenController: SettingsScreenControllerImpl + settingsScreenController: SettingsScreenControllerImpl, + itemsScreenController: ItemsScreenControllerImpl ) { AppNavigation( applicationNavigationHandlers = AppNavigationHandlers( settingsScreenController, scanScreenController, + itemsScreenController ), onClickImportCard = { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply { 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 1a2783e..07778ac 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 @@ -166,6 +166,7 @@ fun getIconResource(index: Int): Int { 5 -> R.drawable.baseline_arrow_up_24 6 -> R.drawable.baseline_timer_24 7 -> R.drawable.baseline_rank_24 + 8 -> R.drawable.baseline_vitals_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 7eaa1bf..3aad016 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 @@ -21,6 +21,14 @@ interface ItemDao { """) suspend fun getAllUserItems(): List + @Query(""" + SELECT Items.*, UserItems.quantity + FROM Items + JOIN UserItems ON Items.id = UserItems.itemId + WHERE UserItems.itemId = :itemId + """) + fun getUserItem(itemId: Long): ItemDtos.ItemsWithQuantities + @Query(""" UPDATE UserItems SET quantity = quantity - 1 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 acf7d0a..13e8fd4 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 @@ -17,11 +17,14 @@ 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.ChooseCharacterScreen +import com.github.nacabaro.vbhelper.screens.itemsScreen.ItemsScreenControllerImpl import com.github.nacabaro.vbhelper.screens.settingsScreen.SettingsScreenControllerImpl data class AppNavigationHandlers( val settingsScreenController: SettingsScreenControllerImpl, val scanScreenController: ScanScreenControllerImpl, + val itemsScreenController: ItemsScreenControllerImpl ) @Composable @@ -96,6 +99,17 @@ fun AppNavigation( navController = navController ) } + composable(NavigationItems.ApplyItem.route) { + val itemId = it.arguments?.getString("itemId") + if (itemId != null) { + ChooseCharacterScreen( + itemsScreenController = applicationNavigationHandlers + .itemsScreenController, + navController = navController, + itemId = itemId.toLong() + ) + } + } } } } diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/navigation/NavigationItems.kt b/app/src/main/java/com/github/nacabaro/vbhelper/navigation/NavigationItems.kt index ee831b0..45c654e 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/navigation/NavigationItems.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/navigation/NavigationItems.kt @@ -18,4 +18,5 @@ sealed class NavigationItems ( object Items : NavigationItems("Items", R.drawable.baseline_data_24, "Items") object MyItems : NavigationItems("MyItems", R.drawable.baseline_data_24, "My items") object ItemsStore : NavigationItems("ItemsStore", R.drawable.baseline_data_24, "Items store") + object ApplyItem : NavigationItems("ApplyItem/{itemId}", R.drawable.baseline_data_24, "Apply item") } \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/StorageScreen.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/StorageScreen.kt index 533b131..ac0f28c 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/StorageScreen.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/StorageScreen.kt @@ -1,6 +1,5 @@ package com.github.nacabaro.vbhelper.screens -import android.util.Log import androidx.compose.foundation.gestures.Orientation import androidx.compose.foundation.gestures.scrollable import androidx.compose.foundation.layout.Arrangement @@ -8,7 +7,6 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.items diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ChooseCharacterScreen.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ChooseCharacterScreen.kt new file mode 100644 index 0000000..fe52df1 --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/ChooseCharacterScreen.kt @@ -0,0 +1,90 @@ +package com.github.nacabaro.vbhelper.screens.itemsScreen + +import android.widget.Toast +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.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.rememberCoroutineScope +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.navigation.NavController +import com.github.nacabaro.vbhelper.components.CharacterEntry +import com.github.nacabaro.vbhelper.components.TopBanner +import com.github.nacabaro.vbhelper.di.VBHelper +import com.github.nacabaro.vbhelper.dtos.CharacterDtos +import com.github.nacabaro.vbhelper.source.StorageRepository +import com.github.nacabaro.vbhelper.utils.BitmapData +import kotlinx.coroutines.launch + + +@Composable +fun ChooseCharacterScreen( + navController: NavController, + itemsScreenController: ItemsScreenControllerImpl, + itemId: Long +) { + val coroutineScope = rememberCoroutineScope() + val application = LocalContext.current.applicationContext as VBHelper + val storageRepository = StorageRepository(application.container.db) + val characterList = remember { + mutableStateOf>(emptyList()) + } + + var selectedCharacter by remember { mutableStateOf(null) } + + LaunchedEffect(storageRepository) { + coroutineScope.launch { + characterList.value = storageRepository.getAllCharacters() + } + } + + LaunchedEffect (selectedCharacter) { + if (selectedCharacter != null) { + itemsScreenController.applyItem(itemId, selectedCharacter!!) { + Toast.makeText( + application.applicationContext, + "Item applied!", + Toast.LENGTH_SHORT + ).show() + navController.popBackStack() + } + } + } + + Scaffold( + topBar = { + TopBanner( + text = "Choose character", + onBackClick = { + navController.popBackStack() + } + ) + } + ) { contentPadding -> + LazyVerticalGrid( + columns = GridCells.Fixed(3), + modifier = Modifier + .padding(top = contentPadding.calculateTopPadding()) + ) { + items(characterList.value) { + CharacterEntry( + icon = BitmapData( + bitmap = it.spriteIdle, + width = it.spriteWidth, + height = it.spriteHeight + ) + ) { + selectedCharacter = it.id + } + } + } + } +} \ No newline at end of file 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 index de3c2d1..d967c08 100644 --- 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 @@ -1,7 +1,6 @@ package com.github.nacabaro.vbhelper.screens.itemsScreen -import com.github.nacabaro.vbhelper.domain.items.Items interface ItemsScreenController { - suspend fun applyItem(item: Items, characterId: Long) + fun applyItem(itemId: Long, characterId: Long, onCompletion: () -> Unit) } \ 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 index 0b02122..70fc514 100644 --- 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 @@ -1,14 +1,22 @@ package com.github.nacabaro.vbhelper.screens.itemsScreen +import androidx.activity.ComponentActivity +import androidx.lifecycle.lifecycleScope import com.github.nacabaro.vbhelper.database.AppDatabase +import com.github.nacabaro.vbhelper.di.VBHelper 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.dtos.ItemDtos import com.github.nacabaro.vbhelper.utils.DeviceType +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext class ItemsScreenControllerImpl ( - private val database: AppDatabase + private val context: ComponentActivity, ): ItemsScreenController { + private var database: AppDatabase + private enum class ItemTypes(val id: Int) { PPTraining(1), HPTraining(2), @@ -20,60 +28,87 @@ class ItemsScreenControllerImpl ( 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) + init { + val application = context.applicationContext as VBHelper + database = application.container.db + } + + override fun applyItem(itemId: Long, characterId: Long, onCompletion: () -> Unit) { + context.lifecycleScope.launch { + withContext(Dispatchers.IO) { + val item = getItem(itemId) + val characterData = database.userCharacterDao().getCharacter(characterId) + val 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 + } + + // VB does not like it when the transformationCountdown is 0 + if (characterData.characterType == DeviceType.VBDevice && + characterData.transformationCountdown <= 0 ) { + characterData.transformationCountdown = 1 + } + + 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) + + context.runOnUiThread { + onCompletion() + } + } } + } - 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 getItem(itemId: Long): ItemDtos.ItemsWithQuantities { + return database + .itemDao() + .getUserItem(itemId) } private fun consumeItem(itemId: Long) { 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 f9e678b..6513f26 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,5 +1,8 @@ package com.github.nacabaro.vbhelper.screens.itemsScreen +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid @@ -11,6 +14,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp @@ -21,6 +25,7 @@ import com.github.nacabaro.vbhelper.components.getIconResource import com.github.nacabaro.vbhelper.components.getLengthResource import com.github.nacabaro.vbhelper.di.VBHelper import com.github.nacabaro.vbhelper.dtos.ItemDtos +import com.github.nacabaro.vbhelper.navigation.NavigationItems import com.github.nacabaro.vbhelper.source.ItemsRepository import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext @@ -42,7 +47,13 @@ fun MyItems( } if (myItems.value.isEmpty()) { - Text("No items") + Column( + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally, + modifier = Modifier.fillMaxSize() + ) { + Text("No items") + } } else { LazyVerticalGrid( columns = GridCells.Fixed(3), @@ -67,7 +78,18 @@ fun MyItems( itemIcon = getIconResource(myItems.value[selectedElementIndex!!].itemIcon), lengthIcon = getLengthResource(myItems.value[selectedElementIndex!!].itemLength), amount = myItems.value[selectedElementIndex!!].quantity, - onClickUse = { }, + onClickUse = { + showDialog = false + navController + .navigate( + NavigationItems + .ApplyItem.route + .replace( + "{itemId}", + myItems.value[selectedElementIndex!!].id.toString() + ) + ) + }, onClickCancel = { showDialog = false } ) } From 35a7c9d959abea512e1ddea239f4a7d0cbc1ddae Mon Sep 17 00:00:00 2001 From: Nacho Date: Mon, 20 Jan 2025 15:23:40 +0100 Subject: [PATCH 6/7] Slowdowns and UI - Current item can be seen from a character when clicked on it, you can also see how much time left does that item have on that character. - Fixed slowdown issue in the items screen. Also fixed this issue in the storage screen as it'd also affect it if there are a lot of characters in the storage. --- .../vbhelper/components/CharacterEntry.kt | 14 ++---- .../vbhelper/components/ItemElement.kt | 11 +++-- .../vbhelper/screens/StorageScreen.kt | 42 ++++++++-------- .../screens/homeScreens/BEBEmHomeScreen.kt | 20 ++++++++ .../screens/homeScreens/BEDiMHomeScreen.kt | 48 +++++++++++++++---- .../itemsScreen/ItemsScreenControllerImpl.kt | 5 +- .../screens/itemsScreen/ItemsStore.kt | 26 +++++----- .../vbhelper/screens/itemsScreen/MyItems.kt | 48 +++++++++---------- 8 files changed, 126 insertions(+), 88 deletions(-) diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/components/CharacterEntry.kt b/app/src/main/java/com/github/nacabaro/vbhelper/components/CharacterEntry.kt index ceebb76..6df7570 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/components/CharacterEntry.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/components/CharacterEntry.kt @@ -1,6 +1,5 @@ package com.github.nacabaro.vbhelper.components -import android.util.Log import android.widget.Toast import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement @@ -23,22 +22,18 @@ import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp import com.github.nacabaro.vbhelper.utils.BitmapData import com.github.nacabaro.vbhelper.utils.getBitmap import androidx.compose.ui.graphics.Shape import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.unit.Dp -import androidx.compose.ui.unit.TextUnit import com.github.nacabaro.vbhelper.utils.getObscuredBitmap -import java.nio.ByteBuffer @Composable fun CharacterEntry( icon: BitmapData, - obscure: Boolean = false, modifier: Modifier = Modifier, + obscure: Boolean = false, shape: Shape = MaterialTheme.shapes.medium, multiplier: Int = 3, onClick: () -> Unit = { } @@ -79,8 +74,6 @@ fun ItemDisplay( icon: Int, textValue: String, modifier: Modifier = Modifier, - iconSize: Dp = 48.dp, - textSize: TextUnit = 24.sp, definition: String = "", ) { val context = LocalContext.current @@ -101,15 +94,14 @@ fun ItemDisplay( painter = painterResource(icon), contentDescription = "Vitals", modifier = Modifier + .fillMaxSize(0.5f) .padding(8.dp) - .size(iconSize) ) Text( text = textValue, textAlign = TextAlign.Center, - fontSize = textSize, fontFamily = MaterialTheme.typography.titleLarge.fontFamily, - fontWeight = FontWeight.Bold + fontWeight = FontWeight.Bold, ) } } 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 07778ac..327d50a 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 @@ -25,6 +25,7 @@ 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.screens.itemsScreen.ItemsScreenControllerImpl import com.github.nacabaro.vbhelper.ui.theme.VBHelperTheme import kotlin.math.absoluteValue @@ -159,11 +160,11 @@ fun ItemDialog( fun getIconResource(index: Int): Int { return when (index) { - 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 + ItemsScreenControllerImpl.ItemTypes.PPTraining.id -> R.drawable.baseline_agility_24 + ItemsScreenControllerImpl.ItemTypes.APTraining.id -> R.drawable.baseline_attack_24 + ItemsScreenControllerImpl.ItemTypes.HPTraining.id -> R.drawable.baseline_shield_24 + ItemsScreenControllerImpl.ItemTypes.BPTraining.id -> R.drawable.baseline_trophy_24 + ItemsScreenControllerImpl.ItemTypes.AllTraining.id -> R.drawable.baseline_arrow_up_24 6 -> R.drawable.baseline_timer_24 7 -> R.drawable.baseline_rank_24 8 -> R.drawable.baseline_vitals_24 diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/StorageScreen.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/StorageScreen.kt index ac0f28c..89a6e52 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/StorageScreen.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/StorageScreen.kt @@ -99,31 +99,31 @@ fun StorageScreen( selectedCharacter = index.id } ) + } + } - if (selectedCharacter != null) { - StorageDialog( - characterId = selectedCharacter!!, - onDismissRequest = { selectedCharacter = null }, - onClickSetActive = { - coroutineScope.launch { - withContext(Dispatchers.IO) { - storageRepository.setActiveCharacter(selectedCharacter!!) - selectedCharacter = null - } - navController.navigate(NavigationItems.Home.route) - } - }, - onSendToBracelet = { - navController.navigate( - NavigationItems.Scan.route.replace( - "{characterId}", - selectedCharacter.toString() - ) - ) + if (selectedCharacter != null) { + StorageDialog( + characterId = selectedCharacter!!, + onDismissRequest = { selectedCharacter = null }, + onClickSetActive = { + coroutineScope.launch { + withContext(Dispatchers.IO) { + storageRepository.setActiveCharacter(selectedCharacter!!) + selectedCharacter = null } + navController.navigate(NavigationItems.Home.route) + } + }, + onSendToBracelet = { + navController.navigate( + NavigationItems.Scan.route.replace( + "{characterId}", + selectedCharacter.toString() + ) ) } - } + ) } } } diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/BEBEmHomeScreen.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/BEBEmHomeScreen.kt index 433530c..9b58058 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/BEBEmHomeScreen.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/BEBEmHomeScreen.kt @@ -15,8 +15,10 @@ import com.github.nacabaro.vbhelper.R import com.github.nacabaro.vbhelper.components.CharacterEntry import com.github.nacabaro.vbhelper.components.ItemDisplay import com.github.nacabaro.vbhelper.components.TransformationHistoryCard +import com.github.nacabaro.vbhelper.components.getIconResource import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData import com.github.nacabaro.vbhelper.dtos.CharacterDtos +import com.github.nacabaro.vbhelper.screens.itemsScreen.ItemsScreenControllerImpl import com.github.nacabaro.vbhelper.utils.BitmapData import java.util.Locale @@ -153,6 +155,24 @@ fun BEBEmHomeScreen( .aspectRatio(1f) .padding(8.dp) ) + if (beData.itemRemainingTime != 0) { + ItemDisplay( + icon = getIconResource(beData.itemType), + textValue = "${beData.itemRemainingTime} m", + definition = when (beData.itemType) { + ItemsScreenControllerImpl.ItemTypes.PPTraining.id -> "PP Training" + ItemsScreenControllerImpl.ItemTypes.HPTraining.id -> "HP Training" + ItemsScreenControllerImpl.ItemTypes.APTraining.id -> "AP Training" + ItemsScreenControllerImpl.ItemTypes.BPTraining.id -> "BP Training" + ItemsScreenControllerImpl.ItemTypes.AllTraining.id -> "All Training" + else -> "" + }, + modifier = Modifier + .weight(1f) + .aspectRatio(1f) + .padding(8.dp) + ) + } } Row ( modifier = Modifier diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/BEDiMHomeScreen.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/BEDiMHomeScreen.kt index 3d8ef15..9b4ea06 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/BEDiMHomeScreen.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/BEDiMHomeScreen.kt @@ -16,8 +16,10 @@ import com.github.nacabaro.vbhelper.R import com.github.nacabaro.vbhelper.components.CharacterEntry import com.github.nacabaro.vbhelper.components.ItemDisplay import com.github.nacabaro.vbhelper.components.TransformationHistoryCard +import com.github.nacabaro.vbhelper.components.getIconResource import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData import com.github.nacabaro.vbhelper.dtos.CharacterDtos +import com.github.nacabaro.vbhelper.screens.itemsScreen.ItemsScreenControllerImpl import com.github.nacabaro.vbhelper.utils.BitmapData import kotlin.text.format @@ -33,7 +35,7 @@ fun BEDiMHomeScreen( .padding(top = contentPadding.calculateTopPadding()) .verticalScroll(state = rememberScrollState()) ) { - Row ( + Row( modifier = Modifier .fillMaxWidth() ) { @@ -49,7 +51,7 @@ fun BEDiMHomeScreen( .weight(1f) .aspectRatio(1f) ) - Column ( + Column( modifier = Modifier .weight(0.5f) .aspectRatio(0.5f) @@ -74,7 +76,7 @@ fun BEDiMHomeScreen( ) } } - Row ( + Row( modifier = Modifier .fillMaxWidth() ) { @@ -108,7 +110,7 @@ fun BEDiMHomeScreen( .padding(8.dp) ) } - Row ( + Row( modifier = Modifier .fillMaxWidth() ) { @@ -130,8 +132,13 @@ fun BEDiMHomeScreen( textValue = when { activeMon.totalBattlesLost == 0 -> "0.00 %" else -> { - val battleWinPercentage = activeMon.totalBattlesWon.toFloat() / (activeMon.totalBattlesWon + activeMon.totalBattlesLost).toFloat() - String.format(Locale.getDefault(), "%.2f", battleWinPercentage * 100) + " %" // Specify locale + val battleWinPercentage = + activeMon.totalBattlesWon.toFloat() / (activeMon.totalBattlesWon + activeMon.totalBattlesLost).toFloat() + String.format( + Locale.getDefault(), + "%.2f", + battleWinPercentage * 100 + ) + " %" // Specify locale } }, definition = "Total battle win %", @@ -145,8 +152,13 @@ fun BEDiMHomeScreen( textValue = when { activeMon.totalBattlesLost == 0 -> "0.00 %" else -> { - val battleWinPercentage = activeMon.currentPhaseBattlesWon.toFloat() / (activeMon.currentPhaseBattlesWon + activeMon.currentPhaseBattlesLost).toFloat() - String.format(Locale.getDefault(), "%.2f", battleWinPercentage * 100) + " %" // Specify locale + val battleWinPercentage = + activeMon.currentPhaseBattlesWon.toFloat() / (activeMon.currentPhaseBattlesWon + activeMon.currentPhaseBattlesLost).toFloat() + String.format( + Locale.getDefault(), + "%.2f", + battleWinPercentage * 100 + ) + " %" // Specify locale } }, definition = "Current phase win %", @@ -155,8 +167,26 @@ fun BEDiMHomeScreen( .aspectRatio(1f) .padding(8.dp) ) + if (beData.itemRemainingTime != 0) { + ItemDisplay( + icon = getIconResource(beData.itemType), + textValue = "${beData.itemRemainingTime} m", + definition = when (beData.itemType) { + ItemsScreenControllerImpl.ItemTypes.PPTraining.id -> "PP Training" + ItemsScreenControllerImpl.ItemTypes.HPTraining.id -> "HP Training" + ItemsScreenControllerImpl.ItemTypes.APTraining.id -> "AP Training" + ItemsScreenControllerImpl.ItemTypes.BPTraining.id -> "BP Training" + ItemsScreenControllerImpl.ItemTypes.AllTraining.id -> "All Training" + else -> "" + }, + modifier = Modifier + .weight(1f) + .aspectRatio(1f) + .padding(8.dp) + ) + } } - Row ( + Row( modifier = Modifier .fillMaxWidth() ) { 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 index 70fc514..c604236 100644 --- 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 @@ -5,7 +5,6 @@ import androidx.lifecycle.lifecycleScope import com.github.nacabaro.vbhelper.database.AppDatabase import com.github.nacabaro.vbhelper.di.VBHelper import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData -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 @@ -17,7 +16,7 @@ class ItemsScreenControllerImpl ( ): ItemsScreenController { private var database: AppDatabase - private enum class ItemTypes(val id: Int) { + enum class ItemTypes(val id: Int) { PPTraining(1), HPTraining(2), APTraining(3), @@ -39,7 +38,7 @@ class ItemsScreenControllerImpl ( val item = getItem(itemId) val characterData = database.userCharacterDao().getCharacter(characterId) val beCharacterData: BECharacterData - var vbCharacterData: VBCharacterData + //var vbCharacterData: VBCharacterData if (characterData.characterType == DeviceType.BEDevice) { beCharacterData = database.userCharacterDao().getBeData(characterId) 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 faea09d..771838c 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 @@ -32,7 +32,6 @@ fun ItemsStore( val application = LocalContext.current.applicationContext as VBHelper val itemsRepository = ItemsRepository(application.container.db) val myItems = remember { mutableStateOf(emptyList()) } - var showDialog by remember { mutableStateOf(false) } var selectedElementIndex by remember { mutableStateOf(null) } LaunchedEffect(itemsRepository) { @@ -55,23 +54,22 @@ fun ItemsStore( modifier = Modifier .padding(8.dp), onClick = { - showDialog = true selectedElementIndex = myItems.value.indexOf(index) } ) - - if (showDialog && selectedElementIndex != null) { - ItemDialog( - name = myItems.value[selectedElementIndex!!].name, - description = myItems.value[selectedElementIndex!!].description, - itemIcon = getIconResource(myItems.value[selectedElementIndex!!].itemIcon), - lengthIcon = getLengthResource(myItems.value[selectedElementIndex!!].itemLength), - amount = myItems.value[selectedElementIndex!!].quantity, - onClickUse = { }, - onClickCancel = { showDialog = false } - ) - } } } + + if (selectedElementIndex != null) { + ItemDialog( + name = myItems.value[selectedElementIndex!!].name, + description = myItems.value[selectedElementIndex!!].description, + itemIcon = getIconResource(myItems.value[selectedElementIndex!!].itemIcon), + lengthIcon = getLengthResource(myItems.value[selectedElementIndex!!].itemLength), + amount = myItems.value[selectedElementIndex!!].quantity, + onClickUse = { }, + onClickCancel = { selectedElementIndex = null } + ) + } } } \ No newline at end of file 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 6513f26..098c2fd 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 @@ -37,7 +37,6 @@ fun MyItems( val application = LocalContext.current.applicationContext as VBHelper val itemsRepository = ItemsRepository(application.container.db) val myItems = remember { mutableStateOf(emptyList()) } - var showDialog by remember { mutableStateOf(false) } var selectedElementIndex by remember { mutableStateOf(null) } LaunchedEffect(itemsRepository) { @@ -66,34 +65,33 @@ fun MyItems( modifier = Modifier .padding(8.dp), onClick = { - showDialog = true selectedElementIndex = myItems.value.indexOf(index) } ) - - if (showDialog && selectedElementIndex != null) { - ItemDialog( - name = myItems.value[selectedElementIndex!!].name, - description = myItems.value[selectedElementIndex!!].description, - itemIcon = getIconResource(myItems.value[selectedElementIndex!!].itemIcon), - lengthIcon = getLengthResource(myItems.value[selectedElementIndex!!].itemLength), - amount = myItems.value[selectedElementIndex!!].quantity, - onClickUse = { - showDialog = false - navController - .navigate( - NavigationItems - .ApplyItem.route - .replace( - "{itemId}", - myItems.value[selectedElementIndex!!].id.toString() - ) - ) - }, - onClickCancel = { showDialog = false } - ) - } } } + + if (selectedElementIndex != null) { + ItemDialog( + name = myItems.value[selectedElementIndex!!].name, + description = myItems.value[selectedElementIndex!!].description, + itemIcon = getIconResource(myItems.value[selectedElementIndex!!].itemIcon), + lengthIcon = getLengthResource(myItems.value[selectedElementIndex!!].itemLength), + amount = myItems.value[selectedElementIndex!!].quantity, + onClickUse = { + navController + .navigate( + NavigationItems + .ApplyItem.route + .replace( + "{itemId}", + myItems.value[selectedElementIndex!!].id.toString() + ) + ) + selectedElementIndex = null + }, + onClickCancel = { selectedElementIndex = null } + ) + } } } \ No newline at end of file From 972a640394d3200150ddd539347c49ca5b60f6f1 Mon Sep 17 00:00:00 2001 From: Nacho Date: Mon, 20 Jan 2025 15:46:53 +0100 Subject: [PATCH 7/7] Added missing icons, ready to merge! --- .../nacabaro/vbhelper/components/ItemElement.kt | 16 ++++++++++++---- .../res/drawable/baseline_double_arrow_down.xml | 12 ++++++++++++ .../res/drawable/baseline_double_arrow_up.xml | 12 ++++++++++++ .../res/drawable/baseline_single_arrow_down.xml | 9 +++++++++ .../res/drawable/baseline_single_arrow_up.xml | 9 +++++++++ .../res/drawable/baseline_triple_arrow_down.xml | 15 +++++++++++++++ .../res/drawable/baseline_triple_arrow_up.xml | 15 +++++++++++++++ 7 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/drawable/baseline_double_arrow_down.xml create mode 100644 app/src/main/res/drawable/baseline_double_arrow_up.xml create mode 100644 app/src/main/res/drawable/baseline_single_arrow_down.xml create mode 100644 app/src/main/res/drawable/baseline_single_arrow_up.xml create mode 100644 app/src/main/res/drawable/baseline_triple_arrow_down.xml create mode 100644 app/src/main/res/drawable/baseline_triple_arrow_up.xml 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 327d50a..067d164 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 @@ -27,7 +27,6 @@ import androidx.compose.ui.window.DialogProperties import com.github.nacabaro.vbhelper.R import com.github.nacabaro.vbhelper.screens.itemsScreen.ItemsScreenControllerImpl import com.github.nacabaro.vbhelper.ui.theme.VBHelperTheme -import kotlin.math.absoluteValue @Composable fun ItemElement( @@ -173,15 +172,24 @@ fun getIconResource(index: Int): Int { } fun getLengthResource(index: Int): Int { - return when (index.absoluteValue) { + return when (index) { 15 -> R.drawable.baseline_15_min_timer 30 -> R.drawable.baseline_30_min_timer 60 -> R.drawable.baseline_60_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 + -720 -> R.drawable.baseline_12_hour_timer + -1440 -> R.drawable.baseline_24_hour_timer 6000 -> R.drawable.baseline_reset_24 + 1000 -> R.drawable.baseline_single_arrow_up + 2500 -> R.drawable.baseline_double_arrow_up + 5000 -> R.drawable.baseline_triple_arrow_up + 9999 -> R.drawable.baseline_health_24 + -500 -> R.drawable.baseline_single_arrow_down + -1000 -> R.drawable.baseline_double_arrow_down + -2500 -> R.drawable.baseline_triple_arrow_down + -9999 -> R.drawable.baseline_reset_24 else -> R.drawable.baseline_question_mark_24 } } diff --git a/app/src/main/res/drawable/baseline_double_arrow_down.xml b/app/src/main/res/drawable/baseline_double_arrow_down.xml new file mode 100644 index 0000000..0c5ea21 --- /dev/null +++ b/app/src/main/res/drawable/baseline_double_arrow_down.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/baseline_double_arrow_up.xml b/app/src/main/res/drawable/baseline_double_arrow_up.xml new file mode 100644 index 0000000..b54d9a0 --- /dev/null +++ b/app/src/main/res/drawable/baseline_double_arrow_up.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/baseline_single_arrow_down.xml b/app/src/main/res/drawable/baseline_single_arrow_down.xml new file mode 100644 index 0000000..6a59bd4 --- /dev/null +++ b/app/src/main/res/drawable/baseline_single_arrow_down.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/baseline_single_arrow_up.xml b/app/src/main/res/drawable/baseline_single_arrow_up.xml new file mode 100644 index 0000000..4223055 --- /dev/null +++ b/app/src/main/res/drawable/baseline_single_arrow_up.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/baseline_triple_arrow_down.xml b/app/src/main/res/drawable/baseline_triple_arrow_down.xml new file mode 100644 index 0000000..1833357 --- /dev/null +++ b/app/src/main/res/drawable/baseline_triple_arrow_down.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/drawable/baseline_triple_arrow_up.xml b/app/src/main/res/drawable/baseline_triple_arrow_up.xml new file mode 100644 index 0000000..b3eabe6 --- /dev/null +++ b/app/src/main/res/drawable/baseline_triple_arrow_up.xml @@ -0,0 +1,15 @@ + + + + +