add system option for language selection

This commit is contained in:
deniscerri 2025-06-15 12:36:13 +02:00
parent dac4909554
commit 82365bc920
No known key found for this signature in database
GPG key ID: 95C43D517D830350
3 changed files with 16 additions and 10 deletions

View file

@ -7,6 +7,7 @@ import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.res.Resources
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.PowerManager import android.os.PowerManager
@ -68,12 +69,15 @@ class GeneralSettingsFragment : BaseSettingsFragment() {
} }
findPreference<ListPreference>("app_language")?.apply { findPreference<ListPreference>("app_language")?.apply {
if (value.isNullOrBlank()) { value = Locale.getDefault().language
value = Locale.getDefault().language
}
summary = Locale.getDefault().displayLanguage summary = Locale.getDefault().displayLanguage
setOnPreferenceChangeListener { _, newValue -> setOnPreferenceChangeListener { _, newValue ->
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags(newValue.toString())) if (newValue == "system") {
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags(null))
}else{
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags(newValue.toString()))
}
summary = Locale.getDefault().displayLanguage summary = Locale.getDefault().displayLanguage
true true
} }

View file

@ -280,9 +280,12 @@ class DownloadWorker(
} }
}catch (e: Exception){ }catch (e: Exception){
e.printStackTrace() e.printStackTrace()
handler.postDelayed({ if (e.message?.isNotBlank() == true) {
Toast.makeText(context, e.message, Toast.LENGTH_SHORT).show() handler.postDelayed({
}, 1000) Toast.makeText(context, e.message, Toast.LENGTH_SHORT).show()
}, 1000)
}
} }
} }
@ -387,9 +390,6 @@ class DownloadWorker(
} }
tempFileDir.delete() tempFileDir.delete()
handler.postDelayed({
Toast.makeText(context, it.message, Toast.LENGTH_LONG).show()
}, 1000)
Log.e(TAG, context.getString(R.string.failed_download), it) Log.e(TAG, context.getString(R.string.failed_download), it)
notificationUtil.cancelDownloadNotification(downloadItem.id.toInt()) notificationUtil.cancelDownloadNotification(downloadItem.id.toInt())

View file

@ -127,6 +127,7 @@
<string-array name="language_entries"> <string-array name="language_entries">
<item>System</item>
<item>English</item> <item>English</item>
<item>العربية</item> <item>العربية</item>
<item>Azərbaycanca</item> <item>Azərbaycanca</item>
@ -171,6 +172,7 @@
</string-array> </string-array>
<string-array name="language_values"> <string-array name="language_values">
<item>system</item>
<item>en</item> <item>en</item>
<item>ar</item> <item>ar</item>
<item>az</item> <item>az</item>