diff --git a/app/src/androidTest/java/de/test/antennapod/service/download/HttpDownloaderTest.java b/app/src/androidTest/java/de/test/antennapod/service/download/HttpDownloaderTest.java index 5cdedc1ac..46800dd50 100644 --- a/app/src/androidTest/java/de/test/antennapod/service/download/HttpDownloaderTest.java +++ b/app/src/androidTest/java/de/test/antennapod/service/download/HttpDownloaderTest.java @@ -9,7 +9,7 @@ import java.io.IOException; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.storage.preferences.UserPreferences; -import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; +import de.danoeh.antennapod.model.download.DownloadRequest; import de.danoeh.antennapod.model.download.DownloadResult; import de.danoeh.antennapod.core.service.download.Downloader; import de.danoeh.antennapod.core.service.download.HttpDownloader; diff --git a/app/src/main/java/de/danoeh/antennapod/PodcastApp.java b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java index 8e840885b..ab52bc98a 100644 --- a/app/src/main/java/de/danoeh/antennapod/PodcastApp.java +++ b/app/src/main/java/de/danoeh/antennapod/PodcastApp.java @@ -30,7 +30,6 @@ public class PodcastApp extends Application { @Override public void onCreate() { super.onCreate(); - ClientConfig.USER_AGENT = "AntennaPod/" + BuildConfig.VERSION_NAME; ClientConfig.applicationCallbacks = new ApplicationCallbacksImpl(); Thread.setDefaultUncaughtExceptionHandler(new CrashReportWriter()); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java index 66d9a4556..7afb98fd1 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -44,7 +44,7 @@ import de.danoeh.antennapod.event.PlayerStatusEvent; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.storage.preferences.UserPreferences; -import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; +import de.danoeh.antennapod.model.download.DownloadRequest; import de.danoeh.antennapod.model.download.DownloadResult; import de.danoeh.antennapod.core.service.download.Downloader; import de.danoeh.antennapod.core.service.download.HttpDownloader; diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistDescriptionAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistDescriptionAdapter.java index a8c29d9ee..9518272bd 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistDescriptionAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistDescriptionAdapter.java @@ -13,7 +13,7 @@ import androidx.annotation.Nullable; import de.danoeh.antennapod.R; import de.danoeh.antennapod.model.playback.MediaType; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.NetworkUtils; import de.danoeh.antennapod.model.playback.RemoteMedia; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.core.service.playback.PlaybackService; diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java index 4d5b0b6d5..31ab2195c 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/DownloadActionButton.java @@ -13,7 +13,7 @@ import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterfa import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.core.preferences.UsageStatistics; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.NetworkUtils; public class DownloadActionButton extends ItemActionButton { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java index 2f5cb5430..afaca2bed 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/actionbutton/StreamActionButton.java @@ -11,7 +11,7 @@ import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.model.playback.MediaType; import de.danoeh.antennapod.core.preferences.UsageStatistics; import de.danoeh.antennapod.core.service.playback.PlaybackService; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.NetworkUtils; import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter; import de.danoeh.antennapod.dialog.StreamingConfirmationDialog; diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java index 64b85a94e..8c7a30bff 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/ProxyDialog.java @@ -28,7 +28,7 @@ import java.util.concurrent.TimeUnit; import de.danoeh.antennapod.R; import de.danoeh.antennapod.storage.preferences.UserPreferences; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; import de.danoeh.antennapod.model.download.ProxyConfig; import de.danoeh.antennapod.ui.common.ThemeUtils; import io.reactivex.Completable; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/synchronization/GpodderAuthenticationFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/synchronization/GpodderAuthenticationFragment.java index e340d6c1d..ccd450345 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/synchronization/GpodderAuthenticationFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/synchronization/GpodderAuthenticationFragment.java @@ -19,7 +19,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import androidx.fragment.app.DialogFragment; import com.google.android.material.button.MaterialButton; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; import de.danoeh.antennapod.core.sync.SyncService; import de.danoeh.antennapod.core.sync.SynchronizationCredentials; import de.danoeh.antennapod.core.sync.SynchronizationProviderViewData; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/synchronization/NextcloudAuthenticationFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/synchronization/NextcloudAuthenticationFragment.java index 2c9e555f1..88f7ec036 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/synchronization/NextcloudAuthenticationFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/synchronization/NextcloudAuthenticationFragment.java @@ -9,7 +9,7 @@ import androidx.annotation.Nullable; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import androidx.fragment.app.DialogFragment; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; import de.danoeh.antennapod.core.sync.SyncService; import de.danoeh.antennapod.core.sync.SynchronizationCredentials; import de.danoeh.antennapod.core.sync.SynchronizationProviderViewData; diff --git a/app/src/main/java/de/danoeh/antennapod/view/ShownotesWebView.java b/app/src/main/java/de/danoeh/antennapod/view/ShownotesWebView.java index c880ab5a6..f470b0aac 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/ShownotesWebView.java +++ b/app/src/main/java/de/danoeh/antennapod/view/ShownotesWebView.java @@ -27,7 +27,7 @@ import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.menuhandler.MenuItemUtils; import de.danoeh.antennapod.ui.common.Converter; import de.danoeh.antennapod.core.util.IntentUtils; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.NetworkUtils; import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.core.util.gui.ShownotesCleaner; diff --git a/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java b/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java index 8344c51cb..391270fe0 100644 --- a/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java +++ b/app/src/main/java/de/danoeh/antennapod/view/viewholder/EpisodeItemViewHolder.java @@ -31,7 +31,7 @@ import de.danoeh.antennapod.core.feed.util.ImageResourceUtils; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.ui.common.Converter; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.NetworkUtils; import de.danoeh.antennapod.model.playback.Playable; import de.danoeh.antennapod.ui.common.CircularProgressBar; import de.danoeh.antennapod.ui.common.ThemeUtils; diff --git a/config/spotbugs/exclude.xml b/config/spotbugs/exclude.xml index 7469f93e3..5d41dc746 100644 --- a/config/spotbugs/exclude.xml +++ b/config/spotbugs/exclude.xml @@ -36,6 +36,10 @@ + + + + diff --git a/core/src/main/java/de/danoeh/antennapod/core/ClientConfig.java b/core/src/main/java/de/danoeh/antennapod/core/ClientConfig.java index 360c8c9e2..69abcee93 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/ClientConfig.java +++ b/core/src/main/java/de/danoeh/antennapod/core/ClientConfig.java @@ -5,10 +5,5 @@ package de.danoeh.antennapod.core; * Apps using the core module of AntennaPod should register implementations of all interfaces here. */ public class ClientConfig { - /** - * Should be used when setting User-Agent header for HTTP-requests. - */ - public static String USER_AGENT; - 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 86d65bbff..85ba7a3d5 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/ClientConfigurator.java +++ b/core/src/main/java/de/danoeh/antennapod/core/ClientConfigurator.java @@ -1,16 +1,19 @@ package de.danoeh.antennapod.core; import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.preferences.SleepTimerPreferences; import de.danoeh.antennapod.core.preferences.UsageStatistics; +import de.danoeh.antennapod.net.common.UserAgentInterceptor; import de.danoeh.antennapod.storage.preferences.UserPreferences; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; 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; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.NetworkUtils; import de.danoeh.antennapod.core.util.download.NetworkConnectionChangeHandler; import de.danoeh.antennapod.net.ssl.SslProviderInstaller; import de.danoeh.antennapod.storage.database.PodDBAdapter; @@ -25,6 +28,12 @@ public class ClientConfigurator { if (initialized) { return; } + try { + PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); + UserAgentInterceptor.USER_AGENT = "AntennaPod/" + packageInfo.versionName; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } PodDBAdapter.init(context); UserPreferences.init(context); UsageStatistics.init(context); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateWorker.java b/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateWorker.java index 2ec938730..5e864c5c0 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateWorker.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateWorker.java @@ -27,13 +27,14 @@ import de.danoeh.antennapod.core.service.download.handler.FeedSyncTask; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBWriter; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.NetworkUtils; import de.danoeh.antennapod.core.util.download.FeedUpdateManager; import de.danoeh.antennapod.model.download.DownloadError; import de.danoeh.antennapod.model.download.DownloadResult; import de.danoeh.antennapod.model.feed.Feed; -import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; +import de.danoeh.antennapod.model.download.DownloadRequest; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequestBuilder; import de.danoeh.antennapod.ui.notifications.NotificationUtils; import java.util.ArrayList; import java.util.Collections; @@ -166,7 +167,7 @@ public class FeedUpdateWorker extends Worker { if (nextPage) { feed.setPageNr(feed.getPageNr() + 1); } - DownloadRequest.Builder builder = DownloadRequestCreator.create(feed); + DownloadRequestBuilder builder = DownloadRequestCreator.create(feed); builder.setForce(force || feed.hasLastUpdateFailed()); if (nextPage) { builder.setSource(feed.getNextPageLink()); 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 ff29e2e15..a1cc9bf6d 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,7 +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; +import de.danoeh.antennapod.model.download.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/DownloadRequestCreator.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequestCreator.java index 9ade2f03a..459ca71aa 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 @@ -2,11 +2,11 @@ package de.danoeh.antennapod.core.service.download; import android.util.Log; import android.webkit.URLUtil; +import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequestBuilder; import de.danoeh.antennapod.storage.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; @@ -19,7 +19,7 @@ public class DownloadRequestCreator { private static final String FEED_DOWNLOADPATH = "cache/"; private static final String MEDIA_DOWNLOADPATH = "media/"; - public static DownloadRequest.Builder create(Feed feed) { + public static DownloadRequestBuilder create(Feed feed) { File dest = new File(getFeedfilePath(), getFeedfileName(feed)); if (dest.exists()) { dest.delete(); @@ -29,12 +29,12 @@ public class DownloadRequestCreator { String username = (feed.getPreferences() != null) ? feed.getPreferences().getUsername() : null; String password = (feed.getPreferences() != null) ? feed.getPreferences().getPassword() : null; - return new DownloadRequest.Builder(dest.toString(), feed) + return new DownloadRequestBuilder(dest.toString(), feed) .withAuthentication(username, password) .lastModified(feed.getLastModified()); } - public static DownloadRequest.Builder create(FeedMedia media) { + public static DownloadRequestBuilder create(FeedMedia media) { final boolean partiallyDownloadedFileExists = media.getFile_url() != null && new File(media.getFile_url()).exists(); File dest; @@ -54,7 +54,7 @@ public class DownloadRequestCreator { String password = (media.getItem().getFeed().getPreferences() != null) ? media.getItem().getFeed().getPreferences().getPassword() : null; - return new DownloadRequest.Builder(dest.toString(), media) + return new DownloadRequestBuilder(dest.toString(), media) .withAuthentication(username, password); } 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 35247509d..d1334190a 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,7 +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.DownloadResult; -import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; +import de.danoeh.antennapod.model.download.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 48601c4f7..45ad45381 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,7 +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; +import de.danoeh.antennapod.model.download.DownloadRequest; public interface DownloaderFactory { @Nullable 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 1e943eed8..6957c25b1 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 @@ -27,7 +27,7 @@ import de.danoeh.antennapod.event.MessageEvent; import de.danoeh.antennapod.model.download.DownloadError; import de.danoeh.antennapod.model.download.DownloadResult; import de.danoeh.antennapod.model.feed.FeedMedia; -import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; +import de.danoeh.antennapod.model.download.DownloadRequest; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter; import de.danoeh.antennapod.ui.notifications.NotificationUtils; 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 94cd81337..5e2a82f33 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 @@ -4,9 +4,10 @@ import androidx.annotation.NonNull; import android.text.TextUtils; import android.util.Log; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.NetworkUtils; import de.danoeh.antennapod.model.download.DownloadResult; -import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; +import de.danoeh.antennapod.model.download.DownloadRequest; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; import okhttp3.CacheControl; import okhttp3.internal.http.StatusLine; import org.apache.commons.io.IOUtils; @@ -29,7 +30,7 @@ import de.danoeh.antennapod.model.feed.FeedMedia; import de.danoeh.antennapod.parser.feed.util.DateUtils; import de.danoeh.antennapod.model.download.DownloadError; import de.danoeh.antennapod.core.util.StorageUtils; -import de.danoeh.antennapod.core.util.URIUtil; +import de.danoeh.antennapod.net.common.UriUtil; import okhttp3.OkHttpClient; import okhttp3.Protocol; import okhttp3.Request; @@ -54,7 +55,7 @@ public class HttpDownloader extends Downloader { ResponseBody responseBody = null; try { - final URI uri = URIUtil.getURIFromRequestUrl(request.getSource()); + final URI uri = UriUtil.getURIFromRequestUrl(request.getSource()); Request.Builder httpReq = new Request.Builder().url(uri.toURL()); httpReq.tag(request); httpReq.cacheControl(new CacheControl.Builder().noStore().build()); 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 264740032..1fecd4b8c 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.net.download.serviceinterface.DownloadRequest; +import de.danoeh.antennapod.model.download.DownloadRequest; import de.danoeh.antennapod.model.download.DownloadResult; 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 3b72ed164..03d7ab6ec 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 @@ -5,7 +5,7 @@ import androidx.annotation.NonNull; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.model.download.DownloadResult; import de.danoeh.antennapod.model.feed.Feed; -import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; +import de.danoeh.antennapod.model.download.DownloadRequest; import de.danoeh.antennapod.parser.feed.FeedHandlerResult; public class FeedSyncTask { 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 55831b821..21a908efa 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 @@ -14,7 +14,7 @@ import java.io.InterruptedIOException; import java.util.concurrent.ExecutionException; import de.danoeh.antennapod.event.UnreadItemsUpdateEvent; -import de.danoeh.antennapod.net.download.serviceinterface.DownloadRequest; +import de.danoeh.antennapod.model.download.DownloadRequest; import de.danoeh.antennapod.model.download.DownloadResult; 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/service/playback/ExoPlayerWrapper.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java index 51adbf477..9d455ebcc 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java @@ -42,13 +42,13 @@ import androidx.media3.extractor.DefaultExtractorsFactory; import androidx.media3.extractor.mp3.Mp3Extractor; import androidx.media3.ui.DefaultTrackNameProvider; import androidx.media3.ui.TrackNameProvider; -import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.R; +import de.danoeh.antennapod.net.common.UserAgentInterceptor; import de.danoeh.antennapod.model.feed.VolumeAdaptionSetting; import de.danoeh.antennapod.storage.preferences.UserPreferences; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; -import de.danoeh.antennapod.core.service.download.HttpCredentialEncoder; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; +import de.danoeh.antennapod.net.common.HttpCredentialEncoder; +import de.danoeh.antennapod.net.common.NetworkUtils; import de.danoeh.antennapod.model.playback.Playable; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -234,7 +234,7 @@ public class ExoPlayerWrapper { Log.d(TAG, "setDataSource: " + s); final OkHttpDataSource.Factory httpDataSourceFactory = new OkHttpDataSource.Factory((Call.Factory) AntennapodHttpClient.getHttpClient()) - .setUserAgent(ClientConfig.USER_AGENT); + .setUserAgent(UserAgentInterceptor.USER_AGENT); if (!TextUtils.isEmpty(user) && !TextUtils.isEmpty(password)) { final HashMap requestProperties = new HashMap<>(); 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 f34a9ba8e..abeb9f942 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 @@ -76,7 +76,7 @@ import de.danoeh.antennapod.core.util.ChapterUtils; import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.FeedUtil; import de.danoeh.antennapod.core.util.IntentUtils; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.NetworkUtils; import de.danoeh.antennapod.core.util.playback.PlayableUtils; import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter; import de.danoeh.antennapod.core.widget.WidgetUpdater; 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 ecfe5f4dd..350a6fbbf 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 @@ -14,7 +14,7 @@ import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedPreferences; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.storage.preferences.UserPreferences; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.NetworkUtils; import de.danoeh.antennapod.core.util.PowerUtils; /** diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java index b390f5f44..16c12bdd5 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java @@ -1,7 +1,6 @@ package de.danoeh.antennapod.core.storage; import android.database.Cursor; -import android.text.TextUtils; import android.util.Log; import androidx.annotation.NonNull; @@ -584,42 +583,6 @@ public final class DBReader { } } - /** - * Returns credentials based on image URL - * - * @param imageUrl The URL of the image - * @return Credentials in format "Username:Password", empty String if no authorization given - */ - public static String getImageAuthentication(final String imageUrl) { - Log.d(TAG, "getImageAuthentication() called with: " + "imageUrl = [" + imageUrl + "]"); - - PodDBAdapter adapter = PodDBAdapter.getInstance(); - adapter.open(); - try { - return getImageAuthentication(imageUrl, adapter); - } finally { - adapter.close(); - } - } - - private static String getImageAuthentication(final String imageUrl, PodDBAdapter adapter) { - String credentials; - try (Cursor cursor = adapter.getImageAuthenticationCursor(imageUrl)) { - if (cursor.moveToFirst()) { - String username = cursor.getString(0); - String password = cursor.getString(1); - if (!TextUtils.isEmpty(username) && password != null) { - credentials = username + ":" + password; - } else { - credentials = ""; - } - } else { - credentials = ""; - } - } - return credentials; - } - /** * Loads a specific FeedItem from the database. * 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 3ee7c2b54..5f750a50b 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 @@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.event.SyncServiceEvent; import de.danoeh.antennapod.storage.preferences.UserPreferences; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBWriter; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/ChapterUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/ChapterUtils.java index 901771913..6253b260d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/ChapterUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/ChapterUtils.java @@ -9,7 +9,7 @@ import androidx.annotation.NonNull; import de.danoeh.antennapod.model.feed.Chapter; import de.danoeh.antennapod.core.feed.ChapterMerger; import de.danoeh.antennapod.model.feed.FeedMedia; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator; import de.danoeh.antennapod.parser.feed.PodcastIndexChapterParser; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/download/FeedUpdateManager.java b/core/src/main/java/de/danoeh/antennapod/core/util/download/FeedUpdateManager.java index 2f2726bdb..89097d9ee 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/download/FeedUpdateManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/download/FeedUpdateManager.java @@ -16,7 +16,7 @@ import androidx.work.WorkManager; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.service.FeedUpdateWorker; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.NetworkUtils; import de.danoeh.antennapod.event.MessageEvent; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.storage.preferences.UserPreferences; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/download/MediaSizeLoader.java b/core/src/main/java/de/danoeh/antennapod/core/util/download/MediaSizeLoader.java index 67ec35327..df35365c9 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/download/MediaSizeLoader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/download/MediaSizeLoader.java @@ -1,9 +1,9 @@ package de.danoeh.antennapod.core.util.download; import android.text.TextUtils; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; import de.danoeh.antennapod.core.storage.DBWriter; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.NetworkUtils; import de.danoeh.antennapod.model.feed.FeedMedia; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; 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 de2d8e9f4..8097a4cb1 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 @@ -4,7 +4,7 @@ import android.content.Context; import android.util.Log; import de.danoeh.antennapod.net.download.serviceinterface.DownloadServiceInterface; import de.danoeh.antennapod.core.storage.DBTasks; -import de.danoeh.antennapod.core.util.NetworkUtils; +import de.danoeh.antennapod.net.common.NetworkUtils; public abstract class NetworkConnectionChangeHandler { private static final String TAG = "NetConnChangeHandler"; diff --git a/model/build.gradle b/model/build.gradle index 93da356f7..5afbdf109 100644 --- a/model/build.gradle +++ b/model/build.gradle @@ -5,6 +5,10 @@ apply from: "../common.gradle" android { namespace "de.danoeh.antennapod.model" + + lint { + disable 'ParcelClassLoader' + } } dependencies { diff --git a/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequest.java b/model/src/main/java/de/danoeh/antennapod/model/download/DownloadRequest.java similarity index 72% rename from net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequest.java rename to model/src/main/java/de/danoeh/antennapod/model/download/DownloadRequest.java index f789fda5c..e9a0bb84b 100644 --- a/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequest.java +++ b/model/src/main/java/de/danoeh/antennapod/model/download/DownloadRequest.java @@ -1,4 +1,4 @@ -package de.danoeh.antennapod.net.download.serviceinterface; +package de.danoeh.antennapod.model.download; import android.os.Bundle; import android.os.Parcel; @@ -8,10 +8,6 @@ import android.text.TextUtils; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import de.danoeh.antennapod.model.feed.Feed; -import de.danoeh.antennapod.net.common.UrlChecker; -import de.danoeh.antennapod.model.feed.FeedMedia; - public class DownloadRequest implements Parcelable { public static final String REQUEST_ARG_PAGE_NR = "page"; @@ -39,19 +35,13 @@ public class DownloadRequest implements Parcelable { arguments, initiatedByUser); } - private DownloadRequest(Builder builder) { - this(builder.destination, builder.source, builder.title, builder.feedfileId, builder.feedfileType, - builder.lastModified, builder.username, builder.password, false, - builder.arguments, builder.initiatedByUser); - } - private DownloadRequest(Parcel in) { this(in.readString(), in.readString(), in.readString(), in.readLong(), in.readInt(), in.readString(), 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, + public DownloadRequest(String destination, String source, String title, long feedfileId, int feedfileType, String lastModified, String username, String password, boolean mediaEnqueued, Bundle arguments, boolean initiatedByUser) { this.destination = destination; @@ -234,64 +224,4 @@ public class DownloadRequest implements Parcelable { public Bundle getArguments() { return arguments; } - - public static class Builder { - private final String destination; - private String source; - private final String title; - private String username; - private String password; - private String lastModified; - 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 = FeedMedia.FEEDFILETYPE_FEEDMEDIA; - } - - 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.FEEDFILETYPE_FEED; - arguments.putInt(REQUEST_ARG_PAGE_NR, feed.getPageNr()); - } - - public Builder withInitiatedByUser(boolean initiatedByUser) { - this.initiatedByUser = initiatedByUser; - return this; - } - - public void setSource(String source) { - this.source = source; - } - - public void setForce(boolean force) { - if (force) { - lastModified = null; - } - } - - 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 DownloadRequest build() { - return new DownloadRequest(this); - } - } } diff --git a/net/common/build.gradle b/net/common/build.gradle index 67efdf43f..57b9f5f23 100644 --- a/net/common/build.gradle +++ b/net/common/build.gradle @@ -2,14 +2,20 @@ plugins { id("com.android.library") } apply from: "../../common.gradle" +apply from: "../../playFlavor.gradle" android { namespace "de.danoeh.antennapod.net.common" } dependencies { + implementation project(':model') + implementation project(':net:ssl') + implementation project(':storage:preferences') + annotationProcessor "androidx.annotation:annotation:$annotationVersion" implementation "com.squareup.okhttp3:okhttp:$okhttpVersion" + implementation "com.squareup.okhttp3:okhttp-urlconnection:$okhttpVersion" testImplementation "junit:junit:$junitVersion" testImplementation "org.robolectric:robolectric:$robolectricVersion" diff --git a/net/common/src/main/AndroidManifest.xml b/net/common/src/main/AndroidManifest.xml new file mode 100644 index 000000000..1ffc73012 --- /dev/null +++ b/net/common/src/main/AndroidManifest.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java b/net/common/src/main/java/de/danoeh/antennapod/net/common/AntennapodHttpClient.java similarity index 95% rename from core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java rename to net/common/src/main/java/de/danoeh/antennapod/net/common/AntennapodHttpClient.java index 9f1f97bf0..0a5231172 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java +++ b/net/common/src/main/java/de/danoeh/antennapod/net/common/AntennapodHttpClient.java @@ -1,10 +1,8 @@ -package de.danoeh.antennapod.core.service.download; +package de.danoeh.antennapod.net.common; import android.text.TextUtils; import android.util.Log; import androidx.annotation.NonNull; -import de.danoeh.antennapod.core.service.BasicAuthorizationInterceptor; -import de.danoeh.antennapod.core.service.UserAgentInterceptor; import de.danoeh.antennapod.model.download.ProxyConfig; import de.danoeh.antennapod.net.ssl.SslClientSetup; import okhttp3.Cache; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/BasicAuthorizationInterceptor.java b/net/common/src/main/java/de/danoeh/antennapod/net/common/BasicAuthorizationInterceptor.java similarity index 86% rename from core/src/main/java/de/danoeh/antennapod/core/service/BasicAuthorizationInterceptor.java rename to net/common/src/main/java/de/danoeh/antennapod/net/common/BasicAuthorizationInterceptor.java index 77a58e682..8e7b9a4f4 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/BasicAuthorizationInterceptor.java +++ b/net/common/src/main/java/de/danoeh/antennapod/net/common/BasicAuthorizationInterceptor.java @@ -1,12 +1,11 @@ -package de.danoeh.antennapod.core.service; +package de.danoeh.antennapod.net.common; import android.text.TextUtils; import android.util.Log; import androidx.annotation.NonNull; -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; +import de.danoeh.antennapod.model.download.DownloadRequest; +import de.danoeh.antennapod.net.common.HttpCredentialEncoder; +import de.danoeh.antennapod.net.common.UriUtil; import java.io.IOException; import java.net.HttpURLConnection; import java.util.List; @@ -43,17 +42,15 @@ public class BasicAuthorizationInterceptor implements Interceptor { } } - String userInfo; + String userInfo = null; if (request.tag() instanceof DownloadRequest) { DownloadRequest downloadRequest = (DownloadRequest) request.tag(); - userInfo = URIUtil.getURIFromRequestUrl(downloadRequest.getSource()).getUserInfo(); + userInfo = UriUtil.getURIFromRequestUrl(downloadRequest.getSource()).getUserInfo(); if (TextUtils.isEmpty(userInfo) && (!TextUtils.isEmpty(downloadRequest.getUsername()) || !TextUtils.isEmpty(downloadRequest.getPassword()))) { userInfo = downloadRequest.getUsername() + ":" + downloadRequest.getPassword(); } - } else { - userInfo = DBReader.getImageAuthentication(request.url().toString()); } if (TextUtils.isEmpty(userInfo)) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpCredentialEncoder.java b/net/common/src/main/java/de/danoeh/antennapod/net/common/HttpCredentialEncoder.java similarity index 91% rename from core/src/main/java/de/danoeh/antennapod/core/service/download/HttpCredentialEncoder.java rename to net/common/src/main/java/de/danoeh/antennapod/net/common/HttpCredentialEncoder.java index 9866f91b6..9b2063ce6 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpCredentialEncoder.java +++ b/net/common/src/main/java/de/danoeh/antennapod/net/common/HttpCredentialEncoder.java @@ -1,4 +1,4 @@ -package de.danoeh.antennapod.core.service.download; +package de.danoeh.antennapod.net.common; import android.util.Base64; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java b/net/common/src/main/java/de/danoeh/antennapod/net/common/NetworkUtils.java similarity index 99% rename from core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java rename to net/common/src/main/java/de/danoeh/antennapod/net/common/NetworkUtils.java index dfdc6c32a..179c4e13e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java +++ b/net/common/src/main/java/de/danoeh/antennapod/net/common/NetworkUtils.java @@ -1,4 +1,4 @@ -package de.danoeh.antennapod.core.util; +package de.danoeh.antennapod.net.common; import android.content.Context; import android.net.ConnectivityManager; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/URIUtil.java b/net/common/src/main/java/de/danoeh/antennapod/net/common/UriUtil.java similarity index 66% rename from core/src/main/java/de/danoeh/antennapod/core/util/URIUtil.java rename to net/common/src/main/java/de/danoeh/antennapod/net/common/UriUtil.java index e093dc766..63fc087d6 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/URIUtil.java +++ b/net/common/src/main/java/de/danoeh/antennapod/net/common/UriUtil.java @@ -1,28 +1,22 @@ -package de.danoeh.antennapod.core.util; - -import android.util.Log; +package de.danoeh.antennapod.net.common; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import de.danoeh.antennapod.core.BuildConfig; - /** * Utility methods for dealing with URL encoding. */ -public class URIUtil { - private static final String TAG = "URIUtil"; - - private URIUtil() {} +public class UriUtil { + private UriUtil() {} public static URI getURIFromRequestUrl(String source) { // try without encoding the URI try { return new URI(source); - } catch (URISyntaxException e) { - if (BuildConfig.DEBUG) Log.d(TAG, "Source is not encoded, encoding now"); + } catch (URISyntaxException ignore) { + System.out.println("Source is not encoded, encoding now"); } try { URL url = new URL(source); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/UserAgentInterceptor.java b/net/common/src/main/java/de/danoeh/antennapod/net/common/UserAgentInterceptor.java similarity index 67% rename from core/src/main/java/de/danoeh/antennapod/core/service/UserAgentInterceptor.java rename to net/common/src/main/java/de/danoeh/antennapod/net/common/UserAgentInterceptor.java index 3676347f7..7a61aa070 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/UserAgentInterceptor.java +++ b/net/common/src/main/java/de/danoeh/antennapod/net/common/UserAgentInterceptor.java @@ -1,16 +1,17 @@ -package de.danoeh.antennapod.core.service; +package de.danoeh.antennapod.net.common; -import de.danoeh.antennapod.core.ClientConfig; import okhttp3.Interceptor; import okhttp3.Response; import java.io.IOException; public class UserAgentInterceptor implements Interceptor { + public static String USER_AGENT = "AntennaPod/0.0.0"; + @Override public Response intercept(Chain chain) throws IOException { return chain.proceed(chain.request().newBuilder() - .header("User-Agent", ClientConfig.USER_AGENT) + .header("User-Agent", USER_AGENT) .build()); } } diff --git a/core/src/test/java/de/danoeh/antennapod/core/util/URIUtilTest.java b/net/common/src/test/java/de/danoeh/antennapod/net/common/UriUtilTest.java similarity index 68% rename from core/src/test/java/de/danoeh/antennapod/core/util/URIUtilTest.java rename to net/common/src/test/java/de/danoeh/antennapod/net/common/UriUtilTest.java index 3feb4d376..32a856284 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/util/URIUtilTest.java +++ b/net/common/src/test/java/de/danoeh/antennapod/net/common/UriUtilTest.java @@ -1,5 +1,6 @@ -package de.danoeh.antennapod.core.util; +package de.danoeh.antennapod.net.common; +import de.danoeh.antennapod.net.common.UriUtil; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -7,18 +8,18 @@ import static org.junit.Assert.assertEquals; /** * Test class for URIUtil */ -public class URIUtilTest { +public class UriUtilTest { @Test public void testGetURIFromRequestUrlShouldNotEncode() { final String testUrl = "http://example.com/this%20is%20encoded"; - assertEquals(testUrl, URIUtil.getURIFromRequestUrl(testUrl).toString()); + assertEquals(testUrl, UriUtil.getURIFromRequestUrl(testUrl).toString()); } @Test public void testGetURIFromRequestUrlShouldEncode() { final String testUrl = "http://example.com/this is not encoded"; final String expected = "http://example.com/this%20is%20not%20encoded"; - assertEquals(expected, URIUtil.getURIFromRequestUrl(testUrl).toString()); + assertEquals(expected, UriUtil.getURIFromRequestUrl(testUrl).toString()); } } diff --git a/net/discovery/build.gradle b/net/discovery/build.gradle index df47258fa..d071f1ba7 100644 --- a/net/discovery/build.gradle +++ b/net/discovery/build.gradle @@ -21,6 +21,7 @@ android { dependencies { implementation project(':core') implementation project(':model') + implementation project(':net:common') implementation project(':net:sync:gpoddernet') implementation project(':net:sync:model') diff --git a/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/FyydPodcastSearcher.java b/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/FyydPodcastSearcher.java index 30be87931..2899af677 100644 --- a/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/FyydPodcastSearcher.java +++ b/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/FyydPodcastSearcher.java @@ -1,6 +1,6 @@ package de.danoeh.antennapod.net.discovery; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; import de.mfietz.fyydlin.FyydClient; import de.mfietz.fyydlin.FyydResponse; import de.mfietz.fyydlin.SearchHit; diff --git a/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/GpodnetPodcastSearcher.java b/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/GpodnetPodcastSearcher.java index 222c415ab..a3f2c648f 100644 --- a/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/GpodnetPodcastSearcher.java +++ b/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/GpodnetPodcastSearcher.java @@ -1,7 +1,7 @@ package de.danoeh.antennapod.net.discovery; import de.danoeh.antennapod.core.sync.SynchronizationCredentials; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; import de.danoeh.antennapod.net.sync.gpoddernet.GpodnetService; import de.danoeh.antennapod.net.sync.gpoddernet.GpodnetServiceException; import de.danoeh.antennapod.net.sync.gpoddernet.model.GpodnetPodcast; diff --git a/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/ItunesPodcastSearcher.java b/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/ItunesPodcastSearcher.java index 32e150f76..b9df9d185 100644 --- a/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/ItunesPodcastSearcher.java +++ b/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/ItunesPodcastSearcher.java @@ -1,7 +1,7 @@ package de.danoeh.antennapod.net.discovery; import de.danoeh.antennapod.core.feed.FeedUrlNotFoundException; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; import io.reactivex.android.schedulers.AndroidSchedulers; diff --git a/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/ItunesTopListLoader.java b/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/ItunesTopListLoader.java index 5fa48458e..128aad593 100644 --- a/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/ItunesTopListLoader.java +++ b/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/ItunesTopListLoader.java @@ -2,8 +2,8 @@ package de.danoeh.antennapod.net.discovery; import android.content.Context; import android.util.Log; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; import de.danoeh.antennapod.model.feed.Feed; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; import okhttp3.CacheControl; import okhttp3.OkHttpClient; import okhttp3.Request; diff --git a/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/PodcastIndexPodcastSearcher.java b/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/PodcastIndexPodcastSearcher.java index 105667393..c777827df 100644 --- a/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/PodcastIndexPodcastSearcher.java +++ b/net/discovery/src/main/java/de/danoeh/antennapod/net/discovery/PodcastIndexPodcastSearcher.java @@ -1,5 +1,7 @@ package de.danoeh.antennapod.net.discovery; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; +import de.danoeh.antennapod.net.common.UserAgentInterceptor; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -15,8 +17,6 @@ import java.util.List; import java.util.Locale; import java.util.TimeZone; -import de.danoeh.antennapod.core.ClientConfig; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -100,7 +100,7 @@ public class PodcastIndexPodcastSearcher implements PodcastSearcher { .addHeader("X-Auth-Date", apiHeaderTime) .addHeader("X-Auth-Key", BuildConfig.PODCASTINDEX_API_KEY) .addHeader("Authorization", hashString) - .addHeader("User-Agent", ClientConfig.USER_AGENT) + .addHeader("User-Agent", UserAgentInterceptor.USER_AGENT) .url(url); return httpReq.build(); } diff --git a/net/download/service-interface/build.gradle b/net/download/service-interface/build.gradle index 784c1375f..84a8dfd05 100644 --- a/net/download/service-interface/build.gradle +++ b/net/download/service-interface/build.gradle @@ -3,6 +3,7 @@ plugins { id("java-test-fixtures") } apply from: "../../../common.gradle" +apply from: "../../../playFlavor.gradle" android { namespace "de.danoeh.antennapod.net.download.serviceinterface" diff --git a/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestBuilder.java b/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestBuilder.java new file mode 100644 index 000000000..15d2858bc --- /dev/null +++ b/net/download/service-interface/src/main/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestBuilder.java @@ -0,0 +1,69 @@ +package de.danoeh.antennapod.net.download.serviceinterface; + +import android.os.Bundle; +import androidx.annotation.NonNull; +import de.danoeh.antennapod.model.download.DownloadRequest; +import de.danoeh.antennapod.model.feed.Feed; +import de.danoeh.antennapod.model.feed.FeedMedia; +import de.danoeh.antennapod.net.common.UrlChecker; + +public class DownloadRequestBuilder { + private final String destination; + private String source; + private final String title; + private String username; + private String password; + private String lastModified; + private final long feedfileId; + private final int feedfileType; + private final Bundle arguments = new Bundle(); + private boolean initiatedByUser = true; + + public DownloadRequestBuilder(@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 = FeedMedia.FEEDFILETYPE_FEEDMEDIA; + } + + public DownloadRequestBuilder(@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.FEEDFILETYPE_FEED; + arguments.putInt(DownloadRequest.REQUEST_ARG_PAGE_NR, feed.getPageNr()); + } + + public DownloadRequestBuilder withInitiatedByUser(boolean initiatedByUser) { + this.initiatedByUser = initiatedByUser; + return this; + } + + public void setSource(String source) { + this.source = source; + } + + public void setForce(boolean force) { + if (force) { + lastModified = null; + } + } + + public DownloadRequestBuilder lastModified(String lastModified) { + this.lastModified = lastModified; + return this; + } + + public DownloadRequestBuilder withAuthentication(String username, String password) { + this.username = username; + this.password = password; + return this; + } + + public DownloadRequest build() { + return new DownloadRequest(destination, source, title, feedfileId, feedfileType, + lastModified, username, password, false, arguments, initiatedByUser); + } +} \ No newline at end of file diff --git a/net/download/service-interface/src/test/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestTest.java b/net/download/service-interface/src/test/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestBuilderTest.java similarity index 89% rename from net/download/service-interface/src/test/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestTest.java rename to net/download/service-interface/src/test/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestBuilderTest.java index a48934cfe..e9876a949 100644 --- a/net/download/service-interface/src/test/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestTest.java +++ b/net/download/service-interface/src/test/java/de/danoeh/antennapod/net/download/serviceinterface/DownloadRequestBuilderTest.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.net.download.serviceinterface; import android.os.Bundle; import android.os.Parcel; +import de.danoeh.antennapod.model.download.DownloadRequest; import de.danoeh.antennapod.model.feed.FeedMedia; import org.junit.Test; import org.junit.runner.RunWith; @@ -14,7 +15,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @RunWith(RobolectricTestRunner.class) -public class DownloadRequestTest { +public class DownloadRequestBuilderTest { @Test public void parcelInArrayListTest_WithAuth() { @@ -40,15 +41,15 @@ public class DownloadRequestTest { String username = "testUser"; String password = "testPassword"; FeedMedia item = createFeedItem(1); - DownloadRequest request1 = new DownloadRequest.Builder(destStr, item) + DownloadRequest request1 = new DownloadRequestBuilder(destStr, item) .withAuthentication(username, password) .build(); - DownloadRequest request2 = new DownloadRequest.Builder(destStr, item) + DownloadRequest request2 = new DownloadRequestBuilder(destStr, item) .withAuthentication(username, password) .build(); - DownloadRequest request3 = new DownloadRequest.Builder(destStr, item) + DownloadRequest request3 = new DownloadRequestBuilder(destStr, item) .withAuthentication("diffUsername", "diffPassword") .build(); @@ -65,12 +66,12 @@ public class DownloadRequestTest { { // test DownloadRequests to parcel String destStr = "file://location/media.mp3"; FeedMedia item1 = createFeedItem(1); - DownloadRequest request1 = new DownloadRequest.Builder(destStr, item1) + DownloadRequest request1 = new DownloadRequestBuilder(destStr, item1) .withAuthentication(username1, password1) .build(); FeedMedia item2 = createFeedItem(2); - DownloadRequest request2 = new DownloadRequest.Builder(destStr, item2) + DownloadRequest request2 = new DownloadRequestBuilder(destStr, item2) .withAuthentication(username2, password2) .build(); diff --git a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java index e577896be..3fc0841e0 100644 --- a/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java +++ b/storage/database/src/main/java/de/danoeh/antennapod/storage/database/PodDBAdapter.java @@ -1177,18 +1177,6 @@ public class PodDBAdapter { return db.rawQuery(query, null); } - public Cursor getImageAuthenticationCursor(final String imageUrl) { - String downloadUrl = DatabaseUtils.sqlEscapeString(imageUrl); - final String query = "" - + "SELECT " + KEY_USERNAME + "," + KEY_PASSWORD + " FROM " + TABLE_NAME_FEED_ITEMS - + " INNER JOIN " + TABLE_NAME_FEEDS - + " ON " + TABLE_NAME_FEED_ITEMS + "." + KEY_FEED + " = " + TABLE_NAME_FEEDS + "." + KEY_ID - + " WHERE " + TABLE_NAME_FEED_ITEMS + "." + KEY_IMAGE_URL + "=" + downloadUrl - + " UNION SELECT " + KEY_USERNAME + "," + KEY_PASSWORD + " FROM " + TABLE_NAME_FEEDS - + " WHERE " + TABLE_NAME_FEEDS + "." + KEY_IMAGE_URL + "=" + downloadUrl; - return db.rawQuery(query, null); - } - public final Cursor getMonthlyStatisticsCursor() { final String query = "SELECT SUM(" + KEY_PLAYED_DURATION + ") AS total_duration" + ", strftime('%m', datetime(" + KEY_LAST_PLAYED_TIME + "/1000, 'unixepoch')) AS month" diff --git a/ui/glide/build.gradle b/ui/glide/build.gradle index d518e1d69..c281fbf04 100644 --- a/ui/glide/build.gradle +++ b/ui/glide/build.gradle @@ -10,7 +10,7 @@ android { dependencies { implementation project(":model") - implementation project(":core") + implementation project(':net:common') implementation project(':storage:preferences') implementation "androidx.palette:palette:$paletteVersion" diff --git a/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ApOkHttpUrlLoader.java b/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ApOkHttpUrlLoader.java index 3814c0700..d66f08ec8 100644 --- a/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ApOkHttpUrlLoader.java +++ b/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ApOkHttpUrlLoader.java @@ -10,10 +10,10 @@ import com.bumptech.glide.load.model.ModelLoader; import com.bumptech.glide.load.model.ModelLoaderFactory; import com.bumptech.glide.load.model.MultiModelLoaderFactory; import com.bumptech.glide.signature.ObjectKey; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; -import de.danoeh.antennapod.core.util.NetworkUtils; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.model.feed.FeedMedia; +import de.danoeh.antennapod.net.common.AntennapodHttpClient; +import de.danoeh.antennapod.net.common.NetworkUtils; import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.Protocol; diff --git a/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ChapterImageModelLoader.java b/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ChapterImageModelLoader.java index 9f82e0b31..3f6aa7c48 100644 --- a/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ChapterImageModelLoader.java +++ b/ui/glide/src/main/java/de/danoeh/antennapod/ui/glide/ChapterImageModelLoader.java @@ -9,13 +9,14 @@ import com.bumptech.glide.load.model.ModelLoader; import com.bumptech.glide.load.model.ModelLoaderFactory; import com.bumptech.glide.load.model.MultiModelLoaderFactory; import com.bumptech.glide.signature.ObjectKey; -import de.danoeh.antennapod.core.service.download.AntennapodHttpClient; import de.danoeh.antennapod.model.feed.EmbeddedChapterImage; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.ByteBuffer; + +import de.danoeh.antennapod.net.common.AntennapodHttpClient; import okhttp3.Request; import okhttp3.Response; import org.apache.commons.io.IOUtils;