~cytrogen/vbhelper

e17f6c23e43f4f27bfb2ea1c49e2218695e5da7b — Nacho 1 year, 2 months ago 409474b
Renaming terms and other bits and bobs
- Changed adventure database so that the original intended time is also stored with the final time. This will come useful once the algorithm for determining which object to give is made.
M app/src/main/java/com/github/nacabaro/vbhelper/daos/AdventureDao.kt => app/src/main/java/com/github/nacabaro/vbhelper/daos/AdventureDao.kt +5 -4
@@ 8,10 8,10 @@ import com.github.nacabaro.vbhelper.dtos.CharacterDtos
@Dao
interface AdventureDao {
    @Query("""
        INSERT INTO Adventure (characterId, finishesAdventure)
        VALUES (:characterId, strftime('%s', 'now') + :timeInSeconds)
        INSERT INTO Adventure (characterId, originalDuration, finishesAdventure)
        VALUES (:characterId, :originalDuration, strftime('%s', 'now') + :timeInSeconds)
    """)
    fun insertNewAdventure(characterId: Long, timeInSeconds: Long)
    fun insertNewAdventure(characterId: Long, originalDuration: Long, timeInSeconds: Long)

    @Query("""
        SELECT COUNT(*) FROM Adventure


@@ 25,7 25,8 @@ interface AdventureDao {
            c.spritesWidth AS spriteWidth,
            c.spritesHeight AS spriteHeight,
            d.isBEm as isBemCard,
            a.finishesAdventure AS timeLeft
            a.finishesAdventure AS finishesAdventure,
            a.originalDuration AS originalTimeInMinutes
        FROM UserCharacter uc
        JOIN Character c ON uc.charId = c.id
        JOIN Card d ON c.dimId = d.id

M app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Adventure.kt => app/src/main/java/com/github/nacabaro/vbhelper/domain/characters/Adventure.kt +1 -0
@@ 17,5 17,6 @@ import com.github.nacabaro.vbhelper.domain.device_data.UserCharacter
)
data class Adventure(
    @PrimaryKey val characterId: Long,
    val originalDuration: Long,
    val finishesAdventure: Long
)

M app/src/main/java/com/github/nacabaro/vbhelper/dtos/CharacterDtos.kt => app/src/main/java/com/github/nacabaro/vbhelper/dtos/CharacterDtos.kt +2 -1
@@ 79,6 79,7 @@ object CharacterDtos {
        val spriteWidth: Int,
        val spriteHeight: Int,
        val isBemCard: Boolean,
        val timeLeft: Long
        val finishesAdventure: Long,
        val originalTimeInMinutes: Long
    )
}
\ No newline at end of file

M app/src/main/java/com/github/nacabaro/vbhelper/screens/adventureScreen/AdventureScreen.kt => app/src/main/java/com/github/nacabaro/vbhelper/screens/adventureScreen/AdventureScreen.kt +39 -22
@@ 1,9 1,13 @@
package com.github.nacabaro.vbhelper.screens.adventureScreen

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.LazyColumn
import androidx.compose.foundation.lazy.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.getValue


@@ 12,6 16,7 @@ import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.NavController


@@ 71,29 76,41 @@ fun AdventureScreen(
            )
        }
    ) { contentPadding ->
        LazyColumn(
            modifier = Modifier
                .padding(top = contentPadding.calculateTopPadding())
        ) {
            items(characterList.value) {
                AdventureEntry(
                    icon = BitmapData(
                        bitmap = it.spriteIdle,
                        width = it.spriteWidth,
                        height = it.spriteHeight
                    ),
                    timeLeft = it.timeLeft - currentTime,
                    onClick = {
                        if (it.timeLeft < currentTime) {
                            storageScreenController
                                .getItemFromAdventure(it.id) { adventureResult ->
                                    obtainedItem = adventureResult
                                }
                        } else {
                            cancelAdventureDialog = it
        if (characterList.value.isEmpty()) {
            Column(
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally,
                modifier = Modifier
                    .padding(top = contentPadding.calculateTopPadding())
                    .fillMaxSize()
            ) {
                Text(text = "Nothing to see here")
            }
        } else {
            LazyColumn(
                modifier = Modifier
                    .padding(top = contentPadding.calculateTopPadding())
            ) {
                items(characterList.value) {
                    AdventureEntry(
                        icon = BitmapData(
                            bitmap = it.spriteIdle,
                            width = it.spriteWidth,
                            height = it.spriteHeight
                        ),
                        timeLeft = it.finishesAdventure - currentTime,
                        onClick = {
                            if (it.finishesAdventure < currentTime) {
                                storageScreenController
                                    .getItemFromAdventure(it.id) { adventureResult ->
                                        obtainedItem = adventureResult
                                    }
                            } else {
                                cancelAdventureDialog = it
                            }
                        }
                    }
                )
                    )
                }
            }
        }
    }

M app/src/main/java/com/github/nacabaro/vbhelper/screens/adventureScreen/AdventureScreenControllerImpl.kt => app/src/main/java/com/github/nacabaro/vbhelper/screens/adventureScreen/AdventureScreenControllerImpl.kt +2 -2
@@ 17,7 17,7 @@ class AdventureScreenControllerImpl(
    private val database = application.container.db

    override fun sendCharacterToAdventure(characterId: Long, timeInMinutes: Long) {
        val timeInSeconds = timeInMinutes * 60
        val finishesAdventureAt = timeInMinutes * 60
        componentActivity.lifecycleScope.launch(Dispatchers.IO) {
            val characterData = database
                .userCharacterDao()


@@ 31,7 31,7 @@ class AdventureScreenControllerImpl(

            database
                .adventureDao()
                .insertNewAdventure(characterId, timeInSeconds)
                .insertNewAdventure(characterId, timeInMinutes, finishesAdventureAt)
        }
    }


M app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/HomeScreenControllerImpl.kt => app/src/main/java/com/github/nacabaro/vbhelper/screens/homeScreens/HomeScreenControllerImpl.kt +1 -1
@@ 20,7 20,7 @@ class HomeScreenControllerImpl(
                .getAdventureCharacters()

            val finishedAdventureCharacters = adventureCharacters.filter { character ->
                character.timeLeft <= currentTime
                character.finishesAdventure <= currentTime
            }

            onCompletion(finishedAdventureCharacters.isNotEmpty())

M app/src/main/java/com/github/nacabaro/vbhelper/screens/storageScreen/StorageScreenControllerImpl.kt => app/src/main/java/com/github/nacabaro/vbhelper/screens/storageScreen/StorageScreenControllerImpl.kt +4 -1
@@ 4,6 4,7 @@ import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.lifecycle.lifecycleScope
import com.github.nacabaro.vbhelper.di.VBHelper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class StorageScreenControllerImpl(


@@ 13,8 14,10 @@ class StorageScreenControllerImpl(
    private val database = application.container.db

    override fun setActive(characterId: Long, onCompletion: () -> Unit) {
        componentActivity.lifecycleScope.launch {
        componentActivity.lifecycleScope.launch(Dispatchers.IO) {
            database.userCharacterDao().clearActiveCharacter()
            database.userCharacterDao().setActiveCharacter(characterId)

            componentActivity.runOnUiThread {
                Toast.makeText(
                    componentActivity,