From d028c971128a648af3f720a26e41c2c7c6c5d19a Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Fri, 4 Oct 2019 22:20:58 -0700 Subject: [PATCH] For #5213 - Use support library attributes --- .../java/org/mozilla/fenix/ext/Context.kt | 6 ++--- .../mozilla/fenix/library/LibraryFragment.kt | 2 +- .../mozilla/fenix/library/LibraryPageView.kt | 10 ++++---- .../library/bookmarks/BookmarkFragment.kt | 13 ++++------ .../addfolder/AddBookmarkFolderFragment.kt | 6 ----- .../bookmarks/edit/EditBookmarkFragment.kt | 6 ----- .../fenix/library/history/HistoryFragment.kt | 23 ++++++------------ .../main/res/menu/bookmarks_add_folder.xml | 8 +++---- app/src/main/res/menu/bookmarks_edit.xml | 8 +++---- app/src/main/res/menu/bookmarks_menu.xml | 13 ++++------ .../main/res/menu/bookmarks_select_folder.xml | 8 +++---- .../main/res/menu/bookmarks_select_multi.xml | 24 ++++++------------- .../menu/bookmarks_select_multi_not_item.xml | 9 ++++--- .../main/res/menu/history_select_multi.xml | 23 +++++------------- app/src/main/res/menu/library_menu.xml | 8 +++---- 15 files changed, 54 insertions(+), 113 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/ext/Context.kt b/app/src/main/java/org/mozilla/fenix/ext/Context.kt index ee63528a0..921a1a257 100644 --- a/app/src/main/java/org/mozilla/fenix/ext/Context.kt +++ b/app/src/main/java/org/mozilla/fenix/ext/Context.kt @@ -18,18 +18,17 @@ import android.view.ViewGroup import androidx.annotation.AttrRes import androidx.annotation.ColorInt import androidx.annotation.StringRes -import androidx.core.content.ContextCompat import androidx.fragment.app.FragmentActivity import mozilla.components.browser.search.SearchEngineManager import mozilla.components.support.base.log.Log import mozilla.components.support.base.log.Log.Priority.WARN +import mozilla.components.support.ktx.android.content.getColorFromAttr import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.Config import org.mozilla.fenix.FenixApplication import org.mozilla.fenix.R import org.mozilla.fenix.components.Components import org.mozilla.fenix.components.metrics.MetricController -import org.mozilla.fenix.theme.ThemeManager import org.mozilla.fenix.utils.Settings /** @@ -106,8 +105,7 @@ fun Context.getRootView(): View? = * Returns the color int corresponding to the attribute. */ @ColorInt -fun Context.getColorFromAttr(@AttrRes attr: Int) = - ContextCompat.getColor(this, ThemeManager.resolveAttribute(attr, this)) +fun Context.getColorFromAttr(@AttrRes attr: Int) = getColorFromAttr(attr) fun Context.settings(isCrashReportEnabledInBuild: Boolean = BuildConfig.CRASH_REPORTING && Config.channel.isReleased) = Settings.getInstance(this, isCrashReportEnabledInBuild) diff --git a/app/src/main/java/org/mozilla/fenix/library/LibraryFragment.kt b/app/src/main/java/org/mozilla/fenix/library/LibraryFragment.kt index c189ac615..7ad503967 100644 --- a/app/src/main/java/org/mozilla/fenix/library/LibraryFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/LibraryFragment.kt @@ -19,9 +19,9 @@ import androidx.fragment.app.Fragment import androidx.navigation.Navigation import kotlinx.android.synthetic.main.fragment_library.* import mozilla.appservices.places.BookmarkRoot +import mozilla.components.support.ktx.android.content.getColorFromAttr import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event -import org.mozilla.fenix.ext.getColorFromAttr import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.requireComponents diff --git a/app/src/main/java/org/mozilla/fenix/library/LibraryPageView.kt b/app/src/main/java/org/mozilla/fenix/library/LibraryPageView.kt index 0b09bec29..dd57f68eb 100644 --- a/app/src/main/java/org/mozilla/fenix/library/LibraryPageView.kt +++ b/app/src/main/java/org/mozilla/fenix/library/LibraryPageView.kt @@ -21,9 +21,9 @@ import androidx.core.view.forEach import androidx.recyclerview.widget.RecyclerView import kotlinx.android.extensions.LayoutContainer import kotlinx.android.synthetic.main.library_site_item.view.* +import mozilla.components.support.ktx.android.content.getColorFromAttr import org.mozilla.fenix.R import org.mozilla.fenix.ext.asActivity -import org.mozilla.fenix.ext.getColorFromAttr open class LibraryPageView( override val containerView: ViewGroup @@ -40,8 +40,8 @@ open class LibraryPageView( context.getColorFromAttr(R.attr.primaryText), context.getColorFromAttr(R.attr.foundation) ) - libraryItemsList.children.forEach { - item -> item.overflow_menu.visibility = View.VISIBLE + libraryItemsList.children.forEach { item -> + item.overflow_menu.visibility = View.VISIBLE } } @@ -54,8 +54,8 @@ open class LibraryPageView( ContextCompat.getColor(context, R.color.white_color), context.getColorFromAttr(R.attr.accentHighContrast) ) - libraryItemsList.children.forEach { - item -> item.overflow_menu.visibility = View.INVISIBLE + libraryItemsList.children.forEach { item -> + item.overflow_menu.visibility = View.INVISIBLE } } 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 270460583..5112906f2 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 @@ -18,16 +18,16 @@ import androidx.lifecycle.lifecycleScope import androidx.navigation.NavDirections import androidx.navigation.fragment.findNavController import kotlinx.android.synthetic.main.fragment_bookmark.view.* -import kotlinx.coroutines.async import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.Job import kotlinx.coroutines.ObsoleteCoroutinesApi +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll import kotlinx.coroutines.isActive import kotlinx.coroutines.launch -import kotlinx.coroutines.awaitAll import kotlinx.coroutines.withContext import mozilla.appservices.places.BookmarkRoot import mozilla.components.concept.storage.BookmarkNode @@ -248,12 +248,9 @@ class BookmarkFragment : LibraryPageFragment(), BackHandler { private suspend fun deleteSelectedBookmarks(selected: Set) { CoroutineScope(IO).launch { val tempStorage = context?.bookmarkStorage - val deferreds = selected.map { - async { - tempStorage?.deleteNode(it.guid) - } - } - deferreds.awaitAll() + selected.map { + async { tempStorage?.deleteNode(it.guid) } + }.awaitAll() } } diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/addfolder/AddBookmarkFolderFragment.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/addfolder/AddBookmarkFolderFragment.kt index 2ee3ed916..3c79a690a 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/addfolder/AddBookmarkFolderFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/addfolder/AddBookmarkFolderFragment.kt @@ -4,8 +4,6 @@ package org.mozilla.fenix.library.bookmarks.addfolder -import android.graphics.PorterDuff -import android.graphics.PorterDuffColorFilter import android.os.Bundle import android.view.LayoutInflater import android.view.Menu @@ -26,7 +24,6 @@ import kotlinx.coroutines.launch import mozilla.appservices.places.BookmarkRoot import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event -import org.mozilla.fenix.ext.getColorFromAttr import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.library.bookmarks.BookmarksSharedViewModel @@ -73,9 +70,6 @@ class AddBookmarkFolderFragment : Fragment() { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { inflater.inflate(R.menu.bookmarks_add_folder, menu) - val textColor = requireContext().getColorFromAttr(R.attr.primaryText) - menu.findItem(R.id.confirm_add_folder_button).icon.colorFilter = - PorterDuffColorFilter(textColor, PorterDuff.Mode.SRC_IN) } override fun onOptionsItemSelected(item: MenuItem): Boolean { diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/edit/EditBookmarkFragment.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/edit/EditBookmarkFragment.kt index 34a1058e3..b54912637 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/edit/EditBookmarkFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/edit/EditBookmarkFragment.kt @@ -5,8 +5,6 @@ package org.mozilla.fenix.library.bookmarks.edit import android.content.DialogInterface -import android.graphics.PorterDuff -import android.graphics.PorterDuffColorFilter import android.os.Bundle import android.view.LayoutInflater import android.view.Menu @@ -42,7 +40,6 @@ import org.mozilla.fenix.R import org.mozilla.fenix.components.FenixSnackbar import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.components -import org.mozilla.fenix.ext.getColorFromAttr import org.mozilla.fenix.ext.getRootView import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.requireComponents @@ -150,9 +147,6 @@ class EditBookmarkFragment : Fragment() { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { inflater.inflate(R.menu.bookmarks_edit, menu) - val textColor = requireContext().getColorFromAttr(R.attr.primaryText) - menu.findItem(R.id.delete_bookmark_button).icon.colorFilter = - PorterDuffColorFilter(textColor, PorterDuff.Mode.SRC_IN) } override fun onOptionsItemSelected(item: MenuItem): Boolean { diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt index a8ce49bcf..728c9ce39 100644 --- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryFragment.kt @@ -5,8 +5,6 @@ package org.mozilla.fenix.library.history import android.content.DialogInterface -import android.graphics.PorterDuff.Mode.SRC_IN -import android.graphics.PorterDuffColorFilter import android.os.Bundle import android.view.LayoutInflater import android.view.Menu @@ -14,9 +12,9 @@ import android.view.MenuInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup +import androidx.annotation.MenuRes import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity -import androidx.core.content.ContextCompat import androidx.lifecycle.Observer import androidx.lifecycle.lifecycleScope import kotlinx.android.synthetic.main.fragment_history.view.* @@ -133,22 +131,15 @@ class HistoryFragment : LibraryPageFragment(), BackHandler { } override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - val mode = historyStore.state.mode - when (mode) { + @MenuRes + val menuRes = when (historyStore.state.mode) { HistoryFragmentState.Mode.Normal -> R.menu.library_menu is HistoryFragmentState.Mode.Editing -> R.menu.history_select_multi - else -> null - }?.let { inflater.inflate(it, menu) } - - if (mode is HistoryFragmentState.Mode.Editing) { - menu.findItem(R.id.share_history_multi_select)?.run { - isVisible = true - icon.colorFilter = PorterDuffColorFilter( - ContextCompat.getColor(context!!, R.color.white_color), - SRC_IN - ) - } + else -> return } + + inflater.inflate(menuRes, menu) + menu.findItem(R.id.share_history_multi_select)?.isVisible = true } override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) { diff --git a/app/src/main/res/menu/bookmarks_add_folder.xml b/app/src/main/res/menu/bookmarks_add_folder.xml index fed65cd91..99c439eff 100644 --- a/app/src/main/res/menu/bookmarks_add_folder.xml +++ b/app/src/main/res/menu/bookmarks_add_folder.xml @@ -3,13 +3,11 @@ - 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/. --> + xmlns:app="http://schemas.android.com/apk/res-auto"> + app:showAsAction="ifRoom" /> diff --git a/app/src/main/res/menu/bookmarks_edit.xml b/app/src/main/res/menu/bookmarks_edit.xml index cee53e663..5b78f158b 100644 --- a/app/src/main/res/menu/bookmarks_edit.xml +++ b/app/src/main/res/menu/bookmarks_edit.xml @@ -3,14 +3,12 @@ - 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/. --> + xmlns:app="http://schemas.android.com/apk/res-auto"> + app:showAsAction="ifRoom" /> diff --git a/app/src/main/res/menu/bookmarks_menu.xml b/app/src/main/res/menu/bookmarks_menu.xml index 443ad2fbd..20a914232 100644 --- a/app/src/main/res/menu/bookmarks_menu.xml +++ b/app/src/main/res/menu/bookmarks_menu.xml @@ -3,20 +3,17 @@ - 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/. --> + xmlns:app="http://schemas.android.com/apk/res-auto"> + app:showAsAction="ifRoom" /> + app:showAsAction="ifRoom" /> diff --git a/app/src/main/res/menu/bookmarks_select_folder.xml b/app/src/main/res/menu/bookmarks_select_folder.xml index 1faef2588..65795bc81 100644 --- a/app/src/main/res/menu/bookmarks_select_folder.xml +++ b/app/src/main/res/menu/bookmarks_select_folder.xml @@ -3,13 +3,11 @@ - 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/. --> + xmlns:app="http://schemas.android.com/apk/res-auto"> + app:showAsAction="ifRoom" /> diff --git a/app/src/main/res/menu/bookmarks_select_multi.xml b/app/src/main/res/menu/bookmarks_select_multi.xml index 75b975836..2901f2dd2 100644 --- a/app/src/main/res/menu/bookmarks_select_multi.xml +++ b/app/src/main/res/menu/bookmarks_select_multi.xml @@ -2,34 +2,24 @@ - + + app:showAsAction="ifRoom" /> + app:showAsAction="never" /> + app:showAsAction="never" /> + app:showAsAction="never" /> diff --git a/app/src/main/res/menu/bookmarks_select_multi_not_item.xml b/app/src/main/res/menu/bookmarks_select_multi_not_item.xml index 5da61f16d..c33d1ca58 100644 --- a/app/src/main/res/menu/bookmarks_select_multi_not_item.xml +++ b/app/src/main/res/menu/bookmarks_select_multi_not_item.xml @@ -2,13 +2,12 @@ - + + app:showAsAction="ifRoom" /> diff --git a/app/src/main/res/menu/history_select_multi.xml b/app/src/main/res/menu/history_select_multi.xml index 2ea6a90a0..a8234ac7a 100644 --- a/app/src/main/res/menu/history_select_multi.xml +++ b/app/src/main/res/menu/history_select_multi.xml @@ -3,34 +3,23 @@ - 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/. --> + xmlns:app="http://schemas.android.com/apk/res-auto"> + app:showAsAction="ifRoom" /> + app:showAsAction="never" /> + app:showAsAction="never" /> + app:showAsAction="never" /> diff --git a/app/src/main/res/menu/library_menu.xml b/app/src/main/res/menu/library_menu.xml index ec0b6816b..489921eec 100644 --- a/app/src/main/res/menu/library_menu.xml +++ b/app/src/main/res/menu/library_menu.xml @@ -3,13 +3,11 @@ - 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/. --> + xmlns:app="http://schemas.android.com/apk/res-auto"> + app:showAsAction="ifRoom" />