diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2024-03-29 13:39:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-29 13:39:19 +0100 |
commit | f9dd837362921df3fbcea424f9e064ecc696f367 (patch) | |
tree | 95cc951dab32ff976a328fbea9897304ee000367 /core/src/main | |
parent | 8f553f08f0347b73b34c80dddef228302cdf5977 (diff) | |
download | AntennaPod-f9dd837362921df3fbcea424f9e064ecc696f367.zip |
Remove ClientConfig class (#7038)
Diffstat (limited to 'core/src/main')
9 files changed, 16 insertions, 124 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/ApplicationCallbacks.java b/core/src/main/java/de/danoeh/antennapod/core/ApplicationCallbacks.java deleted file mode 100644 index 3b591363f..000000000 --- a/core/src/main/java/de/danoeh/antennapod/core/ApplicationCallbacks.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.danoeh.antennapod.core; - -import android.app.Application; - -/** - * Callbacks related to the application in general - */ -public interface ApplicationCallbacks { - - /** - * Returns a non-null instance of the application class - */ - Application getApplicationInstance(); -} diff --git a/core/src/main/java/de/danoeh/antennapod/core/ClientConfig.java b/core/src/main/java/de/danoeh/antennapod/core/ClientConfig.java deleted file mode 100644 index 69abcee93..000000000 --- a/core/src/main/java/de/danoeh/antennapod/core/ClientConfig.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.danoeh.antennapod.core; - -/** - * Stores callbacks for core classes like Services, DB classes etc. and other configuration variables. - * Apps using the core module of AntennaPod should register implementations of all interfaces here. - */ -public class ClientConfig { - public static ApplicationCallbacks applicationCallbacks; -} diff --git a/core/src/main/java/de/danoeh/antennapod/core/ClientConfigurator.java b/core/src/main/java/de/danoeh/antennapod/core/ClientConfigurator.java index b50a1b2ab..48d937266 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/ClientConfigurator.java +++ b/core/src/main/java/de/danoeh/antennapod/core/ClientConfigurator.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.core; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import de.danoeh.antennapod.storage.preferences.SynchronizationSettings; import de.danoeh.antennapod.storage.preferences.SynchronizationCredentials; import de.danoeh.antennapod.storage.preferences.PlaybackPreferences; import de.danoeh.antennapod.storage.preferences.SleepTimerPreferences; @@ -38,6 +39,7 @@ public class ClientConfigurator { PodDBAdapter.init(context); UserPreferences.init(context); SynchronizationCredentials.init(context); + SynchronizationSettings.init(context); UsageStatistics.init(context); PlaybackPreferences.init(context); SslProviderInstaller.install(context); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java index d1334190a..7010d61ba 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/Downloader.java @@ -1,13 +1,10 @@ package de.danoeh.antennapod.core.service.download; -import android.content.Context; -import android.net.wifi.WifiManager; import androidx.annotation.NonNull; import java.util.Date; import java.util.concurrent.Callable; -import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.model.download.DownloadResult; import de.danoeh.antennapod.model.download.DownloadRequest; @@ -39,20 +36,7 @@ public abstract class Downloader implements Callable<Downloader> { protected abstract void download(); public final Downloader call() { - WifiManager wifiManager = (WifiManager) - ClientConfig.applicationCallbacks.getApplicationInstance().getApplicationContext().getSystemService(Context.WIFI_SERVICE); - WifiManager.WifiLock wifiLock = null; - if (wifiManager != null) { - wifiLock = wifiManager.createWifiLock(TAG); - wifiLock.acquire(); - } - download(); - - if (wifiLock != null) { - wifiLock.release(); - } - finished = true; return this; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/EpisodeDownloadWorker.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/EpisodeDownloadWorker.java index 4f9c7a190..9c073713f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/EpisodeDownloadWorker.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/EpisodeDownloadWorker.java @@ -7,6 +7,7 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.net.wifi.WifiManager; import android.os.Build; import android.util.Log; import androidx.annotation.NonNull; @@ -160,12 +161,22 @@ public class EpisodeDownloadWorker extends Worker { return Result.failure(); } + WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); + WifiManager.WifiLock wifiLock = null; + if (wifiManager != null) { + wifiLock = wifiManager.createWifiLock(TAG); + wifiLock.acquire(); + } try { downloader.call(); } catch (Exception e) { DBWriter.addDownloadStatus(downloader.getResult()); sendErrorNotification(request.getTitle()); return Result.failure(); + } finally { + if (wifiLock != null) { + wifiLock.release(); + } } if (downloader.cancelled) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java b/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java index d9399420c..30178edf9 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java @@ -29,6 +29,7 @@ import de.danoeh.antennapod.event.MessageEvent; import de.danoeh.antennapod.model.feed.FeedItemFilter; import de.danoeh.antennapod.model.feed.SortOrder; import de.danoeh.antennapod.storage.preferences.SynchronizationCredentials; +import de.danoeh.antennapod.storage.preferences.SynchronizationSettings; import de.danoeh.antennapod.ui.notifications.NotificationUtils; import org.apache.commons.lang3.StringUtils; import org.greenrobot.eventbus.EventBus; diff --git a/core/src/main/java/de/danoeh/antennapod/core/sync/SynchronizationSettings.java b/core/src/main/java/de/danoeh/antennapod/core/sync/SynchronizationSettings.java deleted file mode 100644 index 1a53ac0fb..000000000 --- a/core/src/main/java/de/danoeh/antennapod/core/sync/SynchronizationSettings.java +++ /dev/null @@ -1,83 +0,0 @@ -package de.danoeh.antennapod.core.sync; - -import android.content.Context; -import android.content.SharedPreferences; - -import de.danoeh.antennapod.core.ClientConfig; - -public class SynchronizationSettings { - - public static final String LAST_SYNC_ATTEMPT_TIMESTAMP = "last_sync_attempt_timestamp"; - private static final String NAME = "synchronization"; - private static final String SELECTED_SYNC_PROVIDER = "selected_sync_provider"; - private static final String LAST_SYNC_ATTEMPT_SUCCESS = "last_sync_attempt_success"; - private static final String LAST_EPISODE_ACTIONS_SYNC_TIMESTAMP = "last_episode_actions_sync_timestamp"; - private static final String LAST_SUBSCRIPTION_SYNC_TIMESTAMP = "last_sync_timestamp"; - - public static boolean isProviderConnected() { - return getSelectedSyncProviderKey() != null; - } - - public static void resetTimestamps() { - getSharedPreferences().edit() - .putLong(LAST_SUBSCRIPTION_SYNC_TIMESTAMP, 0) - .putLong(LAST_EPISODE_ACTIONS_SYNC_TIMESTAMP, 0) - .putLong(LAST_SYNC_ATTEMPT_TIMESTAMP, 0) - .apply(); - } - - public static boolean isLastSyncSuccessful() { - return getSharedPreferences().getBoolean(LAST_SYNC_ATTEMPT_SUCCESS, false); - } - - public static long getLastSyncAttempt() { - return getSharedPreferences().getLong(LAST_SYNC_ATTEMPT_TIMESTAMP, 0); - } - - public static void setSelectedSyncProvider(SynchronizationProviderViewData provider) { - getSharedPreferences() - .edit() - .putString(SELECTED_SYNC_PROVIDER, provider == null ? null : provider.getIdentifier()) - .apply(); - } - - public static String getSelectedSyncProviderKey() { - return getSharedPreferences().getString(SELECTED_SYNC_PROVIDER, null); - } - - public static void updateLastSynchronizationAttempt() { - getSharedPreferences().edit() - .putLong(LAST_SYNC_ATTEMPT_TIMESTAMP, System.currentTimeMillis()) - .apply(); - } - - public static void setLastSynchronizationAttemptSuccess(boolean isSuccess) { - getSharedPreferences().edit() - .putBoolean(LAST_SYNC_ATTEMPT_SUCCESS, isSuccess) - .apply(); - } - - public static long getLastSubscriptionSynchronizationTimestamp() { - return getSharedPreferences().getLong(LAST_SUBSCRIPTION_SYNC_TIMESTAMP, 0); - } - - public static void setLastSubscriptionSynchronizationAttemptTimestamp(long newTimeStamp) { - getSharedPreferences().edit() - .putLong(LAST_SUBSCRIPTION_SYNC_TIMESTAMP, newTimeStamp).apply(); - } - - public static long getLastEpisodeActionSynchronizationTimestamp() { - return getSharedPreferences() - .getLong(LAST_EPISODE_ACTIONS_SYNC_TIMESTAMP, 0); - } - - public static void setLastEpisodeActionSynchronizationAttemptTimestamp(long timestamp) { - getSharedPreferences().edit() - .putLong(LAST_EPISODE_ACTIONS_SYNC_TIMESTAMP, timestamp).apply(); - } - - private static SharedPreferences getSharedPreferences() { - return ClientConfig.applicationCallbacks.getApplicationInstance() - .getSharedPreferences(NAME, Context.MODE_PRIVATE); - } -} diff --git a/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueSink.java b/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueSink.java index cfe3798a7..8d59c9146 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueSink.java +++ b/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueSink.java @@ -3,7 +3,7 @@ package de.danoeh.antennapod.core.sync.queue; import android.content.Context; import de.danoeh.antennapod.core.sync.LockingAsyncExecutor; -import de.danoeh.antennapod.core.sync.SynchronizationSettings; +import de.danoeh.antennapod.storage.preferences.SynchronizationSettings; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.net.sync.model.EpisodeAction; diff --git a/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueStorage.java b/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueStorage.java index e1e373953..407d69fd6 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueStorage.java +++ b/core/src/main/java/de/danoeh/antennapod/core/sync/queue/SynchronizationQueueStorage.java @@ -8,7 +8,7 @@ import org.json.JSONException; import java.util.ArrayList; -import de.danoeh.antennapod.core.sync.SynchronizationSettings; +import de.danoeh.antennapod.storage.preferences.SynchronizationSettings; import de.danoeh.antennapod.net.sync.model.EpisodeAction; public class SynchronizationQueueStorage { |