From 461c8c95743ae2d875c23409b559dfc9c21a0816 Mon Sep 17 00:00:00 2001 From: OpenSauce04 Date: Sat, 8 Jun 2024 19:49:22 +0100 Subject: [PATCH] android: Rework settings UI (#226) Co-authored-by: Ishan09811 <156402647+ishan09811@users.noreply.github.com> Co-authored-by: kleidis <167202775+kleidis@users.noreply.github.com> --- .../settings/model/view/RunnableSetting.kt | 3 + .../settings/model/view/SubmenuSetting.kt | 8 +- .../features/settings/ui/SettingsFragment.kt | 22 +++--- .../settings/ui/SettingsFragmentPresenter.kt | 9 +++ .../ui/viewholder/RunnableViewHolder.kt | 14 ++++ .../ui/viewholder/SubmenuViewHolder.kt | 14 ++++ .../github/lime3ds/android/utils/ViewUtils.kt | 1 + .../app/src/main/res/drawable/ic_audio.xml | 9 +++ .../main/res/drawable/ic_camera_settings.xml | 9 +++ .../res/drawable/ic_controls_settings.xml | 9 +++ .../main/res/drawable/ic_general_settings.xml | 9 +++ .../app/src/main/res/drawable/ic_graphics.xml | 9 +++ .../app/src/main/res/drawable/ic_restore.xml | 9 +++ .../main/res/drawable/ic_system_settings.xml | 9 +++ .../src/main/res/layout/activity_settings.xml | 2 +- .../src/main/res/layout/list_item_setting.xml | 77 +++++++++++-------- .../res/layout/list_item_setting_switch.xml | 8 +- 17 files changed, 172 insertions(+), 49 deletions(-) create mode 100644 src/android/app/src/main/res/drawable/ic_audio.xml create mode 100644 src/android/app/src/main/res/drawable/ic_camera_settings.xml create mode 100644 src/android/app/src/main/res/drawable/ic_controls_settings.xml create mode 100644 src/android/app/src/main/res/drawable/ic_general_settings.xml create mode 100644 src/android/app/src/main/res/drawable/ic_graphics.xml create mode 100644 src/android/app/src/main/res/drawable/ic_restore.xml create mode 100644 src/android/app/src/main/res/drawable/ic_system_settings.xml diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/model/view/RunnableSetting.kt b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/model/view/RunnableSetting.kt index a91ea16f8..e799a325a 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/model/view/RunnableSetting.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/model/view/RunnableSetting.kt @@ -4,10 +4,13 @@ package io.github.lime3ds.android.features.settings.model.view +import androidx.annotation.DrawableRes + class RunnableSetting( titleId: Int, descriptionId: Int, val isRuntimeRunnable: Boolean, + @DrawableRes val iconId: Int = 0, val runnable: () -> Unit, val value: (() -> String)? = null ) : SettingsItem(null, titleId, descriptionId) { diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/model/view/SubmenuSetting.kt b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/model/view/SubmenuSetting.kt index 76a0e76c3..6534f6b8f 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/model/view/SubmenuSetting.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/model/view/SubmenuSetting.kt @@ -4,9 +4,13 @@ package io.github.lime3ds.android.features.settings.model.view +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes + class SubmenuSetting( - titleId: Int, - descriptionId: Int, + @StringRes titleId: Int, + @StringRes descriptionId: Int, + @DrawableRes val iconId: Int, val menuKey: String ) : SettingsItem(null, titleId, descriptionId) { override val type = TYPE_SUBMENU diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/SettingsFragment.kt b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/SettingsFragment.kt index 1c28a6dc6..f7458722e 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/SettingsFragment.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/SettingsFragment.kt @@ -14,11 +14,11 @@ import androidx.core.view.WindowInsetsCompat import androidx.core.view.updatePadding import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager -import com.google.android.material.divider.MaterialDividerItemDecoration import io.github.lime3ds.android.databinding.FragmentSettingsBinding import io.github.lime3ds.android.features.settings.model.AbstractSetting import io.github.lime3ds.android.features.settings.model.view.SettingsItem + class SettingsFragment : Fragment(), SettingsFragmentView { override var activityView: SettingsActivityView? = null @@ -51,15 +51,9 @@ class SettingsFragment : Fragment(), SettingsFragmentView { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { settingsAdapter = SettingsAdapter(this, requireActivity()) - val dividerDecoration = MaterialDividerItemDecoration( - requireContext(), - LinearLayoutManager.VERTICAL - ) - dividerDecoration.isLastItemDecorated = false binding.listSettings.apply { adapter = settingsAdapter layoutManager = LinearLayoutManager(activity) - addItemDecoration(dividerDecoration) } fragmentPresenter.onViewCreated(settingsAdapter!!) @@ -104,10 +98,16 @@ class SettingsFragment : Fragment(), SettingsFragmentView { private fun setInsets() { ViewCompat.setOnApplyWindowInsetsListener( - binding.listSettings - ) { view: View, windowInsets: WindowInsetsCompat -> - val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) - view.updatePadding(bottom = insets.bottom) + binding.root + ) { _: View, windowInsets: WindowInsetsCompat -> + val barInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) + val cutoutInsets = windowInsets.getInsets(WindowInsetsCompat.Type.displayCutout()) + + binding.listSettings.updatePadding( + left = barInsets.left + cutoutInsets.left, + right = barInsets.right + cutoutInsets.right, + bottom = barInsets.bottom + ) windowInsets } } diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/SettingsFragmentPresenter.kt b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/SettingsFragmentPresenter.kt index 8bf9dc43d..b35dc1ebb 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/SettingsFragmentPresenter.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/SettingsFragmentPresenter.kt @@ -109,6 +109,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) SubmenuSetting( R.string.preferences_general, 0, + R.drawable.ic_general_settings, Settings.SECTION_CORE ) ) @@ -116,6 +117,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) SubmenuSetting( R.string.preferences_system, 0, + R.drawable.ic_system_settings, Settings.SECTION_SYSTEM ) ) @@ -123,6 +125,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) SubmenuSetting( R.string.preferences_camera, 0, + R.drawable.ic_camera_settings, Settings.SECTION_CAMERA ) ) @@ -130,6 +133,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) SubmenuSetting( R.string.preferences_controls, 0, + R.drawable.ic_controls_settings, Settings.SECTION_CONTROLS ) ) @@ -137,6 +141,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) SubmenuSetting( R.string.preferences_graphics, 0, + R.drawable.ic_graphics, Settings.SECTION_RENDERER ) ) @@ -144,6 +149,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) SubmenuSetting( R.string.preferences_audio, 0, + R.drawable.ic_audio, Settings.SECTION_AUDIO ) ) @@ -151,6 +157,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) SubmenuSetting( R.string.preferences_debug, 0, + R.drawable.ic_code, Settings.SECTION_DEBUG ) ) @@ -159,6 +166,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) R.string.reset_to_default, 0, false, + R.drawable.ic_restore, { ResetSettingsDialogFragment().show( settingsActivity.supportFragmentManager, @@ -303,6 +311,7 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) R.string.console_id, 0, false, + 0, { settingsAdapter.onClickRegenerateConsoleId() }, { "0x${SystemSaveGame.getConsoleId().toHexString().uppercase()}" } ) diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/viewholder/RunnableViewHolder.kt b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/viewholder/RunnableViewHolder.kt index 617899d06..231de54f4 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/viewholder/RunnableViewHolder.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/viewholder/RunnableViewHolder.kt @@ -5,6 +5,7 @@ package io.github.lime3ds.android.features.settings.ui.viewholder import android.view.View +import androidx.core.content.res.ResourcesCompat import io.github.lime3ds.android.NativeLibrary import io.github.lime3ds.android.databinding.ListItemSettingBinding import io.github.lime3ds.android.features.settings.model.view.RunnableSetting @@ -18,6 +19,19 @@ class RunnableViewHolder(val binding: ListItemSettingBinding, adapter: SettingsA override fun bind(item: SettingsItem) { setting = item as RunnableSetting + if (item.iconId == 0) { + binding.icon.visibility = View.GONE + } else { + binding.icon.visibility = View.VISIBLE + binding.icon.setImageDrawable( + ResourcesCompat.getDrawable( + binding.icon.resources, + item.iconId, + binding.icon.context.theme + ) + ) + } + binding.textSettingName.setText(item.nameId) if (item.descriptionId != 0) { binding.textSettingDescription.setText(item.descriptionId) diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/viewholder/SubmenuViewHolder.kt b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/viewholder/SubmenuViewHolder.kt index f8373091f..e33eff22d 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/viewholder/SubmenuViewHolder.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/features/settings/ui/viewholder/SubmenuViewHolder.kt @@ -5,6 +5,7 @@ package io.github.lime3ds.android.features.settings.ui.viewholder import android.view.View +import androidx.core.content.res.ResourcesCompat import io.github.lime3ds.android.databinding.ListItemSettingBinding import io.github.lime3ds.android.features.settings.model.view.SettingsItem import io.github.lime3ds.android.features.settings.model.view.SubmenuSetting @@ -16,6 +17,18 @@ class SubmenuViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAd override fun bind(item: SettingsItem) { this.item = item as SubmenuSetting + if (item.iconId == 0) { + binding.icon.visibility = View.GONE + } else { + binding.icon.visibility = View.VISIBLE + binding.icon.setImageDrawable( + ResourcesCompat.getDrawable( + binding.icon.resources, + item.iconId, + binding.icon.context.theme + ) + ) + } binding.textSettingName.setText(item.nameId) if (item.descriptionId != 0) { binding.textSettingDescription.setText(item.descriptionId) @@ -23,6 +36,7 @@ class SubmenuViewHolder(val binding: ListItemSettingBinding, adapter: SettingsAd } else { binding.textSettingDescription.visibility = View.GONE } + binding.textSettingValue.visibility = View.GONE } override fun onClick(clicked: View) { diff --git a/src/android/app/src/main/java/io/github/lime3ds/android/utils/ViewUtils.kt b/src/android/app/src/main/java/io/github/lime3ds/android/utils/ViewUtils.kt index 172591da9..658db2b14 100644 --- a/src/android/app/src/main/java/io/github/lime3ds/android/utils/ViewUtils.kt +++ b/src/android/app/src/main/java/io/github/lime3ds/android/utils/ViewUtils.kt @@ -5,6 +5,7 @@ package io.github.lime3ds.android.utils import android.view.View +import android.view.ViewGroup object ViewUtils { fun showView(view: View, length: Long = 300) { diff --git a/src/android/app/src/main/res/drawable/ic_audio.xml b/src/android/app/src/main/res/drawable/ic_audio.xml new file mode 100644 index 000000000..e306c3b0c --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_audio.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/android/app/src/main/res/drawable/ic_camera_settings.xml b/src/android/app/src/main/res/drawable/ic_camera_settings.xml new file mode 100644 index 000000000..dcf48ac0f --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_camera_settings.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/src/android/app/src/main/res/drawable/ic_controls_settings.xml b/src/android/app/src/main/res/drawable/ic_controls_settings.xml new file mode 100644 index 000000000..39dcfc81e --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_controls_settings.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/android/app/src/main/res/drawable/ic_general_settings.xml b/src/android/app/src/main/res/drawable/ic_general_settings.xml new file mode 100644 index 000000000..0b0cc8700 --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_general_settings.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/android/app/src/main/res/drawable/ic_graphics.xml b/src/android/app/src/main/res/drawable/ic_graphics.xml new file mode 100644 index 000000000..2fdb5a4d6 --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_graphics.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/android/app/src/main/res/drawable/ic_restore.xml b/src/android/app/src/main/res/drawable/ic_restore.xml new file mode 100644 index 000000000..d6d9d4017 --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_restore.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/android/app/src/main/res/drawable/ic_system_settings.xml b/src/android/app/src/main/res/drawable/ic_system_settings.xml new file mode 100644 index 000000000..7701a2bab --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_system_settings.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/android/app/src/main/res/layout/activity_settings.xml b/src/android/app/src/main/res/layout/activity_settings.xml index 14ae83b04..510c6129c 100644 --- a/src/android/app/src/main/res/layout/activity_settings.xml +++ b/src/android/app/src/main/res/layout/activity_settings.xml @@ -35,7 +35,7 @@ android:id="@+id/frame_content" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginHorizontal="12dp" + android:layout_marginHorizontal="0dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + android:padding="16dp"> + android:orientation="horizontal"> - - - - - + app:tint="?attr/colorOnSurface" /> + + + + + + + + + + diff --git a/src/android/app/src/main/res/layout/list_item_setting_switch.xml b/src/android/app/src/main/res/layout/list_item_setting_switch.xml index cbace0e7f..dc1e82258 100644 --- a/src/android/app/src/main/res/layout/list_item_setting_switch.xml +++ b/src/android/app/src/main/res/layout/list_item_setting_switch.xml @@ -8,9 +8,7 @@ android:clickable="true" android:focusable="true" android:minHeight="72dp" - android:paddingVertical="@dimen/spacing_large" - android:paddingStart="@dimen/spacing_large" - android:paddingEnd="24dp"> + android:padding="16dp"> @@ -35,7 +33,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAlignment="viewStart" - android:textSize="16sp" + android:textSize="17sp" app:lineHeight="22dp" tools:text="@string/frame_limit_enable" />