mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-18 23:17:28 +01:00
Use some more KTX and Compat stuff (#3933)
* Use more KTX extensions * Update Android Studio * Use more Compat classes
This commit is contained in:
@@ -64,7 +64,7 @@ fun Context.toast(text: String?, duration: Int = Toast.LENGTH_SHORT) {
|
||||
fun Context.copyToClipboard(label: String, content: String) {
|
||||
if (content.isBlank()) return
|
||||
|
||||
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clipboard = getSystemService<ClipboardManager>()!!
|
||||
clipboard.setPrimaryClip(ClipData.newPlainText(label, content))
|
||||
|
||||
toast(getString(R.string.copied_to_clipboard, content.truncateCenter(50)))
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.os.Build
|
||||
import android.view.ContextThemeWrapper
|
||||
import androidx.core.os.ConfigurationCompat
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.browse.source.SourcePresenter
|
||||
@@ -110,10 +111,10 @@ object LocaleHelper {
|
||||
*/
|
||||
fun updateConfiguration(app: Application, config: Configuration, configChange: Boolean = false) {
|
||||
if (systemLocale == null) {
|
||||
systemLocale = getConfigLocale(config)
|
||||
systemLocale = ConfigurationCompat.getLocales(config)[0]
|
||||
}
|
||||
if (configChange) {
|
||||
val configLocale = getConfigLocale(config)
|
||||
val configLocale = ConfigurationCompat.getLocales(config)[0]
|
||||
if (currentLocale == configLocale) {
|
||||
return
|
||||
}
|
||||
@@ -127,17 +128,6 @@ object LocaleHelper {
|
||||
Locale.setDefault(currentLocale)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the locale applied in the given configuration.
|
||||
*/
|
||||
private fun getConfigLocale(config: Configuration): Locale {
|
||||
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||
config.locale
|
||||
} else {
|
||||
config.locales[0]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new configuration with the given locale applied.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user