Skip to content

Commit

Permalink
For mozilla-mobile#23969 - migrate homescreen recent bookmarks to com…
Browse files Browse the repository at this point in the history
…pose

For mozilla-mobile#23969 - migrate homescreen recent bookmarks to compose
  • Loading branch information
sarah541 committed Mar 14, 2022
1 parent 5057f26 commit 10e2916
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@
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.home.recentbookmarks.interactor.RecentBookmarksInteractor
import org.mozilla.fenix.utils.view.ViewHolder
import org.mozilla.fenix.home.recentvisits.view.RecentVisitsHeader
import org.mozilla.fenix.theme.FirefoxTheme

/**
* View holder for the recent bookmarks header and "Show all" button.
Expand All @@ -18,26 +29,52 @@ import org.mozilla.fenix.utils.view.ViewHolder
* @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() {
private fun dismissSearchDialogIfDisplayedAndShowAllClicked() {
val navController = itemView.findNavController()
if (navController.currentDestination?.id == R.id.searchDialogFragment) {
navController.navigateUp()
}
interactor.onShowAllBookmarksClicked()
}

@Composable
override fun Content() {
Column {
Spacer(modifier = Modifier.height(40.dp))

RecentVisitsHeader(
text = stringResource(R.string.recent_bookmarks_title),
description = stringResource(id = R.string.recently_saved_show_all_content_description_2),
onShowAllClick = { dismissSearchDialogIfDisplayedAndShowAllClicked() },
)

Spacer(Modifier.height(16.dp))
}
}

companion object {
const val LAYOUT_ID = R.layout.recent_bookmarks_header
val LAYOUT_ID = View.generateViewId()
}
}

@Composable
@Preview
private fun RecentBookmarksHeaderPreview() {
FirefoxTheme {
RecentVisitsHeader(
stringResource(R.string.recent_bookmarks_title),
stringResource(id = R.string.recently_saved_show_all_content_description_2),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class RecentVisitsHeaderViewHolder(

RecentVisitsHeader(
text = stringResource(R.string.history_metadata_header_2),
description = stringResource(R.string.past_explorations_show_all_content_description_2),
onShowAllClick = interactor::onHistoryShowAllClicked,
)

Expand All @@ -78,6 +79,7 @@ class RecentVisitsHeaderViewHolder(
@Composable
fun RecentVisitsHeader(
text: String,
description: String,
onShowAllClick: () -> Unit = {}
) {
Row(
Expand All @@ -91,7 +93,6 @@ fun RecentVisitsHeader(
.wrapContentHeight(align = Alignment.Top)
)

val description = stringResource(id = R.string.past_explorations_show_all_content_description_2)
ClickableText(
text = AnnotatedString(text = stringResource(id = R.string.recent_tabs_show_all)),
modifier = Modifier.semantics {
Expand All @@ -111,7 +112,8 @@ fun RecentVisitsHeader(
private fun RecentVisitsHeaderPreview() {
FirefoxTheme {
RecentVisitsHeader(
stringResource(R.string.history_metadata_header_2)
stringResource(R.string.history_metadata_header_2),
stringResource(R.string.past_explorations_show_all_content_description_2)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,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)
Expand Down Expand Up @@ -301,7 +306,6 @@ class SessionControlAdapter(
)
ExperimentDefaultBrowserCardViewHolder.LAYOUT_ID -> ExperimentDefaultBrowserCardViewHolder(view, interactor)
RecentTabsHeaderViewHolder.LAYOUT_ID -> RecentTabsHeaderViewHolder(view, interactor)
RecentBookmarksHeaderViewHolder.LAYOUT_ID -> RecentBookmarksHeaderViewHolder(view, interactor)
BottomSpacerViewHolder.LAYOUT_ID -> BottomSpacerViewHolder(view)
else -> throw IllegalStateException()
}
Expand Down
45 changes: 0 additions & 45 deletions app/src/main/res/layout/recent_bookmarks_header.xml

This file was deleted.

This file was deleted.

0 comments on commit 10e2916

Please sign in to comment.