2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[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.
This commit is contained in:
Mugurell 2019-08-22 17:26:34 +03:00 committed by Jeff Boek
parent 09ca0c9e48
commit 4168f278f2
7 changed files with 126 additions and 147 deletions

View File

@ -6,12 +6,10 @@ package org.mozilla.fenix.share
import android.content.Context import android.content.Context
import android.graphics.PorterDuff.Mode.SRC_IN import android.graphics.PorterDuff.Mode.SRC_IN
import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.reactivex.Observer import io.reactivex.Observer
import kotlinx.android.synthetic.main.account_share_list_item.view.* 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.R
import org.mozilla.fenix.ext.components 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( class AccountDevicesShareAdapter(
private val context: Context, private val context: Context,
val actionEmitter: Observer<ShareAction> val actionEmitter: Observer<ShareAction>
@ -141,12 +128,12 @@ class AccountDeviceViewHolder(
} }
} }
itemView.device_icon.apply { itemView.deviceIcon.apply {
setImageResource(drawableRes) setImageResource(drawableRes)
background.setColorFilter(ContextCompat.getColor(context, colorRes), SRC_IN) background.setColorFilter(ContextCompat.getColor(context, colorRes), SRC_IN)
drawable.setTint(ContextCompat.getColor(context, R.color.device_foreground)) drawable.setTint(ContextCompat.getColor(context, R.color.device_foreground))
} }
itemView.device_name.text = name itemView.deviceName.text = name
} }
companion object { companion object {

View File

@ -9,11 +9,9 @@ import android.content.Intent
import android.content.Intent.ACTION_SEND import android.content.Intent.ACTION_SEND
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.reactivex.Observer import io.reactivex.Observer
import kotlinx.android.synthetic.main.app_share_list_item.view.* import kotlinx.android.synthetic.main.app_share_list_item.view.*
@ -24,17 +22,6 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.mozilla.fenix.R 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( class AppShareAdapter(
private val context: Context, private val context: Context,
val actionEmitter: Observer<ShareAction>, val actionEmitter: Observer<ShareAction>,
@ -109,8 +96,8 @@ class AppShareItemViewHolder(
internal fun bind(item: ShareItem) { internal fun bind(item: ShareItem) {
shareItem = item shareItem = item
itemView.app_name.text = item.name itemView.appName.text = item.name
itemView.app_icon.setImageDrawable(item.icon) itemView.appIcon.setImageDrawable(item.icon)
} }
companion object { companion object {

View File

@ -32,23 +32,22 @@ class ShareUIView(
val adapter = AppShareAdapter(view.context, actionEmitter).also { val adapter = AppShareAdapter(view.context, actionEmitter).also {
it.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { it.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onChanged() { override fun onChanged() {
progress_bar.visibility = View.GONE progressBar.visibility = View.GONE
intent_handler_recyclerview.visibility = View.VISIBLE appsList.visibility = View.VISIBLE
} }
}) })
} }
intent_handler_recyclerview.adapter = adapter appsList.adapter = adapter
if (view.context.components.backgroundServices.accountManager.accountNeedsReauth()) { if (view.context.components.backgroundServices.accountManager.accountNeedsReauth()) {
send_tab_group.visibility = View.GONE sendTabGroup.visibility = View.GONE
account_header.visibility = View.GONE accountHeaderText.visibility = View.GONE
} else { } else {
account_devices_recyclerview.adapter = devicesList.adapter = AccountDevicesShareAdapter(view.context, actionEmitter)
AccountDevicesShareAdapter(view.context, actionEmitter)
} }
container.setOnClickListener { actionEmitter.onNext(ShareAction.Close) } container.setOnClickListener { actionEmitter.onNext(ShareAction.Close) }
close_button.setOnClickListener { actionEmitter.onNext(ShareAction.Close) } closeButton.setOnClickListener { actionEmitter.onNext(ShareAction.Close) }
} }
override fun updateView() = Consumer<ShareState> { override fun updateView() = Consumer<ShareState> {

View File

@ -2,44 +2,45 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public <!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. --> - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:background="?selectableItemBackgroundBorderless"
android:layout_width="76dp" android:layout_width="76dp"
android:layout_height="80dp"> android:layout_height="80dp"
android:background="?selectableItemBackgroundBorderless">
<ImageButton <ImageButton
android:id="@+id/deviceIcon"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:id="@+id/device_icon"
android:importantForAccessibility="no"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:background="@drawable/device_background" android:background="@drawable/device_background"
android:clickable="false" android:clickable="false"
android:focusable="false" android:focusable="false"
app:layout_constraintTop_toTopOf="parent" android:importantForAccessibility="no"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toTopOf="@+id/deviceName"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/device_name" app:layout_constraintStart_toStartOf="parent"
tools:srcCompat="@tools:sample/avatars"/> app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
<TextView <TextView
android:id="@+id/deviceName"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/device_name"
android:textSize="10sp"
android:textAlignment="gravity"
android:gravity="center|top"
android:ellipsize="end"
android:lines="2"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
android:layout_marginBottom="5dp" android:layout_marginBottom="5dp"
android:ellipsize="end"
android:gravity="center|top"
android:lines="2"
android:textAlignment="gravity"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/device_icon" app:layout_constraintStart_toStartOf="parent"
tools:text="Firefox on Macbook Pro"/> app:layout_constraintTop_toBottomOf="@id/deviceIcon"
tools:text="Firefox on Macbook Pro" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -2,41 +2,42 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public <!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. --> - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:background="?selectableItemBackgroundBorderless"
android:layout_width="76dp" android:layout_width="76dp"
android:layout_height="80dp"> android:layout_height="80dp"
android:background="?selectableItemBackgroundBorderless">
<ImageView <ImageView
android:id="@+id/appIcon"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:id="@+id/app_icon"
android:importantForAccessibility="no"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent" android:importantForAccessibility="no"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toTopOf="@id/appName"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/app_name" app:layout_constraintStart_toStartOf="parent"
tools:srcCompat="@tools:sample/avatars"/> app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
<TextView <TextView
android:id="@+id/appName"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/app_name"
android:textSize="10sp"
android:textAlignment="gravity"
android:gravity="center|top"
android:ellipsize="end"
android:lines="2"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
android:layout_marginBottom="5dp" android:layout_marginBottom="5dp"
android:ellipsize="end"
android:gravity="center|top"
android:lines="2"
android:textAlignment="gravity"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/app_icon" app:layout_constraintStart_toStartOf="parent"
tools:text="Copy to clipboard"/> app:layout_constraintTop_toBottomOf="@id/appIcon"
tools:text="Copy to clipboard" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -2,6 +2,7 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public <!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. --> - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
@ -10,22 +11,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:clipToPadding="false"> android:clipToPadding="false">
<com.google.android.material.button.MaterialButton
android:id="@+id/close_button"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/share_header"
android:textAppearance="@style/HeaderTextStyle"
android:textColor="@color/neutral_text"
android:textSize="20sp"
app:icon="@drawable/mozac_ic_close"
app:iconPadding="8dp"
app:iconTint="@color/neutral_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -35,48 +20,16 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"> app:layout_constraintStart_toStartOf="parent">
<androidx.constraintlayout.widget.Group <ProgressBar
android:id="@+id/send_tab_group" android:id="@+id/progressBar"
android:layout_width="wrap_content" android:layout_width="76dp"
android:layout_height="wrap_content" android:layout_height="37dp"
app:constraint_referenced_ids="account_header,account_devices_recyclerview,divider_line" /> android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
<TextView app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/account_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:singleLine="true"
android:text="@string/share_device_subheader"
android:textAllCaps="true"
android:textColor="?secondaryText"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<org.mozilla.fenix.share.AccountDevicesShareRecyclerView
android:id="@+id/account_devices_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:clipToPadding="false"
android:paddingStart="16dp"
android:paddingEnd="8dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/account_header" /> app:layout_constraintTop_toBottomOf="@id/link_header" />
<View
android:id="@+id/divider_line"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:background="?neutralFaded"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/account_devices_recyclerview" />
<TextView <TextView
android:id="@+id/link_header" android:id="@+id/link_header"
@ -91,32 +44,85 @@
android:textSize="12sp" android:textSize="12sp"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider_line" /> app:layout_constraintTop_toBottomOf="@id/divider_line" />
<ProgressBar <TextView
android:id="@+id/progress_bar" android:id="@+id/accountHeaderText"
android:layout_width="76dp" android:layout_width="wrap_content"
android:layout_height="37dp" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginStart="16dp"
android:layout_marginBottom="16dp" android:layout_marginTop="12dp"
app:layout_constraintBottom_toBottomOf="parent" android:singleLine="true"
android:text="@string/share_device_subheader"
android:textAllCaps="true"
android:textColor="?secondaryText"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/divider_line"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:background="?neutralFaded"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/link_header" /> app:layout_constraintTop_toBottomOf="@id/devicesList" />
<org.mozilla.fenix.share.AppShareRecyclerView <androidx.constraintlayout.widget.Group
android:id="@+id/intent_handler_recyclerview" android:id="@+id/sendTabGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="accountHeaderText,devicesList,divider_line" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/devicesList"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:clipToPadding="false" android:clipToPadding="false"
android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingEnd="8dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/accountHeaderText" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/appsList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:clipToPadding="false"
android:orientation="horizontal"
android:paddingStart="16dp" android:paddingStart="16dp"
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:visibility="gone" android:visibility="gone"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/link_header" /> app:layout_constraintTop_toBottomOf="@id/link_header"
app:spanCount="2" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/closeButton"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/share_header"
android:textAppearance="@style/HeaderTextStyle"
android:textColor="@color/neutral_text"
android:textSize="20sp"
app:icon="@drawable/mozac_ic_close"
app:iconPadding="8dp"
app:iconTint="@color/neutral_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -3,14 +3,12 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - 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/. --> - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/shareWrapper" android:id="@+id/shareWrapper"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/scrim_background" android:background="@drawable/scrim_background"
android:fitsSystemWindows="true" android:fitsSystemWindows="true"
tools:context="org.mozilla.fenix.share.ShareFragment"> tools:context="org.mozilla.fenix.share.ShareFragment" />
</FrameLayout>