Skip to content

Commit

Permalink
Simplify tab navigation using new extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Sep 21, 2023
1 parent ca8b5b1 commit 8f1c21e
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 18 deletions.
2 changes: 0 additions & 2 deletions app/src/main/java/org/wikipedia/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ object Constants {
const val INTENT_EXTRA_ACTION = "intentAction"
const val INTENT_EXTRA_DELETE_READING_LIST = "deleteReadingList"
const val INTENT_EXTRA_GO_TO_MAIN_TAB = "goToMainTab"
const val INTENT_EXTRA_GO_TO_SE_TAB = "goToSETab"
const val INTENT_EXTRA_HAS_TRANSITION_ANIM = "hasTransitionAnim"
const val INTENT_EXTRA_INVOKE_SOURCE = "invokeSource"
const val INTENT_EXTRA_PREVIEW_SAVED_READING_LISTS = "previewSavedReadingList"
const val INTENT_EXTRA_NOTIFICATION_ID = "notificationId"
const val INTENT_EXTRA_NOTIFICATION_SYNC_CANCEL = "syncCancel"
const val INTENT_EXTRA_NOTIFICATION_SYNC_PAUSE_RESUME = "syncPauseResume"
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/org/wikipedia/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.wikipedia.activity.SingleFragmentActivity
import org.wikipedia.analytics.eventplatform.ImageRecommendationsEvent
import org.wikipedia.databinding.ActivityMainBinding
import org.wikipedia.dataclient.WikiSite
import org.wikipedia.extensions.serializableExtra
import org.wikipedia.navtab.NavTab
import org.wikipedia.onboarding.InitialOnboardingActivity
import org.wikipedia.page.PageActivity
Expand All @@ -39,8 +40,8 @@ class MainActivity : SingleFragmentActivity<MainFragment>(), MainFragment.Callba
super.onCreate(savedInstanceState)

setImageZoomHelper()
if (Prefs.isInitialOnboardingEnabled && savedInstanceState == null && !intent.hasExtra(
Constants.INTENT_EXTRA_PREVIEW_SAVED_READING_LISTS)) {
if (Prefs.isInitialOnboardingEnabled && savedInstanceState == null &&
intent.serializableExtra<NavTab>(Constants.INTENT_EXTRA_GO_TO_MAIN_TAB) != NavTab.READING_LISTS) {
// Updating preference so the search multilingual tooltip
// is not shown again for first time users
Prefs.isMultilingualSearchTooltipShown = false
Expand Down
19 changes: 9 additions & 10 deletions app/src/main/java/org/wikipedia/main/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.wikipedia.databinding.FragmentMainBinding
import org.wikipedia.dataclient.WikiSite
import org.wikipedia.events.ImportReadingListsEvent
import org.wikipedia.events.LoggedOutInBackgroundEvent
import org.wikipedia.extensions.serializableExtra
import org.wikipedia.feed.FeedFragment
import org.wikipedia.feed.image.FeaturedImage
import org.wikipedia.feed.image.FeaturedImageCard
Expand Down Expand Up @@ -296,16 +297,14 @@ class MainFragment : Fragment(), BackPressedHandler, MenuProvider, FeedFragment.
startActivity(PageActivity.newIntent(requireActivity()))
} else if (intent.hasExtra(Constants.INTENT_EXTRA_DELETE_READING_LIST)) {
goToTab(NavTab.READING_LISTS)
} else if (intent.hasExtra(Constants.INTENT_EXTRA_GO_TO_MAIN_TAB) &&
!(binding.mainNavTabLayout.selectedItemId == NavTab.EXPLORE.code() &&
intent.getIntExtra(Constants.INTENT_EXTRA_GO_TO_MAIN_TAB, NavTab.EXPLORE.code()) == NavTab.EXPLORE.code())) {
goToTab(NavTab.of(intent.getIntExtra(Constants.INTENT_EXTRA_GO_TO_MAIN_TAB, NavTab.EXPLORE.code())))
} else if (intent.hasExtra(Constants.INTENT_EXTRA_GO_TO_SE_TAB)) {
goToTab(NavTab.of(intent.getIntExtra(Constants.INTENT_EXTRA_GO_TO_SE_TAB, NavTab.EDITS.code())))
} else if (intent.hasExtra(Constants.INTENT_EXTRA_PREVIEW_SAVED_READING_LISTS)) {
goToTab(NavTab.READING_LISTS)
} else if (lastPageViewedWithin(1) && !intent.hasExtra(Constants.INTENT_RETURN_TO_MAIN) && WikipediaApp.instance.tabCount > 0) {
startActivity(PageActivity.newIntent(requireContext()))
} else {
val tab = intent.serializableExtra<NavTab>(Constants.INTENT_EXTRA_GO_TO_MAIN_TAB)
if (tab != null && (binding.mainNavTabLayout.selectedItemId != NavTab.EXPLORE.code()
|| tab != NavTab.EXPLORE)) {
goToTab(tab)
} else if (lastPageViewedWithin(1) && !intent.hasExtra(Constants.INTENT_RETURN_TO_MAIN) && WikipediaApp.instance.tabCount > 0) {
startActivity(PageActivity.newIntent(requireContext()))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.wikipedia.dataclient.WikiSite
import org.wikipedia.events.UnreadNotificationsEvent
import org.wikipedia.extensions.parcelableExtra
import org.wikipedia.main.MainActivity
import org.wikipedia.navtab.NavTab
import org.wikipedia.notifications.db.Notification
import org.wikipedia.page.PageTitle
import org.wikipedia.push.WikipediaFirebaseMessagingService
Expand Down Expand Up @@ -184,7 +185,9 @@ class NotificationPollBroadcastReceiver : BroadcastReceiver() {
}

fun showSuggestedEditsLocalNotification(context: Context, @StringRes description: Int) {
val intent = NotificationPresenter.addIntentExtras(MainActivity.newIntent(context).putExtra(Constants.INTENT_EXTRA_GO_TO_SE_TAB, true), 0, TYPE_LOCAL)
val mainIntent = MainActivity.newIntent(context)
.putExtra(Constants.INTENT_EXTRA_GO_TO_MAIN_TAB, NavTab.EDITS)
val intent = NotificationPresenter.addIntentExtras(mainIntent, 0, TYPE_LOCAL)
NotificationPresenter.showNotification(context, NotificationPresenter.getDefaultBuilder(context, 0, TYPE_LOCAL), 0,
context.getString(R.string.suggested_edits_reactivation_notification_title),
context.getString(description), context.getString(description), null,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/wikipedia/page/PageFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ class PageFragment : Fragment(), BackPressedHandler, CommunicationBridge.Communi
startActivity(MainActivity.newIntent(requireContext())
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
.putExtra(Constants.INTENT_RETURN_TO_MAIN, true)
.putExtra(Constants.INTENT_EXTRA_GO_TO_MAIN_TAB, NavTab.EXPLORE.code()))
.putExtra(Constants.INTENT_EXTRA_GO_TO_MAIN_TAB, NavTab.EXPLORE))
requireActivity().finish()
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/wikipedia/page/tabs/TabActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class TabActivity : BaseActivity() {
startActivity(MainActivity.newIntent(this)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
.putExtra(Constants.INTENT_RETURN_TO_MAIN, true)
.putExtra(Constants.INTENT_EXTRA_GO_TO_MAIN_TAB, NavTab.EXPLORE.code()))
.putExtra(Constants.INTENT_EXTRA_GO_TO_MAIN_TAB, NavTab.EXPLORE))
finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.wikipedia.events.PageDownloadEvent
import org.wikipedia.history.HistoryEntry
import org.wikipedia.history.SearchActionModeCallback
import org.wikipedia.main.MainActivity
import org.wikipedia.navtab.NavTab
import org.wikipedia.page.ExclusiveBottomSheetPresenter
import org.wikipedia.page.PageActivity
import org.wikipedia.page.PageAvailableOfflineHandler
Expand Down Expand Up @@ -467,7 +468,8 @@ class ReadingListFragment : Fragment(), MenuProvider, ReadingListItemActionsDial
AppDatabase.instance.readingListPageDao().addPagesToList(it, it.pages, true)
Prefs.readingListRecentReceivedId = it.id
requireActivity().startActivity(MainActivity.newIntent(requireContext())
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).putExtra(Constants.INTENT_EXTRA_PREVIEW_SAVED_READING_LISTS, true))
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
.putExtra(Constants.INTENT_EXTRA_GO_TO_MAIN_TAB, NavTab.READING_LISTS))
requireActivity().finish()
}
.setNegativeButton(R.string.reading_lists_preview_save_dialog_cancel, null)
Expand Down

0 comments on commit 8f1c21e

Please sign in to comment.