diff --git a/app/src/main/java/org/breezyweather/background/forecast/ForecastNotificationNotifier.kt b/app/src/main/java/org/breezyweather/background/forecast/ForecastNotificationNotifier.kt index 536c9f5df..bb90a2e1d 100644 --- a/app/src/main/java/org/breezyweather/background/forecast/ForecastNotificationNotifier.kt +++ b/app/src/main/java/org/breezyweather/background/forecast/ForecastNotificationNotifier.kt @@ -19,7 +19,6 @@ package org.breezyweather.background.forecast import android.app.Notification import android.content.Context import android.graphics.drawable.Icon -import android.os.Build import androidx.core.app.NotificationCompat import breezyweather.domain.location.model.Location import breezyweather.domain.weather.model.Daily @@ -130,9 +129,7 @@ class ForecastNotificationNotifier( ) }.build() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && - weather.current?.weatherCode != null - ) { + if (weather.current?.weatherCode != null) { try { notification.javaClass .getMethod("setSmallIcon", Icon::class.java) @@ -144,7 +141,7 @@ class ForecastNotificationNotifier( daytime ) ) - } catch (ignore: Exception) { + } catch (_: Exception) { // do nothing. } } diff --git a/app/src/main/java/org/breezyweather/background/provider/WeatherContentProvider.kt b/app/src/main/java/org/breezyweather/background/provider/WeatherContentProvider.kt index f066703ff..849e6c85f 100644 --- a/app/src/main/java/org/breezyweather/background/provider/WeatherContentProvider.kt +++ b/app/src/main/java/org/breezyweather/background/provider/WeatherContentProvider.kt @@ -177,13 +177,6 @@ class WeatherContentProvider : ContentProvider() { selectionArgs: Array?, sortOrder: String?, ): Cursor? { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - // Disable the content provider on SDK < 23 since it grants dangerous - // permissions at install-time - Log.w(TAG, "Content provider read is only available for SDK >= 23") - return null - } - if (!isAllowedPackage()) { Log.w(TAG, "Content provider is disabled for this app") return null diff --git a/app/src/main/java/org/breezyweather/background/updater/AppUpdateChecker.kt b/app/src/main/java/org/breezyweather/background/updater/AppUpdateChecker.kt index 3106cb1b0..6262bdd5b 100644 --- a/app/src/main/java/org/breezyweather/background/updater/AppUpdateChecker.kt +++ b/app/src/main/java/org/breezyweather/background/updater/AppUpdateChecker.kt @@ -38,10 +38,10 @@ class AppUpdateChecker @Inject constructor( forceCheck: Boolean = false, ): GetApplicationRelease.Result { // Disable app update checks for older Android versions that we're going to drop support for - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + /*if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { AppUpdateNotifier(context).promptOldAndroidVersion() return GetApplicationRelease.Result.OsTooOld - } + }*/ return withIOContext { val result = getApplicationRelease.await( diff --git a/app/src/main/java/org/breezyweather/background/weather/WeatherUpdateJob.kt b/app/src/main/java/org/breezyweather/background/weather/WeatherUpdateJob.kt index 5c532d40f..c9740955a 100644 --- a/app/src/main/java/org/breezyweather/background/weather/WeatherUpdateJob.kt +++ b/app/src/main/java/org/breezyweather/background/weather/WeatherUpdateJob.kt @@ -128,10 +128,10 @@ class WeatherUpdateJob @AssistedInject constructor( } } finally { notifier.cancelProgressNotification() - // if (BuildConfig.FLAVOR != "freenet" && SettingsManager.getInstance(context).isAppUpdateCheckEnabled) { - if ((BuildConfig.FLAVOR != "freenet" && SettingsManager.getInstance(context).isAppUpdateCheckEnabled) || + /*if ((BuildConfig.FLAVOR != "freenet" && SettingsManager.getInstance(context).isAppUpdateCheckEnabled) || Build.VERSION.SDK_INT < Build.VERSION_CODES.M - ) { + ) {*/ + if (BuildConfig.FLAVOR != "freenet" && SettingsManager.getInstance(context).isAppUpdateCheckEnabled) { try { updateChecker.checkForUpdate(context, forceCheck = false) } catch (e: Exception) { diff --git a/app/src/main/java/org/breezyweather/common/actionmodecallback/BreezyFloatingTextActionModeCallback.kt b/app/src/main/java/org/breezyweather/common/actionmodecallback/BreezyFloatingTextActionModeCallback.kt index 92e6e1106..4700e639e 100644 --- a/app/src/main/java/org/breezyweather/common/actionmodecallback/BreezyFloatingTextActionModeCallback.kt +++ b/app/src/main/java/org/breezyweather/common/actionmodecallback/BreezyFloatingTextActionModeCallback.kt @@ -17,14 +17,11 @@ package org.breezyweather.common.actionmodecallback import android.graphics.Rect -import android.os.Build import android.view.ActionMode import android.view.Menu import android.view.MenuItem import android.view.View -import androidx.annotation.RequiresApi -@RequiresApi(Build.VERSION_CODES.M) internal class BreezyFloatingTextActionModeCallback( private val callback: BreezyTextActionModeCallback, ) : ActionMode.Callback2() { diff --git a/app/src/main/java/org/breezyweather/common/actionmodecallback/BreezyTextToolbar.kt b/app/src/main/java/org/breezyweather/common/actionmodecallback/BreezyTextToolbar.kt index 4bd4e3c94..aca88ea29 100644 --- a/app/src/main/java/org/breezyweather/common/actionmodecallback/BreezyTextToolbar.kt +++ b/app/src/main/java/org/breezyweather/common/actionmodecallback/BreezyTextToolbar.kt @@ -21,7 +21,6 @@ import android.content.Intent import android.os.Build import android.view.ActionMode import android.view.View -import androidx.annotation.RequiresApi import androidx.compose.ui.geometry.Rect import androidx.compose.ui.platform.TextToolbar import androidx.compose.ui.platform.TextToolbarStatus @@ -49,40 +48,36 @@ internal class BreezyTextToolbar( textActionModeCallback.rect = rect textActionModeCallback.onCopyRequested = onCopyRequested textActionModeCallback.onSelectAllRequested = onSelectAllRequested - textActionModeCallback.onTranslateRequested = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - { - // Get selected text by copying it, then restore the previous clip - val clipboardManager = view.context.clipboardManager - val previousClipboard = clipboardManager.primaryClip - onCopyRequested?.invoke() - val text = clipboardManager.text - if (previousClipboard != null) { - clipboardManager.setPrimaryClip(previousClipboard) - } else { - clipboardManager.setPrimaryClip(ClipData.newPlainText(null, " ")) - } - - val intent = Intent().apply { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - action = Intent.ACTION_TRANSLATE - putExtra(Intent.EXTRA_TEXT, text.trim()) - } else { - action = Intent.ACTION_PROCESS_TEXT - type = "text/plain" - putExtra(Intent.EXTRA_PROCESS_TEXT, text.trim()) - putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, true) - } - flags = Intent.FLAG_ACTIVITY_NEW_TASK - } - - try { - view.context.startActivity(Intent.createChooser(intent, "")) - } catch (e: Exception) { - SnackbarHelper.showSnackbar(view.context.getString(R.string.action_translate_no_app)) - } + textActionModeCallback.onTranslateRequested = { + // Get selected text by copying it, then restore the previous clip + val clipboardManager = view.context.clipboardManager + val previousClipboard = clipboardManager.primaryClip + onCopyRequested?.invoke() + val text = clipboardManager.text + if (previousClipboard != null) { + clipboardManager.setPrimaryClip(previousClipboard) + } else { + clipboardManager.setPrimaryClip(ClipData.newPlainText(null, " ")) + } + + val intent = Intent().apply { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + action = Intent.ACTION_TRANSLATE + putExtra(Intent.EXTRA_TEXT, text.trim()) + } else { + action = Intent.ACTION_PROCESS_TEXT + type = "text/plain" + putExtra(Intent.EXTRA_PROCESS_TEXT, text.trim()) + putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, true) + } + flags = Intent.FLAG_ACTIVITY_NEW_TASK + } + + try { + view.context.startActivity(Intent.createChooser(intent, "")) + } catch (e: Exception) { + SnackbarHelper.showSnackbar(view.context.getString(R.string.action_translate_no_app)) } - } else { - null } textActionModeCallback.onShareRequested = { // Get selected text by copying it, then restore the previous clip @@ -112,16 +107,11 @@ internal class BreezyTextToolbar( } if (actionMode == null) { status = TextToolbarStatus.Shown - actionMode = - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - TextToolbarHelperMethods.startActionMode( - view, - BreezyFloatingTextActionModeCallback(textActionModeCallback), - ActionMode.TYPE_FLOATING - ) - } else { - view.startActionMode(BreezyPrimaryTextActionModeCallback(textActionModeCallback)) - } + actionMode = TextToolbarHelperMethods.startActionMode( + view, + BreezyFloatingTextActionModeCallback(textActionModeCallback), + ActionMode.TYPE_FLOATING + ) } else { actionMode?.invalidate() } @@ -155,9 +145,7 @@ internal class BreezyTextToolbar( * compiled. It is expected that this class will soft-fail verification, but the classes which use * this method will pass. */ -@RequiresApi(Build.VERSION_CODES.M) internal object TextToolbarHelperMethods { - @RequiresApi(Build.VERSION_CODES.M) fun startActionMode( view: View, actionModeCallback: ActionMode.Callback, @@ -166,7 +154,6 @@ internal object TextToolbarHelperMethods { return view.startActionMode(actionModeCallback, type) } - @RequiresApi(Build.VERSION_CODES.M) fun invalidateContentRect(actionMode: ActionMode) { actionMode.invalidateContentRect() } diff --git a/app/src/main/java/org/breezyweather/common/extensions/DisplayExtensions.kt b/app/src/main/java/org/breezyweather/common/extensions/DisplayExtensions.kt index 35fc3ace5..e238f625a 100644 --- a/app/src/main/java/org/breezyweather/common/extensions/DisplayExtensions.kt +++ b/app/src/main/java/org/breezyweather/common/extensions/DisplayExtensions.kt @@ -222,10 +222,6 @@ fun Window.setSystemBarStyle( val colorSystemBarDark = Color.argb(0x80, 0x1b, 0x1b, 0x1b) val colorSystemBarLight = Color.argb(0xe6, 0xFF, 0xFF, 0xFF) - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - // Always apply a dark shader as a light or transparent status bar is not supported - newLightStatus = false - } statusBarColor = Color.TRANSPARENT navigationBarColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && lightStatus) { diff --git a/app/src/main/java/org/breezyweather/remoteviews/config/AbstractWidgetConfigActivity.kt b/app/src/main/java/org/breezyweather/remoteviews/config/AbstractWidgetConfigActivity.kt index d20b4e5a8..7815cad86 100644 --- a/app/src/main/java/org/breezyweather/remoteviews/config/AbstractWidgetConfigActivity.kt +++ b/app/src/main/java/org/breezyweather/remoteviews/config/AbstractWidgetConfigActivity.kt @@ -655,7 +655,7 @@ abstract class AbstractWidgetConfigActivity : BreezyActivity() { @SuppressLint("MissingPermission") private fun bindWallpaper(checkPermissions: Boolean) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkPermissions) { + if (checkPermissions) { val hasPermission = checkPermissions(0) if (!hasPermission) { return @@ -674,7 +674,6 @@ abstract class AbstractWidgetConfigActivity : BreezyActivity() { * @return true : already got permissions. * false: request permissions. */ - @RequiresApi(Build.VERSION_CODES.M) private fun checkPermissions(requestCode: Int): Boolean { if (!hasPermission(Manifest.permission.READ_EXTERNAL_STORAGE)) { requestPermissions(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), requestCode) @@ -779,10 +778,7 @@ abstract class AbstractWidgetConfigActivity : BreezyActivity() { updateHostView() return } - var hasPermission = true - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - hasPermission = checkPermissions(1) - } + val hasPermission = checkPermissions(1) if (hasPermission) { updateHostView() } diff --git a/app/src/main/java/org/breezyweather/remoteviews/presenters/notification/MultiCityWidgetNotificationIMP.kt b/app/src/main/java/org/breezyweather/remoteviews/presenters/notification/MultiCityWidgetNotificationIMP.kt index 425df852e..0760d24a3 100644 --- a/app/src/main/java/org/breezyweather/remoteviews/presenters/notification/MultiCityWidgetNotificationIMP.kt +++ b/app/src/main/java/org/breezyweather/remoteviews/presenters/notification/MultiCityWidgetNotificationIMP.kt @@ -72,7 +72,7 @@ object MultiCityWidgetNotificationIMP : AbstractRemoteViewsPresenter() { val notification = context.notificationBuilder(Notifications.CHANNEL_WIDGET).apply { priority = NotificationCompat.PRIORITY_MAX setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - if (temperature != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (temperature != null) { setSmallIcon( IconCompat.createWithBitmap( ResourceHelper.createTempBitmap(context, temperature, temperatureUnit) @@ -110,7 +110,7 @@ object MultiCityWidgetNotificationIMP : AbstractRemoteViewsPresenter() { setOnlyAlertOnce(true) }.build() - if (!tempIcon && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (!tempIcon) { current.weatherCode?.let { weatherCode -> try { notification.javaClass diff --git a/app/src/main/java/org/breezyweather/remoteviews/presenters/notification/NativeWidgetNotificationIMP.kt b/app/src/main/java/org/breezyweather/remoteviews/presenters/notification/NativeWidgetNotificationIMP.kt index 8ab1c6adf..c21d9d9c5 100644 --- a/app/src/main/java/org/breezyweather/remoteviews/presenters/notification/NativeWidgetNotificationIMP.kt +++ b/app/src/main/java/org/breezyweather/remoteviews/presenters/notification/NativeWidgetNotificationIMP.kt @@ -87,7 +87,7 @@ object NativeWidgetNotificationIMP : AbstractRemoteViewsPresenter() { val notification = context.notificationBuilder(Notifications.CHANNEL_WIDGET).apply { priority = NotificationCompat.PRIORITY_MAX setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - if (temperature != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (temperature != null) { setSmallIcon( IconCompat.createWithBitmap( ResourceHelper.createTempBitmap(context, temperature, temperatureUnit) @@ -123,7 +123,7 @@ object NativeWidgetNotificationIMP : AbstractRemoteViewsPresenter() { setContentIntent(getWeatherPendingIntent(context, null, Notifications.ID_WIDGET)) }.build() - if (!tempIcon && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (!tempIcon) { current.weatherCode?.let { weatherCode -> try { notification.javaClass diff --git a/app/src/main/java/org/breezyweather/remoteviews/presenters/notification/WidgetNotificationIMP.kt b/app/src/main/java/org/breezyweather/remoteviews/presenters/notification/WidgetNotificationIMP.kt index c22eb5e88..daed0c878 100644 --- a/app/src/main/java/org/breezyweather/remoteviews/presenters/notification/WidgetNotificationIMP.kt +++ b/app/src/main/java/org/breezyweather/remoteviews/presenters/notification/WidgetNotificationIMP.kt @@ -100,7 +100,7 @@ object WidgetNotificationIMP : AbstractRemoteViewsPresenter() { val notification = context.notificationBuilder(Notifications.CHANNEL_WIDGET).apply { priority = NotificationCompat.PRIORITY_MAX setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - if (temperature != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (temperature != null) { setSmallIcon( IconCompat.createWithBitmap( ResourceHelper.createTempBitmap(context, temperature, temperatureUnit) @@ -139,7 +139,7 @@ object WidgetNotificationIMP : AbstractRemoteViewsPresenter() { setOnlyAlertOnce(true) }.build() - if (!tempIcon && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (!tempIcon) { current.weatherCode?.let { weatherCode -> try { notification.javaClass diff --git a/app/src/main/java/org/breezyweather/ui/main/MainActivity.kt b/app/src/main/java/org/breezyweather/ui/main/MainActivity.kt index 88e658868..e8e415c02 100644 --- a/app/src/main/java/org/breezyweather/ui/main/MainActivity.kt +++ b/app/src/main/java/org/breezyweather/ui/main/MainActivity.kt @@ -362,8 +362,7 @@ class MainActivity : BreezyActivity(), HomeFragment.Callback, ManagementFragment lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { viewModel.locationPermissionsRequest.collect { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && - it != null && + if (it != null && it.permissionList.isNotEmpty() && it.consume() ) { diff --git a/app/src/main/java/org/breezyweather/ui/main/MainActivityViewModel.kt b/app/src/main/java/org/breezyweather/ui/main/MainActivityViewModel.kt index 1c2ae7ec5..667997f72 100644 --- a/app/src/main/java/org/breezyweather/ui/main/MainActivityViewModel.kt +++ b/app/src/main/java/org/breezyweather/ui/main/MainActivityViewModel.kt @@ -348,7 +348,7 @@ class MainActivityViewModel @Inject constructor( } } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !checkPermissions) { + if (!checkPermissions) { updating = true SettingsManager.getInstance(getApplication()) .weatherManualUpdateLastTimestamp = Date().time diff --git a/app/src/main/java/org/breezyweather/ui/settings/compose/BackgroundUpdatesSettingsScreen.kt b/app/src/main/java/org/breezyweather/ui/settings/compose/BackgroundUpdatesSettingsScreen.kt index bc9febdc4..eb4c59d74 100644 --- a/app/src/main/java/org/breezyweather/ui/settings/compose/BackgroundUpdatesSettingsScreen.kt +++ b/app/src/main/java/org/breezyweather/ui/settings/compose/BackgroundUpdatesSettingsScreen.kt @@ -235,35 +235,33 @@ fun BackgroundSettingsScreen( largeSeparatorItem() sectionHeaderItem(R.string.settings_background_updates_section_troubleshoot) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - clickablePreferenceItem(R.string.settings_background_updates_battery_optimization) { id -> - PreferenceViewWithCard( - titleId = id, - summaryId = R.string.settings_background_updates_battery_optimization_summary, - isFirst = true - ) { - val packageName: String = context.packageName - if (!context.powerManager.isIgnoringBatteryOptimizations(packageName)) { - try { - @SuppressLint("BatteryLife") - val intent = Intent().apply { - action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS - data = "package:$packageName".toUri() - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - } - context.startActivity(intent) - } catch (e: ActivityNotFoundException) { - SnackbarHelper.showSnackbar( - context.getString( - R.string.settings_background_updates_battery_optimization_activity_not_found - ) - ) + clickablePreferenceItem(R.string.settings_background_updates_battery_optimization) { id -> + PreferenceViewWithCard( + titleId = id, + summaryId = R.string.settings_background_updates_battery_optimization_summary, + isFirst = true + ) { + val packageName: String = context.packageName + if (!context.powerManager.isIgnoringBatteryOptimizations(packageName)) { + try { + @SuppressLint("BatteryLife") + val intent = Intent().apply { + action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS + data = "package:$packageName".toUri() + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } - } else { + context.startActivity(intent) + } catch (e: ActivityNotFoundException) { SnackbarHelper.showSnackbar( - context.getString(R.string.settings_background_updates_battery_optimization_disabled) + context.getString( + R.string.settings_background_updates_battery_optimization_activity_not_found + ) ) } + } else { + SnackbarHelper.showSnackbar( + context.getString(R.string.settings_background_updates_battery_optimization_disabled) + ) } } } diff --git a/app/src/main/java/org/breezyweather/ui/settings/compose/LocationSettingsScreen.kt b/app/src/main/java/org/breezyweather/ui/settings/compose/LocationSettingsScreen.kt index ced52b15c..ce64a80a2 100644 --- a/app/src/main/java/org/breezyweather/ui/settings/compose/LocationSettingsScreen.kt +++ b/app/src/main/java/org/breezyweather/ui/settings/compose/LocationSettingsScreen.kt @@ -171,28 +171,59 @@ fun LocationSettingsScreen( sectionFooterItem(R.string.settings_location_section_general) largeSeparatorItem() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - sectionHeaderItem(R.string.location_service_native) - clickablePreferenceItem(R.string.settings_location_access_switch_title) { id -> + sectionHeaderItem(R.string.location_service_native) + clickablePreferenceItem(R.string.settings_location_access_switch_title) { id -> + PreferenceViewWithCard( + titleId = id, + summaryId = if (accessCoarseLocationPermissionState.status == PermissionStatus.Granted) { + R.string.settings_location_access_switch_summaryOn + } else { + R.string.settings_location_access_switch_summaryOff + }, + isFirst = true, + isLast = accessBackgroundLocationPermissionState == null && + Build.VERSION.SDK_INT < Build.VERSION_CODES.S, + onClick = { + if (accessCoarseLocationPermissionState.status != PermissionStatus.Granted) { + if ( + ActivityCompat.shouldShowRequestPermissionRationale( + context, + Manifest.permission.ACCESS_COARSE_LOCATION + ) + ) { + accessCoarseLocationPermissionState.launchPermissionRequest() + } else { + context.openApplicationDetailsSettings() + } + } else { + SnackbarHelper.showSnackbar( + context.getString(R.string.settings_location_access_permission_already_granted) + ) + } + } + ) + } + accessBackgroundLocationPermissionState?.let { + smallSeparatorItem() + clickablePreferenceItem(R.string.settings_location_access_background_title) { id -> PreferenceViewWithCard( titleId = id, - summaryId = if (accessCoarseLocationPermissionState.status == PermissionStatus.Granted) { - R.string.settings_location_access_switch_summaryOn + summaryId = if (it.status == PermissionStatus.Granted) { + R.string.settings_location_access_background_summaryOn } else { - R.string.settings_location_access_switch_summaryOff + R.string.settings_location_access_background_summaryOff }, - isFirst = true, - isLast = accessBackgroundLocationPermissionState == null && - Build.VERSION.SDK_INT < Build.VERSION_CODES.S, + enabled = accessCoarseLocationPermissionState.status == PermissionStatus.Granted, + isLast = Build.VERSION.SDK_INT < Build.VERSION_CODES.S, onClick = { - if (accessCoarseLocationPermissionState.status != PermissionStatus.Granted) { + if (it.status != PermissionStatus.Granted) { if ( ActivityCompat.shouldShowRequestPermissionRationale( context, - Manifest.permission.ACCESS_COARSE_LOCATION + Manifest.permission.ACCESS_BACKGROUND_LOCATION ) ) { - accessCoarseLocationPermissionState.launchPermissionRequest() + it.launchPermissionRequest() } else { context.openApplicationDetailsSettings() } @@ -204,74 +235,41 @@ fun LocationSettingsScreen( } ) } - accessBackgroundLocationPermissionState?.let { - smallSeparatorItem() - clickablePreferenceItem(R.string.settings_location_access_background_title) { id -> - PreferenceViewWithCard( - titleId = id, - summaryId = if (it.status == PermissionStatus.Granted) { - R.string.settings_location_access_background_summaryOn - } else { - R.string.settings_location_access_background_summaryOff - }, - enabled = accessCoarseLocationPermissionState.status == PermissionStatus.Granted, - isLast = Build.VERSION.SDK_INT < Build.VERSION_CODES.S, - onClick = { - if (it.status != PermissionStatus.Granted) { - if ( - ActivityCompat.shouldShowRequestPermissionRationale( - context, - Manifest.permission.ACCESS_BACKGROUND_LOCATION - ) - ) { - it.launchPermissionRequest() - } else { - context.openApplicationDetailsSettings() - } - } else { - SnackbarHelper.showSnackbar( - context.getString(R.string.settings_location_access_permission_already_granted) - ) - } - } - ) - } - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - smallSeparatorItem() - clickablePreferenceItem(R.string.settings_location_access_precise_title) { id -> - PreferenceViewWithCard( - titleId = id, - summaryId = if (accessFineLocationPermissionState.status == PermissionStatus.Granted) { - R.string.settings_location_access_precise_summaryOn - } else { - R.string.settings_location_access_precise_summaryOff - }, - enabled = accessCoarseLocationPermissionState.status == PermissionStatus.Granted, - isLast = true, - onClick = { - if (accessFineLocationPermissionState.status != PermissionStatus.Granted) { - if ( - ActivityCompat.shouldShowRequestPermissionRationale( - context, - Manifest.permission.ACCESS_FINE_LOCATION - ) - ) { - accessFineLocationPermissionState.launchPermissionRequest() - } else { - context.openApplicationDetailsSettings() - } - } else { - SnackbarHelper.showSnackbar( - context.getString(R.string.settings_location_access_permission_already_granted) - ) - } - } - ) - } - } - sectionFooterItem(R.string.location_service_native) } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + smallSeparatorItem() + clickablePreferenceItem(R.string.settings_location_access_precise_title) { id -> + PreferenceViewWithCard( + titleId = id, + summaryId = if (accessFineLocationPermissionState.status == PermissionStatus.Granted) { + R.string.settings_location_access_precise_summaryOn + } else { + R.string.settings_location_access_precise_summaryOff + }, + enabled = accessCoarseLocationPermissionState.status == PermissionStatus.Granted, + isLast = true, + onClick = { + if (accessFineLocationPermissionState.status != PermissionStatus.Granted) { + if ( + ActivityCompat.shouldShowRequestPermissionRationale( + context, + Manifest.permission.ACCESS_FINE_LOCATION + ) + ) { + accessFineLocationPermissionState.launchPermissionRequest() + } else { + context.openApplicationDetailsSettings() + } + } else { + SnackbarHelper.showSnackbar( + context.getString(R.string.settings_location_access_permission_already_granted) + ) + } + } + ) + } + } + sectionFooterItem(R.string.location_service_native) // TODO: Duplicate code from weather sources locationSources.filterIsInstance().forEach { preferenceSource -> diff --git a/app/src/main/java/org/breezyweather/ui/settings/compose/ModulesSettingsScreen.kt b/app/src/main/java/org/breezyweather/ui/settings/compose/ModulesSettingsScreen.kt index 4ecd34d4e..0819c91b0 100644 --- a/app/src/main/java/org/breezyweather/ui/settings/compose/ModulesSettingsScreen.kt +++ b/app/src/main/java/org/breezyweather/ui/settings/compose/ModulesSettingsScreen.kt @@ -324,7 +324,6 @@ fun ModulesSettingsScreen( nameArrayId = R.array.notification_styles, enabled = notificationEnabled && hasNotificationPermission, card = true, - isLast = Build.VERSION.SDK_INT < Build.VERSION_CODES.M, onValueChanged = { SettingsManager .getInstance(context) @@ -333,46 +332,44 @@ fun ModulesSettingsScreen( } ) } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - smallSeparatorItem() - switchPreferenceItem(R.string.settings_modules_notification_temp_icon_switch) { id -> - SwitchPreferenceView( - titleId = id, - summaryOnId = R.string.settings_enabled, - summaryOffId = R.string.settings_disabled, - checked = SettingsManager + smallSeparatorItem() + switchPreferenceItem(R.string.settings_modules_notification_temp_icon_switch) { id -> + SwitchPreferenceView( + titleId = id, + summaryOnId = R.string.settings_enabled, + summaryOffId = R.string.settings_disabled, + checked = SettingsManager + .getInstance(context) + .isWidgetNotificationTemperatureIconEnabled, + enabled = notificationEnabled && hasNotificationPermission, + onValueChanged = { + SettingsManager .getInstance(context) - .isWidgetNotificationTemperatureIconEnabled, - enabled = notificationEnabled && hasNotificationPermission, - onValueChanged = { - SettingsManager - .getInstance(context) - .isWidgetNotificationTemperatureIconEnabled = it - updateNotificationIfNecessary(context) - } - ) - } - smallSeparatorItem() - switchPreferenceItem(R.string.settings_modules_notification_feels_like_switch) { id -> - SwitchPreferenceView( - titleId = id, - summaryOnId = R.string.settings_enabled, - summaryOffId = R.string.settings_disabled, - checked = SettingsManager + .isWidgetNotificationTemperatureIconEnabled = it + updateNotificationIfNecessary(context) + } + ) + } + smallSeparatorItem() + switchPreferenceItem(R.string.settings_modules_notification_feels_like_switch) { id -> + SwitchPreferenceView( + titleId = id, + summaryOnId = R.string.settings_enabled, + summaryOffId = R.string.settings_disabled, + checked = SettingsManager + .getInstance(context) + .isWidgetNotificationUsingFeelsLike, + enabled = notificationEnabled && + hasNotificationPermission && + notificationTemperatureIconEnabled, + isLast = true, + onValueChanged = { + SettingsManager .getInstance(context) - .isWidgetNotificationUsingFeelsLike, - enabled = notificationEnabled && - hasNotificationPermission && - notificationTemperatureIconEnabled, - isLast = true, - onValueChanged = { - SettingsManager - .getInstance(context) - .isWidgetNotificationUsingFeelsLike = it - updateNotificationIfNecessary(context) - } - ) - } + .isWidgetNotificationUsingFeelsLike = it + updateNotificationIfNecessary(context) + } + ) } sectionFooterItem(R.string.settings_modules_section_notification_widget) diff --git a/app/src/main/java/org/breezyweather/ui/theme/resource/ResourceHelper.kt b/app/src/main/java/org/breezyweather/ui/theme/resource/ResourceHelper.kt index 4c5c6c654..17df95749 100644 --- a/app/src/main/java/org/breezyweather/ui/theme/resource/ResourceHelper.kt +++ b/app/src/main/java/org/breezyweather/ui/theme/resource/ResourceHelper.kt @@ -121,7 +121,6 @@ object ResourceHelper { return provider.getMinimalXmlIcon(code, daytime) } - @RequiresApi(Build.VERSION_CODES.M) fun getMinimalIcon( provider: ResourceProvider, code: WeatherCode, diff --git a/app/src/main/java/org/breezyweather/ui/theme/resource/providers/ChronusResourceProvider.kt b/app/src/main/java/org/breezyweather/ui/theme/resource/providers/ChronusResourceProvider.kt index 948e2eb6e..61184c8cf 100644 --- a/app/src/main/java/org/breezyweather/ui/theme/resource/providers/ChronusResourceProvider.kt +++ b/app/src/main/java/org/breezyweather/ui/theme/resource/providers/ChronusResourceProvider.kt @@ -155,7 +155,6 @@ class ChronusResourceProvider( return mDefaultProvider.getMinimalXmlIcon(code, dayTime) } - @RequiresApi(Build.VERSION_CODES.M) override fun getMinimalIcon(code: WeatherCode?, dayTime: Boolean): Icon { return mDefaultProvider.getMinimalIcon(code, dayTime) } diff --git a/app/src/main/java/org/breezyweather/ui/theme/resource/providers/DefaultResourceProvider.kt b/app/src/main/java/org/breezyweather/ui/theme/resource/providers/DefaultResourceProvider.kt index 1f7a91dd9..76fd2d6b7 100644 --- a/app/src/main/java/org/breezyweather/ui/theme/resource/providers/DefaultResourceProvider.kt +++ b/app/src/main/java/org/breezyweather/ui/theme/resource/providers/DefaultResourceProvider.kt @@ -179,7 +179,6 @@ class DefaultResourceProvider : ResourceProvider() { return getDrawable(getMiniXmlIconName(code, dayTime))!! } - @RequiresApi(Build.VERSION_CODES.M) override fun getMinimalIcon(code: WeatherCode?, dayTime: Boolean): Icon { return Objects.requireNonNull( Icon.createWithResource( diff --git a/app/src/main/java/org/breezyweather/ui/theme/resource/providers/IconPackResourcesProvider.kt b/app/src/main/java/org/breezyweather/ui/theme/resource/providers/IconPackResourcesProvider.kt index a860eb55d..4461534dd 100644 --- a/app/src/main/java/org/breezyweather/ui/theme/resource/providers/IconPackResourcesProvider.kt +++ b/app/src/main/java/org/breezyweather/ui/theme/resource/providers/IconPackResourcesProvider.kt @@ -24,9 +24,7 @@ import android.content.pm.PackageManager import android.graphics.drawable.Drawable import android.graphics.drawable.Icon import android.net.Uri -import android.os.Build import androidx.annotation.IntRange -import androidx.annotation.RequiresApi import androidx.annotation.Size import androidx.core.content.res.ResourcesCompat import breezyweather.domain.weather.reference.WeatherCode @@ -338,12 +336,11 @@ open class IconPackResourcesProvider( if (mConfig.hasMinimalIcons) { return getDrawable(getMiniXmlIconName(code, dayTime))!! } - } catch (ignore: Exception) { + } catch (_: Exception) { } return mDefaultProvider.getMinimalXmlIcon(code, dayTime) } - @RequiresApi(Build.VERSION_CODES.M) override fun getMinimalIcon(code: WeatherCode?, dayTime: Boolean): Icon { try { if (mConfig.hasMinimalIcons) { diff --git a/app/src/main/java/org/breezyweather/ui/theme/resource/providers/ResourceProvider.kt b/app/src/main/java/org/breezyweather/ui/theme/resource/providers/ResourceProvider.kt index c6fd43d7b..288315bfb 100644 --- a/app/src/main/java/org/breezyweather/ui/theme/resource/providers/ResourceProvider.kt +++ b/app/src/main/java/org/breezyweather/ui/theme/resource/providers/ResourceProvider.kt @@ -50,7 +50,6 @@ abstract class ResourceProvider { abstract fun getWeatherAnimators(code: WeatherCode?, dayTime: Boolean): Array // minimal icon. - @RequiresApi(Build.VERSION_CODES.M) abstract fun getMinimalIcon(code: WeatherCode?, dayTime: Boolean): Icon abstract fun getMinimalLightIcon(code: WeatherCode?, dayTime: Boolean): Drawable abstract fun getMinimalLightIconUri(code: WeatherCode?, dayTime: Boolean): Uri diff --git a/buildSrc/src/main/kotlin/breezy/buildlogic/AndroidConfig.kt b/buildSrc/src/main/kotlin/breezy/buildlogic/AndroidConfig.kt index a64f75e06..24dfb9c93 100644 --- a/buildSrc/src/main/kotlin/breezy/buildlogic/AndroidConfig.kt +++ b/buildSrc/src/main/kotlin/breezy/buildlogic/AndroidConfig.kt @@ -5,7 +5,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget as KotlinJvmTarget object AndroidConfig { const val COMPILE_SDK = 36 - const val MIN_SDK = 21 + const val MIN_SDK = 23 const val TARGET_SDK = 36 const val BUILD_TOOLS = "35.0.1"