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.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<ShareAction>
@ -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 {

View File

@ -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<ShareAction>,
@ -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 {

View File

@ -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<ShareState> {

View File

@ -2,44 +2,45 @@
<!-- 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
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="?selectableItemBackgroundBorderless"
android:layout_width="76dp"
android:layout_height="80dp">
android:layout_height="80dp"
android:background="?selectableItemBackgroundBorderless">
<ImageButton
android:id="@+id/deviceIcon"
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/device_icon"
android:importantForAccessibility="no"
android:layout_marginTop="8dp"
android:background="@drawable/device_background"
android:clickable="false"
android:focusable="false"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:importantForAccessibility="no"
app:layout_constraintBottom_toTopOf="@+id/deviceName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/device_name"
tools:srcCompat="@tools:sample/avatars"/>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
<TextView
android:id="@+id/deviceName"
android:layout_width="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_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_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/device_icon"
tools:text="Firefox on Macbook Pro"/>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/deviceIcon"
tools:text="Firefox on Macbook Pro" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -2,41 +2,42 @@
<!-- 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
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="?selectableItemBackgroundBorderless"
android:layout_width="76dp"
android:layout_height="80dp">
android:layout_height="80dp"
android:background="?selectableItemBackgroundBorderless">
<ImageView
android:id="@+id/appIcon"
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/app_icon"
android:importantForAccessibility="no"
android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:importantForAccessibility="no"
app:layout_constraintBottom_toTopOf="@id/appName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/app_name"
tools:srcCompat="@tools:sample/avatars"/>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
<TextView
android:id="@+id/appName"
android:layout_width="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_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_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/app_icon"
tools:text="Copy to clipboard"/>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/appIcon"
tools:text="Copy to clipboard" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -2,6 +2,7 @@
<!-- 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
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
@ -10,22 +11,6 @@
android:layout_height="match_parent"
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
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -35,48 +20,16 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.constraintlayout.widget.Group
android:id="@+id/send_tab_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:constraint_referenced_ids="account_header,account_devices_recyclerview,divider_line" />
<TextView
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"
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="76dp"
android:layout_height="37dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/account_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" />
app:layout_constraintTop_toBottomOf="@id/link_header" />
<TextView
android:id="@+id/link_header"
@ -91,32 +44,85 @@
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider_line" />
app:layout_constraintTop_toBottomOf="@id/divider_line" />
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="76dp"
android:layout_height="37dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
<TextView
android:id="@+id/accountHeaderText"
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" />
<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/link_header" />
app:layout_constraintTop_toBottomOf="@id/devicesList" />
<org.mozilla.fenix.share.AppShareRecyclerView
android:id="@+id/intent_handler_recyclerview"
<androidx.constraintlayout.widget.Group
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_height="wrap_content"
android:layout_marginBottom="8dp"
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:paddingEnd="8dp"
android:visibility="gone"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:layout_constraintBottom_toBottomOf="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>
<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>

View File

@ -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/. -->
<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"
android:id="@+id/shareWrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/scrim_background"
android:fitsSystemWindows="true"
tools:context="org.mozilla.fenix.share.ShareFragment">
</FrameLayout>
tools:context="org.mozilla.fenix.share.ShareFragment" />