For #23971 - Migrate CollectionHeaderViewHolder to Compose

fix ktlint
upstream-sync
sarah541 2 years ago committed by mergify[bot]
parent 582d8ef52d
commit 3a039ca918

@ -271,6 +271,10 @@ class SessionControlAdapter(
viewLifecycleOwner = viewLifecycleOwner,
interactor = interactor
)
CollectionHeaderViewHolder.LAYOUT_ID -> return CollectionHeaderViewHolder(
composeView = ComposeView(parent.context),
viewLifecycleOwner = viewLifecycleOwner
)
}
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
@ -284,7 +288,6 @@ class SessionControlAdapter(
components.core.store,
interactor
)
CollectionHeaderViewHolder.LAYOUT_ID -> CollectionHeaderViewHolder(view)
CollectionViewHolder.LAYOUT_ID -> CollectionViewHolder(view, interactor)
TabInCollectionViewHolder.LAYOUT_ID -> TabInCollectionViewHolder(
view as WidgetSiteItemView,
@ -313,6 +316,7 @@ class SessionControlAdapter(
override fun onViewRecycled(holder: RecyclerView.ViewHolder) {
when (holder) {
is CollectionHeaderViewHolder,
is CustomizeHomeButtonViewHolder,
is RecentlyVisitedViewHolder,
is RecentVisitsHeaderViewHolder,

@ -5,13 +5,52 @@
package org.mozilla.fenix.home.sessioncontrol.viewholders
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.LifecycleOwner
import org.mozilla.fenix.R
import org.mozilla.fenix.compose.ComposeViewHolder
import org.mozilla.fenix.compose.SectionHeader
/**
* View holder for the "Collections" section header with the "Show all" button.
*/
class CollectionHeaderViewHolder(
view: View
) : RecyclerView.ViewHolder(view) {
composeView: ComposeView,
viewLifecycleOwner: LifecycleOwner,
) : ComposeViewHolder(composeView, viewLifecycleOwner) {
companion object {
const val LAYOUT_ID = R.layout.collection_header
val LAYOUT_ID = View.generateViewId()
}
init {
val horizontalPadding =
composeView.resources.getDimensionPixelSize(R.dimen.home_item_horizontal_margin)
composeView.setPadding(horizontalPadding, 0, horizontalPadding, 0)
}
@Composable
override fun Content() {
Column {
Spacer(Modifier.height(56.dp))
SectionHeader(
text = stringResource(R.string.collections_header),
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight(align = Alignment.Top),
)
Spacer(Modifier.height(10.dp))
}
}
}

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/home_item_horizontal_margin"
android:layout_marginTop="40dp">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/collections_header_text"
style="@style/Header16TextStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/collections_header"
android:maxLines="2"
android:gravity="center_vertical"
android:paddingTop="16dp"
android:paddingBottom="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -79,7 +79,6 @@
android:transitionGroup="false"
android:importantForAccessibility="yes"
android:overScrollMode="never"
tools:listheader="@layout/collection_header"
tools:listitem="@layout/collection_home_list_row"
tools:itemCount="3"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"/>

Loading…
Cancel
Save