Skip to content

Commit

Permalink
feat: add Auth Panel for WebView discovery for pre login experience
Browse files Browse the repository at this point in the history
- Auth Panel (SignIn, Register) remains visible during pre-login webview discovery.
- Ensure Sign In & Enroll mirror Native Discovery & Market App functionality.

fixes: LEARNER-9798
  • Loading branch information
farhan-arshad-dev committed Feb 1, 2024
1 parent 975f41a commit f604970
Show file tree
Hide file tree
Showing 21 changed files with 248 additions and 84 deletions.
16 changes: 8 additions & 8 deletions app/src/main/java/org/openedx/app/AppRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
ProfileRouter, AppUpgradeRouter, WhatsNewRouter {

//region AuthRouter
override fun navigateToMain(fm: FragmentManager, courseId: String?) {
override fun navigateToMain(fm: FragmentManager, courseId: String?, infoType: String?) {
fm.popBackStack()
fm.beginTransaction()
.replace(R.id.container, MainFragment.newInstance(courseId))
.replace(R.id.container, MainFragment.newInstance(courseId, infoType))
.commit()
}

override fun navigateToSignIn(fm: FragmentManager, courseId: String?) {
replaceFragmentWithBackStack(fm, SignInFragment.newInstance(courseId))
override fun navigateToSignIn(fm: FragmentManager, courseId: String?, infoType: String?) {
replaceFragmentWithBackStack(fm, SignInFragment.newInstance(courseId, infoType))
}

override fun navigateToSignUp(fm: FragmentManager, courseId: String?) {
replaceFragmentWithBackStack(fm, SignUpFragment.newInstance(courseId))
override fun navigateToSignUp(fm: FragmentManager, courseId: String?, infoType: String?) {
replaceFragmentWithBackStack(fm, SignUpFragment.newInstance(courseId, infoType))
}

override fun navigateToLogistration(fm: FragmentManager, courseId: String?) {
Expand All @@ -88,10 +88,10 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
replaceFragmentWithBackStack(fm, WebViewDiscoveryFragment.newInstance(querySearch))
}

override fun navigateToWhatsNew(fm: FragmentManager, courseId: String?) {
override fun navigateToWhatsNew(fm: FragmentManager, courseId: String?, infoType: String?) {
fm.popBackStack()
fm.beginTransaction()
.replace(R.id.container, WhatsNewFragment.newInstance(courseId))
.replace(R.id.container, WhatsNewFragment.newInstance(courseId, infoType))
.commit()
}

Expand Down
22 changes: 16 additions & 6 deletions app/src/main/java/org/openedx/app/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.openedx.app.adapter.MainNavigationFragmentAdapter
import org.openedx.app.databinding.FragmentMainBinding
import org.openedx.core.config.Config
import org.openedx.core.presentation.global.app_upgrade.UpgradeRequiredFragment
import org.openedx.core.presentation.global.viewBinding
import org.openedx.dashboard.presentation.dashboard.DashboardFragment
Expand All @@ -27,6 +28,7 @@ class MainFragment : Fragment(R.layout.fragment_main) {
private val analytics by inject<AppAnalytics>()
private val viewModel by viewModel<MainViewModel>()
private val router by inject<DiscoveryRouter>()
private val config by inject<Config>()

private lateinit var adapter: MainNavigationFragmentAdapter

Expand Down Expand Up @@ -81,11 +83,17 @@ class MainFragment : Fragment(R.layout.fragment_main) {
}
}

requireArguments().apply {
this.getString(ARG_COURSE_ID, null)?.apply {
router.navigateToCourseDetail(parentFragmentManager, this)
requireArguments().let { bundle ->
bundle.getString(ARG_COURSE_ID, null)?.apply {
val infoType = bundle.getString(ARG_INFO_TYPE, null)
if (config.getDiscoveryConfig().isViewTypeWebView() && infoType != null) {
router.navigateToCourseInfo(parentFragmentManager, this, infoType)
} else {
router.navigateToCourseDetail(parentFragmentManager, this)
}
}
this.putString(ARG_COURSE_ID, null)
bundle.putString(ARG_COURSE_ID, null)
bundle.putString(ARG_INFO_TYPE, null)
}
}

Expand Down Expand Up @@ -119,10 +127,12 @@ class MainFragment : Fragment(R.layout.fragment_main) {

companion object {
private const val ARG_COURSE_ID = "courseId"
fun newInstance(courseId: String? = null): MainFragment {
private const val ARG_INFO_TYPE = "info_type"
fun newInstance(courseId: String? = null, infoType: String? = null): MainFragment {
val fragment = MainFragment()
fragment.arguments = bundleOf(
ARG_COURSE_ID to courseId
ARG_COURSE_ID to courseId,
ARG_INFO_TYPE to infoType
)
return fragment
}
Expand Down
25 changes: 22 additions & 3 deletions app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ val screenModule = module {
factory { AuthRepository(get(), get(), get()) }
factory { AuthInteractor(get()) }
factory { Validator() }
viewModel { (courseId: String?) ->
viewModel { (courseId: String?, infoType: String?) ->
SignInViewModel(
get(),
get(),
Expand All @@ -77,6 +77,7 @@ val screenModule = module {
get(),
get(),
courseId,
infoType,
)
}
viewModel { (courseId: String?) ->
Expand Down Expand Up @@ -126,7 +127,19 @@ val screenModule = module {

single { CourseRepository(get(), get(), get(), get()) }
factory { CourseInteractor(get()) }
viewModel { CourseInfoViewModel(get(), get(), get(), get(), get(), get(), get()) }
viewModel { (pathId: String, infoType: String) ->
CourseInfoViewModel(
get(),
get(),
get(),
get(),
get(),
get(),
get(),
pathId,
infoType
)
}
viewModel { (courseId: String) ->
CourseDetailsViewModel(
courseId,
Expand Down Expand Up @@ -266,7 +279,13 @@ val screenModule = module {
)
}

viewModel { (courseId: String?) -> WhatsNewViewModel(courseId, get()) }
viewModel { (courseId: String?, infoType: String?) ->
WhatsNewViewModel(
courseId,
infoType,
get()
)
}
viewModel { HtmlUnitViewModel(get(), get(), get(), get()) }

viewModel { ProgramViewModel(get(), get(), get(), get(), get(), get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import androidx.fragment.app.FragmentManager

interface AuthRouter {

fun navigateToMain(fm: FragmentManager, courseId: String?)
fun navigateToMain(fm: FragmentManager, courseId: String?, infoType: String?)

fun navigateToSignIn(fm: FragmentManager, courseId: String?)
fun navigateToSignIn(fm: FragmentManager, courseId: String?, infoType: String?)

fun navigateToLogistration(fm: FragmentManager, courseId: String?)

fun navigateToSignUp(fm: FragmentManager, courseId: String?)
fun navigateToSignUp(fm: FragmentManager, courseId: String?, infoType: String?)

fun navigateToRestorePassword(fm: FragmentManager)

fun navigateToWhatsNew(fm: FragmentManager, courseId: String? = null)
fun navigateToWhatsNew(fm: FragmentManager, courseId: String? = null, infoType: String? = null)

fun navigateToWebDiscoverCourses(
fm: FragmentManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,18 @@ class LogistrationFragment : Fragment() {
val isDiscoveryTypeWebView = config.getDiscoveryConfig().isViewTypeWebView()
LogistrationScreen(
onSignInClick = {
router.navigateToSignIn(parentFragmentManager, courseId)
router.navigateToSignIn(parentFragmentManager, courseId, null)
},
onRegisterClick = {
router.navigateToSignUp(parentFragmentManager, courseId)
router.navigateToSignUp(parentFragmentManager, courseId, null)
},
onSearchClick = { querySearch ->
if (isDiscoveryTypeWebView) {
router.navigateToWebDiscoverCourses(parentFragmentManager, querySearch, true)
router.navigateToWebDiscoverCourses(
parentFragmentManager,
querySearch,
true
)
} else {
router.navigateToNativeDiscoverCourses(
parentFragmentManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import org.openedx.core.ui.theme.OpenEdXTheme
class SignInFragment : Fragment() {

private val viewModel: SignInViewModel by viewModel {
parametersOf(requireArguments().getString(ARG_COURSE_ID, null))
parametersOf(
requireArguments().getString(ARG_COURSE_ID, null),
requireArguments().getString(ARG_INFO_TYPE, null)
)
}
private val router: AuthRouter by inject()
private val whatsNewGlobalManager by inject<WhatsNewGlobalManager>()
Expand Down Expand Up @@ -67,7 +70,7 @@ class SignInFragment : Fragment() {

AuthEvent.RegisterClick -> {
viewModel.signUpClickedEvent()
router.navigateToSignUp(parentFragmentManager, null)
router.navigateToSignUp(parentFragmentManager, null, null)
}

AuthEvent.BackClick -> {
Expand All @@ -82,9 +85,17 @@ class SignInFragment : Fragment() {
if (state.loginSuccess) {
router.clearBackStack(parentFragmentManager)
if (isNeedToShowWhatsNew) {
router.navigateToWhatsNew(parentFragmentManager, viewModel.courseId)
router.navigateToWhatsNew(
parentFragmentManager,
viewModel.courseId,
viewModel.infoType
)
} else {
router.navigateToMain(parentFragmentManager, viewModel.courseId)
router.navigateToMain(
parentFragmentManager,
viewModel.courseId,
viewModel.infoType
)
}
}

Expand All @@ -102,10 +113,12 @@ class SignInFragment : Fragment() {

companion object {
private const val ARG_COURSE_ID = "courseId"
fun newInstance(courseId: String?): SignInFragment {
private const val ARG_INFO_TYPE = "info_type"
fun newInstance(courseId: String?, infoType: String?): SignInFragment {
val fragment = SignInFragment()
fragment.arguments = bundleOf(
ARG_COURSE_ID to courseId
ARG_COURSE_ID to courseId,
ARG_INFO_TYPE to infoType
)
return fragment
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class SignInViewModel(
private val microsoftAuthHelper: MicrosoftAuthHelper,
val config: Config,
val courseId: String?,
val infoType: String?,
) : BaseViewModel() {

private val logger = Logger("SignInViewModel")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class SignUpFragment : Fragment() {
LaunchedEffect(successLogin) {
if (successLogin == true) {
router.clearBackStack(requireActivity().supportFragmentManager)
router.navigateToMain(parentFragmentManager, viewModel.courseId)
router.navigateToMain(parentFragmentManager, viewModel.courseId, null)
}
}
} else {
Expand All @@ -164,10 +164,12 @@ class SignUpFragment : Fragment() {

companion object {
private const val ARG_COURSE_ID = "courseId"
fun newInstance(courseId: String?): SignUpFragment {
private const val ARG_INFO_TYPE = "info_type"
fun newInstance(courseId: String?, infoType: String?): SignUpFragment {
val fragment = SignUpFragment()
fragment.arguments = bundleOf(
ARG_COURSE_ID to courseId
ARG_COURSE_ID to courseId,
ARG_INFO_TYPE to infoType
)
return fragment
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ interface CourseRouter {
infoType: String,
)

fun navigateToSignUp(fm: FragmentManager, courseId: String?)
fun navigateToSignUp(fm: FragmentManager, courseId: String?, infoType: String?)

fun navigateToSignIn(fm: FragmentManager, courseId: String?)
fun navigateToSignIn(fm: FragmentManager, courseId: String?, infoType: String?)

fun navigateToLogistration(fm: FragmentManager, courseId: String?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ class CourseDetailsFragment : Fragment() {
}
},
onRegisterClick = {
router.navigateToSignUp(parentFragmentManager, viewModel.courseId)
router.navigateToSignUp(parentFragmentManager, viewModel.courseId, null)
},
onSignInClick = {
router.navigateToSignIn(parentFragmentManager, viewModel.courseId)
router.navigateToSignIn(parentFragmentManager, viewModel.courseId, null)
},
)
}
Expand Down
Loading

0 comments on commit f604970

Please sign in to comment.