From 9901514766b1b5d7919ea980150b0f75f60e3910 Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Mon, 8 Jul 2019 15:45:07 -0400 Subject: [PATCH] Replace deprecated pxToDp (#3932) --- .../org/mozilla/fenix/components/toolbar/ToolbarUIView.kt | 7 ++++--- app/src/main/java/org/mozilla/fenix/ext/View.kt | 6 +++--- .../viewholders/TabInCollectionViewHolder.kt | 8 ++++---- .../home/sessioncontrol/viewholders/TabViewHolder.kt | 4 ++-- .../bookmarks/selectfolder/SelectBookmarkFolderAdapter.kt | 6 +++--- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarUIView.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarUIView.kt index 22b3553129..bddefc3988 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarUIView.kt @@ -14,7 +14,8 @@ import io.reactivex.Observer import io.reactivex.functions.Consumer import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider import mozilla.components.browser.toolbar.BrowserToolbar -import mozilla.components.support.ktx.android.content.res.pxToDp +import mozilla.components.support.ktx.android.util.dpToFloat +import mozilla.components.support.ktx.android.util.dpToPx import org.jetbrains.anko.backgroundDrawable import org.mozilla.fenix.R import org.mozilla.fenix.customtabs.CustomTabToolbarMenu @@ -53,7 +54,7 @@ class ToolbarUIView( editMode() } - elevation = resources.pxToDp(TOOLBAR_ELEVATION).toFloat() + elevation = TOOLBAR_ELEVATION.dpToFloat(resources.displayMetrics) setOnUrlCommitListener { actionEmitter.onNext(SearchAction.UrlCommitted(it, sessionId, state?.engine)) @@ -64,7 +65,7 @@ class ToolbarUIView( false } - browserActionMargin = resources.pxToDp(browserActionMarginDp) + browserActionMargin = browserActionMarginDp.dpToPx(resources.displayMetrics) val isCustomTabSession = (session?.isCustomTabSession() == true) diff --git a/app/src/main/java/org/mozilla/fenix/ext/View.kt b/app/src/main/java/org/mozilla/fenix/ext/View.kt index f944e8e8bf..fa8ed61780 100644 --- a/app/src/main/java/org/mozilla/fenix/ext/View.kt +++ b/app/src/main/java/org/mozilla/fenix/ext/View.kt @@ -7,10 +7,10 @@ package org.mozilla.fenix.ext import android.graphics.Rect import android.view.TouchDelegate import android.view.View -import mozilla.components.support.ktx.android.content.res.pxToDp +import mozilla.components.support.ktx.android.util.dpToPx -fun View?.increaseTapArea(extraDps: Int) { - val dips = this!!.resources.pxToDp(extraDps) +fun View.increaseTapArea(extraDps: Int) { + val dips = extraDps.dpToPx(resources.displayMetrics) val parent = this.parent as View parent.post { val touchRect = Rect() diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabInCollectionViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabInCollectionViewHolder.kt index 97e672ba6a..9dc9fc8ace 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabInCollectionViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabInCollectionViewHolder.kt @@ -17,7 +17,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.launch import mozilla.components.browser.icons.IconRequest -import mozilla.components.support.ktx.android.content.res.pxToDp +import mozilla.components.support.ktx.android.util.dpToFloat import org.jetbrains.anko.backgroundColor import org.mozilla.fenix.R import org.mozilla.fenix.ext.components @@ -50,13 +50,13 @@ class TabInCollectionViewHolder( init { collection_tab_icon.clipToOutline = true collection_tab_icon.outlineProvider = object : ViewOutlineProvider() { - override fun getOutline(view: View?, outline: Outline?) { + override fun getOutline(view: View, outline: Outline?) { outline?.setRoundRect( 0, 0, - view!!.width, + view.width, view.height, - view.context.resources.pxToDp(TabViewHolder.favIconBorderRadiusInPx).toFloat() + TabViewHolder.favIconBorderRadiusInPx.dpToFloat(view.context.resources.displayMetrics) ) } } diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabViewHolder.kt index f2358f566e..e2624a07bf 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabViewHolder.kt @@ -19,7 +19,7 @@ import kotlinx.coroutines.launch import mozilla.components.browser.icons.IconRequest import mozilla.components.browser.menu.BrowserMenuBuilder import mozilla.components.browser.menu.item.SimpleBrowserMenuItem -import mozilla.components.support.ktx.android.content.res.pxToDp +import mozilla.components.support.ktx.android.util.dpToFloat import org.mozilla.fenix.R import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.increaseTapArea @@ -76,7 +76,7 @@ class TabViewHolder( 0, view!!.width, view.height, - view.context.resources.pxToDp(favIconBorderRadiusInPx).toFloat() + favIconBorderRadiusInPx.dpToFloat(view.context.resources.displayMetrics) ) } } diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/selectfolder/SelectBookmarkFolderAdapter.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/selectfolder/SelectBookmarkFolderAdapter.kt index d6dcde0966..d20cbc7cdd 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/selectfolder/SelectBookmarkFolderAdapter.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/selectfolder/SelectBookmarkFolderAdapter.kt @@ -14,7 +14,7 @@ import kotlinx.android.extensions.LayoutContainer import kotlinx.android.synthetic.main.bookmark_row.* import mozilla.components.concept.storage.BookmarkNode import mozilla.components.concept.storage.BookmarkNodeType -import mozilla.components.support.ktx.android.content.res.pxToDp +import mozilla.components.support.ktx.android.util.dpToPx import org.mozilla.fenix.R import org.mozilla.fenix.ext.getColorIntFromAttr import org.mozilla.fenix.library.bookmarks.BookmarksSharedViewModel @@ -110,8 +110,8 @@ class SelectBookmarkFolderAdapter(private val sharedViewModel: BookmarksSharedVi bookmark_layout.setOnClickListener { selectionInterface.itemSelected(folder.node) } - val padding = - containerView.resources.pxToDp(dpsToIndent) * (if (folder.depth > maxDepth) maxDepth else folder.depth) + val pxToIndent = dpsToIndent.dpToPx(containerView.resources.displayMetrics) + val padding = pxToIndent * if (folder.depth > maxDepth) maxDepth else folder.depth bookmark_layout.setPadding(padding, 0, 0, 0) }