Skip to content

Commit

Permalink
Fix #4447: Hide Info tab (#4528)
Browse files Browse the repository at this point in the history
* add EnableExtraTopicTabsUi platform parameter

* use platform parameter to hide extra topic tabs

* fix errors

* shorten line length

* add force method

* make changes to the test. Not completed yet.

* reset to develop

* add tests

* update to correct logic

* change parameter name

* fix some incorrect code

* fix some incorrect code

* adjust code changes for tests in this file

* remove unused resources

* lint

* add platform parameter module to alpha kenya app component

* remove unused resource - position with three tabs

* nit: concise kdoc

* add accidentally removed modules

* update logic ; review required

* lint

* reset all changes to AlphaKenyaApplicationComponent.kt

* add parameter to alpha kenya module

* remove "isSuccessful"

* add suggested changes

* lint

* update logic

* update test logic to account for the removed tabs

* lint

* suggested changes

* lint

* partial: delete practice tab module

* complete: remove practice tab module and enablePracticeTab

* update logic

* fix code after a bad merge

* update some tests according to changes introduced due to hiding tabs

* lint

* update test due to hiding some tabs

* lint

* update tests

* update rest of the tests to include changes from hiding tabs + modify chapter list PR

* lint

* dont use delegates

* remove duplicate entry and revert the "reversion"

* lint

* remove unused resource

* mend incorrect legacy logic

* remove usages of delegates

* lint

* lint
  • Loading branch information
JishnuGoyal authored Sep 27, 2022
1 parent d1e6fdb commit c9c4d9a
Show file tree
Hide file tree
Showing 161 changed files with 395 additions and 478 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.oppia.android.app.devoptions.DeveloperOptionsModule
import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule
import org.oppia.android.app.shim.IntentFactoryShimModule
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.PracticeTabModule
import org.oppia.android.app.translation.ActivityRecreatorProdModule
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
import org.oppia.android.data.backends.gae.NetworkModule
Expand Down Expand Up @@ -84,7 +83,7 @@ import javax.inject.Singleton
RatioInputModule::class, UncaughtExceptionLoggerModule::class,
ApplicationStartupListenerModule::class, LogReportWorkerModule::class,
WorkManagerConfigurationModule::class, HintsAndSolutionConfigModule::class,
FirebaseLogUploaderModule::class, NetworkModule::class, PracticeTabModule::class,
FirebaseLogUploaderModule::class, NetworkModule::class,
PlatformParameterModule::class, PlatformParameterSingletonModule::class,
ExplorationStorageModule::class, DeveloperOptionsModule::class,
PlatformParameterSyncUpWorkerModule::class, NetworkConfigProdModule::class, AssetModule::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.oppia.android.app.devoptions.DeveloperOptionsModule
import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule
import org.oppia.android.app.shim.IntentFactoryShimModule
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.PracticeTabModule
import org.oppia.android.app.translation.ActivityRecreatorProdModule
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
import org.oppia.android.data.backends.gae.NetworkModule
Expand Down Expand Up @@ -85,7 +84,7 @@ import javax.inject.Singleton
RatioInputModule::class, UncaughtExceptionLoggerModule::class,
ApplicationStartupListenerModule::class, LogReportWorkerModule::class,
WorkManagerConfigurationModule::class, HintsAndSolutionConfigAlphaKenyaModule::class,
FirebaseLogUploaderModule::class, NetworkModule::class, PracticeTabModule::class,
FirebaseLogUploaderModule::class, NetworkModule::class,
PlatformParameterAlphaKenyaModule::class, PlatformParameterSingletonModule::class,
ExplorationStorageModule::class, DeveloperOptionsModule::class,
PlatformParameterSyncUpWorkerModule::class, NetworkConfigProdModule::class, AssetModule::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.oppia.android.app.devoptions.DeveloperOptionsModule
import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule
import org.oppia.android.app.shim.IntentFactoryShimModule
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.PracticeTabModule
import org.oppia.android.app.translation.ActivityRecreatorProdModule
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
import org.oppia.android.data.backends.gae.NetworkModule
Expand Down Expand Up @@ -84,7 +83,7 @@ import javax.inject.Singleton
RatioInputModule::class, UncaughtExceptionLoggerModule::class,
ApplicationStartupListenerModule::class, LogReportWorkerModule::class,
WorkManagerConfigurationModule::class, HintsAndSolutionConfigModule::class,
FirebaseLogUploaderModule::class, NetworkModule::class, PracticeTabModule::class,
FirebaseLogUploaderModule::class, NetworkModule::class,
PlatformParameterModule::class, PlatformParameterSingletonModule::class,
ExplorationStorageModule::class, DeveloperOptionsModule::class,
PlatformParameterSyncUpWorkerModule::class, NetworkConfigProdModule::class, AssetModule::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule
import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule
import org.oppia.android.app.shim.IntentFactoryShimModule
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.PracticeTabModule
import org.oppia.android.app.translation.ActivityRecreatorProdModule
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
import org.oppia.android.data.backends.gae.NetworkModule
Expand Down Expand Up @@ -86,7 +85,7 @@ import javax.inject.Singleton
UncaughtExceptionLoggerModule::class, ApplicationStartupListenerModule::class,
LogReportWorkerModule::class, WorkManagerConfigurationModule::class,
HintsAndSolutionConfigModule::class, HintsAndSolutionDebugModule::class,
FirebaseLogUploaderModule::class, NetworkModule::class, PracticeTabModule::class,
FirebaseLogUploaderModule::class, NetworkModule::class,
PlatformParameterModule::class, PlatformParameterSingletonModule::class,
ExplorationStorageModule::class, DeveloperOptionsStarterModule::class,
DeveloperOptionsModule::class, PlatformParameterSyncUpWorkerModule::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.oppia.android.app.devoptions.DeveloperOptionsModule
import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule
import org.oppia.android.app.shim.IntentFactoryShimModule
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.PracticeTabModule
import org.oppia.android.app.translation.ActivityRecreatorProdModule
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
import org.oppia.android.data.backends.gae.NetworkModule
Expand Down Expand Up @@ -84,7 +83,7 @@ import javax.inject.Singleton
RatioInputModule::class, UncaughtExceptionLoggerModule::class,
ApplicationStartupListenerModule::class, LogReportWorkerModule::class,
WorkManagerConfigurationModule::class, HintsAndSolutionConfigModule::class,
FirebaseLogUploaderModule::class, NetworkModule::class, PracticeTabModule::class,
FirebaseLogUploaderModule::class, NetworkModule::class,
PlatformParameterModule::class, PlatformParameterSingletonModule::class,
ExplorationStorageModule::class, DeveloperOptionsModule::class,
PlatformParameterSyncUpWorkerModule::class, NetworkConfigProdModule::class, AssetModule::class,
Expand Down

