diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2024-03-29 13:38:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-29 13:38:31 +0100 |
commit | 8f553f08f0347b73b34c80dddef228302cdf5977 (patch) | |
tree | 112ef05988be5a37bb08ec2aa06ed3727234bbae | |
parent | 5ede21d676af8d879ec8f5d695255ccbf4398e76 (diff) | |
download | AntennaPod-8f553f08f0347b73b34c80dddef228302cdf5977.zip |
Add :ui:discovery module (#7037)
23 files changed, 146 insertions, 107 deletions
diff --git a/app/build.gradle b/app/build.gradle index 6cbc9e64f..02031b9e1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -90,6 +90,7 @@ dependencies { implementation project(':storage:preferences') implementation project(':ui:app-start-intent') implementation project(':ui:common') + implementation project(':ui:discovery') implementation project(':ui:echo') implementation project(':ui:episodes') implementation project(':ui:glide') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8bbe4cdb9..b4323f782 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -305,6 +305,10 @@ <data android:mimeType="text/plain"/> </intent-filter> + <intent-filter> + <category android:name="android.intent.category.DEFAULT" /> + <action android:name="de.danoeh.antennapod.intents.ONLINE_FEEDVIEW" /> + </intent-filter> </activity> <activity android:name=".activity.SelectSubscriptionActivity" diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index 3c867b88c..f7bfbce7b 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -63,6 +63,7 @@ import de.danoeh.antennapod.storage.importexport.AutomaticDatabaseExportWorker; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter; import de.danoeh.antennapod.ui.common.ThemeUtils; +import de.danoeh.antennapod.ui.discovery.DiscoveryFragment; import de.danoeh.antennapod.ui.home.HomeFragment; import de.danoeh.antennapod.view.LockableBottomSheetBehavior; import org.apache.commons.lang3.ArrayUtils; @@ -87,7 +88,6 @@ public class MainActivity extends CastEnabledActivity { public static final String EXTRA_FEED_ID = "fragment_feed_id"; public static final String EXTRA_REFRESH_ON_START = "refresh_on_start"; - public static final String EXTRA_STARTED_FROM_SEARCH = "started_from_search"; public static final String EXTRA_ADD_TO_BACK_STACK = "add_to_back_stack"; public static final String KEY_GENERATED_VIEW_ID = "generated_view_id"; @@ -347,7 +347,7 @@ public class MainActivity extends CastEnabledActivity { return recycledViewPool; } - public void loadFragment(String tag, Bundle args) { + public Fragment createFragmentInstance(String tag, Bundle args) { Log.d(TAG, "loadFragment(tag: " + tag + ", args: " + args + ")"); Fragment fragment; switch (tag) { @@ -375,19 +375,24 @@ public class MainActivity extends CastEnabledActivity { case SubscriptionFragment.TAG: fragment = new SubscriptionFragment(); break; + case DiscoveryFragment.TAG: + fragment = new DiscoveryFragment(); + break; default: // default to home screen fragment = new HomeFragment(); - tag = HomeFragment.TAG; args = null; break; } - if (args != null) { fragment.setArguments(args); } + return fragment; + } + + public void loadFragment(String tag, Bundle args) { NavDrawerFragment.saveLastNavFragment(this, tag); - loadFragment(fragment); + loadFragment(createFragmentInstance(tag, args)); } public void loadFeedFragmentById(long feedId, Bundle args) { @@ -399,7 +404,7 @@ public class MainActivity extends CastEnabledActivity { loadFragment(fragment); } - private void loadFragment(Fragment fragment) { + public void loadFragment(Fragment fragment) { FragmentManager fragmentManager = getSupportFragmentManager(); // clear back stack for (int i = 0; i < fragmentManager.getBackStackEntryCount(); i++) { @@ -591,9 +596,8 @@ public class MainActivity extends CastEnabledActivity { long feedId = intent.getLongExtra(EXTRA_FEED_ID, 0); Bundle args = intent.getBundleExtra(MainActivityStarter.EXTRA_FRAGMENT_ARGS); if (feedId > 0) { - boolean startedFromSearch = intent.getBooleanExtra(EXTRA_STARTED_FROM_SEARCH, false); boolean addToBackStack = intent.getBooleanExtra(EXTRA_ADD_TO_BACK_STACK, false); - if (startedFromSearch || addToBackStack) { + if (addToBackStack) { loadChildFragment(FeedItemlistFragment.newInstance(feedId)); } else { loadFeedFragmentById(feedId, args); @@ -604,7 +608,12 @@ public class MainActivity extends CastEnabledActivity { String tag = intent.getStringExtra(MainActivityStarter.EXTRA_FRAGMENT_TAG); Bundle args = intent.getBundleExtra(MainActivityStarter.EXTRA_FRAGMENT_ARGS); if (tag != null) { - loadFragment(tag, args); + Fragment fragment = createFragmentInstance(tag, args); + if (intent.getBooleanExtra(MainActivityStarter.EXTRA_ADD_TO_BACK_STACK, false)) { + loadChildFragment(fragment); + } else { + loadFragment(fragment); + } } sheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); } else if (intent.getBooleanExtra(MainActivityStarter.EXTRA_OPEN_PLAYER, false)) { 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 72c200231..3a9fc9b46 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -12,7 +12,6 @@ import android.text.SpannableString; import android.text.TextUtils; import android.text.style.ForegroundColorSpan; import android.util.Log; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; @@ -23,13 +22,13 @@ import androidx.annotation.Nullable; import androidx.annotation.UiThread; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.NavUtils; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import com.google.android.material.snackbar.Snackbar; import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.FeedItemlistDescriptionAdapter; +import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter; import de.danoeh.antennapod.ui.common.ThemeSwitcher; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; import de.danoeh.antennapod.net.discovery.FeedUrlNotFoundException; @@ -85,6 +84,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import static de.danoeh.antennapod.ui.appstartintent.OnlineFeedviewActivityStarter.ARG_FEEDURL; +import static de.danoeh.antennapod.ui.appstartintent.OnlineFeedviewActivityStarter.ARG_STARTED_FROM_SEARCH; +import static de.danoeh.antennapod.ui.appstartintent.OnlineFeedviewActivityStarter.ARG_WAS_MANUAL_URL; + /** * Downloads a feed from a feed URL and parses it. Subclasses can display the * feed object that was parsed. This activity MUST be started with a given URL @@ -95,8 +98,6 @@ import java.util.Map; */ public class OnlineFeedViewActivity extends AppCompatActivity { - public static final String ARG_FEEDURL = "arg.feedurl"; - public static final String ARG_WAS_MANUAL_URL = "manual_url"; private static final int RESULT_ERROR = 2; private static final String TAG = "OnlineFeedViewActivity"; private static final String PREFS = "OnlineFeedViewActivityPreferences"; @@ -236,20 +237,6 @@ public class OnlineFeedViewActivity extends AppCompatActivity { overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - Intent destIntent = new Intent(this, MainActivity.class); - if (NavUtils.shouldUpRecreateTask(this, destIntent)) { - startActivity(destIntent); - } else { - NavUtils.navigateUpFromSameTask(this); - } - return true; - } - return super.onOptionsItemSelected(item); - } - private void lookupUrlAndDownload(String url) { download = PodcastSearcherRegistry.lookupUrl(url) .subscribeOn(Schedulers.io()) @@ -521,13 +508,14 @@ public class OnlineFeedViewActivity extends AppCompatActivity { } private void openFeed() { - // feed.getId() is always 0, we have to retrieve the id from the feed list from - // the database - Intent intent = MainActivity.getIntentToOpenFeed(this, getFeedId()); - intent.putExtra(MainActivity.EXTRA_STARTED_FROM_SEARCH, - getIntent().getBooleanExtra(MainActivity.EXTRA_STARTED_FROM_SEARCH, false)); + // feed.getId() is always 0, we have to retrieve the id from the feed list from the database + MainActivityStarter mainActivityStarter = new MainActivityStarter(this); + mainActivityStarter.withOpenFeed(getFeedId()); + if (getIntent().getBooleanExtra(ARG_STARTED_FROM_SEARCH, false)) { + mainActivityStarter.withAddToBackStack(); + } finish(); - startActivity(intent); + startActivity(mainActivityStarter.getIntent()); } private void handleUpdatedFeedStatus() { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java index 5074c5b64..1ec917176 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AddFeedFragment.java @@ -25,7 +25,6 @@ import com.google.android.material.snackbar.Snackbar; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; -import de.danoeh.antennapod.activity.OnlineFeedViewActivity; import de.danoeh.antennapod.activity.OpmlImportActivity; import de.danoeh.antennapod.core.util.download.FeedUpdateManager; import de.danoeh.antennapod.model.feed.Feed; @@ -38,6 +37,8 @@ import de.danoeh.antennapod.net.discovery.FyydPodcastSearcher; import de.danoeh.antennapod.net.discovery.GpodnetPodcastSearcher; import de.danoeh.antennapod.net.discovery.ItunesPodcastSearcher; import de.danoeh.antennapod.net.discovery.PodcastIndexPodcastSearcher; +import de.danoeh.antennapod.ui.appstartintent.OnlineFeedviewActivityStarter; +import de.danoeh.antennapod.ui.discovery.OnlineSearchFragment; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; @@ -145,10 +146,7 @@ public class AddFeedFragment extends Fragment { } private void addUrl(String url) { - Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class); - intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, url); - intent.putExtra(OnlineFeedViewActivity.ARG_WAS_MANUAL_URL, true); - startActivity(intent); + startActivity(new OnlineFeedviewActivityStarter(getContext(), url).withManualUrl().getIntent()); } private void performSearch() { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java index 76b53a264..73fce9f1f 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SearchFragment.java @@ -2,7 +2,6 @@ package de.danoeh.antennapod.fragment; import android.content.Context; -import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -29,7 +28,6 @@ import com.leinardi.android.speeddial.SpeedDialView; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; -import de.danoeh.antennapod.activity.OnlineFeedViewActivity; import de.danoeh.antennapod.adapter.EpisodeItemListAdapter; import de.danoeh.antennapod.adapter.HorizontalFeedListAdapter; import de.danoeh.antennapod.core.menuhandler.MenuItemUtils; @@ -46,6 +44,8 @@ import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; import de.danoeh.antennapod.net.discovery.CombinedSearcher; import de.danoeh.antennapod.storage.database.DBReader; +import de.danoeh.antennapod.ui.appstartintent.OnlineFeedviewActivityStarter; +import de.danoeh.antennapod.ui.discovery.OnlineSearchFragment; import de.danoeh.antennapod.view.EmptyViewHandler; import de.danoeh.antennapod.view.EpisodeItemListRecyclerView; import de.danoeh.antennapod.view.LiftOnScrollListener; @@ -425,9 +425,7 @@ public class SearchFragment extends Fragment implements EpisodeItemListAdapter.O in.hideSoftInputFromWindow(searchView.getWindowToken(), 0); String query = searchView.getQuery().toString(); if (query.matches("http[s]?://.*")) { - Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class); - intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, query); - startActivity(intent); + startActivity(new OnlineFeedviewActivityStarter(getContext(), query).getIntent()); return; } ((MainActivity) getActivity()).loadChildFragment( diff --git a/app/src/main/res/layout/addfeed.xml b/app/src/main/res/layout/addfeed.xml index eee07c669..d3e3c3c1d 100644 --- a/app/src/main/res/layout/addfeed.xml +++ b/app/src/main/res/layout/addfeed.xml @@ -85,7 +85,7 @@ android:id="@+id/quickFeedDiscovery" android:layout_width="match_parent" android:layout_height="wrap_content" - android:name="de.danoeh.antennapod.fragment.QuickFeedDiscoveryFragment" /> + android:name="de.danoeh.antennapod.ui.discovery.QuickFeedDiscoveryFragment" /> <TextView android:layout_width="match_parent" diff --git a/settings.gradle b/settings.gradle index 438cf5e3e..b23f2dc20 100644 --- a/settings.gradle +++ b/settings.gradle @@ -39,6 +39,7 @@ include ':storage:preferences' include ':ui:app-start-intent' include ':ui:common' +include ':ui:discovery' include ':ui:echo' include ':ui:episodes' include ':ui:glide' diff --git a/ui/app-start-intent/src/main/java/de/danoeh/antennapod/ui/appstartintent/OnlineFeedviewActivityStarter.java b/ui/app-start-intent/src/main/java/de/danoeh/antennapod/ui/appstartintent/OnlineFeedviewActivityStarter.java new file mode 100644 index 000000000..4299281f3 --- /dev/null +++ b/ui/app-start-intent/src/main/java/de/danoeh/antennapod/ui/appstartintent/OnlineFeedviewActivityStarter.java @@ -0,0 +1,32 @@ +package de.danoeh.antennapod.ui.appstartintent; + +import android.content.Context; +import android.content.Intent; + +public class OnlineFeedviewActivityStarter { + public static final String INTENT = "de.danoeh.antennapod.intents.ONLINE_FEEDVIEW"; + public static final String ARG_FEEDURL = "arg.feedurl"; + public static final String ARG_WAS_MANUAL_URL = "manual_url"; + public static final String ARG_STARTED_FROM_SEARCH = "started_from_search"; + private final Intent intent; + + public OnlineFeedviewActivityStarter(Context context, String feedUrl) { + intent = new Intent(INTENT); + intent.setPackage(context.getPackageName()); + intent.putExtra(ARG_FEEDURL, feedUrl); + } + + public OnlineFeedviewActivityStarter withStartedFromSearch() { + intent.putExtra(ARG_STARTED_FROM_SEARCH, true); + return this; + } + + public OnlineFeedviewActivityStarter withManualUrl() { + intent.putExtra(ARG_WAS_MANUAL_URL, true); + return this; + } + + public Intent getIntent() { + return intent; + } +} diff --git a/ui/discovery/README.md b/ui/discovery/README.md new file mode 100644 index 000000000..fd8feb580 --- /dev/null +++ b/ui/discovery/README.md @@ -0,0 +1,3 @@ +# :ui:discovery + +This module provides the screens to discover new podcasts. diff --git a/ui/discovery/build.gradle b/ui/discovery/build.gradle new file mode 100644 index 000000000..60b04984b --- /dev/null +++ b/ui/discovery/build.gradle @@ -0,0 +1,26 @@ +plugins { + id("com.android.library") +} +apply from: "../../common.gradle" +apply from: "../../playFlavor.gradle" + +android { + namespace "de.danoeh.antennapod.ui.discovery" +} + +dependencies { + implementation project(":event") + implementation project(":model") + implementation project(':net:discovery') + implementation project(':storage:database') + implementation project(':ui:app-start-intent') + implementation project(':ui:common') + + annotationProcessor "androidx.annotation:annotation:$annotationVersion" + implementation "androidx.appcompat:appcompat:$appcompatVersion" + implementation "com.google.android.material:material:$googleMaterialVersion" + implementation "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion" + implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion" + implementation "com.github.bumptech.glide:glide:$glideVersion" + implementation "org.greenrobot:eventbus:$eventbusVersion" +} diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/DiscoveryFragment.java b/ui/discovery/src/main/java/de/danoeh/antennapod/ui/discovery/DiscoveryFragment.java index f7d9710d7..9cdcdbcb9 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/DiscoveryFragment.java +++ b/ui/discovery/src/main/java/de/danoeh/antennapod/ui/discovery/DiscoveryFragment.java @@ -1,7 +1,6 @@ -package de.danoeh.antennapod.fragment; +package de.danoeh.antennapod.ui.discovery; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; @@ -21,14 +20,12 @@ import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.textfield.MaterialAutoCompleteTextView; import com.google.android.material.textfield.TextInputLayout; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.OnlineFeedViewActivity; -import de.danoeh.antennapod.adapter.itunes.ItunesAdapter; -import de.danoeh.antennapod.core.BuildConfig; +import de.danoeh.antennapod.net.discovery.BuildConfig; import de.danoeh.antennapod.storage.database.DBReader; import de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent; import de.danoeh.antennapod.net.discovery.ItunesTopListLoader; import de.danoeh.antennapod.net.discovery.PodcastSearchResult; +import de.danoeh.antennapod.ui.appstartintent.OnlineFeedviewActivityStarter; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -47,15 +44,14 @@ import java.util.Map; * Searches iTunes store for top podcasts and displays results in a list. */ public class DiscoveryFragment extends Fragment implements Toolbar.OnMenuItemClickListener { - - private static final String TAG = "ItunesSearchFragment"; + public static final String TAG = "DiscoveryFragment"; private static final int NUM_OF_TOP_PODCASTS = 25; private SharedPreferences prefs; /** * Adapter responsible with the search results. */ - private ItunesAdapter adapter; + private OnlineSearchAdapter adapter; private GridView gridView; private ProgressBar progressBar; private TextView txtvError; @@ -110,9 +106,9 @@ public class DiscoveryFragment extends Fragment implements Toolbar.OnMenuItemCli @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View root = inflater.inflate(R.layout.fragment_itunes_search, container, false); + View root = inflater.inflate(R.layout.fragment_online_search, container, false); gridView = root.findViewById(R.id.gridView); - adapter = new ItunesAdapter(getActivity(), new ArrayList<>()); + adapter = new OnlineSearchAdapter(getActivity(), new ArrayList<>()); gridView.setAdapter(adapter); toolbar = root.findViewById(R.id.toolbar); @@ -128,9 +124,7 @@ public class DiscoveryFragment extends Fragment implements Toolbar.OnMenuItemCli if (podcast.feedUrl == null) { return; } - Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class); - intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, podcast.feedUrl); - startActivity(intent); + startActivity(new OnlineFeedviewActivityStarter(getContext(), podcast.feedUrl).getIntent()); }); progressBar = root.findViewById(R.id.progressBar); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/FeedDiscoverAdapter.java b/ui/discovery/src/main/java/de/danoeh/antennapod/ui/discovery/FeedDiscoverAdapter.java index 5e2c091e9..ac400da9f 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/FeedDiscoverAdapter.java +++ b/ui/discovery/src/main/java/de/danoeh/antennapod/ui/discovery/FeedDiscoverAdapter.java @@ -1,5 +1,6 @@ -package de.danoeh.antennapod.adapter; +package de.danoeh.antennapod.ui.discovery; +import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; @@ -8,21 +9,18 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.load.resource.bitmap.FitCenter; import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.request.RequestOptions; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.net.discovery.PodcastSearchResult; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; public class FeedDiscoverAdapter extends BaseAdapter { - private final WeakReference<MainActivity> mainActivityRef; private final List<PodcastSearchResult> data = new ArrayList<>(); + private final Context context; - public FeedDiscoverAdapter(MainActivity mainActivity) { - this.mainActivityRef = new WeakReference<>(mainActivity); + public FeedDiscoverAdapter(Context context) { + this.context = context; } public void updateData(List<PodcastSearchResult> newData) { @@ -51,7 +49,7 @@ public class FeedDiscoverAdapter extends BaseAdapter { Holder holder; if (convertView == null) { - convertView = View.inflate(mainActivityRef.get(), R.layout.quick_feed_discovery_item, null); + convertView = View.inflate(context, R.layout.quick_feed_discovery_item, null); holder = new Holder(); holder.imageView = convertView.findViewById(R.id.discovery_cover); convertView.setTag(holder); @@ -63,12 +61,12 @@ public class FeedDiscoverAdapter extends BaseAdapter { final PodcastSearchResult podcast = getItem(position); holder.imageView.setContentDescription(podcast.title); - Glide.with(mainActivityRef.get()) + Glide.with(context) .load(podcast.imageUrl) .apply(new RequestOptions() .placeholder(R.color.light_gray) .transform(new FitCenter(), new RoundedCorners((int) - (8 * mainActivityRef.get().getResources().getDisplayMetrics().density))) + (8 * context.getResources().getDisplayMetrics().density))) .dontAnimate()) .into(holder.imageView); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java b/ui/discovery/src/main/java/de/danoeh/antennapod/ui/discovery/OnlineSearchAdapter.java index 9b514dd98..a536b8ebd 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java +++ b/ui/discovery/src/main/java/de/danoeh/antennapod/ui/discovery/OnlineSearchAdapter.java @@ -1,4 +1,4 @@ -package de.danoeh.antennapod.adapter.itunes; +package de.danoeh.antennapod.ui.discovery; import android.content.Context; import android.widget.ArrayAdapter; @@ -17,11 +17,9 @@ import com.bumptech.glide.request.RequestOptions; import java.util.List; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.net.discovery.PodcastSearchResult; -public class ItunesAdapter extends ArrayAdapter<PodcastSearchResult> { +public class OnlineSearchAdapter extends ArrayAdapter<PodcastSearchResult> { /** * Related Context */ @@ -38,7 +36,7 @@ public class ItunesAdapter extends ArrayAdapter<PodcastSearchResult> { * @param context Related context * @param objects Search result */ - public ItunesAdapter(Context context, List<PodcastSearchResult> objects) { + public OnlineSearchAdapter(Context context, List<PodcastSearchResult> objects) { super(context, 0, objects); this.data = objects; this.context = context; @@ -57,9 +55,8 @@ public class ItunesAdapter extends ArrayAdapter<PodcastSearchResult> { View view; //Handle view holder stuff - if(convertView == null) { - view = ((MainActivity) context).getLayoutInflater() - .inflate(R.layout.itunes_podcast_listitem, parent, false); + if (convertView == null) { + view = View.inflate(context, R.layout.online_search_listitem, null); viewHolder = new PodcastViewHolder(view); view.setTag(viewHolder); } else { @@ -116,7 +113,7 @@ public class ItunesAdapter extends ArrayAdapter<PodcastSearchResult> { * Constructor * @param view GridView cell */ - PodcastViewHolder(View view){ + PodcastViewHolder(View view) { coverView = view.findViewById(R.id.imgvCover); titleView = view.findViewById(R.id.txtvTitle); authorView = view.findViewById(R.id.txtvAuthor); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/OnlineSearchFragment.java b/ui/discovery/src/main/java/de/danoeh/antennapod/ui/discovery/OnlineSearchFragment.java index 9e34c0a27..00459a174 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/OnlineSearchFragment.java +++ b/ui/discovery/src/main/java/de/danoeh/antennapod/ui/discovery/OnlineSearchFragment.java @@ -1,7 +1,6 @@ -package de.danoeh.antennapod.fragment; +package de.danoeh.antennapod.ui.discovery; import android.content.Context; -import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -23,13 +22,10 @@ import com.google.android.material.appbar.MaterialToolbar; import java.util.ArrayList; import java.util.List; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.MainActivity; -import de.danoeh.antennapod.activity.OnlineFeedViewActivity; -import de.danoeh.antennapod.adapter.itunes.ItunesAdapter; import de.danoeh.antennapod.net.discovery.PodcastSearchResult; import de.danoeh.antennapod.net.discovery.PodcastSearcher; import de.danoeh.antennapod.net.discovery.PodcastSearcherRegistry; +import de.danoeh.antennapod.ui.appstartintent.OnlineFeedviewActivityStarter; import io.reactivex.disposables.Disposable; public class OnlineSearchFragment extends Fragment { @@ -41,7 +37,7 @@ public class OnlineSearchFragment extends Fragment { /** * Adapter responsible with the search results */ - private ItunesAdapter adapter; + private OnlineSearchAdapter adapter; private PodcastSearcher searchProvider; private GridView gridView; private ProgressBar progressBar; @@ -93,18 +89,16 @@ public class OnlineSearchFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View root = inflater.inflate(R.layout.fragment_itunes_search, container, false); + View root = inflater.inflate(R.layout.fragment_online_search, container, false); gridView = root.findViewById(R.id.gridView); - adapter = new ItunesAdapter(getActivity(), new ArrayList<>()); + adapter = new OnlineSearchAdapter(getActivity(), new ArrayList<>()); gridView.setAdapter(adapter); //Show information about the podcast when the list item is clicked gridView.setOnItemClickListener((parent, view1, position, id) -> { PodcastSearchResult podcast = searchResults.get(position); - Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class); - intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, podcast.feedUrl); - intent.putExtra(MainActivity.EXTRA_STARTED_FROM_SEARCH, true); - startActivity(intent); + startActivity(new OnlineFeedviewActivityStarter(getContext(), podcast.feedUrl) + .withStartedFromSearch().getIntent()); }); progressBar = root.findViewById(R.id.progressBar); txtvError = root.findViewById(R.id.txtvError); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QuickFeedDiscoveryFragment.java b/ui/discovery/src/main/java/de/danoeh/antennapod/ui/discovery/QuickFeedDiscoveryFragment.java index f68fc1a81..ff5e328f2 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QuickFeedDiscoveryFragment.java +++ b/ui/discovery/src/main/java/de/danoeh/antennapod/ui/discovery/QuickFeedDiscoveryFragment.java @@ -1,6 +1,5 @@ -package de.danoeh.antennapod.fragment; +package de.danoeh.antennapod.ui.discovery; -import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.text.TextUtils; @@ -16,15 +15,13 @@ import android.widget.GridView; import android.widget.LinearLayout; import android.widget.TextView; import androidx.fragment.app.Fragment; -import de.danoeh.antennapod.BuildConfig; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.MainActivity; -import de.danoeh.antennapod.activity.OnlineFeedViewActivity; -import de.danoeh.antennapod.adapter.FeedDiscoverAdapter; +import de.danoeh.antennapod.net.discovery.BuildConfig; import de.danoeh.antennapod.storage.database.DBReader; import de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent; import de.danoeh.antennapod.net.discovery.ItunesTopListLoader; import de.danoeh.antennapod.net.discovery.PodcastSearchResult; +import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter; +import de.danoeh.antennapod.ui.appstartintent.OnlineFeedviewActivityStarter; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -57,8 +54,10 @@ public class QuickFeedDiscoveryFragment extends Fragment implements AdapterView. super.onCreateView(inflater, container, savedInstanceState); View root = inflater.inflate(R.layout.quick_feed_discovery, container, false); View discoverMore = root.findViewById(R.id.discover_more); - discoverMore.setOnClickListener(v -> - ((MainActivity) getActivity()).loadChildFragment(new DiscoveryFragment())); + discoverMore.setOnClickListener(v -> startActivity(new MainActivityStarter(getContext()) + .withFragmentLoaded(DiscoveryFragment.TAG) + .withAddToBackStack() + .getIntent())); discoverGridLayout = root.findViewById(R.id.discover_grid); errorView = root.findViewById(R.id.discover_error); @@ -66,7 +65,7 @@ public class QuickFeedDiscoveryFragment extends Fragment implements AdapterView. errorRetry = root.findViewById(R.id.discover_error_retry_btn); poweredByTextView = root.findViewById(R.id.discover_powered_by_itunes); - adapter = new FeedDiscoverAdapter((MainActivity) getActivity()); + adapter = new FeedDiscoverAdapter(getActivity()); discoverGridLayout.setAdapter(adapter); discoverGridLayout.setOnItemClickListener(this); @@ -171,8 +170,6 @@ public class QuickFeedDiscoveryFragment extends Fragment implements AdapterView. if (TextUtils.isEmpty(podcast.feedUrl)) { return; } - Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class); - intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, podcast.feedUrl); - startActivity(intent); + startActivity(new OnlineFeedviewActivityStarter(getContext(), podcast.feedUrl).getIntent()); } } diff --git a/app/src/main/res/layout/fragment_itunes_search.xml b/ui/discovery/src/main/res/layout/fragment_online_search.xml index 4dd767d58..902dd8b74 100644 --- a/app/src/main/res/layout/fragment_itunes_search.xml +++ b/ui/discovery/src/main/res/layout/fragment_online_search.xml @@ -40,7 +40,7 @@ android:paddingTop="@dimen/list_vertical_padding" android:stretchMode="columnWidth" android:verticalSpacing="8dp" - tools:listitem="@layout/itunes_podcast_listitem" /> + tools:listitem="@layout/online_search_listitem" /> <TextView android:id="@android:id/empty" diff --git a/app/src/main/res/layout/itunes_podcast_listitem.xml b/ui/discovery/src/main/res/layout/online_search_listitem.xml index da2de457b..da2de457b 100644 --- a/app/src/main/res/layout/itunes_podcast_listitem.xml +++ b/ui/discovery/src/main/res/layout/online_search_listitem.xml diff --git a/app/src/main/res/layout/quick_feed_discovery.xml b/ui/discovery/src/main/res/layout/quick_feed_discovery.xml index 4781bf323..f4e406d20 100644 --- a/app/src/main/res/layout/quick_feed_discovery.xml +++ b/ui/discovery/src/main/res/layout/quick_feed_discovery.xml @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" @@ -46,8 +45,8 @@ android:layout_marginTop="8dp" android:layout_centerInParent="true" android:layout_gravity="center_horizontal" - app:layout_columnWeight="1" - app:layout_rowWeight="1" /> + android:layout_columnWeight="1" + android:layout_rowWeight="1" /> <LinearLayout android:id="@+id/discover_error" diff --git a/app/src/main/res/layout/quick_feed_discovery_item.xml b/ui/discovery/src/main/res/layout/quick_feed_discovery_item.xml index 4407eb2f5..4407eb2f5 100644 --- a/app/src/main/res/layout/quick_feed_discovery_item.xml +++ b/ui/discovery/src/main/res/layout/quick_feed_discovery_item.xml diff --git a/app/src/main/res/layout/select_country_dialog.xml b/ui/discovery/src/main/res/layout/select_country_dialog.xml index 70f93bb77..70f93bb77 100644 --- a/app/src/main/res/layout/select_country_dialog.xml +++ b/ui/discovery/src/main/res/layout/select_country_dialog.xml diff --git a/app/src/main/res/menu/countries_menu.xml b/ui/discovery/src/main/res/menu/countries_menu.xml index e0bd7dafe..e0bd7dafe 100644 --- a/app/src/main/res/menu/countries_menu.xml +++ b/ui/discovery/src/main/res/menu/countries_menu.xml diff --git a/app/src/main/res/menu/online_search.xml b/ui/discovery/src/main/res/menu/online_search.xml index 374a054fa..374a054fa 100644 --- a/app/src/main/res/menu/online_search.xml +++ b/ui/discovery/src/main/res/menu/online_search.xml |