commit 07bec28ac833affeebc7b84fae21ea5f1042821b
parent a049e80ec2ff19177932038796595fd097dc6ad8
Author: rmalicdem <rmalicdem@mozilla.com>
Date: Thu, 20 Nov 2025 02:47:19 +0000
Bug 1998722 - Add shortcut icon to toolbar customization shortcut preview r=android-reviewers,Roger
Differential Revision: https://phabricator.services.mozilla.com/D273088
Diffstat:
6 files changed, 107 insertions(+), 14 deletions(-)
diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ToolbarExpandedShortcutPreference.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ToolbarExpandedShortcutPreference.kt
@@ -6,6 +6,10 @@ package org.mozilla.fenix.settings
import android.content.Context
import android.util.AttributeSet
+import android.view.View.GONE
+import android.view.View.VISIBLE
+import android.widget.ImageView
+import androidx.preference.PreferenceViewHolder
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.settings
@@ -22,5 +26,13 @@ internal class ToolbarExpandedShortcutPreference @JvmOverloads constructor(
context.settings().toolbarExpandedShortcutKey = key
}
- override fun toolbarShortcutPreview(): Int = R.drawable.ic_toolbar_expanded_shortcut_preview
+ override fun getSelectedIconImageView(holder: PreferenceViewHolder): ImageView {
+ val simplePreview = holder.findViewById(R.id.toolbar_simple_shortcut_preview)
+ val expandedPreview = holder.findViewById(R.id.toolbar_expanded_shortcut_preview)
+
+ simplePreview.visibility = GONE
+ expandedPreview.visibility = VISIBLE
+
+ return expandedPreview.findViewById(R.id.selected_expanded_shortcut_icon)
+ }
}
diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ToolbarShortcutPreference.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ToolbarShortcutPreference.kt
@@ -49,12 +49,12 @@ internal abstract class ToolbarShortcutPreference @JvmOverloads constructor(
protected abstract val options: List<ShortcutOption>
protected abstract fun readSelectedKey(): String
protected abstract fun writeSelectedKey(key: String)
- protected abstract fun toolbarShortcutPreview(): Int
+ protected abstract fun getSelectedIconImageView(holder: PreferenceViewHolder): ImageView
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
- val preview = holder.findViewById(R.id.toolbar_preview) as ImageView
+ val selectedIcon = getSelectedIconImageView(holder)
val selectedContainer = holder.findViewById(R.id.selected_container) as LinearLayout
val optionsContainer = holder.findViewById(R.id.options_container) as LinearLayout
val separator = holder.findViewById(R.id.separator) as View
@@ -63,12 +63,11 @@ internal abstract class ToolbarShortcutPreference @JvmOverloads constructor(
colorOnSurface = holder.itemView.getMaterialColor(materialR.attr.colorOnSurface)
colorOnSurfaceVariant = holder.itemView.getMaterialColor(materialR.attr.colorOnSurfaceVariant)
- preview.setImageResource(toolbarShortcutPreview())
-
val selectedKey = readSelectedKey()
val selected = options.firstOrNull {
it.key == ShortcutType.fromValue(selectedKey)
} ?: options.first()
+ selectedIcon.setImageResource(selected.icon)
selectedContainer.removeAllViews()
selectedContainer.addView(
makeRow(
@@ -91,6 +90,7 @@ internal abstract class ToolbarShortcutPreference @JvmOverloads constructor(
isEnabled = true,
) { newlySelected ->
writeSelectedKey(newlySelected.key.value)
+ selectedIcon.setImageResource(newlySelected.icon)
notifyChanged()
},
)
diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ToolbarSimpleShortcutPreference.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ToolbarSimpleShortcutPreference.kt
@@ -6,6 +6,10 @@ package org.mozilla.fenix.settings
import android.content.Context
import android.util.AttributeSet
+import android.view.View.GONE
+import android.view.View.VISIBLE
+import android.widget.ImageView
+import androidx.preference.PreferenceViewHolder
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.settings
@@ -22,5 +26,13 @@ internal class ToolbarSimpleShortcutPreference @JvmOverloads constructor(
context.settings().toolbarSimpleShortcutKey = key
}
- override fun toolbarShortcutPreview(): Int = R.drawable.ic_toolbar_simple_shortcut_preview
+ override fun getSelectedIconImageView(holder: PreferenceViewHolder): ImageView {
+ val simplePreview = holder.findViewById(R.id.toolbar_simple_shortcut_preview)
+ val expandedPreview = holder.findViewById(R.id.toolbar_expanded_shortcut_preview)
+
+ simplePreview.visibility = VISIBLE
+ expandedPreview.visibility = GONE
+
+ return simplePreview.findViewById(R.id.selected_simple_shortcut_icon)
+ }
}
diff --git a/mobile/android/fenix/app/src/main/res/layout/preference_toolbar_shortcut.xml b/mobile/android/fenix/app/src/main/res/layout/preference_toolbar_shortcut.xml
@@ -4,7 +4,6 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
@@ -20,13 +19,15 @@
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
android:text="@string/preferences_toolbar_select_shortcut" />
- <ImageView
- android:id="@+id/toolbar_preview"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="@dimen/top_bar_alignment_margin_start"
- android:layout_marginTop="16dp"
- android:contentDescription="@null" />
+ <include
+ android:id="@+id/toolbar_simple_shortcut_preview"
+ layout="@layout/toolbar_simple_shortcut_preview"
+ android:visibility="gone" />
+
+ <include
+ android:id="@+id/toolbar_expanded_shortcut_preview"
+ layout="@layout/toolbar_expanded_shortcut_preview"
+ android:visibility="gone" />
<LinearLayout
android:id="@+id/selected_container"
diff --git a/mobile/android/fenix/app/src/main/res/layout/toolbar_expanded_shortcut_preview.xml b/mobile/android/fenix/app/src/main/res/layout/toolbar_expanded_shortcut_preview.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/top_bar_alignment_margin_start"
+ android:layout_marginTop="16dp" >
+
+ <ImageView
+ android:id="@+id/toolbar_expanded_preview"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:contentDescription="@null"
+ app:srcCompat="@drawable/ic_toolbar_expanded_shortcut_preview"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+
+ <ImageView
+ android:id="@+id/selected_expanded_shortcut_icon"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:contentDescription="@null"
+ app:tint="@color/fx_mobile_icon_color_accent_violet"
+ app:layout_constraintStart_toStartOf="@id/toolbar_expanded_preview"
+ app:layout_constraintEnd_toEndOf="@id/toolbar_expanded_preview"
+ app:layout_constraintTop_toTopOf="@id/toolbar_expanded_preview"
+ app:layout_constraintBottom_toBottomOf="@id/toolbar_expanded_preview"
+ app:layout_constraintHorizontal_bias="0.103"
+ app:layout_constraintVertical_bias="0.5" />
+</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/mobile/android/fenix/app/src/main/res/layout/toolbar_simple_shortcut_preview.xml b/mobile/android/fenix/app/src/main/res/layout/toolbar_simple_shortcut_preview.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/top_bar_alignment_margin_start"
+ android:layout_marginTop="16dp" >
+
+ <ImageView
+ android:id="@+id/toolbar_simple_preview"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:contentDescription="@null"
+ app:srcCompat="@drawable/ic_toolbar_simple_shortcut_preview"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+
+ <ImageView
+ android:id="@+id/selected_simple_shortcut_icon"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:contentDescription="@null"
+ app:tint="@color/fx_mobile_icon_color_accent_violet"
+ app:layout_constraintStart_toStartOf="@id/toolbar_simple_preview"
+ app:layout_constraintEnd_toEndOf="@id/toolbar_simple_preview"
+ app:layout_constraintTop_toTopOf="@id/toolbar_simple_preview"
+ app:layout_constraintBottom_toBottomOf="@id/toolbar_simple_preview"
+ app:layout_constraintHorizontal_bias="0.67"
+ app:layout_constraintVertical_bias="0.5" />
+</androidx.constraintlayout.widget.ConstraintLayout>