Skip to content

Commit

Permalink
Add descriptions to language setting items
Browse files Browse the repository at this point in the history
  • Loading branch information
Linfye committed Sep 8, 2024
1 parent a9279ad commit 26d73c1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ class LanguageSettingsFragment : Fragment() {
SwitchItem(
isChecked = sharedPref.getBoolean("period_on_double_tap_$language", false),
title = "Double space periods",
description = "Automatically insert a period when the space key is pressed twice.",
action = { enablePeriodOnSpaceBarDoubleTap(language) },
action2 = { disablePeriodOnSpaceBarDoubleTap(language) },
),
SwitchItem(
isChecked = sharedPref.getBoolean("autosuggest_emojis_$language", true),
title = "Autosuggest emojis",
description = "Turn on emoji suggestions and completions for more expressive typing.",
action = { enableEmojiAutosuggestions(language) },
action2 = { disableEmojiAutosuggestions(language) },
),
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/be/scri/helpers/CustomAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ class CustomAdapter(
holder.switchView.isChecked = item.isChecked
holder.switchView.setOnCheckedChangeListener(null)
holder.textView.text = item.title
if (item.description.isNullOrEmpty()) {
holder.descriptionTextView.visibility = View.GONE
} else {
holder.descriptionTextView.visibility = View.VISIBLE
holder.descriptionTextView.text = item.description
}
holder.switchView.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
item.isChecked = isChecked
Expand Down Expand Up @@ -164,6 +170,7 @@ class CustomAdapter(
) : RecyclerView.ViewHolder(itemView) {
val switchView: Switch = itemView.findViewById(R.id.checkbox)
val textView: TextView = itemView.findViewById(R.id.tvText)
val descriptionTextView: TextView = itemView.findViewById(R.id.tvSubTitle)
}

class TextViewHolder(
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/be/scri/models/SwitchItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ sealed class Item

data class SwitchItem(
val title: String,
val description: String? = null,
var isChecked: Boolean,
val action: (() -> Unit)? = null,
val action2: (() -> Unit)? = null,
Expand Down
53 changes: 37 additions & 16 deletions app/src/main/res/layout/card_view_with_switch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cvItem"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:cardCornerRadius="5dp"
Expand All @@ -13,26 +13,47 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="12dp">
android:orientation="vertical"
android:paddingTop="12dp"
android:paddingBottom="6dp"
android:paddingLeft="12dp"
android:paddingRight="12dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/tvText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:autoSizeMaxTextSize="24sp"
android:autoSizeMinTextSize="15sp"
android:autoSizeStepGranularity="2sp"
android:autoSizeTextType="uniform"
android:text="Title"
android:textStyle="normal" />

<Switch
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end" />
</LinearLayout>

<TextView
android:id="@+id/tvText"
android:layout_width="0dp"
android:id="@+id/tvSubTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Get the code on GitHub"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="15sp"
android:autoSizeMaxTextSize="24sp"
android:autoSizeMaxTextSize="16sp"
android:autoSizeMinTextSize="11sp"
android:autoSizeStepGranularity="2sp"
android:autoSizeTextType="uniform"
android:text="Subtitle"
android:textColor="@android:color/darker_gray"
android:textStyle="normal" />

<Switch
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0" />

</LinearLayout>
</androidx.cardview.widget.CardView>

0 comments on commit 26d73c1

Please sign in to comment.