Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
0dbb136
Convert Tabs to use database
cooltey Sep 24, 2024
2d8a9ed
Unused import
cooltey Sep 24, 2024
391ebce
Merge branch 'main' into tabs-database
cooltey Sep 25, 2024
f4625ab
Update database version
cooltey Sep 25, 2024
e6a1417
Update database version
cooltey Sep 25, 2024
11711dc
Merge branch 'main' into tabs-database
cooltey Sep 26, 2024
92d3e1c
Fix error
cooltey Sep 26, 2024
c8a440e
Clear and reset
cooltey Sep 26, 2024
918f977
Merge branch 'main' into tabs-database
cooltey Sep 30, 2024
799a68d
Fix errors
cooltey Sep 30, 2024
c775870
Merge branch 'main' into tabs-database
cooltey Sep 30, 2024
a409ed6
Merge branch 'main' into tabs-database
cooltey Oct 8, 2024
519a4f6
Merge branch 'main' into tabs-database
cooltey Oct 10, 2024
14b756a
Merge branch 'main' into tabs-database
Williamrai Oct 11, 2024
9395b28
Merge branch 'main' into tabs-database
cooltey Oct 15, 2024
8685967
Merge branch 'main' into tabs-database
cooltey Oct 16, 2024
9372430
Merge branch 'main' into tabs-database
cooltey Oct 22, 2024
bc26a8e
Merge branch 'main' into tabs-database
dbrant Oct 25, 2024
e5bffe6
Merge branch 'main' into tabs-database
dbrant Nov 6, 2024
ae2271d
Merge branch 'main' into tabs-database
cooltey Nov 14, 2024
4e81396
Merge branch 'main' into tabs-database
cooltey Nov 15, 2024
3c77685
Merge branch 'main' into tabs-database
dbrant Nov 15, 2024
76e5800
Merge branch 'main' into tabs-database
cooltey Nov 18, 2024
1d5d688
Merge branch 'main' into tabs-database
cooltey Nov 20, 2024
365c170
Merge branch 'main' into tabs-database
cooltey Nov 22, 2024
28d3eeb
Merge branch 'main' into tabs-database
cooltey Jan 15, 2025
c280e52
Merge branch 'main' into tabs-database
cooltey Jan 17, 2025
5f0f76d
Merge branch 'main' into tabs-database
cooltey Feb 11, 2025
51ceef3
Merge branch 'main' into tabs-database
cooltey Feb 13, 2025
6948bcd
Merge branch 'main' into tabs-database
Williamrai Feb 18, 2025
f7a41ed
Merge branch 'main' into tabs-database
cooltey Feb 18, 2025
16f7d73
Merge branch 'main' into tabs-database
cooltey Feb 18, 2025
ff100e2
Merge branch 'main' into tabs-database
cooltey Feb 19, 2025
5587987
Some checks update
cooltey Feb 19, 2025
b72b623
Merge branch 'main' into tabs-database
cooltey Feb 20, 2025
4ced578
Merge branch 'main' into tabs-database
cooltey Jun 23, 2025
63ec651
Merge branch 'main' into tabs-database
cooltey Jun 24, 2025
3da9909
Update json files
cooltey Jun 24, 2025
42938b6
Update the format a bit
cooltey Jun 24, 2025
c201d0a
Merge branch 'main' into tabs-database
cooltey Jun 25, 2025
dae54eb
utilize the db usage
cooltey Jun 26, 2025
92fbfb6
Fix parameter
cooltey Jun 26, 2025
6ff5747
Merge branch 'main' into tabs-database
cooltey Jun 26, 2025
a36da93
Merge branch 'main' into tabs-database
cooltey Jun 26, 2025
44f39d2
Merge branch 'main' into tabs-database
cooltey Jun 26, 2025
9eb5dca
Merge branch 'main' into tabs-database
cooltey Jun 30, 2025
bffba47
Merge branch 'main' into tabs-database
cooltey Jul 2, 2025
9137dec
Merge branch 'main' into tabs-database
cooltey Jul 8, 2025
c13ddf2
Merge branch 'main' into tabs-database
cooltey Jul 8, 2025
b288a53
Convert PageBackStackItem to an entity class
cooltey Jul 8, 2025
62f25c0
Update database for PageBackStackItem
cooltey Jul 8, 2025
d1c79ae
Replace backstack position with backstack id
cooltey Jul 9, 2025
7c4509f
Use list to store the backstack ids
cooltey Jul 9, 2025
93dea56
Update and consolidate
cooltey Jul 9, 2025
8034bc2
Refine the TabHelper
cooltey Jul 9, 2025
588aafe
Add logic of handling the orders
cooltey Jul 10, 2025
5db1e1b
refine commitState
cooltey Jul 10, 2025
a869b09
Merge branch 'main' into tabs-database
cooltey Jul 10, 2025
0dcd7c4
Update
cooltey Jul 10, 2025
7cbce16
Fix references
cooltey Jul 10, 2025
748deb6
Handle database SQL and fix error
cooltey Jul 11, 2025
af64bf9
Add a comment
cooltey Jul 11, 2025
7ecaa53
Merge branch 'main' into tabs-database
cooltey Jul 11, 2025
711afbc
Set up id correctly
cooltey Jul 11, 2025
bd4bbb5
Handling current tab
cooltey Jul 11, 2025
c0cb9e1
build pageTitle correctly
cooltey Jul 11, 2025
ef60b58
Refine migration
cooltey Jul 11, 2025
248f261
Fix lint
cooltey Jul 11, 2025
762d645
Add custom PageBackStackItemSerializer for old vs new format
cooltey Jul 11, 2025
9b439ff
Correctly passing the lifecycleowner
cooltey Jul 11, 2025
5194fad
Oops
cooltey Jul 11, 2025
0f0f59d
Add a todo comment for further improvement
cooltey Jul 11, 2025
5988cfd
Merge branch 'main' into tabs-database
cooltey Jul 14, 2025
dd50476
Add comments
cooltey Jul 14, 2025
e8cda31
A proper migration
cooltey Jul 14, 2025
881bcdb
Merge branch 'main' into tabs-database
cooltey Jul 14, 2025
a11f1a6
Get correct index
cooltey Jul 15, 2025
b6a5bbd
unused import
cooltey Jul 15, 2025
2053dd3
Merge branch 'main' into tabs-database
cooltey Jul 15, 2025
de0d7b6
Create viewModel for TabActivity
cooltey Jul 16, 2025
8e4fa10
regular lifecycle
cooltey Jul 16, 2025
11ea48b
Delete state
cooltey Jul 16, 2025
94a50e9
Merge branch 'main' into tabs-database
cooltey Jul 16, 2025
5c3a696
Handle tabs in viewModel
cooltey Jul 16, 2025
6e14843
visibility
cooltey Jul 16, 2025
6f6f4c4
Re-arrange orders correctly
cooltey Jul 16, 2025
98e9461
Final commit for TabViewModel
cooltey Jul 17, 2025
8415bd0
Adjust the animation
cooltey Jul 17, 2025
f2476fb
Merge branch 'main' into tabs-database
cooltey Jul 17, 2025
6a33ae8
Put coroutine in TabCountView
cooltey Jul 17, 2025
7c57fbe
Merge branch 'tabs-database' of github.com:wikimedia/apps-android-wik…
cooltey Jul 17, 2025
5c4e777
Fix lint
cooltey Jul 17, 2025
f1ab7cf
Add another uistate for undo actions
cooltey Jul 17, 2025
ea4f415
Try to make tab count updated correctly
cooltey Jul 17, 2025
630fe08
Merge branch 'main' into tabs-database
cooltey Jul 17, 2025
843e93c
Update the tab count properly
cooltey Jul 17, 2025
153689d
Merge branch 'tabs-database' of github.com:wikimedia/apps-android-wik…
cooltey Jul 17, 2025
742b733
Handle foreground vs background
cooltey Jul 17, 2025
ffcc7f9
rename the function and order better
cooltey Jul 18, 2025
8147f73
prep for pagefragment
cooltey Jul 18, 2025
9563e30
something more
cooltey Jul 18, 2025
9dbd051
Merge branch 'main' into tabs-database
cooltey Jul 18, 2025
f4e250a
add runBlocking first
cooltey Jul 18, 2025
26613a2
Merge branch 'tabs-database' of github.com:wikimedia/apps-android-wik…
cooltey Jul 18, 2025
3fdedc3
Merge branch 'main' into tabs-database
cooltey Jul 18, 2025
2197052
Fix errors
cooltey Jul 18, 2025
2d42b57
Fix lint
cooltey Jul 18, 2025
51b6631
Handling moveToForeground correctly
cooltey Jul 18, 2025
ac90063
New tab
cooltey Jul 18, 2025
dc4de2b
Further logic change
cooltey Jul 18, 2025
132c96a
Handling tabs in pageFragment
cooltey Jul 18, 2025
e6e7d64
handle reload issue
cooltey Jul 19, 2025
61dd964
Create new tab
cooltey Jul 19, 2025
a3e7d5e
Merge branch 'main' into tabs-database
cooltey Jul 21, 2025
0f7a0b5
Merge branch 'main' into tabs-database
cooltey Jul 28, 2025
94a9177
Merge branch 'main' into tabs-database
cooltey Aug 19, 2025
65fcfbc
Merge branch 'main' into tabs-database
cooltey Aug 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
851 changes: 851 additions & 0 deletions app/schemas/org.wikipedia.database.AppDatabase/32.json

