~cytrogen/vbhelper

c0a67e382ba6a158a82edd32cca0c3da83a5f15f — Nacho 1 year, 3 months ago bc7a05c
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
A app/src/main/assets/items.db => app/src/main/assets/items.db +0 -0
A app/src/main/java/com/github/nacabaro/vbhelper/components/ItemElement.kt => app/src/main/java/com/github/nacabaro/vbhelper/components/ItemElement.kt +63 -0
@@ 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

A app/src/main/java/com/github/nacabaro/vbhelper/daos/ItemDao.kt => app/src/main/java/com/github/nacabaro/vbhelper/daos/ItemDao.kt +19 -0
@@ 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<Items>

    @Query("""
        SELECT Items.*, UserItems.quantity
        FROM Items
        JOIN UserItems ON Items.id = UserItems.itemId
    """)
    suspend fun getAllUserItems(): List<ItemDtos.ItemsWithQuantities>
}
\ No newline at end of file

M app/src/main/java/com/github/nacabaro/vbhelper/database/AppDatabase.kt => app/src/main/java/com/github/nacabaro/vbhelper/database/AppDatabase.kt +7 -1
@@ 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

M app/src/main/java/com/github/nacabaro/vbhelper/di/DefaultAppContainer.kt => app/src/main/java/com/github/nacabaro/vbhelper/di/DefaultAppContainer.kt +3 -1
@@ 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)

A app/src/main/java/com/github/nacabaro/vbhelper/domain/items/Items.kt => app/src/main/java/com/github/nacabaro/vbhelper/domain/items/Items.kt +15 -0
@@ 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
)

A app/src/main/java/com/github/nacabaro/vbhelper/domain/items/UserItems.kt => app/src/main/java/com/github/nacabaro/vbhelper/domain/items/UserItems.kt +20 -0
@@ 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,
)

A app/src/main/java/com/github/nacabaro/vbhelper/dtos/ItemDtos.kt => app/src/main/java/com/github/nacabaro/vbhelper/dtos/ItemDtos.kt +15 -0
@@ 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

M app/src/main/java/com/github/nacabaro/vbhelper/navigation/AppNavigation.kt => app/src/main/java/com/github/nacabaro/vbhelper/navigation/AppNavigation.kt +2 -1
@@ 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
                )
            }

A app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/MyItems.kt => app/src/main/java/com/github/nacabaro/vbhelper/screens/itemsScreen/MyItems.kt +61 -0
@@ 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<ItemDtos.ItemsWithQuantities>()) }

    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

A app/src/main/java/com/github/nacabaro/vbhelper/source/ItemsRepository.kt => app/src/main/java/com/github/nacabaro/vbhelper/source/ItemsRepository.kt +17 -0
@@ 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<Items> {
        return db.itemDao().getAllItems()
    }

    suspend fun getUserItems(): List<ItemDtos.ItemsWithQuantities> {
        return db.itemDao().getAllUserItems()
    }
}
\ No newline at end of file

A app/src/main/res/drawable/baseline_15_min_timer.xml => app/src/main/res/drawable/baseline_15_min_timer.xml +15 -0
@@ 0,0 1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="960"
    android:viewportHeight="960">
  <path
      android:pathData="m360,120v-80h240v80zM480,880c-49.33,0 -95.83,-9.5 -139.5,-28.5 -43.67,-19 -81.83,-44.83 -114.5,-77.5 -32.67,-32.67 -58.5,-70.83 -77.5,-114.5 -19,-43.67 -28.5,-90.17 -28.5,-139.5 0,-49.33 9.5,-95.83 28.5,-139.5 19,-43.67 44.83,-81.83 77.5,-114.5 32.67,-32.67 70.83,-58.5 114.5,-77.5 43.67,-19 90.17,-28.5 139.5,-28.5 41.33,0 81,6.67 119,20 38,13.33 73.67,32.67 107,58l56,-56 56,56 -56,56c25.33,33.33 44.67,69 58,107 13.33,38 20,77.67 20,119 0,49.33 -9.5,95.83 -28.5,139.5 -19,43.67 -44.83,81.83 -77.5,114.5 -32.67,32.67 -70.83,58.5 -114.5,77.5 -43.67,19 -90.17,28.5 -139.5,28.5zM480,800c77.33,0 143.33,-27.33 198,-82 54.67,-54.67 82,-120.67 82,-198 0,-77.33 -27.33,-143.33 -82,-198 -54.67,-54.67 -120.67,-82 -198,-82 -77.33,0 -143.33,27.33 -198,82 -54.67,54.67 -82,120.67 -82,198 0,77.33 27.33,143.33 82,198 54.67,54.67 120.67,82 198,82z"
      android:fillColor="#000000"/>
  <path
      android:pathData="m337.48,503.79q0,-11.09 0.43,-29.01 0.85,-17.92 1.28,-31.57 -2.13,2.56 -9.39,9.39 -6.83,6.4 -12.8,11.52L282.01,492.27 250.87,453.44 349,375.36L401.91,375.36L401.91,680L337.48,680Z"
      android:fillColor="#000000"/>
  <path
      android:pathData="m594.76,485.44q27.73,0 49.49,10.67 21.76,10.67 34.13,31.15 12.8,20.48 12.8,50.77 0,49.49 -30.72,78.08Q629.75,684.27 569.59,684.27 545.7,684.27 524.36,680 503.46,675.73 487.67,667.63L487.67,612.16q15.79,8.11 37.97,14.08 22.19,5.55 41.81,5.55 28.59,0 43.52,-11.52 15.36,-11.95 15.36,-36.69 0,-46.08 -61.01,-46.08 -11.95,0 -24.75,2.56 -12.8,2.13 -21.33,4.27l-25.6,-13.65 11.52,-155.31l165.12,0l0,54.61L561.48,429.97l-5.55,59.73q7.25,-1.28 15.36,-2.56 8.53,-1.71 23.47,-1.71z"
      android:fillColor="#000000"/>
