Skip to content

Commit

Permalink
fix: enable Programs view for new dashboard navigation (#328)
Browse files Browse the repository at this point in the history
- Update/optimise ProgramFragment
- enable ProgramFragment for both dashboards(list/gallery)
- hide dropdown on Learn Tab if programs not available

fix: LEARNER-10035
  • Loading branch information
omerhabib26 authored Jun 7, 2024
1 parent 1bc1d4c commit 09b422a
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 102 deletions.
43 changes: 26 additions & 17 deletions app/src/main/java/org/openedx/app/AppRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
replaceFragmentWithBackStack(fm, AllEnrolledCoursesFragment())
}

override fun getProgramFragmentInstance(): Fragment {
return ProgramFragment(myPrograms = true, isNestedFragment = true)
override fun getProgramFragment(): Fragment {
return ProgramFragment.newInstance(isNestedFragment = true)
}

override fun navigateToCourseInfo(
Expand All @@ -144,7 +144,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
fm: FragmentManager,
courseId: String,
courseTitle: String,
enrollmentMode: String
enrollmentMode: String,
) {
replaceFragmentWithBackStack(
fm,
Expand All @@ -161,21 +161,30 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
courseTitle: String,
enrollmentMode: String,
openTab: String,
resumeBlockId: String
resumeBlockId: String,
) {
replaceFragmentWithBackStack(
fm,
CourseContainerFragment.newInstance(courseId, courseTitle, enrollmentMode, openTab, resumeBlockId)
CourseContainerFragment.newInstance(
courseId,
courseTitle,
enrollmentMode,
openTab,
resumeBlockId
)
)
}

override fun navigateToEnrolledProgramInfo(fm: FragmentManager, pathId: String) {
replaceFragmentWithBackStack(fm, ProgramFragment.newInstance(pathId))
replaceFragmentWithBackStack(
fm,
ProgramFragment.newInstance(pathId = pathId, isNestedFragment = false)
)
}

override fun navigateToNoAccess(
fm: FragmentManager,
title: String
title: String,
) {
replaceFragment(fm, NoAccessCourseContainerFragment.newInstance(title))
}
Expand All @@ -189,7 +198,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
subSectionId: String,
unitId: String,
componentId: String,
mode: CourseViewMode
mode: CourseViewMode,
) {
replaceFragmentWithBackStack(
fm,
Expand All @@ -208,7 +217,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
courseId: String,
unitId: String,
componentId: String,
mode: CourseViewMode
mode: CourseViewMode,
) {
replaceFragmentWithBackStack(
fm,
Expand All @@ -226,7 +235,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
courseId: String,
unitId: String,
componentId: String,
mode: CourseViewMode
mode: CourseViewMode,
) {
replaceFragment(
fm,
Expand All @@ -246,7 +255,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
videoTime: Long,
blockId: String,
courseId: String,
isPlaying: Boolean
isPlaying: Boolean,
) {
replaceFragmentWithBackStack(
fm,
Expand All @@ -260,7 +269,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
videoTime: Long,
blockId: String,
courseId: String,
isPlaying: Boolean
isPlaying: Boolean,
) {
replaceFragmentWithBackStack(
fm,
Expand All @@ -278,7 +287,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
fm: FragmentManager,
courseId: String,
title: String,
type: HandoutsType
type: HandoutsType,
) {
replaceFragmentWithBackStack(
fm,
Expand All @@ -294,7 +303,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
courseId: String,
topicId: String,
title: String,
viewType: FragmentViewType
viewType: FragmentViewType,
) {
replaceFragmentWithBackStack(
fm,
Expand All @@ -312,7 +321,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
override fun navigateToDiscussionResponses(
fm: FragmentManager,
comment: DiscussionComment,
isClosed: Boolean
isClosed: Boolean,
) {
replaceFragmentWithBackStack(
fm,
Expand Down Expand Up @@ -340,7 +349,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di

override fun navigateToAnothersProfile(
fm: FragmentManager,
username: String
username: String,
) {
replaceFragmentWithBackStack(
fm,
Expand Down Expand Up @@ -410,7 +419,7 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
private fun replaceFragment(
fm: FragmentManager,
fragment: Fragment,
transaction: Int = FragmentTransaction.TRANSIT_NONE
transaction: Int = FragmentTransaction.TRANSIT_NONE,
) {
fm.beginTransaction()
.setTransition(transaction)
Expand Down
10 changes: 3 additions & 7 deletions app/src/main/java/org/openedx/app/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import androidx.viewpager2.widget.ViewPager2
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.openedx.DashboardNavigator
import org.openedx.app.databinding.FragmentMainBinding
import org.openedx.core.adapter.NavigationFragmentAdapter
import org.openedx.core.presentation.global.app_upgrade.UpgradeRequiredFragment
import org.openedx.core.presentation.global.viewBinding
import org.openedx.discovery.presentation.DiscoveryNavigator
import org.openedx.discovery.presentation.DiscoveryRouter
import org.openedx.learn.presentation.LearnFragment
import org.openedx.profile.presentation.profile.ProfileFragment

class MainFragment : Fragment(R.layout.fragment_main) {
Expand Down Expand Up @@ -97,12 +96,9 @@ class MainFragment : Fragment(R.layout.fragment_main) {
binding.viewPager.orientation = ViewPager2.ORIENTATION_HORIZONTAL
binding.viewPager.offscreenPageLimit = 4

val discoveryFragment = DiscoveryNavigator(viewModel.isDiscoveryTypeWebView).getDiscoveryFragment()
val dashboardFragment = DashboardNavigator(viewModel.dashboardType).getDashboardFragment()

adapter = NavigationFragmentAdapter(this).apply {
addFragment(dashboardFragment)
addFragment(discoveryFragment)
addFragment(LearnFragment())
addFragment(viewModel.getDiscoveryFragment)
addFragment(ProfileFragment())
}
binding.viewPager.adapter = adapter
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/org/openedx/app/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import org.openedx.core.BaseViewModel
import org.openedx.core.config.Config
import org.openedx.core.system.notifier.DiscoveryNotifier
import org.openedx.core.system.notifier.NavigationToDiscovery
import org.openedx.dashboard.presentation.DashboardRouter
import org.openedx.discovery.presentation.DiscoveryNavigator

class MainViewModel(
private val config: Config,
Expand All @@ -30,7 +32,7 @@ class MainViewModel(
get() = _navigateToDiscovery.asSharedFlow()

val isDiscoveryTypeWebView get() = config.getDiscoveryConfig().isViewTypeWebView()
val dashboardType get() = config.getDashboardConfig().getType()
val getDiscoveryFragment get() = DiscoveryNavigator(isDiscoveryTypeWebView).getDiscoveryFragment()

override fun onCreate(owner: LifecycleOwner) {
super.onCreate(owner)
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/main/java/org/openedx/DashboardNavigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package org.openedx

import androidx.fragment.app.Fragment
import org.openedx.core.config.DashboardConfig
import org.openedx.courses.presentation.DashboardGalleryFragment
import org.openedx.dashboard.presentation.DashboardListFragment
import org.openedx.learn.presentation.LearnFragment

class DashboardNavigator(
private val dashboardType: DashboardConfig.DashboardType,
) {
fun getDashboardFragment(): Fragment {
return when (dashboardType) {
DashboardConfig.DashboardType.GALLERY -> LearnFragment()
DashboardConfig.DashboardType.GALLERY -> DashboardGalleryFragment()
else -> DashboardListFragment()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
Expand Down Expand Up @@ -84,13 +85,11 @@ import org.openedx.core.presentation.global.app_upgrade.AppUpgradeRecommendedBox
import org.openedx.core.system.notifier.AppUpgradeEvent
import org.openedx.core.ui.HandleUIMessage
import org.openedx.core.ui.OfflineModeDialog
import org.openedx.core.ui.Toolbar
import org.openedx.core.ui.WindowSize
import org.openedx.core.ui.WindowType
import org.openedx.core.ui.displayCutoutForLandscape
import org.openedx.core.ui.rememberWindowSize
import org.openedx.core.ui.shouldLoadMore
import org.openedx.core.ui.statusBarsInset
import org.openedx.core.ui.theme.OpenEdXTheme
import org.openedx.core.ui.theme.appColors
import org.openedx.core.ui.theme.appShapes
Expand Down Expand Up @@ -158,9 +157,6 @@ class DashboardListFragment : Fragment() {
AppUpdateState.openPlayMarket(requireContext())
},
),
onSettingsClick = {
router.navigateToSettings(requireActivity().supportFragmentManager)
}
)
}
}
Expand All @@ -180,7 +176,6 @@ internal fun DashboardListView(
onReloadClick: () -> Unit,
onSwipeRefresh: () -> Unit,
paginationCallback: () -> Unit,
onSettingsClick: () -> Unit,
onItemClick: (EnrolledCourse) -> Unit,
appUpgradeParameters: AppUpdateState.AppUpgradeParameters,
) {
Expand All @@ -193,7 +188,7 @@ internal fun DashboardListView(
}
val scrollState = rememberLazyListState()
val firstVisibleIndex = remember {
mutableStateOf(scrollState.firstVisibleItemIndex)
mutableIntStateOf(scrollState.firstVisibleItemIndex)
}

Scaffold(
Expand Down Expand Up @@ -244,15 +239,9 @@ internal fun DashboardListView(
Column(
modifier = Modifier
.padding(paddingValues)
.statusBarsInset()
.displayCutoutForLandscape(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Toolbar(
label = stringResource(id = R.string.dashboard_title),
canShowSettingsIcon = true,
onSettingsClick = onSettingsClick
)

Surface(
color = MaterialTheme.appColors.background,
Expand Down Expand Up @@ -285,12 +274,6 @@ internal fun DashboardListView(
state = scrollState,
contentPadding = contentPaddings,
content = {
item() {
Column {
Header()
Spacer(modifier = Modifier.height(16.dp))
}
}
items(state.courses) { course ->
CourseItem(
apiHostUrl,
Expand Down Expand Up @@ -329,7 +312,6 @@ internal fun DashboardListView(
.then(contentWidth)
.then(emptyStatePaddings)
) {
Header()
EmptyState()
}
}
Expand Down Expand Up @@ -491,24 +473,6 @@ private fun CourseItem(
}
}

@Composable
private fun Header() {
Text(
modifier = Modifier.testTag("txt_courses_title"),
text = stringResource(id = R.string.dashboard_courses),
color = MaterialTheme.appColors.textPrimary,
style = MaterialTheme.appTypography.displaySmall
)
Text(
modifier = Modifier
.testTag("txt_courses_description")
.padding(top = 4.dp),
text = stringResource(id = R.string.dashboard_welcome_back),
color = MaterialTheme.appColors.textPrimaryVariant,
style = MaterialTheme.appTypography.titleSmall
)
}

@Composable
private fun EmptyState() {
Box(
Expand Down Expand Up @@ -542,7 +506,7 @@ private fun EmptyState() {
@Preview(uiMode = UI_MODE_NIGHT_YES)
@Composable
private fun CourseItemPreview() {
OpenEdXTheme() {
OpenEdXTheme {
CourseItem(
"http://localhost:8000",
mockCourseEnrolled,
Expand Down Expand Up @@ -577,7 +541,6 @@ private fun DashboardListViewPreview() {
refreshing = false,
canLoadMore = false,
paginationCallback = {},
onSettingsClick = {},
appUpgradeParameters = AppUpdateState.AppUpgradeParameters()
)
}
Expand Down Expand Up @@ -609,7 +572,6 @@ private fun DashboardListViewTabletPreview() {
refreshing = false,
canLoadMore = false,
paginationCallback = {},
onSettingsClick = {},
appUpgradeParameters = AppUpdateState.AppUpgradeParameters()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ interface DashboardRouter {

fun navigateToAllEnrolledCourses(fm: FragmentManager)

fun getProgramFragmentInstance(): Fragment
fun getProgramFragment(): Fragment
}
Loading

0 comments on commit 09b422a

Please sign in to comment.