Large diffs are not rendered by default.

25 changes: 0 additions & 25 deletions app/src/main/java/org/wikipedia/WikipediaApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import org.wikipedia.language.AcceptLanguageUtil
import org.wikipedia.language.AppLanguageState
import org.wikipedia.notifications.NotificationCategory
import org.wikipedia.notifications.NotificationPollBroadcastReceiver
import org.wikipedia.page.tabs.Tab
import org.wikipedia.push.WikipediaFirebaseMessagingService
import org.wikipedia.settings.Prefs
import org.wikipedia.theme.Theme
Expand Down Expand Up @@ -66,7 +65,6 @@ class WikipediaApp : Application() {
private var defaultWikiSite: WikiSite? = null

val connectionStateMonitor = ConnectionStateMonitor()
val tabList = mutableListOf<Tab>()

var currentTheme = Theme.fallback
set(value) {
Expand Down Expand Up @@ -112,10 +110,6 @@ class WikipediaApp : Application() {
return defaultWikiSite!!
}

// handle the case where we have a single tab with an empty backstack, which shouldn't count as a valid tab:
val tabCount
get() = if (tabList.size > 1) tabList.size else if (tabList.isEmpty()) 0 else if (tabList[0].backStack.isEmpty()) 0 else tabList.size

val isOnline
get() = connectionStateMonitor.isOnline()

Expand Down Expand Up @@ -149,7 +143,6 @@ class WikipediaApp : Application() {

currentTheme = unmarshalTheme(Prefs.currentThemeId)

initTabs()
enableWebViewDebugging()
registerActivityLifecycleCallbacks(activityLifecycleHandler)
registerComponentCallbacks(activityLifecycleHandler)
Expand Down Expand Up @@ -211,15 +204,6 @@ class WikipediaApp : Application() {
// TODO: send exception to custom crash reporting system
}

fun commitTabState() {
if (tabList.isEmpty()) {
Prefs.clearTabs()
initTabs()
} else {
Prefs.tabs = tabList
}
}

/**
* Gets the current size of the app's font. This is given as a device-specific size (not "sp"),
* and can be passed directly to setTextSize() functions.
Expand Down Expand Up @@ -280,15 +264,6 @@ class WikipediaApp : Application() {
return result
}

private fun initTabs() {
if (Prefs.hasTabs) {
tabList.addAll(Prefs.tabs)
}
if (tabList.isEmpty()) {
tabList.add(Tab())
}
}

companion object {
lateinit var instance: WikipediaApp
private set
Expand Down
67 changes: 64 additions & 3 deletions app/src/main/java/org/wikipedia/database/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import org.wikipedia.notifications.db.Notification
import org.wikipedia.notifications.db.NotificationDao
import org.wikipedia.offline.db.OfflineObject
import org.wikipedia.offline.db.OfflineObjectDao
import org.wikipedia.page.tabs.PageBackStackItem
import org.wikipedia.page.tabs.PageBackStackItemDao
import org.wikipedia.page.tabs.Tab
import org.wikipedia.page.tabs.TabDao
import org.wikipedia.pageimages.db.PageImage
import org.wikipedia.pageimages.db.PageImageDao
import org.wikipedia.readinglist.database.ReadingList
Expand All @@ -30,6 +34,7 @@ import org.wikipedia.readinglist.db.ReadingListPageDao
import org.wikipedia.readinglist.db.RecommendedPageDao
import org.wikipedia.search.db.RecentSearch
import org.wikipedia.search.db.RecentSearchDao
import org.wikipedia.settings.Prefs
import org.wikipedia.staticdata.MainPageNameData
import org.wikipedia.talk.db.TalkPageSeen
import org.wikipedia.talk.db.TalkPageSeenDao
Expand All @@ -38,7 +43,7 @@ import org.wikipedia.talk.db.TalkTemplateDao
import java.time.LocalDate

const val DATABASE_NAME = "wikipedia.db"
const val DATABASE_VERSION = 31
const val DATABASE_VERSION = 32

@Database(
entities = [
Expand All @@ -54,7 +59,9 @@ const val DATABASE_VERSION = 31
TalkTemplate::class,
Category::class,
DailyGameHistory::class,
RecommendedPage::class
RecommendedPage::class,
Tab::class,
PageBackStackItem::class
],
version = DATABASE_VERSION
)
Expand All @@ -80,6 +87,8 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun categoryDao(): CategoryDao
abstract fun dailyGameHistoryDao(): DailyGameHistoryDao
abstract fun recommendedPageDao(): RecommendedPageDao
abstract fun tabDao(): TabDao
abstract fun pageBackStackItemDao(): PageBackStackItemDao

companion object {
val MIGRATION_19_20 = object : Migration(19, 20) {
Expand Down Expand Up @@ -347,13 +356,65 @@ abstract class AppDatabase : RoomDatabase() {
db.execSQL("ALTER TABLE Category_temp RENAME TO Category")
}
}
val MIGRATION_31_32 = object : Migration(31, 32) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("CREATE TABLE IF NOT EXISTS `Tab` (" +
" `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," +
" `order` INTEGER NOT NULL," +
" `backStackIds` TEXT NOT NULL," +
" `backStackPosition` INTEGER NOT NULL" +
")")
db.execSQL("CREATE TABLE IF NOT EXISTS `PageBackStackItem` (" +
" `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," +
" `apiTitle` TEXT NOT NULL," +
" `displayTitle` TEXT NOT NULL," +
" `langCode` TEXT NOT NULL," +
" `namespace` TEXT NOT NULL," +
" `timestamp` INTEGER NOT NULL," +
" `scrollY` INTEGER NOT NULL," +
" `source` INTEGER NOT NULL," +
" `thumbUrl` TEXT," +
" `description` TEXT," +
" `extract` TEXT" +
")")

// Migrating from Pres.tabs to database
var pageBackStackItemIndex = 1
Prefs.tabs.forEachIndexed { index, tab ->
// Insert back stack items to PageBackStackItem and get the IDs
var backStackIds = mutableListOf<Int>()
// TODO: make sure the order is correct
tab.backStack.forEach { backStackItem ->
db.execSQL("INSERT INTO PageBackStackItem " +
"(apiTitle, displayTitle, langCode, namespace, timestamp, scrollY, source, thumbUrl, description, extract) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
arrayOf<Any?>(
backStackItem.apiTitle,
backStackItem.displayTitle,
backStackItem.langCode,
backStackItem.namespace,
backStackItem.timestamp,
backStackItem.scrollY,
backStackItem.source,
backStackItem.thumbUrl,
backStackItem.description,
backStackItem.extract
))
backStackIds.add(pageBackStackItemIndex++)
}
// Insert the tab into the Tab table
db.execSQL("INSERT INTO Tab (`order`, backStackIds, backStackPosition) VALUES (?, ?, ?)",
arrayOf<Any?>(index, backStackIds.joinToString(","), tab.backStackPosition))
}
}
}

val instance: AppDatabase by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
Room.databaseBuilder(WikipediaApp.instance, AppDatabase::class.java, DATABASE_NAME)
.addMigrations(MIGRATION_19_20, MIGRATION_20_21, MIGRATION_21_22, MIGRATION_22_23,
MIGRATION_23_24, MIGRATION_24_25, MIGRATION_25_26, MIGRATION_26_27,
MIGRATION_26_28, MIGRATION_27_28, MIGRATION_28_29, MIGRATION_29_30,
MIGRATION_30_31)
MIGRATION_30_31, MIGRATION_31_32)
.fallbackToDestructiveMigration(false)
.build()
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/org/wikipedia/feed/news/NewsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.appbar.AppBarLayout
import org.wikipedia.Constants
Expand All @@ -24,14 +25,14 @@ import org.wikipedia.feed.model.Card
import org.wikipedia.feed.view.ListCardItemView
import org.wikipedia.history.HistoryEntry
import org.wikipedia.page.PageActivity
import org.wikipedia.page.tabs.TabHelper
import org.wikipedia.readinglist.ReadingListBehaviorsUtil
import org.wikipedia.richtext.RichTextUtil
import org.wikipedia.util.DeviceUtil
import org.wikipedia.util.DimenUtil
import org.wikipedia.util.FeedbackUtil
import org.wikipedia.util.GradientUtil
import org.wikipedia.util.ResourceUtil
import org.wikipedia.util.TabUtil
import org.wikipedia.views.DefaultRecyclerAdapter
import org.wikipedia.views.DefaultViewHolder
import org.wikipedia.views.DrawableItemDecoration
Expand Down Expand Up @@ -109,7 +110,7 @@ class NewsFragment : Fragment() {
private inner class Callback : ListCardItemView.Callback {
override fun onSelectPage(card: Card, entry: HistoryEntry, openInNewBackgroundTab: Boolean) {
if (openInNewBackgroundTab) {
TabUtil.openInNewBackgroundTab(entry)
TabHelper.openInNewBackgroundTab(viewLifecycleOwner.lifecycleScope, entry)
FeedbackUtil.showMessage(requireActivity(), R.string.article_opened_in_background_tab)
} else {
startActivity(PageActivity.newIntentForNewTab(requireContext(), entry, entry.title))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import org.wikipedia.Constants
import org.wikipedia.R
import org.wikipedia.dataclient.WikiSite
import org.wikipedia.dataclient.page.PageSummary
import org.wikipedia.history.HistoryEntry
import org.wikipedia.page.PageActivity
import org.wikipedia.page.tabs.TabHelper
import org.wikipedia.readinglist.LongPressMenu
import org.wikipedia.readinglist.ReadingListBehaviorsUtil
import org.wikipedia.readinglist.database.ReadingListPage
import org.wikipedia.util.DeviceUtil
import org.wikipedia.util.DimenUtil
import org.wikipedia.util.FeedbackUtil
import org.wikipedia.util.StringUtil
import org.wikipedia.util.TabUtil
import org.wikipedia.util.TransitionUtil
import org.wikipedia.views.FaceAndColorDetectImageView

Expand Down Expand Up @@ -92,7 +93,7 @@ class OnThisDayPagesViewHolder(
}

override fun onOpenInNewTab(entry: HistoryEntry) {
TabUtil.openInNewBackgroundTab(entry)
TabHelper.openInNewBackgroundTab(activity.lifecycleScope, entry)
FeedbackUtil.showMessage(activity, R.string.article_opened_in_background_tab)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import org.wikipedia.Constants
import org.wikipedia.Constants.InvokeSource
Expand All @@ -20,10 +21,10 @@ import org.wikipedia.feed.model.Card
import org.wikipedia.feed.view.ListCardItemView
import org.wikipedia.history.HistoryEntry
import org.wikipedia.page.PageActivity
import org.wikipedia.page.tabs.TabHelper
import org.wikipedia.readinglist.ReadingListBehaviorsUtil
import org.wikipedia.util.DimenUtil
import org.wikipedia.util.FeedbackUtil
import org.wikipedia.util.TabUtil
import org.wikipedia.views.DefaultRecyclerAdapter
import org.wikipedia.views.DefaultViewHolder
import org.wikipedia.views.DrawableItemDecoration
Expand Down Expand Up @@ -77,7 +78,7 @@ class TopReadFragment : Fragment() {
private inner class Callback : ListCardItemView.Callback {
override fun onSelectPage(card: Card, entry: HistoryEntry, openInNewBackgroundTab: Boolean) {
if (openInNewBackgroundTab) {
TabUtil.openInNewBackgroundTab(entry)
TabHelper.openInNewBackgroundTab(viewLifecycleOwner.lifecycleScope, entry)
FeedbackUtil.showMessage(requireActivity(), R.string.article_opened_in_background_tab)
} else {
startActivity(PageActivity.newIntentForNewTab(requireContext(), entry, entry.title))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.wikipedia.json

import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.buildClassSerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonDecoder
import kotlinx.serialization.json.decodeFromJsonElement
import kotlinx.serialization.json.jsonObject
import org.wikipedia.history.HistoryEntry
import org.wikipedia.page.PageTitle
import org.wikipedia.page.tabs.PageBackStackItem

// TODO: remove on 2026-07-01
object PageBackStackItemSerializer : KSerializer<PageBackStackItem> {
override val descriptor = buildClassSerialDescriptor("PageBackStackItem")

override fun deserialize(decoder: Decoder): PageBackStackItem {
val input = decoder as JsonDecoder
val element = input.decodeJsonElement().jsonObject

// This is to handle the old format of PageBackStackItem which originally stored in the Prefs.tabs
return if (element.containsKey("title") && element.containsKey("historyEntry")) {
val oldFormat = Json.decodeFromJsonElement<OldPageBackStackItem>(element)
PageBackStackItem(oldFormat.title, oldFormat.historyEntry).also {
it.scrollY = oldFormat.scrollY
}
} else {
Json.decodeFromJsonElement<PageBackStackItem>(element)
}
}

override fun serialize(encoder: Encoder, value: PageBackStackItem) {
encoder.encodeSerializableValue(PageBackStackItem.serializer(), value)
}
}

@Serializable
private data class OldPageBackStackItem(
val title: PageTitle,
val historyEntry: HistoryEntry,
val scrollY: Int = 0
)
17 changes: 9 additions & 8 deletions app/src/main/java/org/wikipedia/main/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import org.wikipedia.page.ExclusiveBottomSheetPresenter
import org.wikipedia.page.PageActivity
import org.wikipedia.page.PageTitle
import org.wikipedia.page.tabs.TabActivity
import org.wikipedia.page.tabs.TabHelper
import org.wikipedia.places.PlacesActivity
import org.wikipedia.random.RandomActivity
import org.wikipedia.readinglist.ReadingListBehaviorsUtil
Expand All @@ -82,7 +83,6 @@ import org.wikipedia.usercontrib.UserContribListActivity
import org.wikipedia.util.DimenUtil
import org.wikipedia.util.FeedbackUtil
import org.wikipedia.util.ShareUtil
import org.wikipedia.util.TabUtil
import org.wikipedia.views.NotificationButtonView
import org.wikipedia.views.TabCountsView
import org.wikipedia.views.imageservice.ImageService
Expand Down Expand Up @@ -216,7 +216,7 @@ class MainFragment : Fragment(), BackPressedHandler, MenuProvider, FeedFragment.
FeedbackUtil.showMessage(this, R.string.login_success_toast)
}
} else if (requestCode == Constants.ACTIVITY_REQUEST_BROWSE_TABS) {
if (WikipediaApp.instance.tabCount == 0) {
if (TabHelper.count == 0) {
// They browsed the tabs and cleared all of them, without wanting to open a new tab.
return
}
Expand Down Expand Up @@ -275,14 +275,14 @@ class MainFragment : Fragment(), BackPressedHandler, MenuProvider, FeedFragment.
menu.findItem(R.id.menu_overflow_button).isVisible = currentFragment is ReadingListsFragment

val tabsItem = menu.findItem(R.id.menu_tabs)
if (WikipediaApp.instance.tabCount < 1 || currentFragment is SuggestedEditsTasksFragment) {
if (TabHelper.count < 1 || currentFragment is SuggestedEditsTasksFragment) {
tabsItem.isVisible = false
tabCountsView = null
} else {
tabsItem.isVisible = true
tabCountsView = TabCountsView(requireActivity(), null)
tabCountsView!!.setOnClickListener {
if (WikipediaApp.instance.tabCount == 1) {
if (TabHelper.count == 1) {
startActivity(PageActivity.newIntent(requireActivity()))
} else {
startActivityForResult(TabActivity.newIntent(requireActivity()), Constants.ACTIVITY_REQUEST_BROWSE_TABS)
Expand Down Expand Up @@ -333,7 +333,7 @@ class MainFragment : Fragment(), BackPressedHandler, MenuProvider, FeedFragment.
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) {
} else if (lastPageViewedWithin(1) && !intent.hasExtra(Constants.INTENT_RETURN_TO_MAIN) && TabHelper.count > 0) {
startActivity(PageActivity.newIntent(requireContext()))
}
}
Expand All @@ -354,9 +354,10 @@ class MainFragment : Fragment(), BackPressedHandler, MenuProvider, FeedFragment.

override fun onFeedSelectPage(entry: HistoryEntry, openInNewBackgroundTab: Boolean) {
if (openInNewBackgroundTab) {
TabUtil.openInNewBackgroundTab(entry)
showTabCountsAnimation = true
requireActivity().invalidateOptionsMenu()
TabHelper.openInNewBackgroundTab(viewLifecycleOwner.lifecycleScope, entry) {
showTabCountsAnimation = true
requireActivity().invalidateOptionsMenu()
}
} else {
startActivity(PageActivity.newIntentForNewTab(requireContext(), entry, entry.title))
}
Expand Down
Loading
Loading