Migrate notification channel settings

This commit is contained in:
ByteHamster 2020-10-29 20:39:50 +01:00
parent 151cccce66
commit 7ac4f18561
2 changed files with 38 additions and 1 deletions

View File

@ -307,6 +307,13 @@ public class UserPreferences {
return prefs.getBoolean(PREF_SHOW_DOWNLOAD_REPORT, true);
}
/**
* Used for migration of the preference to system notification channels.
*/
public static boolean getShowDownloadReportRaw() {
return prefs.getBoolean(PREF_SHOW_DOWNLOAD_REPORT, true);
}
public static boolean showAutoDownloadReport() {
if (Build.VERSION.SDK_INT >= 26) {
return true; // System handles notification preferences
@ -314,6 +321,13 @@ public class UserPreferences {
return prefs.getBoolean(PREF_SHOW_AUTO_DOWNLOAD_REPORT, false);
}
/**
* Used for migration of the preference to system notification channels.
*/
public static boolean getShowAutoDownloadReportRaw() {
return prefs.getBoolean(PREF_SHOW_AUTO_DOWNLOAD_REPORT, false);
}
public static boolean enqueueDownloadedEpisodes() {
return prefs.getBoolean(PREF_ENQUEUE_DOWNLOADED, true);
}
@ -740,6 +754,13 @@ public class UserPreferences {
return prefs.getBoolean(PREF_GPODNET_NOTIFICATIONS, true);
}
/**
* Used for migration of the preference to system notification channels.
*/
public static boolean getGpodnetNotificationsEnabledRaw() {
return prefs.getBoolean(PREF_GPODNET_NOTIFICATIONS, true);
}
public static void setGpodnetNotificationsEnabled() {
prefs.edit()
.putBoolean(PREF_GPODNET_NOTIFICATIONS, true)

View File

@ -9,6 +9,7 @@ import android.os.Build;
import androidx.annotation.RequiresApi;
import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.preferences.UserPreferences;
public class NotificationUtils {
public static final String CHANNEL_ID_USER_ACTION = "user_action";
@ -73,6 +74,11 @@ public class NotificationUtils {
c.getString(R.string.notification_channel_download_error), NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setDescription(c.getString(R.string.notification_channel_download_error_description));
notificationChannel.setGroup(GROUP_ID_ERRORS);
if (!UserPreferences.getShowDownloadReportRaw()) {
// Migration from app managed setting: disable notification
notificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE);
}
return notificationChannel;
}
@ -82,15 +88,25 @@ public class NotificationUtils {
c.getString(R.string.notification_channel_sync_error), NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setDescription(c.getString(R.string.notification_channel_sync_error_description));
notificationChannel.setGroup(GROUP_ID_ERRORS);
if (!UserPreferences.getGpodnetNotificationsEnabledRaw()) {
// Migration from app managed setting: disable notification
notificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE);
}
return notificationChannel;
}
@RequiresApi(api = Build.VERSION_CODES.O)
private static NotificationChannel createChannelAutoDownload(Context c) {
NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID_AUTO_DOWNLOAD,
c.getString(R.string.notification_channel_auto_download), NotificationManager.IMPORTANCE_DEFAULT);
c.getString(R.string.notification_channel_auto_download), NotificationManager.IMPORTANCE_NONE);
notificationChannel.setDescription(c.getString(R.string.notification_channel_episode_auto_download));
notificationChannel.setGroup(GROUP_ID_NEWS);
if (UserPreferences.getShowAutoDownloadReportRaw()) {
// Migration from app managed setting: enable notification
notificationChannel.setImportance(NotificationManager.IMPORTANCE_DEFAULT);
}
return notificationChannel;
}