diff options
author | ByteHamster <info@bytehamster.com> | 2022-11-06 11:34:24 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2022-11-06 12:28:30 +0100 |
commit | b140d7297a82dc45037030d4842b60bc2d69df02 (patch) | |
tree | 7faa47ffb3fdbc147c3c30c8fe591463506ea380 /core/src/main | |
parent | e4d4c69519c7854f1852d80a3b47eebe30e6a3d5 (diff) | |
download | AntennaPod-b140d7297a82dc45037030d4842b60bc2d69df02.zip |
Move DownloadService-Interface to new module
Diffstat (limited to 'core/src/main')
25 files changed, 30 insertions, 511 deletions
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 b70a3a61a..8dafa8ed8 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/ClientConfigurator.java +++ b/core/src/main/java/de/danoeh/antennapod/core/ClientConfigurator.java @@ -6,7 +6,7 @@ import de.danoeh.antennapod.core.preferences.SleepTimerPreferences; import de.danoeh.antennapod.core.preferences.UsageStatistics; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; -import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.core.service.download.DownloadServiceInterfaceImpl; import de.danoeh.antennapod.core.sync.SyncService; import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueSink; diff --git a/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java b/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java index ae9b47629..53ed63c2d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/DownloadServiceCallbacks.java @@ -3,7 +3,7 @@ package de.danoeh.antennapod.core; import android.app.PendingIntent; import android.content.Context; -import de.danoeh.antennapod.core.service.download.DownloadRequest; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; /** * Callbacks for the DownloadService of the core module. diff --git a/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java b/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java index d026e1a7b..9046b7165 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java +++ b/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java @@ -8,9 +8,9 @@ import android.content.Context; import android.os.ParcelFileDescriptor; import android.util.Log; -import de.danoeh.antennapod.core.service.download.DownloadRequest; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; -import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import org.apache.commons.io.IOUtils; import org.xmlpull.v1.XmlPullParserException; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/BasicAuthorizationInterceptor.java b/core/src/main/java/de/danoeh/antennapod/core/service/BasicAuthorizationInterceptor.java index 53160e242..77a58e682 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/BasicAuthorizationInterceptor.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/BasicAuthorizationInterceptor.java @@ -3,7 +3,7 @@ package de.danoeh.antennapod.core.service; import android.text.TextUtils; import android.util.Log; import androidx.annotation.NonNull; -import de.danoeh.antennapod.core.service.download.DownloadRequest; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; import de.danoeh.antennapod.core.service.download.HttpCredentialEncoder; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.util.URIUtil; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DefaultDownloaderFactory.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DefaultDownloaderFactory.java index c0de6c825..ff29e2e15 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DefaultDownloaderFactory.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DefaultDownloaderFactory.java @@ -4,6 +4,7 @@ import android.util.Log; import android.webkit.URLUtil; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; public class DefaultDownloaderFactory implements DownloaderFactory { private static final String TAG = "DefaultDwnldrFactory"; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java deleted file mode 100644 index c085bc007..000000000 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java +++ /dev/null @@ -1,331 +0,0 @@ -package de.danoeh.antennapod.core.service.download; - -import android.os.Bundle; -import android.os.Parcel; -import android.os.Parcelable; -import android.text.TextUtils; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import de.danoeh.antennapod.model.feed.Feed; -import de.danoeh.antennapod.core.util.URLChecker; -import de.danoeh.antennapod.model.feed.FeedMedia; - -public class DownloadRequest implements Parcelable { - public static final String REQUEST_ARG_PAGE_NR = "page"; - public static final String REQUEST_ARG_LOAD_ALL_PAGES = "loadAllPages"; - - private final String destination; - private final String source; - private final String title; - private String username; - private String password; - private String lastModified; - private final boolean deleteOnFailure; - private final long feedfileId; - private final int feedfileType; - private final Bundle arguments; - - private int progressPercent; - private long soFar; - private long size; - private int statusMsg; - private boolean mediaEnqueued; - private boolean initiatedByUser; - - public DownloadRequest(@NonNull String destination, @NonNull String source, @NonNull String title, long feedfileId, - int feedfileType, String username, String password, boolean deleteOnFailure, - Bundle arguments, boolean initiatedByUser) { - this(destination, source, title, feedfileId, feedfileType, null, deleteOnFailure, username, password, false, - arguments, initiatedByUser); - } - - private DownloadRequest(Builder builder) { - this(builder.destination, builder.source, builder.title, builder.feedfileId, builder.feedfileType, - builder.lastModified, builder.deleteOnFailure, builder.username, builder.password, false, - builder.arguments != null ? builder.arguments : new Bundle(), builder.initiatedByUser); - } - - private DownloadRequest(Parcel in) { - this(in.readString(), in.readString(), in.readString(), in.readLong(), in.readInt(), in.readString(), - in.readByte() > 0, nullIfEmpty(in.readString()), nullIfEmpty(in.readString()), in.readByte() > 0, - in.readBundle(), in.readByte() > 0); - } - - private DownloadRequest(String destination, String source, String title, long feedfileId, int feedfileType, - String lastModified, boolean deleteOnFailure, String username, String password, - boolean mediaEnqueued, Bundle arguments, boolean initiatedByUser) { - this.destination = destination; - this.source = source; - this.title = title; - this.feedfileId = feedfileId; - this.feedfileType = feedfileType; - this.lastModified = lastModified; - this.deleteOnFailure = deleteOnFailure; - this.username = username; - this.password = password; - this.mediaEnqueued = mediaEnqueued; - this.arguments = arguments; - this.initiatedByUser = initiatedByUser; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeString(destination); - dest.writeString(source); - dest.writeString(title); - dest.writeLong(feedfileId); - dest.writeInt(feedfileType); - dest.writeString(lastModified); - dest.writeByte((deleteOnFailure) ? (byte) 1 : 0); - // in case of null username/password, still write an empty string - // (rather than skipping it). Otherwise, unmarshalling a collection - // of them from a Parcel (from an Intent extra to submit a request to DownloadService) will fail. - // - // see: https://stackoverflow.com/a/22926342 - dest.writeString(nonNullString(username)); - dest.writeString(nonNullString(password)); - dest.writeByte((mediaEnqueued) ? (byte) 1 : 0); - dest.writeBundle(arguments); - dest.writeByte(initiatedByUser ? (byte) 1 : 0); - } - - private static String nonNullString(String str) { - return str != null ? str : ""; - } - - private static String nullIfEmpty(String str) { - return TextUtils.isEmpty(str) ? null : str; - } - - public static final Parcelable.Creator<DownloadRequest> CREATOR = new Parcelable.Creator<DownloadRequest>() { - public DownloadRequest createFromParcel(Parcel in) { - return new DownloadRequest(in); - } - - public DownloadRequest[] newArray(int size) { - return new DownloadRequest[size]; - } - }; - - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof DownloadRequest)) return false; - - DownloadRequest that = (DownloadRequest) o; - - if (lastModified != null ? !lastModified.equals(that.lastModified) : that.lastModified != null) - return false; - if (deleteOnFailure != that.deleteOnFailure) return false; - if (feedfileId != that.feedfileId) return false; - if (feedfileType != that.feedfileType) return false; - if (progressPercent != that.progressPercent) return false; - if (size != that.size) return false; - if (soFar != that.soFar) return false; - if (statusMsg != that.statusMsg) return false; - if (!destination.equals(that.destination)) return false; - if (password != null ? !password.equals(that.password) : that.password != null) - return false; - if (!source.equals(that.source)) return false; - if (title != null ? !title.equals(that.title) : that.title != null) return false; - if (username != null ? !username.equals(that.username) : that.username != null) - return false; - if (mediaEnqueued != that.mediaEnqueued) return false; - if (initiatedByUser != that.initiatedByUser) return false; - return true; - } - - @Override - public int hashCode() { - int result = destination.hashCode(); - result = 31 * result + source.hashCode(); - result = 31 * result + (title != null ? title.hashCode() : 0); - result = 31 * result + (username != null ? username.hashCode() : 0); - result = 31 * result + (password != null ? password.hashCode() : 0); - result = 31 * result + (lastModified != null ? lastModified.hashCode() : 0); - result = 31 * result + (deleteOnFailure ? 1 : 0); - result = 31 * result + (int) (feedfileId ^ (feedfileId >>> 32)); - result = 31 * result + feedfileType; - result = 31 * result + arguments.hashCode(); - result = 31 * result + progressPercent; - result = 31 * result + (int) (soFar ^ (soFar >>> 32)); - result = 31 * result + (int) (size ^ (size >>> 32)); - result = 31 * result + statusMsg; - result = 31 * result + (mediaEnqueued ? 1 : 0); - return result; - } - - public String getDestination() { - return destination; - } - - public String getSource() { - return source; - } - - public String getTitle() { - return title; - } - - public long getFeedfileId() { - return feedfileId; - } - - public int getFeedfileType() { - return feedfileType; - } - - public int getProgressPercent() { - return progressPercent; - } - - public void setProgressPercent(int progressPercent) { - this.progressPercent = progressPercent; - } - - public long getSoFar() { - return soFar; - } - - public void setSoFar(long soFar) { - this.soFar = soFar; - } - - public long getSize() { - return size; - } - - public void setSize(long size) { - this.size = size; - } - - public void setStatusMsg(int statusMsg) { - this.statusMsg = statusMsg; - } - - public String getUsername() { - return username; - } - - public String getPassword() { - return password; - } - - public void setUsername(String username) { - this.username = username; - } - - public void setPassword(String password) { - this.password = password; - } - - public DownloadRequest setLastModified(@Nullable String lastModified) { - this.lastModified = lastModified; - return this; - } - - @Nullable - public String getLastModified() { - return lastModified; - } - - public boolean isDeleteOnFailure() { - return deleteOnFailure; - } - - public boolean isMediaEnqueued() { - return mediaEnqueued; - } - - public boolean isInitiatedByUser() { - return initiatedByUser; - } - - /** - * Set to true if the media is enqueued because of this download. - * The state is helpful if the download is cancelled, and undoing the enqueue is needed. - */ - public void setMediaEnqueued(boolean mediaEnqueued) { - this.mediaEnqueued = mediaEnqueued; - } - - public Bundle getArguments() { - return arguments; - } - - public static class Builder { - private final String destination; - private final String source; - private final String title; - private String username; - private String password; - private String lastModified; - private boolean deleteOnFailure = false; - private final long feedfileId; - private final int feedfileType; - private final Bundle arguments = new Bundle(); - private boolean initiatedByUser = true; - - public Builder(@NonNull String destination, @NonNull FeedMedia media) { - this.destination = destination; - this.source = URLChecker.prepareURL(media.getDownload_url()); - this.title = media.getHumanReadableIdentifier(); - this.feedfileId = media.getId(); - this.feedfileType = media.getTypeAsInt(); - } - - public Builder(@NonNull String destination, @NonNull Feed feed) { - this.destination = destination; - this.source = feed.isLocalFeed() ? feed.getDownload_url() : URLChecker.prepareURL(feed.getDownload_url()); - this.title = feed.getHumanReadableIdentifier(); - this.feedfileId = feed.getId(); - this.feedfileType = feed.getTypeAsInt(); - arguments.putInt(REQUEST_ARG_PAGE_NR, feed.getPageNr()); - } - - public Builder withInitiatedByUser(boolean initiatedByUser) { - this.initiatedByUser = initiatedByUser; - return this; - } - - public void setForce(boolean force) { - if (force) { - lastModified = null; - } - } - - public Builder deleteOnFailure(boolean deleteOnFailure) { - this.deleteOnFailure = deleteOnFailure; - return this; - } - - public Builder lastModified(String lastModified) { - this.lastModified = lastModified; - return this; - } - - public Builder withAuthentication(String username, String password) { - this.username = username; - this.password = password; - return this; - } - - public void loadAllPages(boolean loadAllPages) { - if (loadAllPages) { - arguments.putBoolean(REQUEST_ARG_LOAD_ALL_PAGES, true); - } - } - - public DownloadRequest build() { - return new DownloadRequest(this); - } - } -} diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequestCreator.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequestCreator.java index c33e6b4d6..55546a7db 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequestCreator.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequestCreator.java @@ -6,6 +6,7 @@ import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.FileNameGenerator; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedMedia; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; import org.apache.commons.io.FilenameUtils; import java.io.File; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index 12bbf83d0..751cf0b9b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -21,6 +21,8 @@ import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.feed.LocalFeedUpdater; import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithmFactory; import de.danoeh.antennapod.model.download.DownloadStatus; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import org.apache.commons.io.FileUtils; import org.greenrobot.eventbus.EventBus; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceInterface.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceInterface.java deleted file mode 100644 index aa4b16490..000000000 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceInterface.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.danoeh.antennapod.core.service.download; - -import android.content.Context; - -public abstract class DownloadServiceInterface { - private static DownloadServiceInterface impl; - - public static DownloadServiceInterface get() { - return impl; - } - - public static void setImpl(DownloadServiceInterface impl) { - DownloadServiceInterface.impl = impl; - } - - public abstract void download(Context context, boolean cleanupMedia, DownloadRequest... requests); - - public abstract void refreshAllFeeds(Context context, boolean initiatedByUser); - - public abstract void cancel(Context context, String url); - - public abstract void cancelAll(Context context); -} diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceInterfaceImpl.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceInterfaceImpl.java index f8d34174e..384a6070e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceInterfaceImpl.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceInterfaceImpl.java @@ -5,6 +5,8 @@ import android.content.Intent; import androidx.core.content.ContextCompat; import com.google.android.exoplayer2.util.Log; import de.danoeh.antennapod.core.BuildConfig; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import java.util.ArrayList; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java index e24922ab0..ea1e68bbf 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadServiceNotification.java @@ -14,6 +14,7 @@ import de.danoeh.antennapod.model.download.DownloadStatus; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.core.util.gui.NotificationUtils; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; import java.util.List; 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 22c4e9b87..f7f5e8e9c 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 @@ -10,6 +10,7 @@ import java.util.concurrent.Callable; import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.model.download.DownloadStatus; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; /** * Downloads files diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloaderFactory.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloaderFactory.java index d96210a6e..48601c4f7 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloaderFactory.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloaderFactory.java @@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.service.download; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; public interface DownloaderFactory { @Nullable diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java index 9a2a10490..a0a0615cb 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java @@ -6,6 +6,7 @@ import android.util.Log; import de.danoeh.antennapod.core.util.NetworkUtils; import de.danoeh.antennapod.model.download.DownloadStatus; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; import okhttp3.CacheControl; import okhttp3.internal.http.StatusLine; import org.apache.commons.io.IOUtils; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/LocalFeedStubDownloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/LocalFeedStubDownloader.java index feb5fc6be..750255958 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/LocalFeedStubDownloader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/LocalFeedStubDownloader.java @@ -1,6 +1,7 @@ package de.danoeh.antennapod.core.service.download; import androidx.annotation.NonNull; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; /** * This does not actually download, but it keeps track of a local feed's refresh state. diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FailedDownloadHandler.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FailedDownloadHandler.java index 748559909..937f051ec 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FailedDownloadHandler.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FailedDownloadHandler.java @@ -2,7 +2,7 @@ package de.danoeh.antennapod.core.service.download.handler; import android.util.Log; import de.danoeh.antennapod.model.feed.Feed; -import de.danoeh.antennapod.core.service.download.DownloadRequest; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; import de.danoeh.antennapod.core.storage.DBWriter; /** diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java index dc5893b23..a5ed5c3dd 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedParserTask.java @@ -7,7 +7,7 @@ import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedPreferences; import de.danoeh.antennapod.model.feed.VolumeAdaptionSetting; -import de.danoeh.antennapod.core.service.download.DownloadRequest; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; import de.danoeh.antennapod.model.download.DownloadStatus; import de.danoeh.antennapod.parser.feed.FeedHandler; import de.danoeh.antennapod.parser.feed.FeedHandlerResult; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedSyncTask.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedSyncTask.java index 5e97c233f..07670bff3 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedSyncTask.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/FeedSyncTask.java @@ -4,7 +4,7 @@ import android.content.Context; import androidx.annotation.NonNull; import de.danoeh.antennapod.model.feed.Feed; -import de.danoeh.antennapod.core.service.download.DownloadRequest; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; import de.danoeh.antennapod.model.download.DownloadStatus; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.parser.feed.FeedHandlerResult; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java index b30f44eec..442e3173d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/handler/MediaDownloadedHandler.java @@ -12,7 +12,7 @@ import java.io.File; import java.util.concurrent.ExecutionException; import de.danoeh.antennapod.event.UnreadItemsUpdateEvent; -import de.danoeh.antennapod.core.service.download.DownloadRequest; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; import de.danoeh.antennapod.model.download.DownloadStatus; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java b/core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java index 4d8a0c25e..4ad2aa665 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/AutomaticDownloadAlgorithm.java @@ -7,9 +7,9 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import de.danoeh.antennapod.core.service.download.DownloadRequest; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; -import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.core.util.PlaybackStatus; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedPreferences; diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java index 13a18b0d7..9a9525324 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java @@ -10,9 +10,9 @@ import android.util.Log; import androidx.annotation.VisibleForTesting; -import de.danoeh.antennapod.core.service.download.DownloadRequest; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; -import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.storage.database.PodDBAdapter; import de.danoeh.antennapod.storage.database.mapper.FeedCursorMapper; import org.greenrobot.eventbus.EventBus; diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index fbcb86586..48d88f803 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -8,7 +8,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.NotificationManagerCompat; -import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.core.service.playback.PlaybackServiceInterface; import de.danoeh.antennapod.storage.database.PodDBAdapter; import org.greenrobot.eventbus.EventBus; 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 c304d67d2..952c047c7 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 @@ -20,10 +20,10 @@ import androidx.work.WorkManager; import androidx.work.Worker; import androidx.work.WorkerParameters; -import de.danoeh.antennapod.core.service.download.DownloadRequest; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; import de.danoeh.antennapod.core.service.download.DownloadService; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; -import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import org.apache.commons.lang3.StringUtils; import org.greenrobot.eventbus.EventBus; @@ -42,7 +42,7 @@ import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.sync.queue.SynchronizationQueueStorage; import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.LongList; -import de.danoeh.antennapod.core.util.URLChecker; +import de.danoeh.antennapod.net.common.UrlChecker; import de.danoeh.antennapod.core.util.gui.NotificationUtils; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedItem; @@ -150,7 +150,7 @@ public class SyncService extends Worker { Log.d(TAG, "Skipping url: " + downloadUrl); continue; } - if (!URLChecker.containsUrl(localSubscriptions, downloadUrl) && !queuedRemovedFeeds.contains(downloadUrl)) { + if (!UrlChecker.containsUrl(localSubscriptions, downloadUrl) && !queuedRemovedFeeds.contains(downloadUrl)) { Feed feed = new Feed(downloadUrl, null); DownloadRequest.Builder builder = DownloadRequestCreator.create(feed); DownloadServiceInterface.get().download(getApplicationContext(), false, builder.build()); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/URLChecker.java b/core/src/main/java/de/danoeh/antennapod/core/util/URLChecker.java deleted file mode 100644 index a72d2034b..000000000 --- a/core/src/main/java/de/danoeh/antennapod/core/util/URLChecker.java +++ /dev/null @@ -1,138 +0,0 @@ -package de.danoeh.antennapod.core.util; - -import android.net.Uri; -import android.text.TextUtils; -import androidx.annotation.NonNull; -import android.util.Log; - -import okhttp3.HttpUrl; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.List; - -/** - * Provides methods for checking and editing a URL. - */ -public final class URLChecker { - - /** - * Class shall not be instantiated. - */ - private URLChecker() { - } - - /** - * Logging tag. - */ - private static final String TAG = "URLChecker"; - - private static final String AP_SUBSCRIBE = "antennapod-subscribe://"; - private static final String AP_SUBSCRIBE_DEEPLINK = "antennapod.org/deeplink/subscribe"; - - /** - * Checks if URL is valid and modifies it if necessary. - * - * @param url The url which is going to be prepared - * @return The prepared url - */ - public static String prepareURL(@NonNull String url) { - url = url.trim(); - String lowerCaseUrl = url.toLowerCase(); // protocol names are case insensitive - if (lowerCaseUrl.startsWith("feed://")) { - Log.d(TAG, "Replacing feed:// with http://"); - return prepareURL(url.substring("feed://".length())); - } else if (lowerCaseUrl.startsWith("pcast://")) { - Log.d(TAG, "Removing pcast://"); - return prepareURL(url.substring("pcast://".length())); - } else if (lowerCaseUrl.startsWith("pcast:")) { - Log.d(TAG, "Removing pcast:"); - return prepareURL(url.substring("pcast:".length())); - } else if (lowerCaseUrl.startsWith("itpc")) { - Log.d(TAG, "Replacing itpc:// with http://"); - return prepareURL(url.substring("itpc://".length())); - } else if (lowerCaseUrl.startsWith(AP_SUBSCRIBE)) { - Log.d(TAG, "Removing antennapod-subscribe://"); - return prepareURL(url.substring(AP_SUBSCRIBE.length())); - } else if (lowerCaseUrl.contains(AP_SUBSCRIBE_DEEPLINK)) { - Log.d(TAG, "Removing " + AP_SUBSCRIBE_DEEPLINK); - String removedWebsite = url.substring(url.indexOf("?url=") + "?url=".length()); - try { - return prepareURL(URLDecoder.decode(removedWebsite, "UTF-8")); - } catch (UnsupportedEncodingException e) { - return prepareURL(removedWebsite); - } - } else if (!(lowerCaseUrl.startsWith("http://") || lowerCaseUrl.startsWith("https://"))) { - Log.d(TAG, "Adding http:// at the beginning of the URL"); - return "http://" + url; - } else { - return url; - } - } - - /** - * Checks if URL is valid and modifies it if necessary. - * This method also handles protocol relative URLs. - * - * @param url The url which is going to be prepared - * @param base The url against which the (possibly relative) url is applied. If this is null, - * the result of prepareURL(url) is returned instead. - * @return The prepared url - */ - public static String prepareURL(String url, String base) { - if (base == null) { - return prepareURL(url); - } - url = url.trim(); - base = prepareURL(base); - Uri urlUri = Uri.parse(url); - Uri baseUri = Uri.parse(base); - if (urlUri.isRelative() && baseUri.isAbsolute()) { - return urlUri.buildUpon().scheme(baseUri.getScheme()).build().toString(); - } else { - return prepareURL(url); - } - } - - public static boolean containsUrl(List<String> list, String url) { - for (String item : list) { - if (urlEquals(item, url)) { - return true; - } - } - return false; - } - - public static boolean urlEquals(String string1, String string2) { - HttpUrl url1 = HttpUrl.parse(string1); - HttpUrl url2 = HttpUrl.parse(string2); - if (!url1.host().equals(url2.host())) { - return false; - } - List<String> pathSegments1 = normalizePathSegments(url1.pathSegments()); - List<String> pathSegments2 = normalizePathSegments(url2.pathSegments()); - if (!pathSegments1.equals(pathSegments2)) { - return false; - } - if (TextUtils.isEmpty(url1.query())) { - return TextUtils.isEmpty(url2.query()); - } - return url1.query().equals(url2.query()); - } - - /** - * Removes empty segments and converts all to lower case. - * @param input List of path segments - * @return Normalized list of path segments - */ - private static List<String> normalizePathSegments(List<String> input) { - List<String> result = new ArrayList<>(); - for (String string : input) { - if (!TextUtils.isEmpty(string)) { - result.add(string.toLowerCase()); - } - } - return result; - } -} diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/download/NetworkConnectionChangeHandler.java b/core/src/main/java/de/danoeh/antennapod/core/util/download/NetworkConnectionChangeHandler.java index 0eca498c9..0547e353b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/download/NetworkConnectionChangeHandler.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/download/NetworkConnectionChangeHandler.java @@ -2,7 +2,7 @@ package de.danoeh.antennapod.core.util.download; import android.content.Context; import com.google.android.exoplayer2.util.Log; -import de.danoeh.antennapod.core.service.download.DownloadServiceInterface; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.util.NetworkUtils; |