Add link between location and quest.
This commit is contained in:
parent
82b6c49787
commit
0783c6ba02
3 changed files with 25 additions and 3 deletions
|
|
@ -24,6 +24,10 @@ class LocationRepository @Inject constructor(
|
|||
private val _data = MutableStateFlow<List<Location>>(emptyList())
|
||||
val data: StateFlow<List<Location>> get() = _data
|
||||
|
||||
fun findId(name: String?): Int? {
|
||||
return name?.let { _data.value.firstOrNull { item -> item.name == it }?.id }
|
||||
}
|
||||
|
||||
@Throws(ServiceNotReady::class, IncompatibleSheetStructure::class, Exception::class)
|
||||
suspend fun fetchLocation() {
|
||||
googleRepository.fetch { sheet: Sheets.Spreadsheets.Values ->
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ import com.pixelized.rplexicon.R
|
|||
import com.pixelized.rplexicon.ui.composable.BackgroundImage
|
||||
import com.pixelized.rplexicon.ui.navigation.LocalScreenNavHost
|
||||
import com.pixelized.rplexicon.ui.navigation.screens.navigateToLexiconDetail
|
||||
import com.pixelized.rplexicon.ui.navigation.screens.navigateToLocationDetail
|
||||
import com.pixelized.rplexicon.ui.theme.LexiconTheme
|
||||
import com.pixelized.rplexicon.utilitary.LOS_FULL
|
||||
import com.pixelized.rplexicon.utilitary.LOS_HOLLOW
|
||||
|
|
@ -71,6 +72,7 @@ data class QuestDetailUio(
|
|||
val subtitle: String?,
|
||||
val giverId: Int? = null,
|
||||
val giver: String?,
|
||||
val placeId: Int? = null,
|
||||
val place: String?,
|
||||
val individualReward: String?,
|
||||
val globalReward: String?,
|
||||
|
|
@ -90,6 +92,7 @@ data class AnnotatedQuestDetailUio(
|
|||
val subtitle: String?,
|
||||
val giverId: Int?,
|
||||
val giver: String?,
|
||||
val placeId: Int?,
|
||||
val place: String?,
|
||||
val individualReward: String?,
|
||||
val globalReward: String?,
|
||||
|
|
@ -121,6 +124,7 @@ private fun QuestDetailUio.QuestStep.annotate(): AnnotatedQuestDetailUio.Annotat
|
|||
subtitle = subtitle,
|
||||
giverId = giverId,
|
||||
giver = giver,
|
||||
placeId = placeId,
|
||||
place = place,
|
||||
individualReward = individualReward,
|
||||
globalReward = globalReward,
|
||||
|
|
@ -149,7 +153,8 @@ fun QuestDetailScreen(
|
|||
modifier = Modifier.fillMaxSize(),
|
||||
item = viewModel.quest,
|
||||
onBack = { screen.popBackStack() },
|
||||
onGiver = { screen.navigateToLexiconDetail(id = it) }
|
||||
onGiver = { screen.navigateToLexiconDetail(id = it) },
|
||||
onLocation = { screen.navigateToLocationDetail(id = it) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -162,6 +167,7 @@ private fun QuestDetailContent(
|
|||
item: State<QuestDetailUio>,
|
||||
onBack: () -> Unit,
|
||||
onGiver: (Int) -> Unit,
|
||||
onLocation: (Int) -> Unit,
|
||||
) {
|
||||
val annotatedQuest = item.value.annotate()
|
||||
|
||||
|
|
@ -300,7 +306,12 @@ private fun QuestDetailContent(
|
|||
}
|
||||
}
|
||||
quest.place?.let {
|
||||
Column {
|
||||
Column(
|
||||
modifier = Modifier.clickable(
|
||||
enabled = quest.placeId != null,
|
||||
onClick = { quest.placeId?.let { onLocation(it) } }
|
||||
)
|
||||
) {
|
||||
Text(
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = FontWeight.Bold,
|
||||
|
|
@ -308,7 +319,10 @@ private fun QuestDetailContent(
|
|||
)
|
||||
Text(
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
text = it,
|
||||
text = when (quest.placeId) {
|
||||
null -> "$LOS_HOLLOW $it"
|
||||
else -> "$LOS_FULL $it"
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -363,6 +377,7 @@ private fun QuestDetailPreview(
|
|||
item = preview,
|
||||
onBack = { },
|
||||
onGiver = { },
|
||||
onLocation = { },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import androidx.compose.runtime.mutableStateOf
|
|||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
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.ui.navigation.screens.questDetailArgument
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
|
|
@ -15,6 +16,7 @@ class QuestDetailViewModel @Inject constructor(
|
|||
savedStateHandle: SavedStateHandle,
|
||||
questRepository: QuestRepository,
|
||||
lexiconRepository: LexiconRepository,
|
||||
locationRepository: LocationRepository,
|
||||
) : ViewModel() {
|
||||
val quest: State<QuestDetailUio>
|
||||
|
||||
|
|
@ -33,6 +35,7 @@ class QuestDetailViewModel @Inject constructor(
|
|||
subtitle = entry.subtitle,
|
||||
giverId = lexiconRepository.findId(entry.questGiver),
|
||||
giver = entry.questGiver,
|
||||
placeId = locationRepository.findId(entry.area),
|
||||
place = entry.area,
|
||||
individualReward = entry.individualReward,
|
||||
globalReward = entry.groupReward,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue