From cd97f6156f17ddda83f9e28b7f8c692366376e62 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 11 Oct 2024 09:43:54 +0800 Subject: [PATCH] Refactor(minSdk): Upgrade minSdk from 21 to 24 --- app/build.gradle.kts | 6 +++--- .../ConnectivityManagerNetworkMonitor.kt | 12 +++--------- .../top/fatweb/oxygen/toolbox/ui/OxygenApp.kt | 4 ++-- .../ui/component/scrollbar/Scrollbar.kt | 2 +- .../oxygen/toolbox/ui/util/LocaleUtils.kt | 19 +------------------ .../oxygen/toolbox/ui/util/ResourcesUtils.kt | 9 +++------ .../ui/view/ToolViewScreenViewModel.kt | 2 +- .../oxygen/toolbox/util/NativeWebApi.kt | 4 ++-- .../fatweb/oxygen/toolbox/util/Permissions.kt | 2 +- 9 files changed, 17 insertions(+), 43 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 032755f..6d5684e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -35,12 +35,12 @@ plugins { android { namespace = "top.fatweb.oxygen.toolbox" - compileSdk = 34 + compileSdk = 35 defaultConfig { applicationId = "top.fatweb.oxygen.toolbox" - minSdk = 21 - targetSdk = 34 + minSdk = 24 + targetSdk = 35 versionCode = baseVersionCode versionName = "$baseVersionName${ if (baseVersionCode % 100 != 0) ".${ diff --git a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/monitor/ConnectivityManagerNetworkMonitor.kt b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/monitor/ConnectivityManagerNetworkMonitor.kt index cc04290..1c60497 100644 --- a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/monitor/ConnectivityManagerNetworkMonitor.kt +++ b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/monitor/ConnectivityManagerNetworkMonitor.kt @@ -57,14 +57,8 @@ internal class ConnectivityManagerNetworkMonitor @Inject constructor( } .conflate() - @Suppress("DEPRECATION") private fun ConnectivityManager.isCurrentlyConnected() = - when { - VERSION.SDK_INT >= VERSION_CODES.M -> - activeNetwork - ?.let(::getNetworkCapabilities) - ?.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) - - else -> activeNetworkInfo?.isConnected - } ?: false + activeNetwork + ?.let(::getNetworkCapabilities) + ?.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) == true } diff --git a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/OxygenApp.kt b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/OxygenApp.kt index e3e6e1e..7aa5603 100644 --- a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/OxygenApp.kt +++ b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/OxygenApp.kt @@ -293,5 +293,5 @@ private fun OxygenNavRail( private fun NavDestination?.isTopLevelDestinationInHierarchy(destination: TopLevelDestination) = this?.hierarchy?.any { - it.route?.equals(destination.route) ?: false - } ?: false + it.route?.equals(destination.route) == true + } == true diff --git a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/component/scrollbar/Scrollbar.kt b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/component/scrollbar/Scrollbar.kt index dd2ede0..742bb2b 100644 --- a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/component/scrollbar/Scrollbar.kt +++ b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/component/scrollbar/Scrollbar.kt @@ -221,7 +221,7 @@ fun Scrollbar( withTimeout(viewConfiguration.longPressTimeoutMillis) { tryAwaitRelease() } - } catch (e: TimeoutCancellationException) { + } catch (_: TimeoutCancellationException) { // Start the press triggered scroll val initialPress = PressInteraction.Press(offset) interactionSource?.tryEmit(initialPress) diff --git a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/util/LocaleUtils.kt b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/util/LocaleUtils.kt index ffa1b04..ce985d3 100644 --- a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/util/LocaleUtils.kt +++ b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/util/LocaleUtils.kt @@ -2,9 +2,7 @@ package top.fatweb.oxygen.toolbox.ui.util import android.app.Activity import android.content.Context -import android.os.Build import android.os.LocaleList -import androidx.annotation.RequiresApi import top.fatweb.oxygen.toolbox.model.userdata.LanguageConfig import java.util.Locale @@ -24,11 +22,7 @@ object LocaleUtils { fun attachBaseContext(context: Context, languageConfig: LanguageConfig): Context { val locale: Locale = getLocaleFromLanguageConfig(languageConfig) - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - createConfigurationContext(context, locale) - } else { - updateConfiguration(context, locale) - } + return createConfigurationContext(context, locale) } private fun getLocaleFromLanguageConfig(languageConfig: LanguageConfig): Locale = @@ -38,21 +32,10 @@ object LocaleUtils { LanguageConfig.English -> Locale("en") } - @RequiresApi(Build.VERSION_CODES.N) private fun createConfigurationContext(context: Context, locale: Locale): Context { val configuration = context.resources.configuration configuration.setLocales(LocaleList(locale)) return context.createConfigurationContext(configuration) } - - @Suppress("DEPRECATION") - private fun updateConfiguration(context: Context, locale: Locale): Context { - val resources = context.resources - val configuration = resources.configuration - configuration.locale = locale - resources.updateConfiguration(configuration, resources.displayMetrics) - - return context - } } diff --git a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/util/ResourcesUtils.kt b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/util/ResourcesUtils.kt index 45067dc..689c3fb 100644 --- a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/util/ResourcesUtils.kt +++ b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/util/ResourcesUtils.kt @@ -13,10 +13,7 @@ import java.util.Locale object ResourcesUtils { private fun getConfiguration(context: Context): Configuration = context.resources.configuration - @Suppress("DEPRECATION") - fun getAppLocale(context: Context): Locale = - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) getConfiguration(context).locales.get(0) - else getConfiguration(context).locale + fun getAppLocale(context: Context): Locale = getConfiguration(context).locales.get(0) fun getSystemLocale(): LocaleListCompat = ConfigurationCompat.getLocales(Resources.getSystem().configuration) @@ -24,7 +21,7 @@ object ResourcesUtils { fun getAppVersionName(context: Context): String = try { context.packageManager.getPackageInfo(context.packageName, 0)?.versionName ?: "Unknown" - } catch (e: PackageManager.NameNotFoundException) { + } catch (_: PackageManager.NameNotFoundException) { "Unknown" } @@ -37,7 +34,7 @@ object ResourcesUtils { context.packageName, 0 )?.versionCode?.toLong() ?: -1 - } catch (e: PackageManager.NameNotFoundException) { + } catch (_: PackageManager.NameNotFoundException) { -1 } diff --git a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/view/ToolViewScreenViewModel.kt b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/view/ToolViewScreenViewModel.kt index d245b50..abaad4e 100644 --- a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/view/ToolViewScreenViewModel.kt +++ b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/ui/view/ToolViewScreenViewModel.kt @@ -121,7 +121,7 @@ private suspend fun FlowCollector.emitResult( is Result.Loading -> ToolViewUiState.Loading is Result.Error -> { - Timber.e("Can not load tool", result.exception) + Timber.e(result.exception, "Can not load tool") ToolViewUiState.Error } diff --git a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/util/NativeWebApi.kt b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/util/NativeWebApi.kt index c9c971d..cab0360 100644 --- a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/util/NativeWebApi.kt +++ b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/util/NativeWebApi.kt @@ -30,7 +30,7 @@ class NativeWebApi( return clipboardManager?.let { it.setPrimaryClip(ClipData.newPlainText("copy", text)) true - } ?: false + } == true } @JavascriptInterface @@ -95,7 +95,7 @@ class NativeWebApi( } true } catch (e: IOException) { - Timber.e("Could not save file $fileName to ${file.absolutePath}", e) + Timber.e(e, "Could not save file $fileName to ${file.absolutePath}") false } } diff --git a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/util/Permissions.kt b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/util/Permissions.kt index 52175d3..a1e1317 100644 --- a/app/src/main/kotlin/top/fatweb/oxygen/toolbox/util/Permissions.kt +++ b/app/src/main/kotlin/top/fatweb/oxygen/toolbox/util/Permissions.kt @@ -17,7 +17,7 @@ object Permissions { context: Context, permissionLauncher: ManagedActivityResultLauncher ): Boolean { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { return true }