</vector>

A app/src/main/res/drawable/baseline_30_min_timer.xml => app/src/main/res/drawable/baseline_30_min_timer.xml +15 -0
@@ 0,0 1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="960"
    android:viewportHeight="960">
  <path
      android:pathData="m360,120v-80h240v80zM480,880c-49.33,0 -95.83,-9.5 -139.5,-28.5 -43.67,-19 -81.83,-44.83 -114.5,-77.5 -32.67,-32.67 -58.5,-70.83 -77.5,-114.5 -19,-43.67 -28.5,-90.17 -28.5,-139.5 0,-49.33 9.5,-95.83 28.5,-139.5 19,-43.67 44.83,-81.83 77.5,-114.5 32.67,-32.67 70.83,-58.5 114.5,-77.5 43.67,-19 90.17,-28.5 139.5,-28.5 41.33,0 81,6.67 119,20 38,13.33 73.67,32.67 107,58l56,-56 56,56 -56,56c25.33,33.33 44.67,69 58,107 13.33,38 20,77.67 20,119 0,49.33 -9.5,95.83 -28.5,139.5 -19,43.67 -44.83,81.83 -77.5,114.5 -32.67,32.67 -70.83,58.5 -114.5,77.5 -43.67,19 -90.17,28.5 -139.5,28.5zM480,800c77.33,0 143.33,-27.33 198,-82 54.67,-54.67 82,-120.67 82,-198 0,-77.33 -27.33,-143.33 -82,-198 -54.67,-54.67 -120.67,-82 -198,-82 -77.33,0 -143.33,27.33 -198,82 -54.67,54.67 -82,120.67 -82,198 0,77.33 27.33,143.33 82,198 54.67,54.67 120.67,82 198,82z"
      android:fillColor="#000000"/>
  <path
      android:pathData="m453.77,437.38q0,31.57 -19.2,50.35 -18.77,18.77 -46.51,25.6l0,1.28q36.69,4.27 55.47,22.19 19.2,17.92 19.2,48.21 0,26.45 -13.23,47.79Q436.71,653.7 409.4,666.07 382.52,678.02 339.85,678.02q-49.49,0 -87.89,-16.64L251.96,606.76q19.63,9.81 40.96,14.93 21.76,5.12 40.11,5.12 34.56,0 48.21,-11.95 14.08,-11.95 14.08,-33.71 0,-12.8 -6.4,-21.33Q382.52,550.87 366.31,546.6 350.52,541.91 321.93,541.91L298.89,541.91l0,-49.49l23.47,0q28.16,0 42.67,-5.12 14.93,-5.55 20.05,-14.51 5.55,-9.39 5.55,-21.33 0,-16.21 -10.24,-25.17 -9.81,-9.39 -33.28,-9.39 -21.76,0 -37.97,7.68 -15.79,7.25 -26.88,14.51L252.39,394.71q17.92,-12.8 41.81,-21.33 24.32,-8.53 57.6,-8.53 46.93,0 74.24,19.2 27.73,18.77 27.73,53.33z"
      android:fillColor="#000000"/>
  <path
      android:pathData="m715.32,521.43q0,49.07 -10.67,84.05 -10.24,34.99 -33.71,53.76Q647.91,678.02 608.66,678.02q-55.04,0 -80.64,-41.39 -25.6,-41.81 -25.6,-115.2 0,-49.49 10.24,-84.48 10.24,-34.99 33.71,-53.76 23.47,-18.77 62.29,-18.77 54.61,0 80.64,41.39 26.03,41.39 26.03,115.63zM566.42,521.43q0,52.05 8.96,78.51 8.96,26.03 33.28,26.03 23.89,0 33.28,-26.03 9.39,-26.03 9.39,-78.51 0,-52.05 -9.39,-78.51 -9.39,-26.45 -33.28,-26.45 -24.32,0 -33.28,26.45 -8.96,26.45 -8.96,78.51z"
      android:fillColor="#000000"/>
