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>
This commit is contained in:
OpenSauce04 2024-06-08 19:49:22 +01:00
parent ab99fff953
commit 461c8c9574
17 changed files with 172 additions and 49 deletions

View file

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

View file

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

View file

@ -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
}
}

View file

@ -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()}" }
)

View file

@ -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)

View file

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

View file

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

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="?attr/colorControlNormal"
android:pathData="M3,9v6h4l5,5L12,4L7,9L3,9zM16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v8.05c1.48,-0.73 2.5,-2.25 2.5,-4.02zM14,3.23v2.06c2.89,0.86 5,3.54 5,6.71s-2.11,5.85 -5,6.71v2.06c4.01,-0.91 7,-4.49 7,-8.77s-2.99,-7.86 -7,-8.77z" />
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M480,700Q555,700 607.5,647.5Q660,595 660,520Q660,445 607.5,392.5Q555,340 480,340Q405,340 352.5,392.5Q300,445 300,520Q300,595 352.5,647.5Q405,700 480,700ZM480,620Q438,620 409,591Q380,562 380,520Q380,478 409,449Q438,420 480,420Q522,420 551,449Q580,478 580,520Q580,562 551,591Q522,620 480,620ZM160,840Q127,840 103.5,816.5Q80,793 80,760L80,280Q80,247 103.5,223.5Q127,200 160,200L286,200L360,120L600,120L674,200L800,200Q833,200 856.5,223.5Q880,247 880,280L880,760Q880,793 856.5,816.5Q833,840 800,840L160,840Z"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M160,720Q127,720 103.5,696.5Q80,673 80,640L80,320Q80,287 103.5,263.5Q127,240 160,240L800,240Q833,240 856.5,263.5Q880,287 880,320L880,640Q880,673 856.5,696.5Q833,720 800,720L160,720ZM160,640L800,640Q800,640 800,640Q800,640 800,640L800,320Q800,320 800,320Q800,320 800,320L160,320Q160,320 160,320Q160,320 160,320L160,640Q160,640 160,640Q160,640 160,640ZM280,600L360,600L360,520L440,520L440,440L360,440L360,360L280,360L280,440L200,440L200,520L280,520L280,600ZM580,600Q605,600 622.5,582.5Q640,565 640,540Q640,515 622.5,497.5Q605,480 580,480Q555,480 537.5,497.5Q520,515 520,540Q520,565 537.5,582.5Q555,600 580,600ZM700,480Q725,480 742.5,462.5Q760,445 760,420Q760,395 742.5,377.5Q725,360 700,360Q675,360 657.5,377.5Q640,395 640,420Q640,445 657.5,462.5Q675,480 700,480ZM160,640Q160,640 160,640Q160,640 160,640L160,320Q160,320 160,320Q160,320 160,320L160,320Q160,320 160,320Q160,320 160,320L160,640Q160,640 160,640Q160,640 160,640L160,640Z"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M370,880L354,752Q341,747 329.5,740Q318,733 307,725L188,775L78,585L181,507Q180,500 180,493.5Q180,487 180,480Q180,473 180,466.5Q180,460 181,453L78,375L188,185L307,235Q318,227 330,220Q342,213 354,208L370,80L590,80L606,208Q619,213 630.5,220Q642,227 653,235L772,185L882,375L779,453Q780,460 780,466.5Q780,473 780,480Q780,487 780,493.5Q780,500 778,507L881,585L771,775L653,725Q642,733 630,740Q618,747 606,752L590,880L370,880ZM482,620Q540,620 581,579Q622,538 622,480Q622,422 581,381Q540,340 482,340Q423,340 382.5,381Q342,422 342,480Q342,538 382.5,579Q423,620 482,620Z"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="?attr/colorControlNormal"
android:pathData="M160,840q-33,0 -56.5,-23.5T80,760v-560q0,-33 23.5,-56.5T160,120h560q33,0 56.5,23.5T800,200v80h80v80h-80v80h80v80h-80v80h80v80h-80v80q0,33 -23.5,56.5T720,840L160,840ZM160,760h560v-560L160,200v560ZM240,680h200v-160L240,520v160ZM480,400h160v-120L480,280v120ZM240,480h200v-200L240,280v200ZM480,680h160v-240L480,440v240ZM160,200v560,-560Z"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/colorControlNormal"
android:pathData="M13,3c-4.97,0 -9,4.03 -9,9L1,12l3.89,3.89 0.07,0.14L9,12L6,12c0,-3.87 3.13,-7 7,-7s7,3.13 7,7 -3.13,7 -7,7c-1.93,0 -3.68,-0.79 -4.94,-2.06l-1.42,1.42C8.27,19.99 10.51,21 13,21c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,8v5l4.28,2.54 0.72,-1.21 -3.5,-2.08L13.5,8L12,8z" />
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="?attr/colorControlNormal"
android:pathData="M320,960q-17,0 -28.5,-11.5T280,920q0,-17 11.5,-28.5T320,880q17,0 28.5,11.5T360,920q0,17 -11.5,28.5T320,960ZM480,960q-17,0 -28.5,-11.5T440,920q0,-17 11.5,-28.5T480,880q17,0 28.5,11.5T520,920q0,17 -11.5,28.5T480,960ZM640,960q-17,0 -28.5,-11.5T600,920q0,-17 11.5,-28.5T640,880q17,0 28.5,11.5T680,920q0,17 -11.5,28.5T640,960ZM320,800q-33,0 -56.5,-23.5T240,720v-640q0,-33 23.5,-56.5T320,0h320q33,0 56.5,23.5T720,80v640q0,33 -23.5,56.5T640,800L320,800ZM320,720h320v-40L320,680v40ZM320,600h320v-400L320,200v400ZM320,120h320v-40L320,80v40ZM320,120v-40,40ZM320,720v-40,40Z"/>
</vector>

View file

@ -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" />
<View

View file

@ -10,42 +10,59 @@
android:focusable="true"
android:gravity="center_vertical"
android:minHeight="72dp"
android:padding="@dimen/spacing_large">
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="horizontal">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_setting_name"
style="@style/TextAppearance.Material3.HeadlineMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="viewStart"
android:textSize="16sp"
app:lineHeight="22dp"
tools:text="Setting Name" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_setting_description"
style="@style/TextAppearance.Material3.BodySmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_small"
android:textAlignment="viewStart"
tools:text="@string/app_disclaimer" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_setting_value"
style="@style/TextAppearance.Material3.LabelMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_small"
android:textAlignment="viewStart"
android:textStyle="bold"
<ImageView
android:id="@+id/icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="24dp"
android:layout_gravity="center_vertical"
android:visibility="gone"
tools:text="1x" />
app:tint="?attr/colorOnSurface" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_setting_name"
style="@style/TextAppearance.Material3.HeadlineMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="viewStart"
android:textSize="17sp"
app:lineHeight="22dp"
tools:text="Setting Name" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_setting_description"
style="@style/TextAppearance.Material3.BodySmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_small"
android:textAlignment="viewStart"
tools:text="@string/app_disclaimer" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/text_setting_value"
style="@style/TextAppearance.Material3.LabelMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_small"
android:textAlignment="viewStart"
android:textStyle="bold"
android:textSize="13sp"
tools:text="1x" />
</LinearLayout>
</LinearLayout>

View file

@ -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">
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/switch_widget"
@ -24,7 +22,7 @@
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerVertical="true"
android:layout_marginEnd="@dimen/spacing_large"
android:layout_marginEnd="24dp"
android:layout_toStartOf="@+id/switch_widget"
android:gravity="center_vertical"
android:orientation="vertical">
@ -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" />