Update the error management
This commit is contained in:
parent
a55e2c8162
commit
4123eaeccd
10 changed files with 152 additions and 109 deletions
|
|
@ -12,16 +12,18 @@ import com.pixelized.rplexicon.repository.data.character.CharacterSheetRepositor
|
|||
import com.pixelized.rplexicon.repository.data.character.DescriptionRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.EquipmentRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.InventoryRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.SkillRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.SpellRepository
|
||||
import com.pixelized.rplexicon.repository.data.lexicon.LexiconRepository
|
||||
import com.pixelized.rplexicon.repository.data.lexicon.LocationRepository
|
||||
import com.pixelized.rplexicon.repository.data.lexicon.QuestRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.SkillRepository
|
||||
import com.pixelized.rplexicon.repository.data.character.SpellRepository
|
||||
import com.pixelized.rplexicon.ui.composable.error.FetchErrorUio
|
||||
import com.pixelized.rplexicon.ui.composable.error.FetchErrorUio.Structure.Type
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -40,8 +42,8 @@ class LauncherViewModel @Inject constructor(
|
|||
equipmentRepository: EquipmentRepository,
|
||||
) : ViewModel() {
|
||||
|
||||
private val _error = MutableSharedFlow<String>()
|
||||
val error: SharedFlow<String> get() = _error
|
||||
private val _error = MutableStateFlow<FetchErrorUio?>(null)
|
||||
val error: Flow<FetchErrorUio?> get() = _error
|
||||
|
||||
var isLoading by mutableStateOf(true)
|
||||
private set
|
||||
|
|
@ -53,7 +55,7 @@ class LauncherViewModel @Inject constructor(
|
|||
lexiconRepository.fetchLexicon()
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("Lexicon fail to update")
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.LEXICON))
|
||||
}
|
||||
}
|
||||
val location = async {
|
||||
|
|
@ -61,7 +63,7 @@ class LauncherViewModel @Inject constructor(
|
|||
locationRepository.fetchLocation()
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("Location fail to update")
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.LOCATION))
|
||||
}
|
||||
}
|
||||
val quest = async {
|
||||
|
|
@ -69,7 +71,7 @@ class LauncherViewModel @Inject constructor(
|
|||
questRepository.fetchQuests()
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("Quest fail to update")
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.QUEST))
|
||||
}
|
||||
}
|
||||
val characterSheet = async {
|
||||
|
|
@ -77,7 +79,7 @@ class LauncherViewModel @Inject constructor(
|
|||
characterSheetRepository.fetchCharacterSheet()
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("CharacterSheet fail to update")
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.CHARACTER))
|
||||
}
|
||||
}
|
||||
val description = async {
|
||||
|
|
@ -85,7 +87,7 @@ class LauncherViewModel @Inject constructor(
|
|||
descriptionRepository.fetchDescription()
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("Skill/Spell description fail to update")
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.DESCRIPTION))
|
||||
}
|
||||
}
|
||||
val inventory = async {
|
||||
|
|
@ -93,7 +95,7 @@ class LauncherViewModel @Inject constructor(
|
|||
inventoryRepository.fetchInventory()
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("Inventories fail to update")
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.INVENTORY))
|
||||
}
|
||||
}
|
||||
val equipment = async {
|
||||
|
|
@ -101,7 +103,7 @@ class LauncherViewModel @Inject constructor(
|
|||
equipmentRepository.fetchEquipment()
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("Equipments fail to update")
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.EQUIPMENT))
|
||||
}
|
||||
}
|
||||
awaitAll(characterSheet)
|
||||
|
|
@ -111,7 +113,7 @@ class LauncherViewModel @Inject constructor(
|
|||
alterationRepository.fetchAlterationSheet(sheets = characterSheetRepository.sheets)
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("Alteration lexicon fail to update")
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.ALTERATION))
|
||||
}
|
||||
}
|
||||
val action = async {
|
||||
|
|
@ -119,7 +121,7 @@ class LauncherViewModel @Inject constructor(
|
|||
actionRepository.fetchActions(characters = characterSheetRepository.data.value)
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("Action fail to update")
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.ACTION))
|
||||
}
|
||||
}
|
||||
val spell = async {
|
||||
|
|
@ -127,7 +129,7 @@ class LauncherViewModel @Inject constructor(
|
|||
spellRepository.fetchSpells()
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("Spell fail to update")
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.SPELL))
|
||||
}
|
||||
}
|
||||
val skill = async {
|
||||
|
|
@ -135,13 +137,12 @@ class LauncherViewModel @Inject constructor(
|
|||
skillRepository.fetchSkills()
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.tryEmit("Skill fail to update")
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.SKILL))
|
||||
}
|
||||
}
|
||||
awaitAll(
|
||||
lexicon, location, quest, description, inventory,
|
||||
equipment, alteration, action, spell, skill,
|
||||
)
|
||||
|
||||
awaitAll(lexicon, location, quest)
|
||||
awaitAll(description, inventory, equipment, alteration, action, spell, skill)
|
||||
|
||||
isLoading = false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue