diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkFragment.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkFragment.kt index 6443ed71fd..4336027e9a 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkFragment.kt @@ -21,8 +21,6 @@ import androidx.lifecycle.lifecycleScope import androidx.navigation.NavDirections import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs -import kotlinx.android.synthetic.main.component_bookmark.view.* -import kotlinx.android.synthetic.main.fragment_bookmark.view.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main @@ -44,6 +42,7 @@ import org.mozilla.fenix.R import org.mozilla.fenix.components.FenixSnackbar import org.mozilla.fenix.components.StoreProvider import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.databinding.FragmentBookmarkBinding import org.mozilla.fenix.ext.bookmarkStorage import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.minus @@ -72,13 +71,16 @@ class BookmarkFragment : LibraryPageFragment(), UserInteractionHan private var pendingBookmarkDeletionJob: (suspend () -> Unit)? = null private var pendingBookmarksToDelete: MutableSet = mutableSetOf() + private var _binding: FragmentBookmarkBinding? = null + private val binding get() = _binding!! + private val metrics get() = context?.components?.analytics?.metrics override val selectedItems get() = bookmarkStore.state.mode.selectedItems - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - val view = inflater.inflate(R.layout.fragment_bookmark, container, false) + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + _binding = FragmentBookmarkBinding.inflate(inflater, container, false) bookmarkStore = StoreProvider.get(this) { BookmarkFragmentStore(BookmarkFragmentState(null)) @@ -103,8 +105,8 @@ class BookmarkFragment : LibraryPageFragment(), UserInteractionHan metrics = metrics!! ) - bookmarkView = BookmarkView(view.bookmarkLayout, bookmarkInteractor, findNavController()) - bookmarkView.view.bookmark_folders_sign_in.visibility = View.GONE + bookmarkView = BookmarkView(binding.bookmarkLayout, bookmarkInteractor, findNavController()) + bookmarkView.binding.bookmarkFoldersSignIn.visibility = View.GONE viewLifecycleOwner.lifecycle.addObserver( BookmarkDeselectNavigationListener( @@ -114,7 +116,7 @@ class BookmarkFragment : LibraryPageFragment(), UserInteractionHan ) ) - return view + return binding.root } private fun showSnackBarWithText(text: String) { @@ -138,7 +140,7 @@ class BookmarkFragment : LibraryPageFragment(), UserInteractionHan // Don't want to pester user too much with it, and if there are lots of bookmarks present, // it'll just get visually lost. Inside of the "Desktop Bookmarks" node, it'll nicely stand-out, // since there are always only three other items in there. It's also the right place contextually. - bookmarkView.view.bookmark_folders_sign_in.isVisible = + bookmarkView.binding.bookmarkFoldersSignIn.isVisible = it.tree?.guid == BookmarkRoot.Root.id && accountManager.authenticatedAccount() == null } } @@ -361,6 +363,7 @@ class BookmarkFragment : LibraryPageFragment(), UserInteractionHan override fun onDestroyView() { super.onDestroyView() _bookmarkInteractor = null + _binding = null } private fun showRemoveFolderDialog(selected: Set) { diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkView.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkView.kt index 6c581a8f8c..7c7925079c 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkView.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkView.kt @@ -5,16 +5,15 @@ package org.mozilla.fenix.library.bookmarks import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup import androidx.core.view.isVisible import androidx.navigation.NavController -import kotlinx.android.synthetic.main.component_bookmark.view.* import mozilla.appservices.places.BookmarkRoot import mozilla.components.concept.storage.BookmarkNode import mozilla.components.support.base.feature.UserInteractionHandler import org.mozilla.fenix.NavGraphDirections import org.mozilla.fenix.R +import org.mozilla.fenix.databinding.ComponentBookmarkBinding import org.mozilla.fenix.library.LibraryPageView import org.mozilla.fenix.selection.SelectionInteractor @@ -106,22 +105,23 @@ class BookmarkView( private val navController: NavController ) : LibraryPageView(container), UserInteractionHandler { - val view: View = LayoutInflater.from(container.context) - .inflate(R.layout.component_bookmark, container, true) + val binding = ComponentBookmarkBinding.inflate( + LayoutInflater.from(container.context), container, true + ) private var mode: BookmarkFragmentState.Mode = BookmarkFragmentState.Mode.Normal() private var tree: BookmarkNode? = null - private val bookmarkAdapter = BookmarkAdapter(view.bookmarks_empty_view, interactor) + private val bookmarkAdapter = BookmarkAdapter(binding.bookmarksEmptyView, interactor) init { - view.bookmark_list.apply { + binding.bookmarkList.apply { adapter = bookmarkAdapter } - view.bookmark_folders_sign_in.setOnClickListener { + binding.bookmarkFoldersSignIn.setOnClickListener { navController.navigate(NavGraphDirections.actionGlobalTurnOnSync()) } - view.swipe_refresh.setOnRefreshListener { + binding.swipeRefresh.setOnRefreshListener { interactor.onRequestSync() } } @@ -150,10 +150,10 @@ class BookmarkView( ) } } - view.bookmarks_progress_bar.isVisible = state.isLoading - view.swipe_refresh.isEnabled = + binding.bookmarksProgressBar.isVisible = state.isLoading + binding.swipeRefresh.isEnabled = state.mode is BookmarkFragmentState.Mode.Normal || state.mode is BookmarkFragmentState.Mode.Syncing - view.swipe_refresh.isRefreshing = state.mode is BookmarkFragmentState.Mode.Syncing + binding.swipeRefresh.isRefreshing = state.mode is BookmarkFragmentState.Mode.Syncing } override fun onBackPressed(): Boolean {