</vector>

A app/src/main/res/drawable/baseline_60_min_timer.xml => app/src/main/res/drawable/baseline_60_min_timer.xml +15 -0
@@ 0,0 1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="960"
    android:viewportHeight="960">
  <path
      android:pathData="m360,120v-80h240v80zM480,880c-49.33,0 -95.83,-9.5 -139.5,-28.5 -43.67,-19 -81.83,-44.83 -114.5,-77.5 -32.67,-32.67 -58.5,-70.83 -77.5,-114.5 -19,-43.67 -28.5,-90.17 -28.5,-139.5 0,-49.33 9.5,-95.83 28.5,-139.5 19,-43.67 44.83,-81.83 77.5,-114.5 32.67,-32.67 70.83,-58.5 114.5,-77.5 43.67,-19 90.17,-28.5 139.5,-28.5 41.33,0 81,6.67 119,20 38,13.33 73.67,32.67 107,58l56,-56 56,56 -56,56c25.33,33.33 44.67,69 58,107 13.33,38 20,77.67 20,119 0,49.33 -9.5,95.83 -28.5,139.5 -19,43.67 -44.83,81.83 -77.5,114.5 -32.67,32.67 -70.83,58.5 -114.5,77.5 -43.67,19 -90.17,28.5 -139.5,28.5zM480,800c77.33,0 143.33,-27.33 198,-82 54.67,-54.67 82,-120.67 82,-198 0,-77.33 -27.33,-143.33 -82,-198 -54.67,-54.67 -120.67,-82 -198,-82 -77.33,0 -143.33,27.33 -198,82 -54.67,54.67 -82,120.67 -82,198 0,77.33 27.33,143.33 82,198 54.67,54.67 120.67,82 198,82z"
      android:fillColor="#000000"/>
  <path
      android:pathData="m240.86,541.97q0,-26.45 3.84,-52.05 3.84,-25.6 13.23,-48.21 9.81,-23.04 26.88,-40.53 17.49,-17.92 43.95,-27.73 26.88,-10.24 64.85,-10.24 8.96,0 20.91,0.85 11.95,0.43 20.05,2.13L434.57,417.81q-8.11,-2.13 -17.92,-2.99 -9.39,-1.28 -18.77,-1.28 -37.97,0 -58.88,11.95 -20.48,11.95 -29.01,33.71 -8.53,21.33 -9.81,49.49l2.56,0Q311.26,493.76 327.05,483.52 343.26,473.28 368.86,473.28q40.11,0 63.57,25.17 23.47,25.17 23.47,71.25 0,49.49 -28.16,77.65Q400.01,675.52 352.22,675.52q-31.15,0 -56.32,-14.08Q270.73,646.93 255.79,617.49 240.86,587.62 240.86,541.97ZM350.94,623.89q18.77,0 30.72,-12.8 11.95,-13.23 11.95,-40.53 0,-22.19 -10.24,-34.99 -10.24,-12.8 -31.15,-12.8 -14.08,0 -24.75,6.4 -10.67,5.97 -16.64,15.79 -5.97,9.81 -5.97,20.05 0,14.08 5.12,27.73 5.12,13.23 15.36,22.19 10.67,8.96 25.6,8.96z"
      android:fillColor="#000000"/>
  <path
      android:pathData="m710.62,518.93q0,49.07 -10.67,84.05 -10.24,34.99 -33.71,53.76Q643.21,675.52 603.96,675.52q-55.04,0 -80.64,-41.39 -25.6,-41.81 -25.6,-115.2 0,-49.49 10.24,-84.48 10.24,-34.99 33.71,-53.76 23.47,-18.77 62.29,-18.77 54.61,0 80.64,41.39 26.03,41.39 26.03,115.63zM561.71,518.93q0,52.05 8.96,78.51 8.96,26.03 33.28,26.03 23.89,0 33.28,-26.03 9.39,-26.03 9.39,-78.51 0,-52.05 -9.39,-78.51 -9.39,-26.45 -33.28,-26.45 -24.32,0 -33.28,26.45 -8.96,26.45 -8.96,78.51z"
      android:fillColor="#000000"/>
</vector>

A app/src/main/res/drawable/baseline_shield_24.xml => app/src/main/res/drawable/baseline_shield_24.xml +9 -0
@@ 0,0 1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
  <path
      android:fillColor="#FF000000"
      android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12V5l-9,-4z"/>
</vector>