Refactor(minSdk): Upgrade minSdk from 21 to 24

This commit is contained in:
2024-10-11 09:43:54 +08:00
parent 3979027471
commit cd97f6156f
9 changed files with 17 additions and 43 deletions

View File

@@ -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) ".${

View File

@@ -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
}

View File

@@ -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

View File

@@ -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)

View File

@@ -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
}
}

View File

@@ -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
}

View File

@@ -121,7 +121,7 @@ private suspend fun FlowCollector<ToolViewUiState>.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
}

View File

@@ -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
}
}

View File

@@ -17,7 +17,7 @@ object Permissions {
context: Context,
permissionLauncher: ManagedActivityResultLauncher<String, Boolean>
): 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
}