From 4168f278f283adeaa8cbc9ad1b796e03f8e0f826 Mon Sep 17 00:00:00 2001 From: Mugurell Date: Thu, 22 Aug 2019 17:26:34 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/4007 - Use camelCase for views referenced from code As per https://github.com/mozilla-mobile/fenix/issues/4341. Also reformatted layouts to have a more consistent style. Also refactored `AppShareRecyclerView` and `AccountDevicesShareRecyclerView` by defining their LayoutManager in XML to reduce code complexity. --- .../fenix/share/AccountDevicesShareView.kt | 17 +-- .../org/mozilla/fenix/share/AppShareView.kt | 17 +-- .../org/mozilla/fenix/share/ShareUIView.kt | 15 +- .../res/layout/account_share_list_item.xml | 37 ++--- .../main/res/layout/app_share_list_item.xml | 37 ++--- app/src/main/res/layout/component_share.xml | 142 +++++++++--------- app/src/main/res/layout/fragment_share.xml | 8 +- 7 files changed, 126 insertions(+), 147 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/share/AccountDevicesShareView.kt b/app/src/main/java/org/mozilla/fenix/share/AccountDevicesShareView.kt index a29deaa749..d7d37295e6 100644 --- a/app/src/main/java/org/mozilla/fenix/share/AccountDevicesShareView.kt +++ b/app/src/main/java/org/mozilla/fenix/share/AccountDevicesShareView.kt @@ -6,12 +6,10 @@ package org.mozilla.fenix.share import android.content.Context import android.graphics.PorterDuff.Mode.SRC_IN -import android.util.AttributeSet import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.core.content.ContextCompat -import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.reactivex.Observer import kotlinx.android.synthetic.main.account_share_list_item.view.* @@ -21,17 +19,6 @@ import mozilla.components.concept.sync.DeviceType import org.mozilla.fenix.R import org.mozilla.fenix.ext.components -class AccountDevicesShareRecyclerView @JvmOverloads constructor( - context: Context, - attrs: AttributeSet? = null, - defStyleAttr: Int = 0 -) : RecyclerView(context, attrs, defStyleAttr) { - - init { - layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) - } -} - class AccountDevicesShareAdapter( private val context: Context, val actionEmitter: Observer @@ -141,12 +128,12 @@ class AccountDeviceViewHolder( } } - itemView.device_icon.apply { + itemView.deviceIcon.apply { setImageResource(drawableRes) background.setColorFilter(ContextCompat.getColor(context, colorRes), SRC_IN) drawable.setTint(ContextCompat.getColor(context, R.color.device_foreground)) } - itemView.device_name.text = name + itemView.deviceName.text = name } companion object { diff --git a/app/src/main/java/org/mozilla/fenix/share/AppShareView.kt b/app/src/main/java/org/mozilla/fenix/share/AppShareView.kt index 53529fa0dd..d34ada1e97 100644 --- a/app/src/main/java/org/mozilla/fenix/share/AppShareView.kt +++ b/app/src/main/java/org/mozilla/fenix/share/AppShareView.kt @@ -9,11 +9,9 @@ import android.content.Intent import android.content.Intent.ACTION_SEND import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.graphics.drawable.Drawable -import android.util.AttributeSet import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import io.reactivex.Observer import kotlinx.android.synthetic.main.app_share_list_item.view.* @@ -24,17 +22,6 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.mozilla.fenix.R -class AppShareRecyclerView @JvmOverloads constructor( - context: Context, - attrs: AttributeSet? = null, - defStyleAttr: Int = 0 -) : RecyclerView(context, attrs, defStyleAttr) { - - init { - layoutManager = GridLayoutManager(context, 2, GridLayoutManager.HORIZONTAL, false) - } -} - class AppShareAdapter( private val context: Context, val actionEmitter: Observer, @@ -109,8 +96,8 @@ class AppShareItemViewHolder( internal fun bind(item: ShareItem) { shareItem = item - itemView.app_name.text = item.name - itemView.app_icon.setImageDrawable(item.icon) + itemView.appName.text = item.name + itemView.appIcon.setImageDrawable(item.icon) } companion object { diff --git a/app/src/main/java/org/mozilla/fenix/share/ShareUIView.kt b/app/src/main/java/org/mozilla/fenix/share/ShareUIView.kt index f0aa0b0cdb..30cf3a79fa 100644 --- a/app/src/main/java/org/mozilla/fenix/share/ShareUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/share/ShareUIView.kt @@ -32,23 +32,22 @@ class ShareUIView( val adapter = AppShareAdapter(view.context, actionEmitter).also { it.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { override fun onChanged() { - progress_bar.visibility = View.GONE - intent_handler_recyclerview.visibility = View.VISIBLE + progressBar.visibility = View.GONE + appsList.visibility = View.VISIBLE } }) } - intent_handler_recyclerview.adapter = adapter + appsList.adapter = adapter if (view.context.components.backgroundServices.accountManager.accountNeedsReauth()) { - send_tab_group.visibility = View.GONE - account_header.visibility = View.GONE + sendTabGroup.visibility = View.GONE + accountHeaderText.visibility = View.GONE } else { - account_devices_recyclerview.adapter = - AccountDevicesShareAdapter(view.context, actionEmitter) + devicesList.adapter = AccountDevicesShareAdapter(view.context, actionEmitter) } container.setOnClickListener { actionEmitter.onNext(ShareAction.Close) } - close_button.setOnClickListener { actionEmitter.onNext(ShareAction.Close) } + closeButton.setOnClickListener { actionEmitter.onNext(ShareAction.Close) } } override fun updateView() = Consumer { diff --git a/app/src/main/res/layout/account_share_list_item.xml b/app/src/main/res/layout/account_share_list_item.xml index b0924d8e9f..5dba582d41 100644 --- a/app/src/main/res/layout/account_share_list_item.xml +++ b/app/src/main/res/layout/account_share_list_item.xml @@ -2,44 +2,45 @@ + + android:layout_height="80dp" + android:background="?selectableItemBackgroundBorderless"> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:srcCompat="@tools:sample/avatars" /> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/deviceIcon" + tools:text="Firefox on Macbook Pro" /> - \ No newline at end of file + diff --git a/app/src/main/res/layout/app_share_list_item.xml b/app/src/main/res/layout/app_share_list_item.xml index de393c34bf..09d7c16972 100644 --- a/app/src/main/res/layout/app_share_list_item.xml +++ b/app/src/main/res/layout/app_share_list_item.xml @@ -2,41 +2,42 @@ + + android:layout_height="80dp" + android:background="?selectableItemBackgroundBorderless"> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:srcCompat="@tools:sample/avatars" /> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/appIcon" + tools:text="Copy to clipboard" /> - \ No newline at end of file + diff --git a/app/src/main/res/layout/component_share.xml b/app/src/main/res/layout/component_share.xml index 7b317a973d..b9b7448c48 100644 --- a/app/src/main/res/layout/component_share.xml +++ b/app/src/main/res/layout/component_share.xml @@ -2,6 +2,7 @@ + - - - - - - - - - + app:layout_constraintTop_toBottomOf="@id/link_header" /> + app:layout_constraintTop_toBottomOf="@id/divider_line" /> - + + + app:layout_constraintTop_toBottomOf="@id/devicesList" /> - + + + + + app:layout_constraintTop_toBottomOf="@id/link_header" + app:spanCount="2" /> + + diff --git a/app/src/main/res/layout/fragment_share.xml b/app/src/main/res/layout/fragment_share.xml index 0597fef787..aaf2e58d40 100644 --- a/app/src/main/res/layout/fragment_share.xml +++ b/app/src/main/res/layout/fragment_share.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/. --> - - - - \ No newline at end of file + tools:context="org.mozilla.fenix.share.ShareFragment" />