Merge branch 'master' into develop

This commit is contained in:
ByteHamster 2022-08-04 19:36:38 +02:00
commit eaafd58bd3
5 changed files with 52 additions and 3 deletions

View File

@ -10,8 +10,8 @@ android {
// Version code schema:
// "1.2.3-beta4" -> 1020304
// "1.2.3" -> 1020395
versionCode 2060195
versionName "2.6.1"
versionCode 2060295
versionName "2.6.2"
def commit = ""
try {

View File

@ -5,6 +5,7 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.os.Bundle;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
@ -39,6 +40,7 @@ public class MainPreferencesFragment extends PreferenceFragmentCompat {
private static final String PREF_ABOUT = "prefAbout";
private static final String PREF_NOTIFICATION = "notifications";
private static final String PREF_CONTRIBUTE = "prefContribute";
private static final String PREF_STATISTICS = "statistics";
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@ -128,6 +130,15 @@ public class MainPreferencesFragment extends PreferenceFragmentCompat {
startActivity(new Intent(getActivity(), BugReportActivity.class));
return true;
});
findPreference(PREF_STATISTICS).setOnPreferenceClickListener(
preference -> {
new AlertDialog.Builder(getContext())
.setMessage(R.string.statistics_moved)
.setPositiveButton(android.R.string.ok, null)
.show();
return true;
}
);
}
private String getLocalizedWebsiteLink() {

View File

@ -44,6 +44,12 @@
android:title="@string/notification_pref_fragment"
android:icon="@drawable/ic_notifications"/>
<Preference
android:key="statistics"
android:title="@string/statistics_label"
android:summary="@string/statistics_moved"
android:icon="@drawable/chart_box_outline"/>
<PreferenceCategory
android:key="project"
android:title="@string/project_pref">

View File

@ -2,16 +2,22 @@ package de.danoeh.antennapod.core.receiver;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import androidx.work.ExistingWorkPolicy;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
import de.danoeh.antennapod.core.widget.WidgetUpdaterWorker;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
public class PlayerWidget extends AppWidgetProvider {
private static final String TAG = "PlayerWidget";
public static final String PREFS_NAME = "PlayerWidgetPrefs";
private static final String KEY_WORKAROUND_ENABLED = "WorkaroundEnabled";
private static final String KEY_ENABLED = "WidgetEnabled";
public static final String KEY_WIDGET_COLOR = "widget_color";
public static final String KEY_WIDGET_PLAYBACK_SPEED = "widget_playback_speed";
@ -19,6 +25,7 @@ public class PlayerWidget extends AppWidgetProvider {
public static final String KEY_WIDGET_FAST_FORWARD = "widget_fast_forward";
public static final String KEY_WIDGET_REWIND = "widget_rewind";
public static final int DEFAULT_COLOR = 0x00262C31;
private static final String WORKAROUND_WORK_NAME = "WidgetUpdaterWorkaround";
@Override
public void onEnabled(Context context) {
@ -26,6 +33,7 @@ public class PlayerWidget extends AppWidgetProvider {
Log.d(TAG, "Widget enabled");
setEnabled(context, true);
WidgetUpdaterWorker.enqueueWork(context);
scheduleWorkaround(context);
}
@Override
@ -33,6 +41,12 @@ public class PlayerWidget extends AppWidgetProvider {
Log.d(TAG, "onUpdate() called with: " + "context = [" + context + "], appWidgetManager = ["
+ appWidgetManager + "], appWidgetIds = [" + Arrays.toString(appWidgetIds) + "]");
WidgetUpdaterWorker.enqueueWork(context);
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
if (!prefs.getBoolean(KEY_WORKAROUND_ENABLED, false)) {
scheduleWorkaround(context);
prefs.edit().putBoolean(KEY_WORKAROUND_ENABLED, true).apply();
}
}
@Override
@ -45,17 +59,34 @@ public class PlayerWidget extends AppWidgetProvider {
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
Log.d(TAG, "OnDeleted");
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
for (int appWidgetId : appWidgetIds) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
prefs.edit().remove(KEY_WIDGET_COLOR + appWidgetId).apply();
prefs.edit().remove(KEY_WIDGET_PLAYBACK_SPEED + appWidgetId).apply();
prefs.edit().remove(KEY_WIDGET_REWIND + appWidgetId).apply();
prefs.edit().remove(KEY_WIDGET_FAST_FORWARD + appWidgetId).apply();
prefs.edit().remove(KEY_WIDGET_SKIP + appWidgetId).apply();
}
AppWidgetManager manager = AppWidgetManager.getInstance(context);
int[] widgetIds = manager.getAppWidgetIds(new ComponentName(context, PlayerWidget.class));
if (widgetIds.length == 0) {
prefs.edit().putBoolean(KEY_WORKAROUND_ENABLED, false).apply();
WorkManager.getInstance(context).cancelUniqueWork(WORKAROUND_WORK_NAME);
}
super.onDeleted(context, appWidgetIds);
}
private static void scheduleWorkaround(Context context) {
// Enqueueing work enables a BOOT_COMPLETED receiver, which in turn makes Android refresh widgets.
// This creates an endless loop with a flickering widget.
// Workaround: When there is a widget, schedule a dummy task in the far future, so that the receiver stays.
final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(WidgetUpdaterWorker.class)
.setInitialDelay(100 * 356, TimeUnit.DAYS)
.build();
WorkManager.getInstance(context)
.enqueueUniqueWork(WORKAROUND_WORK_NAME, ExistingWorkPolicy.REPLACE, workRequest);
}
public static boolean isEnabled(Context context) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
return prefs.getBoolean(KEY_ENABLED, false);

View File

@ -349,6 +349,7 @@
<!-- Preferences -->
<string name="storage_pref">Storage</string>
<string name="storage_sum">Episode auto delete, Import, Export</string>
<string name="statistics_moved">The statistics screen was moved to the subscriptions screen. You can open it from there.</string>
<string name="project_pref">Project</string>
<string name="synchronization_pref">Synchronization</string>
<string name="synchronization_sum">Synchronize with other devices</string>