Skip to content

Commit

Permalink
feat: Empty states and settings button
Browse files Browse the repository at this point in the history
  • Loading branch information
PavloNetrebchuk committed May 10, 2024
1 parent f9069a0 commit 45aa988
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 60 deletions.
13 changes: 9 additions & 4 deletions app/src/main/java/org/openedx/app/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
Expand Down Expand Up @@ -31,13 +32,17 @@ class MainViewModel(

val isDiscoveryTypeWebView get() = config.getDiscoveryConfig().isViewTypeWebView()

@OptIn(FlowPreview::class)
override fun onCreate(owner: LifecycleOwner) {
super.onCreate(owner)
notifier.notifier.onEach {
if (it is NavigationToDiscovery) {
_navigateToDiscovery.emit(true)
notifier.notifier
.onEach {
if (it is NavigationToDiscovery) {
_navigateToDiscovery.emit(true)
}
}
}.distinctUntilChanged().launchIn(viewModelScope)
.distinctUntilChanged()
.launchIn(viewModelScope)
}

fun enableBottomBar(enable: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class CourseContainerViewModelTest {
"",
"",
"",
"",
config,
interactor,
calendarManager,
Expand Down Expand Up @@ -167,6 +168,7 @@ class CourseContainerViewModelTest {
"",
"",
"",
"",
config,
interactor,
calendarManager,
Expand Down Expand Up @@ -200,6 +202,7 @@ class CourseContainerViewModelTest {
"",
"",
"",
"",
config,
interactor,
calendarManager,
Expand Down Expand Up @@ -233,6 +236,7 @@ class CourseContainerViewModelTest {
"",
"",
"",
"",
config,
interactor,
calendarManager,
Expand Down Expand Up @@ -267,6 +271,7 @@ class CourseContainerViewModelTest {
"",
"",
"",
"",
config,
interactor,
calendarManager,
Expand Down Expand Up @@ -297,6 +302,7 @@ class CourseContainerViewModelTest {
"",
"",
"",
"",
config,
interactor,
calendarManager,
Expand Down Expand Up @@ -327,6 +333,7 @@ class CourseContainerViewModelTest {
"",
"",
"",
"",
config,
interactor,
calendarManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import org.openedx.core.system.notifier.CourseLoading
import org.openedx.core.system.notifier.CourseNotifier
import org.openedx.course.domain.interactor.CourseInteractor
import org.openedx.course.presentation.CourseAnalytics
import org.openedx.course.presentation.CourseRouter
import org.openedx.course.presentation.calendarsync.CalendarManager
import java.net.UnknownHostException
import java.util.Date
Expand All @@ -62,6 +63,7 @@ class CourseDatesViewModelTest {
private val corePreferences = mockk<CorePreferences>()
private val analytics = mockk<CourseAnalytics>()
private val config = mockk<Config>()
private val courseRouter = mockk<CourseRouter>()

private val openEdx = "OpenEdx"
private val calendarTitle = "OpenEdx - Abc"
Expand Down Expand Up @@ -169,7 +171,8 @@ class CourseDatesViewModelTest {
resourceManager,
corePreferences,
analytics,
config
config,
courseRouter
)
coEvery { interactor.getCourseDates(any()) } throws UnknownHostException()
val message = async {
Expand All @@ -195,7 +198,8 @@ class CourseDatesViewModelTest {
resourceManager,
corePreferences,
analytics,
config
config,
courseRouter
)
coEvery { interactor.getCourseDates(any()) } throws Exception()
val message = async {
Expand All @@ -221,7 +225,8 @@ class CourseDatesViewModelTest {
resourceManager,
corePreferences,
analytics,
config
config,
courseRouter
)
coEvery { interactor.getCourseDates(any()) } returns mockedCourseDatesResult
val message = async {
Expand All @@ -247,7 +252,8 @@ class CourseDatesViewModelTest {
resourceManager,
corePreferences,
analytics,
config
config,
courseRouter
)
coEvery { interactor.getCourseDates(any()) } returns CourseDatesResult(
datesSection = linkedMapOf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import org.openedx.core.system.notifier.CourseNotifier
import org.openedx.core.system.notifier.CourseStructureUpdated
import org.openedx.course.domain.interactor.CourseInteractor
import org.openedx.course.presentation.CourseAnalytics
import org.openedx.course.presentation.CourseRouter
import java.net.UnknownHostException
import java.util.Date

Expand All @@ -77,6 +78,7 @@ class CourseOutlineViewModelTest {
private val workerController = mockk<DownloadWorkerController>()
private val analytics = mockk<CourseAnalytics>()
private val coreAnalytics = mockk<CoreAnalytics>()
private val courseRouter = mockk<CourseRouter>()

private val noInternet = "Slow or no internet connection"
private val somethingWrong = "Something went wrong"
Expand Down Expand Up @@ -233,6 +235,7 @@ class CourseOutlineViewModelTest {
networkConnection,
preferencesManager,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController,
Expand Down Expand Up @@ -267,6 +270,7 @@ class CourseOutlineViewModelTest {
networkConnection,
preferencesManager,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
Expand Down Expand Up @@ -311,6 +315,7 @@ class CourseOutlineViewModelTest {
networkConnection,
preferencesManager,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
Expand Down Expand Up @@ -357,6 +362,7 @@ class CourseOutlineViewModelTest {
networkConnection,
preferencesManager,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
Expand Down Expand Up @@ -403,6 +409,7 @@ class CourseOutlineViewModelTest {
networkConnection,
preferencesManager,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
Expand Down Expand Up @@ -437,6 +444,7 @@ class CourseOutlineViewModelTest {
networkConnection,
preferencesManager,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
Expand Down Expand Up @@ -485,6 +493,7 @@ class CourseOutlineViewModelTest {
networkConnection,
preferencesManager,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
Expand Down Expand Up @@ -528,6 +537,7 @@ class CourseOutlineViewModelTest {
networkConnection,
preferencesManager,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
Expand Down Expand Up @@ -563,6 +573,7 @@ class CourseOutlineViewModelTest {
networkConnection,
preferencesManager,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import org.openedx.core.system.notifier.VideoNotifier
import org.openedx.course.R
import org.openedx.course.domain.interactor.CourseInteractor
import org.openedx.course.presentation.CourseAnalytics
import org.openedx.course.presentation.CourseRouter
import java.util.Date

@OptIn(ExperimentalCoroutinesApi::class)
Expand All @@ -73,6 +74,7 @@ class CourseVideoViewModelTest {
private val networkConnection = mockk<NetworkConnection>()
private val downloadDao = mockk<DownloadDao>()
private val workerController = mockk<DownloadWorkerController>()
private val courseRouter = mockk<CourseRouter>()

private val cantDownload = "You can download content only from Wi-fi"

Expand Down Expand Up @@ -196,9 +198,10 @@ class CourseVideoViewModelTest {
courseNotifier,
videoNotifier,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
workerController,
)

viewModel.getVideos()
Expand Down Expand Up @@ -227,6 +230,7 @@ class CourseVideoViewModelTest {
courseNotifier,
videoNotifier,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
Expand Down Expand Up @@ -267,6 +271,7 @@ class CourseVideoViewModelTest {
courseNotifier,
videoNotifier,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
Expand Down Expand Up @@ -308,6 +313,7 @@ class CourseVideoViewModelTest {
courseNotifier,
videoNotifier,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
Expand Down Expand Up @@ -344,6 +350,7 @@ class CourseVideoViewModelTest {
courseNotifier,
videoNotifier,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
Expand Down Expand Up @@ -384,6 +391,7 @@ class CourseVideoViewModelTest {
courseNotifier,
videoNotifier,
analytics,
courseRouter,
coreAnalytics,
downloadDao,
workerController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,9 @@ private fun AllEnrolledCoursesScreen(
.fillMaxHeight()
.then(emptyStatePaddings)
) {
EmptyState()
EmptyState(
currentCourseStatus = CourseStatusFilter.entries[tabPagerState.currentPage]
)
}
}
}
Expand Down Expand Up @@ -560,28 +562,33 @@ private fun Header(
}

@Composable
private fun EmptyState() {
private fun EmptyState(
currentCourseStatus: CourseStatusFilter
) {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Column(
Modifier.width(185.dp),
Modifier.width(200.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Icon(
painter = painterResource(id = R.drawable.dashboard_ic_empty),
contentDescription = null,
tint = MaterialTheme.appColors.textFieldBorder
painter = painterResource(id = R.drawable.dashboard_ic_book),
tint = MaterialTheme.appColors.textFieldBorder,
contentDescription = null
)
Spacer(Modifier.height(16.dp))
Spacer(Modifier.height(4.dp))
Text(
modifier = Modifier
.testTag("txt_empty_state_description")
.testTag("txt_empty_state_title")
.fillMaxWidth(),
text = stringResource(id = R.string.dashboard_you_are_not_enrolled),
color = MaterialTheme.appColors.textPrimaryVariant,
style = MaterialTheme.appTypography.bodySmall,
text = stringResource(
id = R.string.dashboard_no_status_courses,
stringResource(currentCourseStatus.labelResId)
),
color = MaterialTheme.appColors.textDark,
style = MaterialTheme.appTypography.titleMedium,
textAlign = TextAlign.Center
)
}
Expand Down Expand Up @@ -616,6 +623,16 @@ private fun AllEnrolledCoursesPreview() {
}
}

@Preview
@Composable
private fun EmptyStatePreview() {
OpenEdXTheme {
EmptyState(
currentCourseStatus = CourseStatusFilter.COMPLETE
)
}
}

private val mockCourseAssignments = CourseAssignments(null, emptyList())
private val mockCourseEnrolled = EnrolledCourse(
auditAccessExpires = Date(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import org.openedx.core.domain.model.EnrolledCourse

sealed class AllEnrolledCoursesUIState {
data class Courses(val courses: List<EnrolledCourse>) : AllEnrolledCoursesUIState()
object Empty : AllEnrolledCoursesUIState()
object Loading : AllEnrolledCoursesUIState()
data object Empty : AllEnrolledCoursesUIState()
data object Loading : AllEnrolledCoursesUIState()
}
Loading

0 comments on commit 45aa988

Please sign in to comment.