Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Don't use ProcessLifecycleOwner for view-tied consume
Browse files Browse the repository at this point in the history
  • Loading branch information
ekager committed Apr 20, 2020
1 parent f801f32 commit 5d51c4f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
6 changes: 4 additions & 2 deletions app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,17 @@ class HomeFragment : Fragment() {
showDeleteCollectionPrompt = ::showDeleteCollectionPrompt,
openSettingsScreen = ::openSettingsScreen,
openSearchScreen = ::navigateToSearch,
openWhatsNewLink = { openCustomTab(SupportUtils.getWhatsNewUrl(view.context)) },
openWhatsNewLink = { openCustomTab(SupportUtils.getWhatsNewUrl(activity)) },
openPrivacyNotice = { openCustomTab(SupportUtils.getPrivacyNoticeUrl()) }
)
)
updateLayout(view)
setOffset(view)
sessionControlView = SessionControlView(
homeFragmentStore,
view.sessionControlRecyclerView, sessionControlInteractor,
view.sessionControlRecyclerView,
sessionControlInteractor,
viewLifecycleOwner,
homeViewModel
)
activity.themeManager.applyStatusBarTheme(activity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.lifecycle.ViewModel

class HomeScreenViewModel : ViewModel() {
var layoutManagerState: Parcelable? = null
var motionLayoutProgress = 0F

/**
* Used to remember if we need to scroll to top of the homeFragment's recycleView (top sites) see #8561
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package org.mozilla.fenix.home.sessioncontrol

import android.os.Build
import android.view.View
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
Expand Down Expand Up @@ -164,6 +164,7 @@ class SessionControlView(
private val homeFragmentStore: HomeFragmentStore,
override val containerView: View?,
interactor: SessionControlInteractor,
private val viewLifecycleOwner: LifecycleOwner,
private var homeScreenViewModel: HomeScreenViewModel
) : LayoutContainer {

Expand All @@ -183,7 +184,7 @@ class SessionControlView(
)
itemTouchHelper.attachToRecyclerView(this)

view.consumeFrom(homeFragmentStore, ProcessLifecycleOwner.get()) {
view.consumeFrom(homeFragmentStore, viewLifecycleOwner) {
update(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.nav

Expand All @@ -43,7 +42,7 @@ interface BookmarkController {
class DefaultBookmarkController(
private val context: Context,
private val navController: NavController,
private val snackbar: FenixSnackbar,
private val showSnackbar: (String) -> Unit,
private val deleteBookmarkNodes: (Set<BookmarkNode>, Event) -> Unit,
private val invokePendingDeletion: () -> Unit
) : BookmarkController {
Expand All @@ -68,15 +67,13 @@ class DefaultBookmarkController(
}

override fun handleBookmarkSelected(node: BookmarkNode) {
snackbar.setText(resources.getString(R.string.bookmark_cannot_edit_root))
snackbar.show()
showSnackbar(resources.getString(R.string.bookmark_cannot_edit_root))
}

override fun handleCopyUrl(item: BookmarkNode) {
val urlClipData = ClipData.newPlainText(item.url, item.url)
context.getSystemService<ClipboardManager>()?.primaryClip = urlClipData
snackbar.setText(resources.getString(R.string.url_copied))
snackbar.show()
showSnackbar(resources.getString(R.string.url_copied))
}

override fun handleBookmarkSharing(item: BookmarkNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ class BookmarkFragment : LibraryPageFragment<BookmarkNode>(), UserInteractionHan
bookmarksController = DefaultBookmarkController(
context = context!!,
navController = findNavController(),
snackbar = FenixSnackbar.make(
view = view,
duration = FenixSnackbar.LENGTH_LONG,
isDisplayedWithBrowserToolbar = false
),
showSnackbar = ::showSnackBarWithText,
deleteBookmarkNodes = ::deleteMulti,
invokePendingDeletion = ::invokePendingDeletion
),
Expand All @@ -107,6 +103,16 @@ class BookmarkFragment : LibraryPageFragment<BookmarkNode>(), UserInteractionHan
return view
}

private fun showSnackBarWithText(text: String) {
view?.let {
FenixSnackbar.make(
view = it,
duration = FenixSnackbar.LENGTH_LONG,
isDisplayedWithBrowserToolbar = false
).setText(text).show()
}
}

@ExperimentalCoroutinesApi
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.Services
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
Expand All @@ -41,7 +40,7 @@ class BookmarkControllerTest {

private val context: Context = mockk(relaxed = true)
private val navController: NavController = mockk(relaxed = true)
private val snackbar: FenixSnackbar = mockk(relaxed = true)
private val showSnackbar: (String) -> Unit = mockk(relaxed = true)
private val deleteBookmarkNodes: (Set<BookmarkNode>, Event) -> Unit = mockk(relaxed = true)
private val invokePendingDeletion: () -> Unit = mockk(relaxed = true)

Expand Down Expand Up @@ -91,7 +90,7 @@ class BookmarkControllerTest {
controller = DefaultBookmarkController(
context = homeActivity,
navController = navController,
snackbar = snackbar,
showSnackbar = showSnackbar,
deleteBookmarkNodes = deleteBookmarkNodes,
invokePendingDeletion = invokePendingDeletion
)
Expand Down Expand Up @@ -166,8 +165,7 @@ class BookmarkControllerTest {
controller.handleBookmarkSelected(root)

verify {
snackbar.setText(errorMessage)
snackbar.show()
showSnackbar(errorMessage)
}
}

Expand All @@ -182,8 +180,7 @@ class BookmarkControllerTest {

verifyOrder {
ClipData.newPlainText(item.url, item.url)
snackbar.setText(urlCopiedMessage)
snackbar.show()
showSnackbar(urlCopiedMessage)
}
}

Expand Down

0 comments on commit 5d51c4f

Please sign in to comment.