Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ internal fun LessonsLayout(state: UiState, modifier: Modifier = Modifier) {
)
}

if (state.mode == UiState.Mode.PERSONALIZATION && state.dataLoaded && state.lessons.isEmpty()) {
item("no-personalized-lessons", "no-personalized-lessons") {
Comment thread
tjohnson009 marked this conversation as resolved.
NoPersonalizedLessons(
onGoToAllLessons = { state.eventSink(UiEvent.ChangeMode(UiState.Mode.ALL_LESSONS)) },
modifier = Modifier.padding(top = 16.dp, horizontal = MARGIN_LESSONS_LAYOUT_HORIZONTAL)
)
}
}

item("spacer", "spacer") {
Spacer(modifier = Modifier.height(16.dp))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class LessonsPresenter @AssistedInject internal constructor(
data class UiState internal constructor(
val mode: Mode = Mode.ALL_LESSONS,
val isPersonalizationEnabled: Boolean = false,
val dataLoaded: Boolean = true,
val languageFilter: FilterMenu.UiState<Language> = FilterMenu.UiState(),
val lessons: List<ToolCardPresenter.UiState> = emptyList(),
internal val eventSink: (UiEvent) -> Unit = {},
Expand Down Expand Up @@ -108,11 +109,14 @@ class LessonsPresenter @AssistedInject internal constructor(

RegisterSyncTask(languageFilter.selectedItem?.code ?: appLanguage)

val lessons = rememberLessons(mode, languageFilter.selectedItem?.code ?: appLanguage)

return UiState(
mode = mode,
isPersonalizationEnabled = isPersonalizationEnabled,
dataLoaded = lessons != null,
languageFilter = languageFilter,
lessons = rememberLessons(mode, languageFilter.selectedItem?.code ?: appLanguage),
lessons = lessons.orEmpty(),
) {
when (it) {
is UiEvent.ChangeMode -> mode = it.mode
Expand Down Expand Up @@ -181,9 +185,9 @@ class LessonsPresenter @AssistedInject internal constructor(
}

@Composable
private fun rememberLessons(mode: UiState.Mode, locale: Locale): List<ToolCardPresenter.UiState> {
val lessons by remember(mode, locale) { lessonsFlowProducer.getFlow(mode, locale) }.collectAsState(emptyList())
return lessons.map { tool ->
private fun rememberLessons(mode: UiState.Mode, locale: Locale): List<ToolCardPresenter.UiState>? {
val lessons by remember(mode, locale) { lessonsFlowProducer.getFlow(mode, locale) }.collectAsState(null)
return lessons?.map { tool ->
key(tool.code) {
lateinit var toolState: ToolCardPresenter.UiState
toolState = toolCardPresenter.present(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.cru.godtools.ui.dashboard.lessons

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import org.cru.godtools.R

@Composable
internal fun NoPersonalizedLessons(onGoToAllLessons: () -> Unit, modifier: Modifier = Modifier) {
Surface(
color = MaterialTheme.colorScheme.surfaceVariant,
modifier = modifier.fillMaxWidth(),
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.padding(24.dp),
) {
Icon(
painter = painterResource(R.drawable.ic_priority_high),
contentDescription = null,
modifier = Modifier.size(64.dp),
)
Comment thread
tjohnson009 marked this conversation as resolved.
Text(
text = stringResource(R.string.dashboard_lessons_section_personalized_no_lessons_title),
style = MaterialTheme.typography.titleMedium,
textAlign = TextAlign.Center,
modifier = Modifier.padding(top = 16.dp),
)
Text(
text = stringResource(R.string.dashboard_lessons_section_personalized_no_lessons_description),
style = MaterialTheme.typography.bodyMedium,
textAlign = TextAlign.Center,
modifier = Modifier.padding(top = 8.dp),
)
Button(
onClick = onGoToAllLessons,
modifier = Modifier.padding(top = 16.dp),
) {
Text(stringResource(R.string.dashboard_lessons_section_personalized_no_lessons_action_all_lessons))
}
}
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_priority_high.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M479.88,796.92q-21.78,0 -37.18,-15.51 -15.39,-15.52 -15.39,-37.3 0,-21.78 15.51,-37.18 15.51,-15.39 37.3,-15.39 21.78,0 37.18,15.51 15.39,15.51 15.39,37.3 0,21.78 -15.51,37.18 -15.51,15.39 -37.3,15.39ZM432.69,600.77v-457.69h94.62v457.69h-94.62Z"
android:fillColor="@color/tintable"/>
</vector>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings_dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ An online version can be found at https://knowgod.com/</string>
<string name="dashboard_lessons_progress_in_progress">%1$d%% Complete</string>
<string name="dashboard_lessons_section_personalized_localization_title">Displaying localized Lessons list</string>
<string name="dashboard_lessons_section_personalized_localization_text">The lessons shown on this page are based on your Localization setting. You can alter this at any time.</string>
<string name="dashboard_lessons_section_personalized_no_lessons_title">Personalization unavailable</string>
<string name="dashboard_lessons_section_personalized_no_lessons_description">The lessons shown on this page are based on your Language and Localization settings. Your current selection does not yet offer personalization.</string>
<string name="dashboard_lessons_section_personalized_no_lessons_action_all_lessons">Go to All Lessons</string>

<!-- Home -->
<eat-comment />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class LessonsPresenterTest {
@Test
fun `State - mode - personalization enabled`() = testScope.runTest {
presenter.test {
val state = awaitItem()
val state = awaitItemMatching { it.dataLoaded }
assertEquals(UiState.Mode.PERSONALIZATION, state.mode)

state.eventSink(UiEvent.ChangeMode(UiState.Mode.ALL_LESSONS))
Expand Down Expand Up @@ -437,7 +437,7 @@ class LessonsPresenterTest {
@Test
fun `SideEffect - RegisterSyncTask - Triggers initial sync`() = testScope.runTest {
presenter.test {
awaitItem()
awaitItemMatching { it.dataLoaded }
toolOrderSync.send(true)
coVerifyAll { syncService.syncToolOrder(Locale.ENGLISH, "US", false) }
}
Expand All @@ -447,7 +447,7 @@ class LessonsPresenterTest {
fun `SideEffect - RegisterSyncTask - uses locale from language filter`() = testScope.runTest {
appLangFlow.value = Locale.FRENCH
presenter.test {
awaitItem()
awaitItemMatching { it.dataLoaded }
toolOrderSync.send(true)
coVerifyAll { syncService.syncToolOrder(Locale.FRENCH, "US", false) }
}
Expand All @@ -471,7 +471,7 @@ class LessonsPresenterTest {
@Test
fun `SideEffect - RegisterSyncTask - passes force on triggered sync`() = testScope.runTest {
presenter.test {
awaitItem()
awaitItemMatching { it.dataLoaded }
toolOrderSync.send(true)
coVerify { syncService.syncToolOrder(Locale.ENGLISH, "US", false) }

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,16 @@ class DashboardLayoutPaparazziTest(

@Test
fun `LessonsLayout() - Personalization - Localization Settings Box`() {
assumeTrue(locale == null)
lessonsState = lessonsState.copy(
mode = LessonsPresenter.UiState.Mode.PERSONALIZATION,
lessons = lessonsState.lessons.subList(0, 1)
)
snapshotDashboardLayout(state.copy(initialPage = LessonsScreen))
}
Comment thread
tjohnson009 marked this conversation as resolved.

@Test
fun `LessonsLayout() - Personalization - No Personalized Lessons`() {
assumeTrue(locale == null)
lessonsState = lessonsState.copy(
mode = LessonsPresenter.UiState.Mode.PERSONALIZATION,
Expand Down