Add proper skills management.

This commit is contained in:
Thomas Andres Gomez 2023-10-09 16:07:33 +02:00
parent 6528b89f6b
commit 7b6f5b6430
45 changed files with 1355 additions and 706 deletions

View file

@ -1,11 +1,11 @@
package com.pixelized.rplexicon
import android.util.Log
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.pixelized.rplexicon.model.Description
import com.pixelized.rplexicon.repository.data.ActionRepository
import com.pixelized.rplexicon.repository.data.AlterationRepository
import com.pixelized.rplexicon.repository.data.CharacterSheetRepository
@ -13,6 +13,7 @@ import com.pixelized.rplexicon.repository.data.DescriptionRepository
import com.pixelized.rplexicon.repository.data.LexiconRepository
import com.pixelized.rplexicon.repository.data.LocationRepository
import com.pixelized.rplexicon.repository.data.QuestRepository
import com.pixelized.rplexicon.repository.data.SkillRepository
import com.pixelized.rplexicon.repository.data.SpellRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.async
@ -31,6 +32,7 @@ class LauncherViewModel @Inject constructor(
characterSheetRepository: CharacterSheetRepository,
actionRepository: ActionRepository,
spellRepository: SpellRepository,
skillRepository: SkillRepository,
descriptionRepository: DescriptionRepository,
) : ViewModel() {
@ -46,6 +48,7 @@ class LauncherViewModel @Inject constructor(
try {
lexiconRepository.fetchLexicon()
} catch (exception: Exception) {
Log.e(TAG, exception.message, exception)
_error.tryEmit("Lexicon fail to update")
}
}
@ -53,6 +56,7 @@ class LauncherViewModel @Inject constructor(
try {
locationRepository.fetchLocation()
} catch (exception: Exception) {
Log.e(TAG, exception.message, exception)
_error.tryEmit("Location fail to update")
}
}
@ -60,6 +64,7 @@ class LauncherViewModel @Inject constructor(
try {
questRepository.fetchQuests()
} catch (exception: Exception) {
Log.e(TAG, exception.message, exception)
_error.tryEmit("Quest fail to update")
}
}
@ -67,6 +72,7 @@ class LauncherViewModel @Inject constructor(
try {
characterSheetRepository.fetchCharacterSheet()
} catch (exception: Exception) {
Log.e(TAG, exception.message, exception)
_error.tryEmit("CharacterSheet fail to update")
}
}
@ -74,6 +80,7 @@ class LauncherViewModel @Inject constructor(
try {
descriptionRepository.fetchDescription()
} catch (exception: Exception) {
Log.e(TAG, exception.message, exception)
_error.tryEmit("Skill/Spell description fail to update")
}
}
@ -83,6 +90,7 @@ class LauncherViewModel @Inject constructor(
try {
alterationRepository.fetchAlterationSheet(sheets = characterSheetRepository.sheets)
} catch (exception: Exception) {
Log.e(TAG, exception.message, exception)
_error.tryEmit("Alteration lexicon fail to update")
}
}
@ -90,6 +98,7 @@ class LauncherViewModel @Inject constructor(
try {
actionRepository.fetchActions()
} catch (exception: Exception) {
Log.e(TAG, exception.message, exception)
_error.tryEmit("Action fail to update")
}
}
@ -97,12 +106,25 @@ class LauncherViewModel @Inject constructor(
try {
spellRepository.fetchSpells()
} catch (exception: Exception) {
Log.e(TAG, exception.message, exception)
_error.tryEmit("Spell fail to update")
}
}
awaitAll(alteration, action, spell)
val skill = async {
try {
skillRepository.fetchSkills()
} catch (exception: Exception) {
Log.e(TAG, exception.message, exception)
_error.tryEmit("Skill fail to update")
}
}
awaitAll(alteration, action, spell, skill)
isLoading = false
}
}
companion object {
private const val TAG = "LauncherViewModel"
}
}