Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/src/main/java/app/opass/ccip/ui/LanguagePreferenceFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
Expand Down Expand Up @@ -82,6 +83,7 @@ class LanguagePreferenceFragment : DialogFragment() {
)
) { item ->
dialog?.dismiss()

AppCompatDelegate.setApplicationLocales(
(
if (item.languageTag == "x-default") {
Expand Down Expand Up @@ -126,12 +128,25 @@ class LanguagePreferenceAdapter(

override fun onBindViewHolder(holder: LanguagePreferenceViewHolder, position: Int) {
val item = items[position]
val isSelected = (
if (item.languageTag == "x-default") {
AppCompatDelegate.getApplicationLocales() == LocaleListCompat.getEmptyLocaleList()
} else {
AppCompatDelegate.getApplicationLocales() == LocaleListCompat.forLanguageTags(item.languageTag)
}
)

holder.localName.text = item.localName
holder.translatedName.text = item.translatedName

if (!isSelected) {
holder.selectedIcon.setImageDrawable(null)
}
}
}

class LanguagePreferenceViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val localName: TextView = view.findViewById(R.id.option_local_name)
val translatedName: TextView = view.findViewById(R.id.option_translated_name)
val selectedIcon: ImageView = view.findViewById(R.id.icon_selected)
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_done_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z" />
</vector>
46 changes: 32 additions & 14 deletions app/src/main/res/layout/item_option_language.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:focusable="true"
android:orientation="vertical"
android:orientation="horizontal"
android:paddingStart="32dp"
android:paddingTop="16dp"
android:paddingEnd="8dp"
android:paddingEnd="16dp"
android:paddingBottom="16dp">

<TextView
android:id="@+id/option_local_name"
style="@style/TextAppearance.MaterialComponents.Body1"
android:layout_width="wrap_content"
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/textColorPrimary"
tools:text="繁體中文" />
android:background="?attr/selectableItemBackground"
android:focusable="true"
android:orientation="vertical">
<TextView
android:id="@+id/option_local_name"
style="@style/TextAppearance.MaterialComponents.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/textColorPrimary"
tools:text="繁體中文" />

<TextView
android:id="@+id/option_translated_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
tools:text="Mandarin - Traditional Han script" />
<TextView
android:id="@+id/option_translated_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
tools:text="Mandarin - Traditional Han script" />
</LinearLayout>

<ImageView
android:id="@+id/icon_selected"
android:layout_width="35dip"
android:layout_height="fill_parent"
android:padding="5dp"
android:src="@drawable/ic_baseline_done_24"
app:tint="@color/colorWhite"
tools:tint="@color/colorAccent"/>
</LinearLayout>