This file was deleted.

12 changes: 0 additions & 12 deletions app/src/main/java/org/oppia/android/app/topic/PracticeTabModule.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import org.oppia.android.app.fragment.FragmentScope
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.databinding.TopicFragmentBinding
import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.util.platformparameter.EnableExtraTopicTabsUi
import org.oppia.android.util.platformparameter.PlatformParameterValue
import javax.inject.Inject

/** The presenter for [TopicFragment]. */
Expand All @@ -23,7 +25,7 @@ class TopicFragmentPresenter @Inject constructor(
private val fragment: Fragment,
private val viewModel: TopicViewModel,
private val oppiaLogger: OppiaLogger,
@EnablePracticeTab private val enablePracticeTab: Boolean,
@EnableExtraTopicTabsUi private val enableExtraTopicTabsUi: PlatformParameterValue<Boolean>,
private val resourceHandler: AppLanguageResourceHandler
) {
private lateinit var tabLayout: TabLayout
Expand Down Expand Up @@ -69,21 +71,29 @@ class TopicFragmentPresenter @Inject constructor(
}

private fun setCurrentTab(tab: TopicTab) {
viewPager.setCurrentItem(tab.ordinal, true)
viewPager.setCurrentItem(computeTabPosition(tab), true)
logTopicEvents(tab)
}

private fun computeTabPosition(tab: TopicTab): Int {
return if (enableExtraTopicTabsUi.value) tab.positionWithFourTabs else tab.positionWithTwoTabs
}

private fun setUpViewPager(viewPager2: ViewPager2, topicId: String, isConfigChanged: Boolean) {
val adapter =
ViewPagerAdapter(fragment, internalProfileId, topicId, storyId, enablePracticeTab)
ViewPagerAdapter(fragment, internalProfileId, topicId, storyId, enableExtraTopicTabsUi.value)
viewPager2.adapter = adapter
TabLayoutMediator(tabLayout, viewPager2) { tab, position ->
val topicTab = TopicTab.getTabForPosition(position, enablePracticeTab)
val topicTab = TopicTab.getTabForPosition(position, enableExtraTopicTabsUi.value)
tab.text = resourceHandler.getStringInLocale(topicTab.tabLabelResId)
tab.icon = ContextCompat.getDrawable(activity, topicTab.tabIconResId)
}.attach()
if (!isConfigChanged && topicId.isNotEmpty()) {
setCurrentTab(if (storyId.isNotEmpty()) TopicTab.LESSONS else TopicTab.INFO)
if (enableExtraTopicTabsUi.value) {
setCurrentTab(if (storyId.isNotEmpty()) TopicTab.LESSONS else TopicTab.INFO)
} else {
setCurrentTab(TopicTab.LESSONS)
}
}
}

Expand Down
26 changes: 14 additions & 12 deletions app/src/main/java/org/oppia/android/app/topic/TopicTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,53 @@ import org.oppia.android.R

/** Enum to store the tabs of [TopicFragment] and get tab by position. */
enum class TopicTab(
private val positionWithFourTabs: Int,
private val positionWithThreeTabs: Int,
val positionWithTwoTabs: Int,
val positionWithFourTabs: Int,
@StringRes val tabLabelResId: Int,
@DrawableRes val tabIconResId: Int
) {
INFO(
positionWithTwoTabs = -1,
positionWithFourTabs = 0,
positionWithThreeTabs = 0,
tabLabelResId = R.string.info,
tabIconResId = R.drawable.ic_info_icon_24dp
),
LESSONS(
positionWithTwoTabs = 0,
positionWithFourTabs = 1,
positionWithThreeTabs = 1,
tabLabelResId = R.string.lessons,
tabIconResId = R.drawable.ic_lessons_icon_24dp
),
PRACTICE(
positionWithTwoTabs = -1,
positionWithFourTabs = 2,
positionWithThreeTabs = -1,
tabLabelResId = R.string.practice,
tabIconResId = R.drawable.ic_practice_icon_24dp
),
REVISION(
positionWithTwoTabs = 1,
positionWithFourTabs = 3,
positionWithThreeTabs = 2,
tabLabelResId = R.string.revision,
tabIconResId = R.drawable.ic_revision_icon_24dp
);

companion object {
/**
* Returns the [TopicTab] corresponding to the specified tab position, considering whether the
* practice tab is enabled per [enablePracticeTab].
* info and practice tabs are enabled per [enableExtraTopicTabsUi].
*/
fun getTabForPosition(position: Int, enablePracticeTab: Boolean): TopicTab {
fun getTabForPosition(position: Int, enableExtraTopicTabsUi: Boolean): TopicTab {
return checkNotNull(
values().find {
position == if (enablePracticeTab) it.positionWithFourTabs else it.positionWithThreeTabs
position == if (enableExtraTopicTabsUi) {
it.positionWithFourTabs
} else it.positionWithTwoTabs
}
) { "No tab corresponding to position: $position" }
}

/** Returns the number of active tabs considering [enablePracticeTab] */
fun getTabCount(enablePracticeTab: Boolean) =
if (enablePracticeTab) values().size else values().size - 1
/** Returns the number of active tabs considering [enableExtraTopicTabsUi] */
fun getTabCount(enableExtraTopicTabsUi: Boolean) =
if (enableExtraTopicTabsUi) values().size else values().size - 2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class ViewPagerAdapter(
private val internalProfileId: Int,
private val topicId: String,
private val storyId: String,
private val enablePracticeTab: Boolean
private val enableExtraTopicTabsUi: Boolean
) : FragmentStateAdapter(fragment) {

override fun getItemCount(): Int = TopicTab.getTabCount(enablePracticeTab)
override fun getItemCount(): Int = TopicTab.getTabCount(enableExtraTopicTabsUi)

override fun createFragment(position: Int): Fragment {
return when (TopicTab.getTabForPosition(position, enablePracticeTab)) {
return when (TopicTab.getTabForPosition(position, enableExtraTopicTabsUi)) {
TopicTab.INFO -> {
TopicInfoFragment.newInstance(internalProfileId, topicId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import org.oppia.android.app.profile.ProfileChooserActivity
import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositionOnView
import org.oppia.android.app.settings.profile.ProfileListActivity
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.PracticeTabModule
import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule
import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
Expand Down Expand Up @@ -839,7 +838,7 @@ class AdministratorControlsActivityTest {
ViewBindingShimModule::class, RatioInputModule::class, WorkManagerConfigurationModule::class,
ApplicationStartupListenerModule::class, LogReportWorkerModule::class,
HintsAndSolutionConfigModule::class, HintsAndSolutionProdModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class, PracticeTabModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class,
DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class,
ExplorationStorageModule::class, NetworkModule::class, NetworkConfigProdModule::class,
NetworkConnectionUtilDebugModule::class, NetworkConnectionDebugUtilModule::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionMo
import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositionOnView
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.testing.AdministratorControlsFragmentTestActivity
import org.oppia.android.app.topic.PracticeTabModule
import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule
import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape
import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationPortrait
Expand Down Expand Up @@ -607,7 +606,7 @@ class AdministratorControlsFragmentTest {
ViewBindingShimModule::class, RatioInputModule::class, WorkManagerConfigurationModule::class,
ApplicationStartupListenerModule::class, LogReportWorkerModule::class,
HintsAndSolutionConfigModule::class, HintsAndSolutionProdModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class, PracticeTabModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class,
DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class,
ExplorationStorageModule::class, NetworkModule::class, NetworkConfigProdModule::class,
NetworkConnectionUtilDebugModule::class, NetworkConnectionDebugUtilModule::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule
import org.oppia.android.app.model.ScreenName
import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.PracticeTabModule
import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule
import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape
import org.oppia.android.app.utility.getLastUpdateTime
Expand Down Expand Up @@ -294,7 +293,7 @@ class AppVersionActivityTest {
ViewBindingShimModule::class, RatioInputModule::class, WorkManagerConfigurationModule::class,
ApplicationStartupListenerModule::class, LogReportWorkerModule::class,
HintsAndSolutionConfigModule::class, HintsAndSolutionProdModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class, PracticeTabModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class,
DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class,
ExplorationStorageModule::class, NetworkModule::class, NetworkConfigProdModule::class,
NetworkConnectionUtilDebugModule::class, NetworkConnectionDebugUtilModule::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import org.oppia.android.app.model.ScreenName
import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule
import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.hasItemCount
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.PracticeTabModule
import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
import org.oppia.android.data.backends.gae.NetworkModule
Expand Down Expand Up @@ -205,7 +204,7 @@ class ProfileAndDeviceIdActivityTest {
ViewBindingShimModule::class, RatioInputModule::class, WorkManagerConfigurationModule::class,
ApplicationStartupListenerModule::class, LogReportWorkerModule::class,
HintsAndSolutionConfigModule::class, HintsAndSolutionProdModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class, PracticeTabModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class,
DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class,
ExplorationStorageModule::class, NetworkModule::class, NetworkConfigProdModule::class,
NetworkConnectionUtilDebugModule::class, NetworkConnectionDebugUtilModule::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositi
import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.hasItemCount
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.testing.activity.TestActivity
import org.oppia.android.app.topic.PracticeTabModule
import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule
import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
Expand Down Expand Up @@ -620,7 +619,7 @@ class ProfileAndDeviceIdFragmentTest {
RatioInputModule::class, WorkManagerConfigurationModule::class,
ApplicationStartupListenerModule::class, LogReportWorkerModule::class,
HintsAndSolutionConfigModule::class, HintsAndSolutionProdModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class, PracticeTabModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class,
DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class,
ExplorationStorageModule::class, NetworkModule::class, NetworkConfigProdModule::class,
NetworkConnectionUtilDebugModule::class, NetworkConnectionDebugUtilModule::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import org.oppia.android.app.model.ScreenName
import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule
import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositionOnView
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.PracticeTabModule
import org.oppia.android.app.topic.TopicActivity
import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule
import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape
Expand Down Expand Up @@ -518,7 +517,7 @@ class CompletedStoryListActivityTest {
ViewBindingShimModule::class, RatioInputModule::class, WorkManagerConfigurationModule::class,
ApplicationStartupListenerModule::class, LogReportWorkerModule::class,
HintsAndSolutionConfigModule::class, HintsAndSolutionProdModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class, PracticeTabModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class,
DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class,
ExplorationStorageModule::class, NetworkModule::class, NetworkConfigProdModule::class,
NetworkConnectionUtilDebugModule::class, NetworkConnectionDebugUtilModule::class,
Expand Down
Loading

0 comments on commit c9c4d9a

Please sign in to comment.