For #23969 - Migrate homescreen recent bookmarks to compose

upstream-sync
sarah541 2 years ago committed by mergify[bot]
parent e11c9b2e8f
commit ce7d2d1962

@ -5,29 +5,39 @@
package org.mozilla.fenix.home.recentbookmarks.view
import android.view.View
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.LifecycleOwner
import androidx.navigation.findNavController
import org.mozilla.fenix.R
import org.mozilla.fenix.databinding.RecentBookmarksHeaderBinding
import org.mozilla.fenix.compose.ComposeViewHolder
import org.mozilla.fenix.compose.home.HomeSectionHeader
import org.mozilla.fenix.home.recentbookmarks.interactor.RecentBookmarksInteractor
import org.mozilla.fenix.utils.view.ViewHolder
import org.mozilla.fenix.theme.FirefoxTheme
/**
* View holder for the recent bookmarks header and "Show all" button.
*
* @param view The container [View] for this view holder.
* @paramcomposeView [ComposeView] which will be populated with Jetpack Compose UI content.
* @param interactor [RecentBookmarksInteractor] which will have delegated to all user interactions.
*/
class RecentBookmarksHeaderViewHolder(
view: View,
composeView: ComposeView,
viewLifecycleOwner: LifecycleOwner,
private val interactor: RecentBookmarksInteractor
) : ViewHolder(view) {
) : ComposeViewHolder(composeView, viewLifecycleOwner) {
init {
val binding = RecentBookmarksHeaderBinding.bind(view)
binding.showAllBookmarksButton.setOnClickListener {
dismissSearchDialogIfDisplayed()
interactor.onShowAllBookmarksClicked()
}
val horizontalPadding =
composeView.resources.getDimensionPixelSize(R.dimen.home_item_horizontal_margin)
composeView.setPadding(horizontalPadding, 0, horizontalPadding, 0)
}
private fun dismissSearchDialogIfDisplayed() {
@ -37,7 +47,26 @@ class RecentBookmarksHeaderViewHolder(
}
}
@Composable
override fun Content() {
Column {
Spacer(modifier = Modifier.height(40.dp))
HomeSectionHeader(
text = stringResource(R.string.recent_bookmarks_title),
description = stringResource(id = R.string.recently_saved_show_all_content_description_2),
onShowAllClick = {
dismissSearchDialogIfDisplayed()
interactor.onShowAllBookmarksClicked()
}
)
Spacer(Modifier.height(16.dp))
}
}
companion object {
const val LAYOUT_ID = R.layout.recent_bookmarks_header
val LAYOUT_ID = View.generateViewId()
}
}

@ -256,6 +256,11 @@ class SessionControlAdapter(
viewLifecycleOwner,
interactor
)
RecentBookmarksHeaderViewHolder.LAYOUT_ID -> return RecentBookmarksHeaderViewHolder(
composeView = ComposeView(parent.context),
viewLifecycleOwner,
interactor
)
}
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
@ -296,7 +301,6 @@ class SessionControlAdapter(
)
MessageCardViewHolder.LAYOUT_ID -> MessageCardViewHolder(view, interactor)
RecentTabsHeaderViewHolder.LAYOUT_ID -> RecentTabsHeaderViewHolder(view, interactor)
RecentBookmarksHeaderViewHolder.LAYOUT_ID -> RecentBookmarksHeaderViewHolder(view, interactor)
BottomSpacerViewHolder.LAYOUT_ID -> BottomSpacerViewHolder(view)
else -> throw IllegalStateException()
}
@ -308,6 +312,7 @@ class SessionControlAdapter(
is RecentlyVisitedViewHolder,
is RecentVisitsHeaderViewHolder,
is RecentBookmarksViewHolder,
is RecentBookmarksHeaderViewHolder,
is RecentTabViewHolder,
is PocketCategoriesViewHolder,
is PocketRecommendationsHeaderViewHolder,

@ -1,45 +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"
android:layout_marginBottom="16dp">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/header"
style="@style/Header16TextStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:contentDescription="@string/recently_saved_bookmarks_content_description"
android:maxLines="2"
android:text="@string/recent_bookmarks_title"
android:gravity="top"
android:paddingTop="1dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/showAllBookmarksButton"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/showAllBookmarksButton"
style="@style/Button14TextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:contentDescription="@string/recently_saved_show_all_content_description_2"
android:insetTop="0dp"
android:paddingStart="16dp"
android:paddingEnd="0dp"
android:maxLines="1"
android:nestedScrollingEnabled="false"
android:text="@string/recently_saved_show_all"
android:textColor="@color/fx_mobile_text_color_accent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@id/header" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -39,7 +39,7 @@
<!-- Title for the home screen section with recently saved bookmarks. -->
<string name="recent_bookmarks_title">Recent bookmarks</string>
<!-- Content description for the recently saved bookmarks section on the home screen. -->
<string name="recently_saved_bookmarks_content_description">Recently saved bookmarks</string>
<string moz:removedIn="100" name="recently_saved_bookmarks_content_description" tools:ignore="UnusedResources">Recently saved bookmarks</string>
<!-- Title for the button which navigates the user to show all of their saved bookmarks. -->
<string name="recently_saved_show_all">Show all</string>
<!-- Content description for the button which navigates the user to show all of their saved bookmarks. -->

@ -1,40 +0,0 @@
/* 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.recentbookmarks.view
import android.view.LayoutInflater
import androidx.navigation.Navigation
import io.mockk.mockk
import io.mockk.verify
import mozilla.components.support.test.robolectric.testContext
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.databinding.RecentBookmarksHeaderBinding
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.home.recentbookmarks.interactor.RecentBookmarksInteractor
@RunWith(FenixRobolectricTestRunner::class)
class RecentBookmarksHeaderViewHolderTest {
private lateinit var binding: RecentBookmarksHeaderBinding
private lateinit var interactor: RecentBookmarksInteractor
@Before
fun setup() {
binding = RecentBookmarksHeaderBinding.inflate(LayoutInflater.from(testContext))
Navigation.setViewNavController(binding.root, mockk(relaxed = true))
interactor = mockk(relaxed = true)
}
@Test
fun `WHEN show all button is clicked THEN interactor is called`() {
RecentBookmarksHeaderViewHolder(binding.root, interactor)
binding.showAllBookmarksButton.performClick()
verify { interactor.onShowAllBookmarksClicked() }
}
}
Loading…
Cancel
Save