This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For #26421 - Extract synced tabs into it's own viewholder
- Loading branch information
1 parent
9798623
commit 0b0e31a
Showing
7 changed files
with
96 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/src/main/java/org/mozilla/fenix/home/recentsyncedtabs/view/RecentSyncedTabViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* 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.recentsyncedtabs.view | ||
|
||
import android.view.View | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.platform.ComposeView | ||
import androidx.lifecycle.LifecycleOwner | ||
import mozilla.components.lib.state.ext.observeAsComposableState | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.components.components | ||
import org.mozilla.fenix.compose.ComposeViewHolder | ||
import org.mozilla.fenix.home.recentsyncedtabs.RecentSyncedTabState | ||
import org.mozilla.fenix.home.recentsyncedtabs.interactor.RecentSyncedTabInteractor | ||
|
||
/** | ||
* View holder for a recent synced tab item. | ||
* | ||
* @param composeView [ComposeView] which will be populated with Jetpack Compose UI content. | ||
* @param recentSyncedTabInteractor [RecentSyncedTabInteractor] which will have delegated to all | ||
* recent synced tab user interactions. | ||
*/ | ||
class RecentSyncedTabViewHolder( | ||
composeView: ComposeView, | ||
viewLifecycleOwner: LifecycleOwner, | ||
private val recentSyncedTabInteractor: RecentSyncedTabInteractor, | ||
) : ComposeViewHolder(composeView, viewLifecycleOwner) { | ||
|
||
init { | ||
val horizontalPadding = | ||
composeView.resources.getDimensionPixelSize(R.dimen.home_item_horizontal_margin) | ||
val verticalPadding = | ||
composeView.resources.getDimensionPixelSize(R.dimen.home_item_vertical_margin) | ||
composeView.setPadding(horizontalPadding, verticalPadding, horizontalPadding, 0) | ||
} | ||
|
||
companion object { | ||
val LAYOUT_ID = View.generateViewId() | ||
} | ||
|
||
@Composable | ||
override fun Content() { | ||
val recentSyncedTabState = | ||
components.appStore.observeAsComposableState { state -> state.recentSyncedTabState } | ||
recentSyncedTabState.value?.let { | ||
val syncedTab = when (it) { | ||
RecentSyncedTabState.None, | ||
RecentSyncedTabState.Loading -> null | ||
is RecentSyncedTabState.Success -> it.tab | ||
} | ||
RecentSyncedTab( | ||
tab = syncedTab, | ||
onRecentSyncedTabClick = recentSyncedTabInteractor::onRecentSyncedTabClicked, | ||
onSeeAllSyncedTabsButtonClick = recentSyncedTabInteractor::onSyncedTabShowAllClicked, | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters