Refactor(minSdk): Upgrade minSdk from 21 to 24
This commit is contained in:
@@ -35,12 +35,12 @@ plugins {
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "top.fatweb.oxygen.toolbox"
|
namespace = "top.fatweb.oxygen.toolbox"
|
||||||
compileSdk = 34
|
compileSdk = 35
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "top.fatweb.oxygen.toolbox"
|
applicationId = "top.fatweb.oxygen.toolbox"
|
||||||
minSdk = 21
|
minSdk = 24
|
||||||
targetSdk = 34
|
targetSdk = 35
|
||||||
versionCode = baseVersionCode
|
versionCode = baseVersionCode
|
||||||
versionName = "$baseVersionName${
|
versionName = "$baseVersionName${
|
||||||
if (baseVersionCode % 100 != 0) ".${
|
if (baseVersionCode % 100 != 0) ".${
|
||||||
|
|||||||
@@ -57,14 +57,8 @@ internal class ConnectivityManagerNetworkMonitor @Inject constructor(
|
|||||||
}
|
}
|
||||||
.conflate()
|
.conflate()
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
private fun ConnectivityManager.isCurrentlyConnected() =
|
private fun ConnectivityManager.isCurrentlyConnected() =
|
||||||
when {
|
activeNetwork
|
||||||
VERSION.SDK_INT >= VERSION_CODES.M ->
|
?.let(::getNetworkCapabilities)
|
||||||
activeNetwork
|
?.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) == true
|
||||||
?.let(::getNetworkCapabilities)
|
|
||||||
?.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
|
||||||
|
|
||||||
else -> activeNetworkInfo?.isConnected
|
|
||||||
} ?: false
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -293,5 +293,5 @@ private fun OxygenNavRail(
|
|||||||
|
|
||||||
private fun NavDestination?.isTopLevelDestinationInHierarchy(destination: TopLevelDestination) =
|
private fun NavDestination?.isTopLevelDestinationInHierarchy(destination: TopLevelDestination) =
|
||||||
this?.hierarchy?.any {
|
this?.hierarchy?.any {
|
||||||
it.route?.equals(destination.route) ?: false
|
it.route?.equals(destination.route) == true
|
||||||
} ?: false
|
} == true
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ fun Scrollbar(
|
|||||||
withTimeout(viewConfiguration.longPressTimeoutMillis) {
|
withTimeout(viewConfiguration.longPressTimeoutMillis) {
|
||||||
tryAwaitRelease()
|
tryAwaitRelease()
|
||||||
}
|
}
|
||||||
} catch (e: TimeoutCancellationException) {
|
} catch (_: TimeoutCancellationException) {
|
||||||
// Start the press triggered scroll
|
// Start the press triggered scroll
|
||||||
val initialPress = PressInteraction.Press(offset)
|
val initialPress = PressInteraction.Press(offset)
|
||||||
interactionSource?.tryEmit(initialPress)
|
interactionSource?.tryEmit(initialPress)
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ package top.fatweb.oxygen.toolbox.ui.util
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
|
||||||
import android.os.LocaleList
|
import android.os.LocaleList
|
||||||
import androidx.annotation.RequiresApi
|
|
||||||
import top.fatweb.oxygen.toolbox.model.userdata.LanguageConfig
|
import top.fatweb.oxygen.toolbox.model.userdata.LanguageConfig
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
@@ -24,11 +22,7 @@ object LocaleUtils {
|
|||||||
fun attachBaseContext(context: Context, languageConfig: LanguageConfig): Context {
|
fun attachBaseContext(context: Context, languageConfig: LanguageConfig): Context {
|
||||||
val locale: Locale = getLocaleFromLanguageConfig(languageConfig)
|
val locale: Locale = getLocaleFromLanguageConfig(languageConfig)
|
||||||
|
|
||||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
return createConfigurationContext(context, locale)
|
||||||
createConfigurationContext(context, locale)
|
|
||||||
} else {
|
|
||||||
updateConfiguration(context, locale)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getLocaleFromLanguageConfig(languageConfig: LanguageConfig): Locale =
|
private fun getLocaleFromLanguageConfig(languageConfig: LanguageConfig): Locale =
|
||||||
@@ -38,21 +32,10 @@ object LocaleUtils {
|
|||||||
LanguageConfig.English -> Locale("en")
|
LanguageConfig.English -> Locale("en")
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.N)
|
|
||||||
private fun createConfigurationContext(context: Context, locale: Locale): Context {
|
private fun createConfigurationContext(context: Context, locale: Locale): Context {
|
||||||
val configuration = context.resources.configuration
|
val configuration = context.resources.configuration
|
||||||
configuration.setLocales(LocaleList(locale))
|
configuration.setLocales(LocaleList(locale))
|
||||||
|
|
||||||
return context.createConfigurationContext(configuration)
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ import java.util.Locale
|
|||||||
object ResourcesUtils {
|
object ResourcesUtils {
|
||||||
private fun getConfiguration(context: Context): Configuration = context.resources.configuration
|
private fun getConfiguration(context: Context): Configuration = context.resources.configuration
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
fun getAppLocale(context: Context): Locale = getConfiguration(context).locales.get(0)
|
||||||
fun getAppLocale(context: Context): Locale =
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) getConfiguration(context).locales.get(0)
|
|
||||||
else getConfiguration(context).locale
|
|
||||||
|
|
||||||
fun getSystemLocale(): LocaleListCompat =
|
fun getSystemLocale(): LocaleListCompat =
|
||||||
ConfigurationCompat.getLocales(Resources.getSystem().configuration)
|
ConfigurationCompat.getLocales(Resources.getSystem().configuration)
|
||||||
@@ -24,7 +21,7 @@ object ResourcesUtils {
|
|||||||
fun getAppVersionName(context: Context): String =
|
fun getAppVersionName(context: Context): String =
|
||||||
try {
|
try {
|
||||||
context.packageManager.getPackageInfo(context.packageName, 0)?.versionName ?: "Unknown"
|
context.packageManager.getPackageInfo(context.packageName, 0)?.versionName ?: "Unknown"
|
||||||
} catch (e: PackageManager.NameNotFoundException) {
|
} catch (_: PackageManager.NameNotFoundException) {
|
||||||
"Unknown"
|
"Unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +34,7 @@ object ResourcesUtils {
|
|||||||
context.packageName,
|
context.packageName,
|
||||||
0
|
0
|
||||||
)?.versionCode?.toLong() ?: -1
|
)?.versionCode?.toLong() ?: -1
|
||||||
} catch (e: PackageManager.NameNotFoundException) {
|
} catch (_: PackageManager.NameNotFoundException) {
|
||||||
-1
|
-1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ private suspend fun FlowCollector<ToolViewUiState>.emitResult(
|
|||||||
|
|
||||||
is Result.Loading -> ToolViewUiState.Loading
|
is Result.Loading -> ToolViewUiState.Loading
|
||||||
is Result.Error -> {
|
is Result.Error -> {
|
||||||
Timber.e("Can not load tool", result.exception)
|
Timber.e(result.exception, "Can not load tool")
|
||||||
ToolViewUiState.Error
|
ToolViewUiState.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class NativeWebApi(
|
|||||||
return clipboardManager?.let {
|
return clipboardManager?.let {
|
||||||
it.setPrimaryClip(ClipData.newPlainText("copy", text))
|
it.setPrimaryClip(ClipData.newPlainText("copy", text))
|
||||||
true
|
true
|
||||||
} ?: false
|
} == true
|
||||||
}
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
@@ -95,7 +95,7 @@ class NativeWebApi(
|
|||||||
}
|
}
|
||||||
true
|
true
|
||||||
} catch (e: IOException) {
|
} 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
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ object Permissions {
|
|||||||
context: Context,
|
context: Context,
|
||||||
permissionLauncher: ManagedActivityResultLauncher<String, Boolean>
|
permissionLauncher: ManagedActivityResultLauncher<String, Boolean>
|
||||||
): 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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user