@ -5,6 +5,7 @@
package org.mozilla.fenix.home.sessioncontrol
package org.mozilla.fenix.home.sessioncontrol
import android.view.View
import android.view.View
import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView
@ -13,6 +14,7 @@ import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.feature.top.sites.TopSite
import org.mozilla.fenix.R
import org.mozilla.fenix.R
import org.mozilla.fenix.components.tips.Tip
import org.mozilla.fenix.components.tips.Tip
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.home.HomeFragmentState
import org.mozilla.fenix.home.HomeFragmentState
import org.mozilla.fenix.home.HomeScreenViewModel
import org.mozilla.fenix.home.HomeScreenViewModel
import org.mozilla.fenix.home.Mode
import org.mozilla.fenix.home.Mode
@ -25,7 +27,8 @@ private fun normalModeAdapterItems(
topSites : List < TopSite > ,
topSites : List < TopSite > ,
collections : List < TabCollection > ,
collections : List < TabCollection > ,
expandedCollections : Set < Long > ,
expandedCollections : Set < Long > ,
tip : Tip ?
tip : Tip ? ,
showCollectionsPlaceholder : Boolean
) : List < AdapterItem > {
) : List < AdapterItem > {
val items = mutableListOf < AdapterItem > ( )
val items = mutableListOf < AdapterItem > ( )
@ -36,8 +39,9 @@ private fun normalModeAdapterItems(
}
}
if ( collections . isEmpty ( ) ) {
if ( collections . isEmpty ( ) ) {
items . add ( AdapterItem . CollectionHeader )
if ( showCollectionsPlaceholder ) {
items . add ( AdapterItem . NoCollectionsMessage )
items . add ( AdapterItem . NoCollectionsMessage )
}
} else {
} else {
showCollections ( collections , expandedCollections , items )
showCollections ( collections , expandedCollections , items )
}
}
@ -68,62 +72,77 @@ private fun onboardingAdapterItems(onboardingState: OnboardingState): List<Adapt
val items : MutableList < AdapterItem > = mutableListOf ( AdapterItem . OnboardingHeader )
val items : MutableList < AdapterItem > = mutableListOf ( AdapterItem . OnboardingHeader )
// Customize FxA items based on where we are with the account state:
// Customize FxA items based on where we are with the account state:
items . addAll ( when ( onboardingState ) {
items . addAll (
OnboardingState . SignedOutNoAutoSignIn -> {
when ( onboardingState ) {
listOf (
OnboardingState . SignedOutNoAutoSignIn -> {
AdapterItem . OnboardingManualSignIn
listOf (
)
AdapterItem . OnboardingManualSignIn
}
)
is OnboardingState . SignedOutCanAutoSignIn -> {
}
listOf (
is OnboardingState . SignedOutCanAutoSignIn -> {
AdapterItem . OnboardingAutomaticSignIn ( onboardingState )
listOf (
)
AdapterItem . OnboardingAutomaticSignIn ( onboardingState )
)
}
OnboardingState . SignedIn -> listOf ( )
}
}
OnboardingState . SignedIn -> listOf ( )
)
} )
items . addAll (
items . addAll ( listOf (
listOf (
AdapterItem . OnboardingSectionHeader {
AdapterItem . OnboardingSectionHeader {
val appName = it . getString ( R . string . app _name )
val appName = it . getString ( R . string . app _name )
it . getString ( R . string . onboarding _feature _section _header , appName )
it . getString ( R . string . onboarding _feature _section _header , appName )
} ,
} ,
AdapterItem . OnboardingWhatsNew ,
AdapterItem . OnboardingWhatsNew ,
AdapterItem . OnboardingTrackingProtection ,
AdapterItem . OnboardingTrackingProtection ,
AdapterItem . OnboardingThemePicker ,
AdapterItem . OnboardingThemePicker ,
AdapterItem . OnboardingPrivateBrowsing ,
AdapterItem . OnboardingPrivateBrowsing ,
AdapterItem . OnboardingToolbarPositionPicker ,
AdapterItem . OnboardingToolbarPositionPicker ,
AdapterItem . OnboardingPrivacyNotice ,
AdapterItem . OnboardingPrivacyNotice ,
AdapterItem . OnboardingFinish
AdapterItem . OnboardingFinish
) )
)
)
return items
return items
}
}
private fun HomeFragmentState . toAdapterList ( ) : List < AdapterItem > = when ( mode ) {
private fun HomeFragmentState . toAdapterList ( ) : List < AdapterItem > = when ( mode ) {
is Mode . Normal -> normalModeAdapterItems ( topSites , collections , expandedCollections , tip )
is Mode . Normal -> normalModeAdapterItems (
topSites ,
collections ,
expandedCollections ,
tip ,
showCollectionPlaceholder
)
is Mode . Private -> privateModeAdapterItems ( )
is Mode . Private -> privateModeAdapterItems ( )
is Mode . Onboarding -> onboardingAdapterItems ( mode . state )
is Mode . Onboarding -> onboardingAdapterItems ( mode . state )
}
}
private fun collectionTabItems ( collection : TabCollection ) = collection . tabs . mapIndexed { index , tab ->
private fun collectionTabItems ( collection : TabCollection ) =
collection . tabs . mapIndexed { index , tab ->
AdapterItem . TabInCollectionItem ( collection , tab , index == collection . tabs . lastIndex )
AdapterItem . TabInCollectionItem ( collection , tab , index == collection . tabs . lastIndex )
}
}
class SessionControlView (
class SessionControlView (
override val containerView : View ? ,
override val containerView : View ,
viewLifecycleOwner : LifecycleOwner ,
interactor : SessionControlInteractor ,
interactor : SessionControlInteractor ,
private var homeScreenViewModel : HomeScreenViewModel ,
private var homeScreenViewModel : HomeScreenViewModel
private val hasNormalTabsOpened : Boolean
) : LayoutContainer {
) : LayoutContainer {
val view : RecyclerView = containerView as RecyclerView
val view : RecyclerView = containerView as RecyclerView
private val sessionControlAdapter = SessionControlAdapter ( interactor , hasNormalTabsOpened )
private val sessionControlAdapter = SessionControlAdapter (
interactor ,
viewLifecycleOwner ,
containerView . context . components
)
init {
init {
view . apply {
view . apply {
adapter = sessionControlAdapter
adapter = sessionControlAdapter
layoutManager = LinearLayoutManager ( containerView !! . context )
layoutManager = LinearLayoutManager ( containerView . context )
val itemTouchHelper =
val itemTouchHelper =
ItemTouchHelper (
ItemTouchHelper (
SwipeToDeleteCallback (
SwipeToDeleteCallback (