You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iceraven-browser/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlAdapter.kt

395 lines
18 KiB
Kotlin

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.home.sessioncontrol
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import mozilla.components.browser.state.state.TabSessionState
For FNX-22339: Recently saved bookmarks (#19835) * Title and button for home screen recently saved bookmarks section Create bookmark item view with favicon and title * View holders and interactors for recently saved bookmarks Recent bookmark item view holder binding Create adapter for recent bookmarks. Implement controller methods. Implement view holder bindings for items Top level adapter for recent bookmarks section Retrieve list of recent bookmarks on home View holders and interactors for recently saved bookmarks Recent bookmark item view holder binding Create adapter for recent bookmarks. Implement controller methods. Implement view holder bindings for items Top level adapter for recent bookmarks section Retrieve list of recent bookmarks on home Update list on app start and when bookmarks are added View holders and interactors for recently saved bookmarks Recent bookmark item view holder binding Create adapter for recent bookmarks. Implement controller methods. Implement view holder bindings for items Top level adapter for recent bookmarks section Retrieve list of recent bookmarks on home Update list on app start and when bookmarks are added Make a use case for retrieving and updating the list of recently saved bookmarks Add adapter items and define header viewholder binding Use session interactor for header button clicks. Bind in the adapter * Retrieve list of bookmarks asynchronously on home Interactor and controller tests Address review comments Split up tests for recent bookmarks Update to new interactors Dark mode and light mode styles Refactor bookmarks home stuff * Add RecentBookmarksFeature to home Move interactor to SessionControlInteractor Clean up lint, styles, and dimens. * Bookmarks use case tests for retrieving recently saved bookmarks. Linting. * View holder tests * Match ux to designs for colors, margins, and scrolling * Clean up clean up * Tests for the view bound feature * Controller test * Clean up: check state of store in feature tests; ellipsize textviews for bookmark item; remove unused attr; format Co-authored-by: Jonathan Almeida <jalmeida@mozilla.com>
3 years ago
import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.storage.HistoryMetadata
For #5574 - Migrate SessionControl to LibState (#6651) * For #5574 - Part 1: Port TabAction.SaveTabGroup to TabSessionInteractor and SessionControlController. (#6651) - Introduces the TabSessionInteractor, SessionControlInteractor and SessionControlController classes. - Removes the TabAction.SaveTabGroup. * For #5574 - Part 2: Port TabAction.PrivateBrowsingLearnMore to TabSessionInteractor and SessionControlController (#6651) * For #5574 - Part 3: Port TabAction.ShareTabs to TabSessionInteractor and SessionControlController (#6651) * For #5574 - Part 4: Remove unused TabAction.Share and TabItemMenu (#6651) In #2205, the tab overflow button was removed which would have shown the TabItemMenu when clicked. So, we can remove TabItemMenu since it is not used and as a result, we can also remove TabAction.Share since there are no consumers. * For #5574 - Part 5: Port TabAction.PlayMedia and TabAction.PauseMedia to TabSessionInteractor and SessionControlController (#6651) * For #5574 - Part 6: Port TabAction.Select to TabSessionInteractor and SessionControlController (#6651) * For #5574 - Part 7: Port Onboarding.Finish to OnboardingInteractor and SessionControlController (#6651) * For #5574 - Part 8: Port TabAction.Close and TabAction.CloseAll to TabSessionInteractor and SessionControlController (#6651) - Removes TabAction * For #5574 - Part 9: Port CollectionAction.Delete to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 10: Port CollectionAction.ShareTabs to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 11: Port CollectionAction.AddTab and CollectionAction.Rename to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 12: Port CollectionAction.RemoveTab to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 13: Port CollectionAction.OpenTab to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 14: Port CollectionAction.CloseTabs to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 15: Introduce a HomeFragmentStore (#6651) - We will hook up the HomeFragmentStore in later parts. - Removes List<Tab>.toSessionBundle(context: Context) since it is unused. * For #5574 - Part 16: Port CollectionAction.Collapse and CollectionAction.Expand to CollectionInteractor and SessionControlController (#6651) - We assume the store is hooked up to the SessionControlController in this part, but this work will be done in a later part. - Removes CollectionAction. * For #5574 - Part 20: Remove the architecture module. (#6651) * For #5574 - Part 17: Remove duplicate subscribeToTabCollections in BrowserFragment.kt (#6651) There is a duplicate call of subscribeToTabCollections() in both HomeFragment and BrowserFragment. In this patch, we remove the call in BrowserFragment to avoid passing the HomeFragmentStore to BrowserFragment in order to dispatch the CollectionsChange event. * For #5574 - Part 18: Delete SessionControlComponent and fix TabCollection and Tab imports (#6651) * For #5574 - Part 19: Use the new HomeFragmentStore in the HomeFragment (#6651) - Renames SessionControlUIView to SessionControlView * For #5574 - Part 21: Fix white screen on home fragment (#6651) * For #5574 - Part 22: Fix formatting in SessionControlInteractor and replace See with @see in SessionControlController (#6651) * For #5574 - Part 23: Move to metrics.track call to the beginning of handleCollectionRemoveTab (#6651) This ensures that the metrics.track will be called immediately before the tab is removed from the collection. * For #5574 - Part 24: Use the sessionManager getter in SessionControlController (#6651) * For #5574 - Part 25: Use mapNotNull in List<Tab>.toSessionBundle (#6651) * For #5574 - Part 26: Simplify closeTab and closeAllTabs functions by assigning a deletionJob constant (#6651) * For #5574 - Part 27: Replace listOf() with emptyList() in removeAllTabsWithUndo (#6651) * For #5574 - Part 28: Replace the Context parameter with the HomeActivity in SessionControlController (#6651) * For #5574 - Part 29: Add test for HomeFragmentStore, DefaultSessionControlController and SessionControlInteractor (#6651) * For #5574 - Removes running CI against the architecture debug build varient
5 years ago
import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.feature.top.sites.TopSite.Type.FRECENT
import mozilla.components.ui.widgets.WidgetSiteItemView
import org.mozilla.fenix.components.Components
import org.mozilla.fenix.components.tips.Tip
import org.mozilla.fenix.historymetadata.view.HistoryMetadataGroupViewHolder
import org.mozilla.fenix.historymetadata.view.HistoryMetadataHeaderViewHolder
import org.mozilla.fenix.historymetadata.view.HistoryMetadataViewHolder
import org.mozilla.fenix.home.OnboardingState
import org.mozilla.fenix.home.recentbookmarks.view.RecentBookmarksViewHolder
import org.mozilla.fenix.home.recenttabs.view.RecentTabViewDecorator
import org.mozilla.fenix.home.recenttabs.view.RecentTabViewHolder
import org.mozilla.fenix.home.recenttabs.view.RecentTabsHeaderViewHolder
import org.mozilla.fenix.home.recenttabs.view.RecentTabsItemPosition
import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionHeaderViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.NoCollectionsMessageViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.PrivateBrowsingDescriptionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.TabInCollectionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.TopSitePagerViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.ExperimentDefaultBrowserCardViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingAutomaticSignInViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingFinishViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingHeaderViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingManualSignInViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingPrivacyNoticeViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingPrivateBrowsingViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingSectionHeaderViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingThemePickerViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingToolbarPositionPickerViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingTrackingProtectionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingWhatsNewViewHolder
import org.mozilla.fenix.home.tips.ButtonTipViewHolder
import mozilla.components.feature.tab.collections.Tab as ComponentTab
sealed class AdapterItem(@LayoutRes val viewType: Int) {
data class TipItem(val tip: Tip) : AdapterItem(
ButtonTipViewHolder.LAYOUT_ID
)
/**
* Contains a set of [Pair]s where [Pair.first] is the index of the changed [TopSite] and
* [Pair.second] is the new [TopSite].
*/
data class TopSitePagerPayload(
val changed: Set<Pair<Int, TopSite>>
)
data class TopSitePager(val topSites: List<TopSite>) :
AdapterItem(TopSitePagerViewHolder.LAYOUT_ID) {
override fun sameAs(other: AdapterItem): Boolean {
return other is TopSitePager
}
override fun contentsSameAs(other: AdapterItem): Boolean {
val newTopSites = (other as? TopSitePager) ?: return false
if (newTopSites.topSites.size != this.topSites.size) return false
val newSitesSequence = newTopSites.topSites.asSequence()
val oldTopSites = this.topSites.asSequence()
return newSitesSequence.zip(oldTopSites).all { (new, old) -> new == old }
}
/**
* Returns a payload if there's been a change, or null if not, but adds a "dummy" item for
* each deleted [TopSite]. This is done in order to more easily identify the actual views
* that need to be removed in [TopSitesPagerAdapter.update].
*
* See https://github.com/mozilla-mobile/fenix/pull/20189#issuecomment-877124730
*/
override fun getChangePayload(newItem: AdapterItem): Any? {
val newTopSites = (newItem as? TopSitePager)
val oldTopSites = (this as? TopSitePager)
if (newTopSites == null || oldTopSites == null ||
(newTopSites.topSites.size > TopSitePagerViewHolder.TOP_SITES_PER_PAGE)
!= (oldTopSites.topSites.size > TopSitePagerViewHolder.TOP_SITES_PER_PAGE)
) {
return null
}
val changed = mutableSetOf<Pair<Int, TopSite>>()
for ((index, item) in oldTopSites.topSites.withIndex()) {
val changedItem =
newTopSites.topSites.getOrNull(index) ?: TopSite(-1, "REMOVED", "", 0, FRECENT)
if (changedItem != item) {
changed.add((Pair(index, changedItem)))
}
}
return if (changed.isNotEmpty()) TopSitePagerPayload(changed) else null
}
}
object PrivateBrowsingDescription : AdapterItem(PrivateBrowsingDescriptionViewHolder.LAYOUT_ID)
object NoCollectionsMessage : AdapterItem(NoCollectionsMessageViewHolder.LAYOUT_ID)
object CollectionHeader : AdapterItem(CollectionHeaderViewHolder.LAYOUT_ID)
data class CollectionItem(
val collection: TabCollection,
val expanded: Boolean
) : AdapterItem(CollectionViewHolder.LAYOUT_ID) {
override fun sameAs(other: AdapterItem) =
other is CollectionItem && collection.id == other.collection.id
override fun contentsSameAs(other: AdapterItem): Boolean {
(other as? CollectionItem)?.let {
return it.expanded == this.expanded && it.collection.title == this.collection.title
} ?: return false
}
}
data class TabInCollectionItem(
val collection: TabCollection,
val tab: ComponentTab,
val isLastTab: Boolean
) : AdapterItem(TabInCollectionViewHolder.LAYOUT_ID) {
override fun sameAs(other: AdapterItem) =
other is TabInCollectionItem && tab.id == other.tab.id
}
object OnboardingHeader : AdapterItem(OnboardingHeaderViewHolder.LAYOUT_ID)
data class OnboardingSectionHeader(
val labelBuilder: (Context) -> String
) : AdapterItem(OnboardingSectionHeaderViewHolder.LAYOUT_ID) {
override fun sameAs(other: AdapterItem) =
other is OnboardingSectionHeader && labelBuilder == other.labelBuilder
}
object OnboardingManualSignIn : AdapterItem(OnboardingManualSignInViewHolder.LAYOUT_ID)
data class OnboardingAutomaticSignIn(
val state: OnboardingState.SignedOutCanAutoSignIn
) : AdapterItem(OnboardingAutomaticSignInViewHolder.LAYOUT_ID)
object ExperimentDefaultBrowserCard : AdapterItem(ExperimentDefaultBrowserCardViewHolder.LAYOUT_ID)
object OnboardingThemePicker : AdapterItem(OnboardingThemePickerViewHolder.LAYOUT_ID)
object OnboardingTrackingProtection :
AdapterItem(OnboardingTrackingProtectionViewHolder.LAYOUT_ID)
object OnboardingPrivateBrowsing : AdapterItem(OnboardingPrivateBrowsingViewHolder.LAYOUT_ID)
object OnboardingPrivacyNotice : AdapterItem(OnboardingPrivacyNoticeViewHolder.LAYOUT_ID)
object OnboardingFinish : AdapterItem(OnboardingFinishViewHolder.LAYOUT_ID)
object OnboardingToolbarPositionPicker :
AdapterItem(OnboardingToolbarPositionPickerViewHolder.LAYOUT_ID)
object OnboardingWhatsNew : AdapterItem(OnboardingWhatsNewViewHolder.LAYOUT_ID)
object RecentTabsHeader : AdapterItem(RecentTabsHeaderViewHolder.LAYOUT_ID)
data class RecentTabItem(
val tab: TabSessionState,
val position: RecentTabsItemPosition
) : AdapterItem(RecentTabViewHolder.LAYOUT_ID) {
override fun sameAs(other: AdapterItem) = other is RecentTabItem && tab.id == other.tab.id &&
position == other.position
override fun contentsSameAs(other: AdapterItem): Boolean {
val otherItem = other as RecentTabItem
// We only care about updating if the title and icon have changed because that is
// all we show today. This should be updated if we want to show updates for more.
return tab.content.title == otherItem.tab.content.title &&
tab.content.icon == otherItem.tab.content.icon
}
}
object HistoryMetadataHeader : AdapterItem(HistoryMetadataHeaderViewHolder.LAYOUT_ID)
data class HistoryMetadataGroup(val historyMetadataGroup: org.mozilla.fenix.historymetadata.HistoryMetadataGroup) :
AdapterItem(HistoryMetadataGroupViewHolder.LAYOUT_ID) {
override fun sameAs(other: AdapterItem) =
other is HistoryMetadataGroup && historyMetadataGroup == other.historyMetadataGroup
override fun contentsSameAs(other: AdapterItem): Boolean {
(other as? HistoryMetadataGroup)?.let {
return it.historyMetadataGroup.expanded == this.historyMetadataGroup.expanded &&
it.historyMetadataGroup.title == this.historyMetadataGroup.title
} ?: return false
}
}
For FNX-22339: Recently saved bookmarks (#19835) * Title and button for home screen recently saved bookmarks section Create bookmark item view with favicon and title * View holders and interactors for recently saved bookmarks Recent bookmark item view holder binding Create adapter for recent bookmarks. Implement controller methods. Implement view holder bindings for items Top level adapter for recent bookmarks section Retrieve list of recent bookmarks on home View holders and interactors for recently saved bookmarks Recent bookmark item view holder binding Create adapter for recent bookmarks. Implement controller methods. Implement view holder bindings for items Top level adapter for recent bookmarks section Retrieve list of recent bookmarks on home Update list on app start and when bookmarks are added View holders and interactors for recently saved bookmarks Recent bookmark item view holder binding Create adapter for recent bookmarks. Implement controller methods. Implement view holder bindings for items Top level adapter for recent bookmarks section Retrieve list of recent bookmarks on home Update list on app start and when bookmarks are added Make a use case for retrieving and updating the list of recently saved bookmarks Add adapter items and define header viewholder binding Use session interactor for header button clicks. Bind in the adapter * Retrieve list of bookmarks asynchronously on home Interactor and controller tests Address review comments Split up tests for recent bookmarks Update to new interactors Dark mode and light mode styles Refactor bookmarks home stuff * Add RecentBookmarksFeature to home Move interactor to SessionControlInteractor Clean up lint, styles, and dimens. * Bookmarks use case tests for retrieving recently saved bookmarks. Linting. * View holder tests * Match ux to designs for colors, margins, and scrolling * Clean up clean up * Tests for the view bound feature * Controller test * Clean up: check state of store in feature tests; ellipsize textviews for bookmark item; remove unused attr; format Co-authored-by: Jonathan Almeida <jalmeida@mozilla.com>
3 years ago
data class RecentBookmarks(val recentBookmarks: List<BookmarkNode>) :
AdapterItem(RecentBookmarksViewHolder.LAYOUT_ID) {
override fun sameAs(other: AdapterItem): Boolean {
val newBookmarks = (other as? RecentBookmarks) ?: return false
if (newBookmarks.recentBookmarks.size != this.recentBookmarks.size) {
return false
}
return recentBookmarks.zip(newBookmarks.recentBookmarks).all { (new, old) ->
new.guid == old.guid
}
}
override fun contentsSameAs(other: AdapterItem): Boolean {
val newBookmarks = (other as? RecentBookmarks) ?: return false
val newBookmarksSequence = newBookmarks.recentBookmarks.asSequence()
val oldBookmarksList = this.recentBookmarks.asSequence()
return newBookmarksSequence.zip(oldBookmarksList).all { (new, old) ->
new == old
}
}
}
data class HistoryMetadataItem(val historyMetadata: HistoryMetadata) : AdapterItem(
HistoryMetadataViewHolder.LAYOUT_ID
) {
override fun sameAs(other: AdapterItem) =
other is HistoryMetadataItem && historyMetadata.key.url == other.historyMetadata.key.url
}
/**
* True if this item represents the same value as other. Used by [AdapterItemDiffCallback].
*/
open fun sameAs(other: AdapterItem) = this::class == other::class
/**
* Returns a payload if there's been a change, or null if not
*/
open fun getChangePayload(newItem: AdapterItem): Any? = null
open fun contentsSameAs(other: AdapterItem) = this::class == other::class
}
class AdapterItemDiffCallback : DiffUtil.ItemCallback<AdapterItem>() {
override fun areItemsTheSame(oldItem: AdapterItem, newItem: AdapterItem) =
oldItem.sameAs(newItem)
@Suppress("DiffUtilEquals")
override fun areContentsTheSame(oldItem: AdapterItem, newItem: AdapterItem) =
oldItem.contentsSameAs(newItem)
override fun getChangePayload(oldItem: AdapterItem, newItem: AdapterItem): Any? {
return oldItem.getChangePayload(newItem) ?: return super.getChangePayload(oldItem, newItem)
}
}
class SessionControlAdapter(
private val interactor: SessionControlInteractor,
private val viewLifecycleOwner: LifecycleOwner,
private val components: Components
) : ListAdapter<AdapterItem, RecyclerView.ViewHolder>(AdapterItemDiffCallback()) {
// This method triggers the ComplexMethod lint error when in fact it's quite simple.
@SuppressWarnings("ComplexMethod")
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
return when (viewType) {
ButtonTipViewHolder.LAYOUT_ID -> ButtonTipViewHolder(view, interactor)
TopSitePagerViewHolder.LAYOUT_ID -> TopSitePagerViewHolder(view, interactor)
PrivateBrowsingDescriptionViewHolder.LAYOUT_ID -> PrivateBrowsingDescriptionViewHolder(
view,
interactor
)
NoCollectionsMessageViewHolder.LAYOUT_ID ->
NoCollectionsMessageViewHolder(
view,
viewLifecycleOwner,
components.core.store,
interactor
)
CollectionHeaderViewHolder.LAYOUT_ID -> CollectionHeaderViewHolder(view)
For #5574 - Migrate SessionControl to LibState (#6651) * For #5574 - Part 1: Port TabAction.SaveTabGroup to TabSessionInteractor and SessionControlController. (#6651) - Introduces the TabSessionInteractor, SessionControlInteractor and SessionControlController classes. - Removes the TabAction.SaveTabGroup. * For #5574 - Part 2: Port TabAction.PrivateBrowsingLearnMore to TabSessionInteractor and SessionControlController (#6651) * For #5574 - Part 3: Port TabAction.ShareTabs to TabSessionInteractor and SessionControlController (#6651) * For #5574 - Part 4: Remove unused TabAction.Share and TabItemMenu (#6651) In #2205, the tab overflow button was removed which would have shown the TabItemMenu when clicked. So, we can remove TabItemMenu since it is not used and as a result, we can also remove TabAction.Share since there are no consumers. * For #5574 - Part 5: Port TabAction.PlayMedia and TabAction.PauseMedia to TabSessionInteractor and SessionControlController (#6651) * For #5574 - Part 6: Port TabAction.Select to TabSessionInteractor and SessionControlController (#6651) * For #5574 - Part 7: Port Onboarding.Finish to OnboardingInteractor and SessionControlController (#6651) * For #5574 - Part 8: Port TabAction.Close and TabAction.CloseAll to TabSessionInteractor and SessionControlController (#6651) - Removes TabAction * For #5574 - Part 9: Port CollectionAction.Delete to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 10: Port CollectionAction.ShareTabs to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 11: Port CollectionAction.AddTab and CollectionAction.Rename to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 12: Port CollectionAction.RemoveTab to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 13: Port CollectionAction.OpenTab to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 14: Port CollectionAction.CloseTabs to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 15: Introduce a HomeFragmentStore (#6651) - We will hook up the HomeFragmentStore in later parts. - Removes List<Tab>.toSessionBundle(context: Context) since it is unused. * For #5574 - Part 16: Port CollectionAction.Collapse and CollectionAction.Expand to CollectionInteractor and SessionControlController (#6651) - We assume the store is hooked up to the SessionControlController in this part, but this work will be done in a later part. - Removes CollectionAction. * For #5574 - Part 20: Remove the architecture module. (#6651) * For #5574 - Part 17: Remove duplicate subscribeToTabCollections in BrowserFragment.kt (#6651) There is a duplicate call of subscribeToTabCollections() in both HomeFragment and BrowserFragment. In this patch, we remove the call in BrowserFragment to avoid passing the HomeFragmentStore to BrowserFragment in order to dispatch the CollectionsChange event. * For #5574 - Part 18: Delete SessionControlComponent and fix TabCollection and Tab imports (#6651) * For #5574 - Part 19: Use the new HomeFragmentStore in the HomeFragment (#6651) - Renames SessionControlUIView to SessionControlView * For #5574 - Part 21: Fix white screen on home fragment (#6651) * For #5574 - Part 22: Fix formatting in SessionControlInteractor and replace See with @see in SessionControlController (#6651) * For #5574 - Part 23: Move to metrics.track call to the beginning of handleCollectionRemoveTab (#6651) This ensures that the metrics.track will be called immediately before the tab is removed from the collection. * For #5574 - Part 24: Use the sessionManager getter in SessionControlController (#6651) * For #5574 - Part 25: Use mapNotNull in List<Tab>.toSessionBundle (#6651) * For #5574 - Part 26: Simplify closeTab and closeAllTabs functions by assigning a deletionJob constant (#6651) * For #5574 - Part 27: Replace listOf() with emptyList() in removeAllTabsWithUndo (#6651) * For #5574 - Part 28: Replace the Context parameter with the HomeActivity in SessionControlController (#6651) * For #5574 - Part 29: Add test for HomeFragmentStore, DefaultSessionControlController and SessionControlInteractor (#6651) * For #5574 - Removes running CI against the architecture debug build varient
5 years ago
CollectionViewHolder.LAYOUT_ID -> CollectionViewHolder(view, interactor)
TabInCollectionViewHolder.LAYOUT_ID -> TabInCollectionViewHolder(
view as WidgetSiteItemView,
interactor
)
OnboardingHeaderViewHolder.LAYOUT_ID -> OnboardingHeaderViewHolder(view)
OnboardingSectionHeaderViewHolder.LAYOUT_ID -> OnboardingSectionHeaderViewHolder(view)
OnboardingAutomaticSignInViewHolder.LAYOUT_ID -> OnboardingAutomaticSignInViewHolder(
view
)
OnboardingManualSignInViewHolder.LAYOUT_ID -> OnboardingManualSignInViewHolder(view)
OnboardingThemePickerViewHolder.LAYOUT_ID -> OnboardingThemePickerViewHolder(view)
OnboardingTrackingProtectionViewHolder.LAYOUT_ID -> OnboardingTrackingProtectionViewHolder(
view
)
OnboardingPrivateBrowsingViewHolder.LAYOUT_ID -> OnboardingPrivateBrowsingViewHolder(
view,
interactor
)
OnboardingPrivacyNoticeViewHolder.LAYOUT_ID -> OnboardingPrivacyNoticeViewHolder(
view,
interactor
)
For #5574 - Migrate SessionControl to LibState (#6651) * For #5574 - Part 1: Port TabAction.SaveTabGroup to TabSessionInteractor and SessionControlController. (#6651) - Introduces the TabSessionInteractor, SessionControlInteractor and SessionControlController classes. - Removes the TabAction.SaveTabGroup. * For #5574 - Part 2: Port TabAction.PrivateBrowsingLearnMore to TabSessionInteractor and SessionControlController (#6651) * For #5574 - Part 3: Port TabAction.ShareTabs to TabSessionInteractor and SessionControlController (#6651) * For #5574 - Part 4: Remove unused TabAction.Share and TabItemMenu (#6651) In #2205, the tab overflow button was removed which would have shown the TabItemMenu when clicked. So, we can remove TabItemMenu since it is not used and as a result, we can also remove TabAction.Share since there are no consumers. * For #5574 - Part 5: Port TabAction.PlayMedia and TabAction.PauseMedia to TabSessionInteractor and SessionControlController (#6651) * For #5574 - Part 6: Port TabAction.Select to TabSessionInteractor and SessionControlController (#6651) * For #5574 - Part 7: Port Onboarding.Finish to OnboardingInteractor and SessionControlController (#6651) * For #5574 - Part 8: Port TabAction.Close and TabAction.CloseAll to TabSessionInteractor and SessionControlController (#6651) - Removes TabAction * For #5574 - Part 9: Port CollectionAction.Delete to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 10: Port CollectionAction.ShareTabs to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 11: Port CollectionAction.AddTab and CollectionAction.Rename to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 12: Port CollectionAction.RemoveTab to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 13: Port CollectionAction.OpenTab to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 14: Port CollectionAction.CloseTabs to CollectionInteractor and SessionControlController (#6651) * For #5574 - Part 15: Introduce a HomeFragmentStore (#6651) - We will hook up the HomeFragmentStore in later parts. - Removes List<Tab>.toSessionBundle(context: Context) since it is unused. * For #5574 - Part 16: Port CollectionAction.Collapse and CollectionAction.Expand to CollectionInteractor and SessionControlController (#6651) - We assume the store is hooked up to the SessionControlController in this part, but this work will be done in a later part. - Removes CollectionAction. * For #5574 - Part 20: Remove the architecture module. (#6651) * For #5574 - Part 17: Remove duplicate subscribeToTabCollections in BrowserFragment.kt (#6651) There is a duplicate call of subscribeToTabCollections() in both HomeFragment and BrowserFragment. In this patch, we remove the call in BrowserFragment to avoid passing the HomeFragmentStore to BrowserFragment in order to dispatch the CollectionsChange event. * For #5574 - Part 18: Delete SessionControlComponent and fix TabCollection and Tab imports (#6651) * For #5574 - Part 19: Use the new HomeFragmentStore in the HomeFragment (#6651) - Renames SessionControlUIView to SessionControlView * For #5574 - Part 21: Fix white screen on home fragment (#6651) * For #5574 - Part 22: Fix formatting in SessionControlInteractor and replace See with @see in SessionControlController (#6651) * For #5574 - Part 23: Move to metrics.track call to the beginning of handleCollectionRemoveTab (#6651) This ensures that the metrics.track will be called immediately before the tab is removed from the collection. * For #5574 - Part 24: Use the sessionManager getter in SessionControlController (#6651) * For #5574 - Part 25: Use mapNotNull in List<Tab>.toSessionBundle (#6651) * For #5574 - Part 26: Simplify closeTab and closeAllTabs functions by assigning a deletionJob constant (#6651) * For #5574 - Part 27: Replace listOf() with emptyList() in removeAllTabsWithUndo (#6651) * For #5574 - Part 28: Replace the Context parameter with the HomeActivity in SessionControlController (#6651) * For #5574 - Part 29: Add test for HomeFragmentStore, DefaultSessionControlController and SessionControlInteractor (#6651) * For #5574 - Removes running CI against the architecture debug build varient
5 years ago
OnboardingFinishViewHolder.LAYOUT_ID -> OnboardingFinishViewHolder(view, interactor)
OnboardingWhatsNewViewHolder.LAYOUT_ID -> OnboardingWhatsNewViewHolder(view, interactor)
OnboardingToolbarPositionPickerViewHolder.LAYOUT_ID -> OnboardingToolbarPositionPickerViewHolder(
view
)
ExperimentDefaultBrowserCardViewHolder.LAYOUT_ID -> ExperimentDefaultBrowserCardViewHolder(view, interactor)
RecentTabsHeaderViewHolder.LAYOUT_ID -> RecentTabsHeaderViewHolder(view, interactor)
RecentTabViewHolder.LAYOUT_ID -> RecentTabViewHolder(view, interactor)
For FNX-22339: Recently saved bookmarks (#19835) * Title and button for home screen recently saved bookmarks section Create bookmark item view with favicon and title * View holders and interactors for recently saved bookmarks Recent bookmark item view holder binding Create adapter for recent bookmarks. Implement controller methods. Implement view holder bindings for items Top level adapter for recent bookmarks section Retrieve list of recent bookmarks on home View holders and interactors for recently saved bookmarks Recent bookmark item view holder binding Create adapter for recent bookmarks. Implement controller methods. Implement view holder bindings for items Top level adapter for recent bookmarks section Retrieve list of recent bookmarks on home Update list on app start and when bookmarks are added View holders and interactors for recently saved bookmarks Recent bookmark item view holder binding Create adapter for recent bookmarks. Implement controller methods. Implement view holder bindings for items Top level adapter for recent bookmarks section Retrieve list of recent bookmarks on home Update list on app start and when bookmarks are added Make a use case for retrieving and updating the list of recently saved bookmarks Add adapter items and define header viewholder binding Use session interactor for header button clicks. Bind in the adapter * Retrieve list of bookmarks asynchronously on home Interactor and controller tests Address review comments Split up tests for recent bookmarks Update to new interactors Dark mode and light mode styles Refactor bookmarks home stuff * Add RecentBookmarksFeature to home Move interactor to SessionControlInteractor Clean up lint, styles, and dimens. * Bookmarks use case tests for retrieving recently saved bookmarks. Linting. * View holder tests * Match ux to designs for colors, margins, and scrolling * Clean up clean up * Tests for the view bound feature * Controller test * Clean up: check state of store in feature tests; ellipsize textviews for bookmark item; remove unused attr; format Co-authored-by: Jonathan Almeida <jalmeida@mozilla.com>
3 years ago
RecentBookmarksViewHolder.LAYOUT_ID -> {
RecentBookmarksViewHolder(view, interactor)
}
HistoryMetadataHeaderViewHolder.LAYOUT_ID -> HistoryMetadataHeaderViewHolder(
view,
interactor
)
HistoryMetadataGroupViewHolder.LAYOUT_ID -> HistoryMetadataGroupViewHolder(
view,
interactor
)
HistoryMetadataViewHolder.LAYOUT_ID -> HistoryMetadataViewHolder(view, interactor)
else -> throw IllegalStateException()
}
}
override fun getItemViewType(position: Int) = getItem(position).viewType
override fun onBindViewHolder(
holder: RecyclerView.ViewHolder,
position: Int,
payloads: MutableList<Any>
) {
if (payloads.isNullOrEmpty()) {
onBindViewHolder(holder, position)
} else {
when (holder) {
is TopSitePagerViewHolder -> {
if (payloads[0] is AdapterItem.TopSitePagerPayload) {
val payload = payloads[0] as AdapterItem.TopSitePagerPayload
holder.update(payload)
}
}
}
}
}
@SuppressWarnings("ComplexMethod")
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val item = getItem(position)
when (holder) {
is ButtonTipViewHolder -> {
val tipItem = item as AdapterItem.TipItem
holder.bind(tipItem.tip)
}
is TopSitePagerViewHolder -> {
holder.bind((item as AdapterItem.TopSitePager).topSites)
}
is CollectionViewHolder -> {
val (collection, expanded) = item as AdapterItem.CollectionItem
holder.bindSession(collection, expanded)
}
is TabInCollectionViewHolder -> {
val (collection, tab, isLastTab) = item as AdapterItem.TabInCollectionItem
holder.bindSession(collection, tab, isLastTab)
}
is OnboardingSectionHeaderViewHolder -> holder.bind(
(item as AdapterItem.OnboardingSectionHeader).labelBuilder
)
is OnboardingManualSignInViewHolder -> holder.bind()
is OnboardingAutomaticSignInViewHolder -> holder.bind(
(item as AdapterItem.OnboardingAutomaticSignIn).state.withAccount
)
is RecentTabViewHolder -> {
val (tab, tabPosition) = item as AdapterItem.RecentTabItem
holder.bindTab(tab).apply {
RecentTabViewDecorator.forPosition(tabPosition).invoke(this)
}
}
For FNX-22339: Recently saved bookmarks (#19835) * Title and button for home screen recently saved bookmarks section Create bookmark item view with favicon and title * View holders and interactors for recently saved bookmarks Recent bookmark item view holder binding Create adapter for recent bookmarks. Implement controller methods. Implement view holder bindings for items Top level adapter for recent bookmarks section Retrieve list of recent bookmarks on home View holders and interactors for recently saved bookmarks Recent bookmark item view holder binding Create adapter for recent bookmarks. Implement controller methods. Implement view holder bindings for items Top level adapter for recent bookmarks section Retrieve list of recent bookmarks on home Update list on app start and when bookmarks are added View holders and interactors for recently saved bookmarks Recent bookmark item view holder binding Create adapter for recent bookmarks. Implement controller methods. Implement view holder bindings for items Top level adapter for recent bookmarks section Retrieve list of recent bookmarks on home Update list on app start and when bookmarks are added Make a use case for retrieving and updating the list of recently saved bookmarks Add adapter items and define header viewholder binding Use session interactor for header button clicks. Bind in the adapter * Retrieve list of bookmarks asynchronously on home Interactor and controller tests Address review comments Split up tests for recent bookmarks Update to new interactors Dark mode and light mode styles Refactor bookmarks home stuff * Add RecentBookmarksFeature to home Move interactor to SessionControlInteractor Clean up lint, styles, and dimens. * Bookmarks use case tests for retrieving recently saved bookmarks. Linting. * View holder tests * Match ux to designs for colors, margins, and scrolling * Clean up clean up * Tests for the view bound feature * Controller test * Clean up: check state of store in feature tests; ellipsize textviews for bookmark item; remove unused attr; format Co-authored-by: Jonathan Almeida <jalmeida@mozilla.com>
3 years ago
is RecentBookmarksViewHolder -> {
holder.bind(
(item as AdapterItem.RecentBookmarks).recentBookmarks
)
}
is HistoryMetadataViewHolder -> {
holder.bind((item as AdapterItem.HistoryMetadataItem).historyMetadata)
}
is HistoryMetadataGroupViewHolder -> {
holder.bind((item as AdapterItem.HistoryMetadataGroup).historyMetadataGroup)
}
}
}
}