diff --git a/app/src/main/assets/items.db b/app/src/main/assets/items.db new file mode 100644 index 0000000..9064ecf Binary files /dev/null and b/app/src/main/assets/items.db differ diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/components/ItemElement.kt b/app/src/main/java/com/github/nacabaro/vbhelper/components/ItemElement.kt 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 @@ + + +