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 1d1485a..033f574 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/MainActivity.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/MainActivity.kt @@ -18,21 +18,20 @@ import com.github.cfogrady.vbnfc.be.BENfcCharacter import com.github.cfogrady.vbnfc.data.NfcCharacter import com.github.cfogrady.vbnfc.vb.VBNfcCharacter import com.github.nacabaro.vbhelper.di.VBHelper -import com.github.nacabaro.vbhelper.domain.Dim +import com.github.nacabaro.vbhelper.domain.characters.Card import com.github.nacabaro.vbhelper.domain.Sprites -import com.github.nacabaro.vbhelper.domain.Character +import com.github.nacabaro.vbhelper.domain.characters.Character +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.device_data.VBCharacterData import com.github.nacabaro.vbhelper.navigation.AppNavigationHandlers import com.github.nacabaro.vbhelper.screens.scanScreen.ScanScreenControllerImpl import com.github.nacabaro.vbhelper.screens.SettingsScreenController import com.github.nacabaro.vbhelper.source.ApkSecretsImporter import com.github.nacabaro.vbhelper.ui.theme.VBHelperTheme +import com.github.nacabaro.vbhelper.utils.DeviceType import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.launch -import java.util.Date import java.util.GregorianCalendar class MainActivity : ComponentActivity() { @@ -113,7 +112,7 @@ class MainActivity : ComponentActivity() { Log.i("MainActivity", "Card name: ${card is BemCard}") - val dimModel = Dim( + val cardModel = Card( dimId = card.header.dimId, logo = card.spriteData.sprites[0].pixelData, name = card.spriteData.text, // TODO Make user write card name @@ -125,7 +124,7 @@ class MainActivity : ComponentActivity() { val dimId = storageRepository .dimDao() - .insertNewDim(dimModel) + .insertNewDim(cardModel) val characters = card.characterStats.characterEntries @@ -216,7 +215,6 @@ class MainActivity : ComponentActivity() { // /* TODO: - - Make it able to detect the different model of watches - Support for regular VB The good news is that the theory behind inserting to the database should be working @@ -255,8 +253,8 @@ class MainActivity : ComponentActivity() { activityLevel = nfcCharacter.value!!.activityLevel.toInt(), heartRateCurrent = nfcCharacter.value!!.heartRateCurrent.toInt(), characterType = when (nfcCharacter.value) { - is BENfcCharacter -> com.github.nacabaro.vbhelper.domain.DeviceType.BEDevice - else -> com.github.nacabaro.vbhelper.domain.DeviceType.VBDevice + is BENfcCharacter -> DeviceType.BEDevice + else -> DeviceType.VBDevice }, isActive = true ) @@ -307,12 +305,16 @@ class MainActivity : ComponentActivity() { val date = GregorianCalendar(item.year.toInt(), item.month.toInt(), item.day.toInt()) .time .time + storageRepository .characterDao() .insertTransformation(characterId, item.toCharIndex.toInt(), dimData.id, date) + + storageRepository + .dexDao() + .insertCharacter(item.toCharIndex.toInt(), dimData.id, date) } } - } else if (nfcCharacter.value is VBNfcCharacter) { return "Not implemented yet" } diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/components/DexDimEntry.kt b/app/src/main/java/com/github/nacabaro/vbhelper/components/DexDimEntry.kt index 336b2b9..36c4976 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/components/DexDimEntry.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/components/DexDimEntry.kt @@ -2,6 +2,7 @@ package com.github.nacabaro.vbhelper.components import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size @@ -23,6 +24,8 @@ import com.github.nacabaro.vbhelper.utils.getBitmap fun DexDiMEntry( name: String, logo: BitmapData, + obtainedCharacters: Int, + totalCharacters: Int, onClick: () -> Unit, modifier: Modifier = Modifier ) { @@ -50,11 +53,21 @@ fun DexDiMEntry( .padding(8.dp) .size(dpSize) ) - Text( - text = name, + Column( modifier = Modifier .padding(8.dp) - ) + ) { + Text( + text = name, + modifier = Modifier + ) + Text( + text = "$obtainedCharacters of $totalCharacters characters obtained", + fontFamily = MaterialTheme.typography.labelSmall.fontFamily, + fontSize = MaterialTheme.typography.labelSmall.fontSize, + modifier = Modifier + ) + } } } } \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/daos/CharacterDao.kt b/app/src/main/java/com/github/nacabaro/vbhelper/daos/CharacterDao.kt index e15aada..a42e6c7 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/daos/CharacterDao.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/daos/CharacterDao.kt @@ -3,10 +3,9 @@ package com.github.nacabaro.vbhelper.daos import androidx.room.Dao import androidx.room.Insert import androidx.room.Query -import com.github.nacabaro.vbhelper.domain.Character +import com.github.nacabaro.vbhelper.domain.characters.Character import com.github.nacabaro.vbhelper.domain.Sprites import com.github.nacabaro.vbhelper.dtos.CharacterDtos -import java.util.GregorianCalendar @Dao interface CharacterDao { @@ -28,15 +27,17 @@ interface CharacterDao { @Query("SELECT * FROM Sprites") suspend fun getAllSprites(): List - @Query(""" + @Query( + """ SELECT d.dimId as cardId, c.monIndex as charId FROM Character c JOIN UserCharacter uc ON c.id = uc.charId - JOIN Dim d ON c.dimId = d.id + JOIN Card d ON c.dimId = d.id WHERE uc.id = :charId - """) + """ + ) suspend fun getCharacterInfo(charId: Long): CharacterDtos.DiMInfo @Query(""" diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/daos/DexDao.kt b/app/src/main/java/com/github/nacabaro/vbhelper/daos/DexDao.kt new file mode 100644 index 0000000..d20b76f --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/daos/DexDao.kt @@ -0,0 +1,44 @@ +package com.github.nacabaro.vbhelper.daos + +import androidx.room.Dao +import androidx.room.Query +import com.github.nacabaro.vbhelper.dtos.CardDtos +import com.github.nacabaro.vbhelper.dtos.CharacterDtos + +@Dao +interface DexDao { + @Query(""" + INSERT OR IGNORE INTO Dex(id, discoveredOn) + VALUES ( + (SELECT id FROM Character WHERE monIndex = :charIndex AND dimId = :cardId), + :discoveredOn + ) + """) + fun insertCharacter(charIndex: Int, cardId: Long, discoveredOn: Long) + + @Query(""" + SELECT + c.id AS id, + c.sprite1 AS spriteIdle, + c.spritesWidth AS spriteWidth, + c.spritesHeight AS spriteHeight, + d.discoveredOn AS discoveredOn + FROM character c + LEFT JOIN dex d ON c.id = d.id + WHERE c.dimId = :cardId + """) + suspend fun getSingleCardProgress(cardId: Long): List + + @Query(""" + SELECT + c.id as cardId, + c.name as cardName, + c.logo as cardLogo, + c.logoWidth as logoWidth, + c.logoHeight as logoHeight, + (SELECT COUNT(*) FROM Character cc WHERE cc.dimId = c.id) AS totalCharacters, + (SELECT COUNT(*) FROM Dex d JOIN Character cc ON d.id = cc.id WHERE cc.dimId = c.id AND d.discoveredOn IS NOT NULL) AS obtainedCharacters + FROM Card c + """) + suspend fun getCardsWithProgress(): List +} \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/daos/DiMDao.kt b/app/src/main/java/com/github/nacabaro/vbhelper/daos/DiMDao.kt index 17527c1..885449f 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/daos/DiMDao.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/daos/DiMDao.kt @@ -4,16 +4,16 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query -import com.github.nacabaro.vbhelper.domain.Dim +import com.github.nacabaro.vbhelper.domain.characters.Card @Dao interface DiMDao { @Insert(onConflict = OnConflictStrategy.IGNORE) - suspend fun insertNewDim(dim: Dim): Long + suspend fun insertNewDim(card: Card): Long - @Query("SELECT * FROM Dim") - suspend fun getAllDims(): List + @Query("SELECT * FROM Card") + suspend fun getAllDims(): List - @Query("SELECT * FROM Dim WHERE dimId = :id") - fun getDimById(id: Int): Dim? + @Query("SELECT * FROM Card WHERE dimId = :id") + fun getDimById(id: Int): Card? } \ 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 e2cffed..90975cb 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 @@ -34,7 +34,8 @@ interface UserCharacterDao { """) fun getTransformationHistory(monId: Long): List? - @Query(""" + @Query( + """ SELECT uc.*, c.sprite1 AS spriteIdle, @@ -43,8 +44,9 @@ interface UserCharacterDao { d.isBEm as isBemCard FROM UserCharacter uc JOIN Character c ON uc.charId = c.id - JOIN Dim d ON c.dimId = d.id - """) + JOIN Card d ON c.dimId = d.id + """ + ) suspend fun getAllCharacters(): List @Query("SELECT * FROM UserCharacter WHERE id = :id") @@ -53,7 +55,8 @@ interface UserCharacterDao { @Query("SELECT * FROM BECharacterData WHERE id = :id") suspend fun getBeData(id: Long): BECharacterData - @Query(""" + @Query( + """ SELECT uc.*, c.sprite1 AS spriteIdle, @@ -62,10 +65,11 @@ interface UserCharacterDao { d.isBEm as isBemCard FROM UserCharacter uc JOIN Character c ON uc.charId = c.id - JOIN Dim d ON c.dimId = d.id + JOIN Card d ON c.dimId = d.id WHERE uc.isActive = 1 LIMIT 1 - """) + """ + ) suspend fun getActiveCharacter(): CharacterDtos.CharacterWithSprites? @Query("DELETE FROM UserCharacter WHERE id = :id") 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 6f1a35c..25501a5 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 @@ -3,11 +3,13 @@ package com.github.nacabaro.vbhelper.database import androidx.room.Database 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.UserCharacterDao -import com.github.nacabaro.vbhelper.domain.Character -import com.github.nacabaro.vbhelper.domain.Dim +import com.github.nacabaro.vbhelper.domain.characters.Character +import com.github.nacabaro.vbhelper.domain.characters.Card import com.github.nacabaro.vbhelper.domain.Sprites +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 @@ -15,16 +17,18 @@ import com.github.nacabaro.vbhelper.domain.device_data.UserCharacter @Database( version = 1, entities = [ - Dim::class, + Card::class, Character::class, Sprites::class, UserCharacter::class, BECharacterData::class, - TransformationHistory::class + TransformationHistory::class, + Dex::class ] ) abstract class AppDatabase : RoomDatabase() { abstract fun dimDao(): DiMDao abstract fun characterDao(): CharacterDao abstract fun userCharacterDao(): UserCharacterDao + abstract fun dexDao(): DexDao } \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/DimProgress.kt b/app/src/main/java/com/github/nacabaro/vbhelper/domain/DimProgress.kt index cb37abb..df9bbff 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/domain/DimProgress.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/DimProgress.kt @@ -3,6 +3,7 @@ package com.github.nacabaro.vbhelper.domain import androidx.room.Entity import androidx.room.ForeignKey import androidx.room.PrimaryKey +import com.github.nacabaro.vbhelper.domain.characters.Card @Entity( foreignKeys = [ @@ -13,7 +14,7 @@ import androidx.room.PrimaryKey onDelete = ForeignKey.CASCADE ), ForeignKey( - entity = Dim::class, + entity = Card::class, parentColumns = ["id"], childColumns = ["dimId"], onDelete = ForeignKey.CASCADE diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/Evolutions.kt b/app/src/main/java/com/github/nacabaro/vbhelper/domain/Evolutions.kt index ba4583e..dc4f94f 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/domain/Evolutions.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/Evolutions.kt @@ -3,6 +3,7 @@ package com.github.nacabaro.vbhelper.domain import androidx.room.Entity import androidx.room.ForeignKey import androidx.room.PrimaryKey +import com.github.nacabaro.vbhelper.domain.characters.Character @Entity( foreignKeys = [ diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/UserMonsters.kt b/app/src/main/java/com/github/nacabaro/vbhelper/domain/UserMonsters.kt index df1aee5..abf4c76 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/domain/UserMonsters.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/UserMonsters.kt @@ -3,6 +3,7 @@ package com.github.nacabaro.vbhelper.domain import androidx.room.Entity import androidx.room.ForeignKey import androidx.room.PrimaryKey +import com.github.nacabaro.vbhelper.domain.characters.Character @Entity( foreignKeys = [ diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/Dim.kt b/app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Card.kt similarity index 73% rename from app/src/main/java/com/github/nacabaro/vbhelper/domain/Dim.kt rename to app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Card.kt index 58dad07..8e3a379 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/domain/Dim.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Card.kt @@ -1,11 +1,10 @@ -package com.github.nacabaro.vbhelper.domain +package com.github.nacabaro.vbhelper.domain.characters -import android.icu.text.ListFormatter.Width import androidx.room.Entity import androidx.room.PrimaryKey @Entity -data class Dim( +data class Card( @PrimaryKey(autoGenerate = true) val id: Long = 0, val dimId: Int, diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/Character.kt b/app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Character.kt similarity index 89% rename from app/src/main/java/com/github/nacabaro/vbhelper/domain/Character.kt rename to app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Character.kt index d829ac8..3cb5b19 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/domain/Character.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Character.kt @@ -1,4 +1,4 @@ -package com.github.nacabaro.vbhelper.domain +package com.github.nacabaro.vbhelper.domain.characters import androidx.room.Entity import androidx.room.PrimaryKey @@ -7,7 +7,7 @@ import androidx.room.ForeignKey @Entity( foreignKeys = [ ForeignKey( - entity = Dim::class, + entity = Card::class, parentColumns = ["id"], childColumns = ["dimId"], onDelete = ForeignKey.CASCADE diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Dex.kt b/app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Dex.kt new file mode 100644 index 0000000..d038cbb --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Dex.kt @@ -0,0 +1,20 @@ +package com.github.nacabaro.vbhelper.domain.characters + +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey + +@Entity( + foreignKeys = [ + ForeignKey( + entity = Character::class, + parentColumns = ["id"], + childColumns = ["id"], + onDelete = ForeignKey.CASCADE + ) + ] +) +data class Dex( + @PrimaryKey val id: Long = 0, + val discoveredOn: Long +) \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/TransformationHistory.kt b/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/TransformationHistory.kt index 4d493d1..70a321e 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/TransformationHistory.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/TransformationHistory.kt @@ -3,7 +3,7 @@ package com.github.nacabaro.vbhelper.domain.device_data import androidx.room.Entity import androidx.room.ForeignKey import androidx.room.PrimaryKey -import com.github.nacabaro.vbhelper.domain.Character +import com.github.nacabaro.vbhelper.domain.characters.Character @Entity( foreignKeys = [ diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/UserCharacter.kt b/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/UserCharacter.kt index 2169495..75007d7 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/UserCharacter.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/domain/device_data/UserCharacter.kt @@ -4,8 +4,8 @@ import androidx.room.Entity import androidx.room.ForeignKey import androidx.room.PrimaryKey import com.github.cfogrady.vbnfc.data.NfcCharacter -import com.github.nacabaro.vbhelper.domain.DeviceType -import com.github.nacabaro.vbhelper.domain.Character +import com.github.nacabaro.vbhelper.utils.DeviceType +import com.github.nacabaro.vbhelper.domain.characters.Character @Entity( foreignKeys = [ diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/dtos/CardDtos.kt b/app/src/main/java/com/github/nacabaro/vbhelper/dtos/CardDtos.kt new file mode 100644 index 0000000..48e7c74 --- /dev/null +++ b/app/src/main/java/com/github/nacabaro/vbhelper/dtos/CardDtos.kt @@ -0,0 +1,13 @@ +package com.github.nacabaro.vbhelper.dtos + +object CardDtos { + data class CardProgress ( + val cardId: Long, + val cardName: String, + val cardLogo: ByteArray, + val logoWidth: Int, + val logoHeight: Int, + val totalCharacters: Int, + val obtainedCharacters: Int, + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/dtos/CharacterDtos.kt b/app/src/main/java/com/github/nacabaro/vbhelper/dtos/CharacterDtos.kt index 5e9717e..1c91f6d 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/dtos/CharacterDtos.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/dtos/CharacterDtos.kt @@ -1,7 +1,7 @@ package com.github.nacabaro.vbhelper.dtos import com.github.cfogrady.vbnfc.data.NfcCharacter -import com.github.nacabaro.vbhelper.domain.DeviceType +import com.github.nacabaro.vbhelper.utils.DeviceType object CharacterDtos { @@ -43,4 +43,12 @@ object CharacterDtos { val monIndex: Int, val transformationDate: Long ) + + data class CardProgress( + val id: Long, + val spriteIdle: ByteArray, + val spriteWidth: Int, + val spriteHeight: Int, + val discoveredOn: Long? + ) } \ 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 892e627..6f5fb75 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 @@ -81,12 +81,11 @@ fun AppNavigation( ) } composable(NavigationItems.CardView.route) { - val dimId = it.arguments?.getString("dimId") - Log.d("dimId", dimId.toString()) - if (dimId != null) { + val cardId = it.arguments?.getString("cardId") + if (cardId != null) { DiMScreen( navController = navController, - dimId = dimId.toInt() + dimId = cardId.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 4f47596..bc0bd38 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 @@ -14,6 +14,6 @@ sealed class NavigationItems ( object Storage : NavigationItems("Storage", R.drawable.baseline_catching_pokemon_24, "Storage") object Settings : NavigationItems("Settings", R.drawable.baseline_settings_24, "Settings") object Viewer : NavigationItems("Viewer", R.drawable.baseline_image_24, "Viewer") - object CardView : NavigationItems("Card/{dimId}", R.drawable.baseline_image_24, "Card") + object CardView : NavigationItems("Card/{cardId}", R.drawable.baseline_image_24, "Card") object Items : NavigationItems("Items", R.drawable.baseline_data_24, "Items") } \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/DexScreen.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/DexScreen.kt index da9d9e6..bec0a25 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/DexScreen.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/DexScreen.kt @@ -18,7 +18,8 @@ import com.github.nacabaro.vbhelper.utils.BitmapData import com.github.nacabaro.vbhelper.components.DexDiMEntry import com.github.nacabaro.vbhelper.components.TopBanner import com.github.nacabaro.vbhelper.di.VBHelper -import com.github.nacabaro.vbhelper.domain.Dim +import com.github.nacabaro.vbhelper.domain.characters.Card +import com.github.nacabaro.vbhelper.dtos.CardDtos import com.github.nacabaro.vbhelper.navigation.NavigationItems import com.github.nacabaro.vbhelper.source.DexRepository import kotlinx.coroutines.launch @@ -31,19 +32,19 @@ fun DexScreen( val application = LocalContext.current.applicationContext as VBHelper val dexRepository = DexRepository(application.container.db) - val dimList = remember { mutableStateOf>(emptyList()) } + val cardList = remember { mutableStateOf>(emptyList()) } LaunchedEffect(dexRepository) { coroutineScope.launch { val newDimList = dexRepository.getAllDims() - dimList.value = newDimList // Replace the entire list atomically + cardList.value = newDimList // Replace the entire list atomically } } Scaffold ( topBar = { TopBanner( - text = "Discovered Digimon", + text = "Discovered characters", onGearClick = { navController.navigate(NavigationItems.Viewer.route) } @@ -54,11 +55,11 @@ fun DexScreen( modifier = Modifier .padding(top = contentPadding.calculateTopPadding()) ) { - items(dimList.value) { + items(cardList.value) { DexDiMEntry( - name = it.name, + name = it.cardName, logo = BitmapData( - bitmap = it.logo, + bitmap = it.cardLogo, width = it.logoWidth, height = it.logoHeight ), @@ -67,9 +68,11 @@ fun DexScreen( .navigate( NavigationItems .CardView.route - .replace("{dimId}", "${it.id}") + .replace("{cardId}", "${it.cardId}") ) }, + obtainedCharacters = it.obtainedCharacters, + totalCharacters = it.totalCharacters, modifier = Modifier .fillMaxWidth() .padding(8.dp) diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/DimScreen.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/DimScreen.kt index c9f6585..609be95 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/DimScreen.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/DimScreen.kt @@ -1,6 +1,5 @@ package com.github.nacabaro.vbhelper.screens -import android.util.Log import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.items @@ -15,21 +14,22 @@ import androidx.navigation.NavController import com.github.nacabaro.vbhelper.utils.BitmapData import com.github.nacabaro.vbhelper.components.CharacterEntry import com.github.nacabaro.vbhelper.components.TopBanner -import com.github.nacabaro.vbhelper.domain.Character +import com.github.nacabaro.vbhelper.domain.characters.Character import com.github.nacabaro.vbhelper.di.VBHelper +import com.github.nacabaro.vbhelper.dtos.CharacterDtos import com.github.nacabaro.vbhelper.source.DexRepository import kotlinx.coroutines.launch @Composable fun DiMScreen( navController: NavController, - dimId: Int + dimId: Long ) { val coroutineScope = rememberCoroutineScope() val application = LocalContext.current.applicationContext as VBHelper val dexRepository = DexRepository(application.container.db) - val characterList = remember { mutableStateOf>(emptyList()) } + val characterList = remember { mutableStateOf>(emptyList()) } LaunchedEffect(dexRepository) { coroutineScope.launch { @@ -41,7 +41,7 @@ fun DiMScreen( Scaffold ( topBar = { TopBanner( - text = "Discovered Digimon", + text = "Discovered characters", onBackClick = { navController.popBackStack() } @@ -55,11 +55,11 @@ fun DiMScreen( items(characterList.value) { character -> CharacterEntry( onClick = { }, - obscure = true, + obscure = character.discoveredOn == null, icon = BitmapData( - bitmap = character.sprite1, - width = character.spritesWidth, - height = character.spritesHeight + bitmap = character.spriteIdle, + width = character.spriteWidth, + height = character.spriteHeight, ), ) } diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/HomeScreen.kt b/app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/HomeScreen.kt index b19f9ce..35863a7 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/HomeScreen.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/HomeScreen.kt @@ -17,7 +17,7 @@ import androidx.compose.ui.platform.LocalContext import androidx.navigation.NavController import com.github.nacabaro.vbhelper.components.TopBanner import com.github.nacabaro.vbhelper.di.VBHelper -import com.github.nacabaro.vbhelper.domain.DeviceType +import com.github.nacabaro.vbhelper.utils.DeviceType import com.github.nacabaro.vbhelper.domain.device_data.BECharacterData import com.github.nacabaro.vbhelper.domain.device_data.VBCharacterData import com.github.nacabaro.vbhelper.dtos.CharacterDtos diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/source/DexRepository.kt b/app/src/main/java/com/github/nacabaro/vbhelper/source/DexRepository.kt index 5e9a103..6105620 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/source/DexRepository.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/source/DexRepository.kt @@ -1,18 +1,18 @@ package com.github.nacabaro.vbhelper.source import com.github.nacabaro.vbhelper.database.AppDatabase -import com.github.nacabaro.vbhelper.domain.Character -import com.github.nacabaro.vbhelper.domain.Dim -import kotlinx.coroutines.flow.Flow +import com.github.nacabaro.vbhelper.domain.characters.Card +import com.github.nacabaro.vbhelper.dtos.CardDtos +import com.github.nacabaro.vbhelper.dtos.CharacterDtos class DexRepository ( private val db: AppDatabase ) { - suspend fun getAllDims(): List { - return db.dimDao().getAllDims() + suspend fun getAllDims(): List { + return db.dexDao().getCardsWithProgress() } - suspend fun getCharactersByDimId(dimId: Int): List { - return db.characterDao().getCharacterByDimId(dimId) + suspend fun getCharactersByDimId(cardId: Long): List { + return db.dexDao().getSingleCardProgress(cardId) } } \ No newline at end of file diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/utils/CharacterToNFCCharacter.kt b/app/src/main/java/com/github/nacabaro/vbhelper/utils/CharacterToNFCCharacter.kt index 655ceb8..8abd9a1 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/utils/CharacterToNFCCharacter.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/utils/CharacterToNFCCharacter.kt @@ -7,7 +7,6 @@ import com.github.cfogrady.vbnfc.be.BENfcCharacter import com.github.cfogrady.vbnfc.be.FirmwareVersion import com.github.cfogrady.vbnfc.data.NfcCharacter import com.github.nacabaro.vbhelper.di.VBHelper -import com.github.nacabaro.vbhelper.domain.DeviceType import com.github.nacabaro.vbhelper.source.StorageRepository import java.util.Date diff --git a/app/src/main/java/com/github/nacabaro/vbhelper/domain/DeviceType.kt b/app/src/main/java/com/github/nacabaro/vbhelper/utils/DeviceType.kt similarity index 54% rename from app/src/main/java/com/github/nacabaro/vbhelper/domain/DeviceType.kt rename to app/src/main/java/com/github/nacabaro/vbhelper/utils/DeviceType.kt index e1b8b72..5d06c67 100644 --- a/app/src/main/java/com/github/nacabaro/vbhelper/domain/DeviceType.kt +++ b/app/src/main/java/com/github/nacabaro/vbhelper/utils/DeviceType.kt @@ -1,4 +1,4 @@ -package com.github.nacabaro.vbhelper.domain +package com.github.nacabaro.vbhelper.utils enum class DeviceType { VBDevice,