From 3f81e22eed78f6f0735f3639953fdec20acad302 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Tue, 2 Nov 2021 21:26:13 +0100 Subject: [PATCH] Bump to minimum SDK version 19 (Android 4.4) --- app/src/main/AndroidManifest.xml | 1 - .../activity/OnlineFeedViewActivity.java | 4 +- .../dialog/VariableSpeedDialog.java | 5 +- .../ImportExportPreferencesFragment.java | 40 +++++-------- common.gradle | 2 +- .../service/playback/PlaybackService.java | 12 ++-- .../antennapod/core/util/StorageUtils.java | 23 ++------ .../antennapod/core/widget/WidgetUpdater.java | 59 +++++++++---------- core/src/main/res/layout/player_widget.xml | 7 --- core/src/main/res/values/strings.xml | 1 - 10 files changed, 54 insertions(+), 100 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8f100f0f9..45c21ce6b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -73,7 +73,6 @@ - { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN - && description.getMaxLines() > MAX_LINES_COLLAPSED) { + if (description.getMaxLines() > MAX_LINES_COLLAPSED) { description.setMaxLines(MAX_LINES_COLLAPSED); } else { description.setMaxLines(2000); diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java index 1c4f1804c..2bce73b79 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java @@ -1,6 +1,5 @@ package de.danoeh.antennapod.dialog; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -118,9 +117,7 @@ public class VariableSpeedDialog extends BottomSheetDialogFragment { @NonNull public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { Chip chip = new Chip(getContext()); - if (Build.VERSION.SDK_INT >= 17) { - chip.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - } + chip.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); return new ViewHolder(chip); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java index ce0f667df..b72d1eb32 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java @@ -195,18 +195,10 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat { // add a button builder.setNegativeButton(R.string.no, null); builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> { - if (Build.VERSION.SDK_INT >= 19) { - Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); - intent.setType("*/*"); - restoreDatabaseLauncher.launch(intent); - } else { - Intent intent = new Intent(Intent.ACTION_GET_CONTENT); - intent.setType("*/*"); - restoreDatabaseLauncher.launch(Intent.createChooser(intent, - getString(R.string.import_select_file))); - } - } - ); + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + intent.setType("*/*"); + restoreDatabaseLauncher.launch(intent); + }); // create and show the alert dialog builder.show(); @@ -318,20 +310,18 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat { private void openExportPathPicker(String contentType, String title, final ActivityResultLauncher result, ExportWriter writer) { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) { - Intent intentPickAction = new Intent(Intent.ACTION_CREATE_DOCUMENT) - .addCategory(Intent.CATEGORY_OPENABLE) - .setType(contentType) - .putExtra(Intent.EXTRA_TITLE, title); + Intent intentPickAction = new Intent(Intent.ACTION_CREATE_DOCUMENT) + .addCategory(Intent.CATEGORY_OPENABLE) + .setType(contentType) + .putExtra(Intent.EXTRA_TITLE, title); - // Creates an implicit intent to launch a file manager which lets - // the user choose a specific directory to export to. - try { - result.launch(intentPickAction); - return; - } catch (ActivityNotFoundException e) { - Log.e(TAG, "No activity found. Should never happen..."); - } + // Creates an implicit intent to launch a file manager which lets + // the user choose a specific directory to export to. + try { + result.launch(intentPickAction); + return; + } catch (ActivityNotFoundException e) { + Log.e(TAG, "No activity found. Should never happen..."); } // If we are using a SDK lower than API 21 or the implicit intent failed diff --git a/common.gradle b/common.gradle index 8063952ce..fb3045f81 100644 --- a/common.gradle +++ b/common.gradle @@ -2,7 +2,7 @@ android { compileSdkVersion 31 defaultConfig { - minSdkVersion 16 + minSdkVersion 19 targetSdkVersion 30 multiDexEnabled false diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 415b9f1ed..60ccb5c9e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -815,9 +815,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { taskManager.startChapterLoader(newInfo.playable); break; case PAUSED: - if ((UserPreferences.isPersistNotify() || isCasting) && - android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - // do not remove notification on pause based on user pref and whether android version supports expanded notifications + if (UserPreferences.isPersistNotify() || isCasting) { + // do not remove notification on pause based on user pref // Change [Play] button to [Pause] updateNotificationAndMediaSession(newInfo.playable); } else if (!UserPreferences.isPersistNotify() && !isCasting) { @@ -1967,11 +1966,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { PlaybackService.this.updateNotificationAndMediaSession(info.playable); } else { PlayerStatus status = info.playerStatus; - if ((status == PlayerStatus.PLAYING || - status == PlayerStatus.SEEKING || - status == PlayerStatus.PREPARING || - UserPreferences.isPersistNotify()) && - android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + if (status == PlayerStatus.PLAYING || status == PlayerStatus.SEEKING + || status == PlayerStatus.PREPARING || UserPreferences.isPersistNotify()) { PlaybackService.this.updateNotificationAndMediaSession(info.playable); } else if (!UserPreferences.isPersistNotify()) { stateManager.stopForeground(true); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java index 414b5c781..cf049ed80 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java @@ -1,7 +1,6 @@ package de.danoeh.antennapod.core.util; import android.app.Activity; -import android.os.Build; import android.os.StatFs; import android.util.Log; @@ -63,29 +62,15 @@ public class StorageUtils { */ public static long getFreeSpaceAvailable(String path) { StatFs stat = new StatFs(path); - long availableBlocks; - long blockSize; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - availableBlocks = stat.getAvailableBlocksLong(); - blockSize = stat.getBlockSizeLong(); - } else { - availableBlocks = stat.getAvailableBlocks(); - blockSize = stat.getBlockSize(); - } + long availableBlocks = stat.getAvailableBlocksLong(); + long blockSize = stat.getBlockSizeLong(); return availableBlocks * blockSize; } public static long getTotalSpaceAvailable(String path) { StatFs stat = new StatFs(path); - long blockCount; - long blockSize; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - blockCount = stat.getBlockCountLong(); - blockSize = stat.getBlockSizeLong(); - } else { - blockCount = stat.getBlockCount(); - blockSize = stat.getBlockSize(); - } + long blockCount = stat.getBlockCountLong(); + long blockSize = stat.getBlockSizeLong(); return blockCount * blockSize; } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java b/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java index ed3f1800d..5275e7080 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java +++ b/core/src/main/java/de/danoeh/antennapod/core/widget/WidgetUpdater.java @@ -69,9 +69,6 @@ public abstract class WidgetUpdater { if (!PlayerWidget.isEnabled(context) || widgetState == null) { return; } - ComponentName playerWidget = new ComponentName(context, PlayerWidget.class); - AppWidgetManager manager = AppWidgetManager.getInstance(context); - int[] widgetIds = manager.getAppWidgetIds(playerWidget); PendingIntent startMediaPlayer; if (widgetState.media != null && widgetState.media.getMediaType() == MediaType.VIDEO @@ -158,36 +155,36 @@ public abstract class WidgetUpdater { views.setImageViewResource(R.id.butPlayExtended, R.drawable.ic_widget_play); } - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { - for (int id : widgetIds) { - Bundle options = manager.getAppWidgetOptions(id); - SharedPreferences prefs = context.getSharedPreferences(PlayerWidget.PREFS_NAME, Context.MODE_PRIVATE); - int minWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH); - int columns = getCellsForSize(minWidth); - if (columns < 3) { - views.setViewVisibility(R.id.layout_center, View.INVISIBLE); - } else { - views.setViewVisibility(R.id.layout_center, View.VISIBLE); - } - boolean showRewind = prefs.getBoolean(PlayerWidget.KEY_WIDGET_REWIND + id, false); - boolean showFastForward = prefs.getBoolean(PlayerWidget.KEY_WIDGET_FAST_FORWARD + id, false); - boolean showSkip = prefs.getBoolean(PlayerWidget.KEY_WIDGET_SKIP + id, false); + ComponentName playerWidget = new ComponentName(context, PlayerWidget.class); + AppWidgetManager manager = AppWidgetManager.getInstance(context); + int[] widgetIds = manager.getAppWidgetIds(playerWidget); - if (showRewind || showSkip || showFastForward) { - views.setInt(R.id.extendedButtonsContainer, "setVisibility", View.VISIBLE); - views.setInt(R.id.butPlay, "setVisibility", View.GONE); - views.setInt(R.id.butRew, "setVisibility", showRewind ? View.VISIBLE : View.GONE); - views.setInt(R.id.butFastForward, "setVisibility", showFastForward ? View.VISIBLE : View.GONE); - views.setInt(R.id.butSkip, "setVisibility", showSkip ? View.VISIBLE : View.GONE); - } - - int backgroundColor = prefs.getInt(PlayerWidget.KEY_WIDGET_COLOR + id, PlayerWidget.DEFAULT_COLOR); - views.setInt(R.id.widgetLayout, "setBackgroundColor", backgroundColor); - - manager.updateAppWidget(id, views); + for (int id : widgetIds) { + Bundle options = manager.getAppWidgetOptions(id); + SharedPreferences prefs = context.getSharedPreferences(PlayerWidget.PREFS_NAME, Context.MODE_PRIVATE); + int minWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH); + int columns = getCellsForSize(minWidth); + if (columns < 3) { + views.setViewVisibility(R.id.layout_center, View.INVISIBLE); + } else { + views.setViewVisibility(R.id.layout_center, View.VISIBLE); } - } else { - manager.updateAppWidget(playerWidget, views); + boolean showRewind = prefs.getBoolean(PlayerWidget.KEY_WIDGET_REWIND + id, false); + boolean showFastForward = prefs.getBoolean(PlayerWidget.KEY_WIDGET_FAST_FORWARD + id, false); + boolean showSkip = prefs.getBoolean(PlayerWidget.KEY_WIDGET_SKIP + id, false); + + if (showRewind || showSkip || showFastForward) { + views.setInt(R.id.extendedButtonsContainer, "setVisibility", View.VISIBLE); + views.setInt(R.id.butPlay, "setVisibility", View.GONE); + views.setInt(R.id.butRew, "setVisibility", showRewind ? View.VISIBLE : View.GONE); + views.setInt(R.id.butFastForward, "setVisibility", showFastForward ? View.VISIBLE : View.GONE); + views.setInt(R.id.butSkip, "setVisibility", showSkip ? View.VISIBLE : View.GONE); + } + + int backgroundColor = prefs.getInt(PlayerWidget.KEY_WIDGET_COLOR + id, PlayerWidget.DEFAULT_COLOR); + views.setInt(R.id.widgetLayout, "setBackgroundColor", backgroundColor); + + manager.updateAppWidget(id, views); } } diff --git a/core/src/main/res/layout/player_widget.xml b/core/src/main/res/layout/player_widget.xml index a70e98f0f..60d40e6b5 100644 --- a/core/src/main/res/layout/player_widget.xml +++ b/core/src/main/res/layout/player_widget.xml @@ -19,7 +19,6 @@ android:layout_width="@android:dimen/app_icon_size" android:layout_height="match_parent" android:contentDescription="@string/play_label" - android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_margin="12dp" android:background="?android:attr/selectableItemBackground" @@ -31,9 +30,7 @@ android:id="@+id/layout_left" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_alignParentLeft="true" android:layout_alignParentStart="true" - android:layout_toLeftOf="@id/butPlay" android:layout_toStartOf="@id/butPlay" android:background="@android:color/transparent" android:gravity="fill_horizontal" @@ -97,7 +94,6 @@ android:layout_height="36dp" android:background="?android:attr/selectableItemBackground" android:contentDescription="@string/rewind_label" - android:layout_marginRight="2dp" android:layout_marginEnd="2dp" android:scaleType="fitXY" android:src="@drawable/ic_widget_fast_rewind" /> @@ -108,7 +104,6 @@ android:layout_height="36dp" android:background="?android:attr/selectableItemBackground" android:contentDescription="@string/play_label" - android:layout_marginRight="2dp" android:layout_marginEnd="2dp" android:scaleType="fitXY" android:src="@drawable/ic_widget_play" /> @@ -119,7 +114,6 @@ android:layout_height="36dp" android:background="?android:attr/selectableItemBackground" android:contentDescription="@string/fast_forward_label" - android:layout_marginRight="2dp" android:layout_marginEnd="2dp" android:scaleType="fitXY" android:src="@drawable/ic_widget_fast_forward" /> @@ -130,7 +124,6 @@ android:layout_height="36dp" android:background="?android:attr/selectableItemBackground" android:contentDescription="@string/skip_episode_label" - android:layout_marginRight="2dp" android:layout_marginEnd="2dp" android:scaleType="fitXY" android:src="@drawable/ic_widget_skip" /> diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 011a9fe52..1ab5b2184 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -597,7 +597,6 @@ Export successful The exported file was written to:\n\n%1$s Access to external storage is required to read the OPML file - Select file to import Import successful Please press OK to restart AntennaPod This database was exported with a newer version of AntennaPod. Your current installation does not yet know how to handle this file.