Add :ui:discovery module (#7037)

This commit is contained in:
ByteHamster 2024-03-29 13:38:31 +01:00 committed by GitHub
parent 5ede21d676
commit 8f553f08f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 146 additions and 107 deletions

View File

@ -90,6 +90,7 @@ dependencies {
implementation project(':storage:preferences') implementation project(':storage:preferences')
implementation project(':ui:app-start-intent') implementation project(':ui:app-start-intent')
implementation project(':ui:common') implementation project(':ui:common')
implementation project(':ui:discovery')
implementation project(':ui:echo') implementation project(':ui:echo')
implementation project(':ui:episodes') implementation project(':ui:episodes')
implementation project(':ui:glide') implementation project(':ui:glide')

View File

@ -305,6 +305,10 @@
<data android:mimeType="text/plain"/> <data android:mimeType="text/plain"/>
</intent-filter> </intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="de.danoeh.antennapod.intents.ONLINE_FEEDVIEW" />
</intent-filter>
</activity> </activity>
<activity android:name=".activity.SelectSubscriptionActivity" <activity android:name=".activity.SelectSubscriptionActivity"

View File

@ -63,6 +63,7 @@ import de.danoeh.antennapod.storage.importexport.AutomaticDatabaseExportWorker;
import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter; import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter;
import de.danoeh.antennapod.ui.common.ThemeUtils; 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.ui.home.HomeFragment;
import de.danoeh.antennapod.view.LockableBottomSheetBehavior; import de.danoeh.antennapod.view.LockableBottomSheetBehavior;
import org.apache.commons.lang3.ArrayUtils; 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_FEED_ID = "fragment_feed_id";
public static final String EXTRA_REFRESH_ON_START = "refresh_on_start"; 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 EXTRA_ADD_TO_BACK_STACK = "add_to_back_stack";
public static final String KEY_GENERATED_VIEW_ID = "generated_view_id"; public static final String KEY_GENERATED_VIEW_ID = "generated_view_id";
@ -347,7 +347,7 @@ public class MainActivity extends CastEnabledActivity {
return recycledViewPool; return recycledViewPool;
} }
public void loadFragment(String tag, Bundle args) { public Fragment createFragmentInstance(String tag, Bundle args) {
Log.d(TAG, "loadFragment(tag: " + tag + ", args: " + args + ")"); Log.d(TAG, "loadFragment(tag: " + tag + ", args: " + args + ")");
Fragment fragment; Fragment fragment;
switch (tag) { switch (tag) {
@ -375,19 +375,24 @@ public class MainActivity extends CastEnabledActivity {
case SubscriptionFragment.TAG: case SubscriptionFragment.TAG:
fragment = new SubscriptionFragment(); fragment = new SubscriptionFragment();
break; break;
case DiscoveryFragment.TAG:
fragment = new DiscoveryFragment();
break;
default: default:
// default to home screen // default to home screen
fragment = new HomeFragment(); fragment = new HomeFragment();
tag = HomeFragment.TAG;
args = null; args = null;
break; break;
} }
if (args != null) { if (args != null) {
fragment.setArguments(args); fragment.setArguments(args);
} }
return fragment;
}
public void loadFragment(String tag, Bundle args) {
NavDrawerFragment.saveLastNavFragment(this, tag); NavDrawerFragment.saveLastNavFragment(this, tag);
loadFragment(fragment); loadFragment(createFragmentInstance(tag, args));
} }
public void loadFeedFragmentById(long feedId, Bundle args) { public void loadFeedFragmentById(long feedId, Bundle args) {
@ -399,7 +404,7 @@ public class MainActivity extends CastEnabledActivity {
loadFragment(fragment); loadFragment(fragment);
} }
private void loadFragment(Fragment fragment) { public void loadFragment(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
// clear back stack // clear back stack
for (int i = 0; i < fragmentManager.getBackStackEntryCount(); i++) { 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); long feedId = intent.getLongExtra(EXTRA_FEED_ID, 0);
Bundle args = intent.getBundleExtra(MainActivityStarter.EXTRA_FRAGMENT_ARGS); Bundle args = intent.getBundleExtra(MainActivityStarter.EXTRA_FRAGMENT_ARGS);
if (feedId > 0) { if (feedId > 0) {
boolean startedFromSearch = intent.getBooleanExtra(EXTRA_STARTED_FROM_SEARCH, false);
boolean addToBackStack = intent.getBooleanExtra(EXTRA_ADD_TO_BACK_STACK, false); boolean addToBackStack = intent.getBooleanExtra(EXTRA_ADD_TO_BACK_STACK, false);
if (startedFromSearch || addToBackStack) { if (addToBackStack) {
loadChildFragment(FeedItemlistFragment.newInstance(feedId)); loadChildFragment(FeedItemlistFragment.newInstance(feedId));
} else { } else {
loadFeedFragmentById(feedId, args); loadFeedFragmentById(feedId, args);
@ -604,7 +608,12 @@ public class MainActivity extends CastEnabledActivity {
String tag = intent.getStringExtra(MainActivityStarter.EXTRA_FRAGMENT_TAG); String tag = intent.getStringExtra(MainActivityStarter.EXTRA_FRAGMENT_TAG);
Bundle args = intent.getBundleExtra(MainActivityStarter.EXTRA_FRAGMENT_ARGS); Bundle args = intent.getBundleExtra(MainActivityStarter.EXTRA_FRAGMENT_ARGS);
if (tag != null) { 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); sheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
} else if (intent.getBooleanExtra(MainActivityStarter.EXTRA_OPEN_PLAYER, false)) { } else if (intent.getBooleanExtra(MainActivityStarter.EXTRA_OPEN_PLAYER, false)) {

View File

@ -12,7 +12,6 @@ import android.text.SpannableString;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.util.Log; import android.util.Log;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
@ -23,13 +22,13 @@ import androidx.annotation.Nullable;
import androidx.annotation.UiThread; import androidx.annotation.UiThread;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NavUtils;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.FeedItemlistDescriptionAdapter; import de.danoeh.antennapod.adapter.FeedItemlistDescriptionAdapter;
import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter;
import de.danoeh.antennapod.ui.common.ThemeSwitcher; import de.danoeh.antennapod.ui.common.ThemeSwitcher;
import de.danoeh.antennapod.core.service.download.DownloadRequestCreator; import de.danoeh.antennapod.core.service.download.DownloadRequestCreator;
import de.danoeh.antennapod.net.discovery.FeedUrlNotFoundException; import de.danoeh.antennapod.net.discovery.FeedUrlNotFoundException;
@ -85,6 +84,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; 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 * 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 * 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 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 int RESULT_ERROR = 2;
private static final String TAG = "OnlineFeedViewActivity"; private static final String TAG = "OnlineFeedViewActivity";
private static final String PREFS = "OnlineFeedViewActivityPreferences"; 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); 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) { private void lookupUrlAndDownload(String url) {
download = PodcastSearcherRegistry.lookupUrl(url) download = PodcastSearcherRegistry.lookupUrl(url)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
@ -521,13 +508,14 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
} }
private void openFeed() { private void openFeed() {
// feed.getId() is always 0, we have to retrieve the id from the feed list from // feed.getId() is always 0, we have to retrieve the id from the feed list from the database
// the database MainActivityStarter mainActivityStarter = new MainActivityStarter(this);
Intent intent = MainActivity.getIntentToOpenFeed(this, getFeedId()); mainActivityStarter.withOpenFeed(getFeedId());
intent.putExtra(MainActivity.EXTRA_STARTED_FROM_SEARCH, if (getIntent().getBooleanExtra(ARG_STARTED_FROM_SEARCH, false)) {
getIntent().getBooleanExtra(MainActivity.EXTRA_STARTED_FROM_SEARCH, false)); mainActivityStarter.withAddToBackStack();
}
finish(); finish();
startActivity(intent); startActivity(mainActivityStarter.getIntent());
} }
private void handleUpdatedFeedStatus() { private void handleUpdatedFeedStatus() {

View File

@ -25,7 +25,6 @@ import com.google.android.material.snackbar.Snackbar;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.OnlineFeedViewActivity;
import de.danoeh.antennapod.activity.OpmlImportActivity; import de.danoeh.antennapod.activity.OpmlImportActivity;
import de.danoeh.antennapod.core.util.download.FeedUpdateManager; import de.danoeh.antennapod.core.util.download.FeedUpdateManager;
import de.danoeh.antennapod.model.feed.Feed; 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.GpodnetPodcastSearcher;
import de.danoeh.antennapod.net.discovery.ItunesPodcastSearcher; import de.danoeh.antennapod.net.discovery.ItunesPodcastSearcher;
import de.danoeh.antennapod.net.discovery.PodcastIndexPodcastSearcher; 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.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
@ -145,10 +146,7 @@ public class AddFeedFragment extends Fragment {
} }
private void addUrl(String url) { private void addUrl(String url) {
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class); startActivity(new OnlineFeedviewActivityStarter(getContext(), url).withManualUrl().getIntent());
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, url);
intent.putExtra(OnlineFeedViewActivity.ARG_WAS_MANUAL_URL, true);
startActivity(intent);
} }
private void performSearch() { private void performSearch() {

View File

@ -2,7 +2,6 @@ package de.danoeh.antennapod.fragment;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
@ -29,7 +28,6 @@ import com.leinardi.android.speeddial.SpeedDialView;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.activity.OnlineFeedViewActivity;
import de.danoeh.antennapod.adapter.EpisodeItemListAdapter; import de.danoeh.antennapod.adapter.EpisodeItemListAdapter;
import de.danoeh.antennapod.adapter.HorizontalFeedListAdapter; import de.danoeh.antennapod.adapter.HorizontalFeedListAdapter;
import de.danoeh.antennapod.core.menuhandler.MenuItemUtils; 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.menuhandler.FeedItemMenuHandler;
import de.danoeh.antennapod.net.discovery.CombinedSearcher; import de.danoeh.antennapod.net.discovery.CombinedSearcher;
import de.danoeh.antennapod.storage.database.DBReader; 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.EmptyViewHandler;
import de.danoeh.antennapod.view.EpisodeItemListRecyclerView; import de.danoeh.antennapod.view.EpisodeItemListRecyclerView;
import de.danoeh.antennapod.view.LiftOnScrollListener; import de.danoeh.antennapod.view.LiftOnScrollListener;
@ -425,9 +425,7 @@ public class SearchFragment extends Fragment implements EpisodeItemListAdapter.O
in.hideSoftInputFromWindow(searchView.getWindowToken(), 0); in.hideSoftInputFromWindow(searchView.getWindowToken(), 0);
String query = searchView.getQuery().toString(); String query = searchView.getQuery().toString();
if (query.matches("http[s]?://.*")) { if (query.matches("http[s]?://.*")) {
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class); startActivity(new OnlineFeedviewActivityStarter(getContext(), query).getIntent());
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, query);
startActivity(intent);
return; return;
} }
((MainActivity) getActivity()).loadChildFragment( ((MainActivity) getActivity()).loadChildFragment(

View File

@ -85,7 +85,7 @@
android:id="@+id/quickFeedDiscovery" android:id="@+id/quickFeedDiscovery"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:name="de.danoeh.antennapod.fragment.QuickFeedDiscoveryFragment" /> android:name="de.danoeh.antennapod.ui.discovery.QuickFeedDiscoveryFragment" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -39,6 +39,7 @@ include ':storage:preferences'
include ':ui:app-start-intent' include ':ui:app-start-intent'
include ':ui:common' include ':ui:common'
include ':ui:discovery'
include ':ui:echo' include ':ui:echo'
include ':ui:episodes' include ':ui:episodes'
include ':ui:glide' include ':ui:glide'

View File

@ -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;
}
}

3
ui/discovery/README.md Normal file
View File

@ -0,0 +1,3 @@
# :ui:discovery
This module provides the screens to discover new podcasts.

26
ui/discovery/build.gradle Normal file
View File

@ -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"
}

View File

@ -1,7 +1,6 @@
package de.danoeh.antennapod.fragment; package de.danoeh.antennapod.ui.discovery;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; 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.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.textfield.MaterialAutoCompleteTextView; import com.google.android.material.textfield.MaterialAutoCompleteTextView;
import com.google.android.material.textfield.TextInputLayout; import com.google.android.material.textfield.TextInputLayout;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.net.discovery.BuildConfig;
import de.danoeh.antennapod.activity.OnlineFeedViewActivity;
import de.danoeh.antennapod.adapter.itunes.ItunesAdapter;
import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.storage.database.DBReader; import de.danoeh.antennapod.storage.database.DBReader;
import de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent; import de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent;
import de.danoeh.antennapod.net.discovery.ItunesTopListLoader; import de.danoeh.antennapod.net.discovery.ItunesTopListLoader;
import de.danoeh.antennapod.net.discovery.PodcastSearchResult; import de.danoeh.antennapod.net.discovery.PodcastSearchResult;
import de.danoeh.antennapod.ui.appstartintent.OnlineFeedviewActivityStarter;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; 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. * Searches iTunes store for top podcasts and displays results in a list.
*/ */
public class DiscoveryFragment extends Fragment implements Toolbar.OnMenuItemClickListener { public class DiscoveryFragment extends Fragment implements Toolbar.OnMenuItemClickListener {
public static final String TAG = "DiscoveryFragment";
private static final String TAG = "ItunesSearchFragment";
private static final int NUM_OF_TOP_PODCASTS = 25; private static final int NUM_OF_TOP_PODCASTS = 25;
private SharedPreferences prefs; private SharedPreferences prefs;
/** /**
* Adapter responsible with the search results. * Adapter responsible with the search results.
*/ */
private ItunesAdapter adapter; private OnlineSearchAdapter adapter;
private GridView gridView; private GridView gridView;
private ProgressBar progressBar; private ProgressBar progressBar;
private TextView txtvError; private TextView txtvError;
@ -110,9 +106,9 @@ public class DiscoveryFragment extends Fragment implements Toolbar.OnMenuItemCli
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment // 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); gridView = root.findViewById(R.id.gridView);
adapter = new ItunesAdapter(getActivity(), new ArrayList<>()); adapter = new OnlineSearchAdapter(getActivity(), new ArrayList<>());
gridView.setAdapter(adapter); gridView.setAdapter(adapter);
toolbar = root.findViewById(R.id.toolbar); toolbar = root.findViewById(R.id.toolbar);
@ -128,9 +124,7 @@ public class DiscoveryFragment extends Fragment implements Toolbar.OnMenuItemCli
if (podcast.feedUrl == null) { if (podcast.feedUrl == null) {
return; return;
} }
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class); startActivity(new OnlineFeedviewActivityStarter(getContext(), podcast.feedUrl).getIntent());
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, podcast.feedUrl);
startActivity(intent);
}); });
progressBar = root.findViewById(R.id.progressBar); progressBar = root.findViewById(R.id.progressBar);

View File

@ -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.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.BaseAdapter; 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.FitCenter;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions; 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 de.danoeh.antennapod.net.discovery.PodcastSearchResult;
import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class FeedDiscoverAdapter extends BaseAdapter { public class FeedDiscoverAdapter extends BaseAdapter {
private final WeakReference<MainActivity> mainActivityRef;
private final List<PodcastSearchResult> data = new ArrayList<>(); private final List<PodcastSearchResult> data = new ArrayList<>();
private final Context context;
public FeedDiscoverAdapter(MainActivity mainActivity) { public FeedDiscoverAdapter(Context context) {
this.mainActivityRef = new WeakReference<>(mainActivity); this.context = context;
} }
public void updateData(List<PodcastSearchResult> newData) { public void updateData(List<PodcastSearchResult> newData) {
@ -51,7 +49,7 @@ public class FeedDiscoverAdapter extends BaseAdapter {
Holder holder; Holder holder;
if (convertView == null) { 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 = new Holder();
holder.imageView = convertView.findViewById(R.id.discovery_cover); holder.imageView = convertView.findViewById(R.id.discovery_cover);
convertView.setTag(holder); convertView.setTag(holder);
@ -63,12 +61,12 @@ public class FeedDiscoverAdapter extends BaseAdapter {
final PodcastSearchResult podcast = getItem(position); final PodcastSearchResult podcast = getItem(position);
holder.imageView.setContentDescription(podcast.title); holder.imageView.setContentDescription(podcast.title);
Glide.with(mainActivityRef.get()) Glide.with(context)
.load(podcast.imageUrl) .load(podcast.imageUrl)
.apply(new RequestOptions() .apply(new RequestOptions()
.placeholder(R.color.light_gray) .placeholder(R.color.light_gray)
.transform(new FitCenter(), new RoundedCorners((int) .transform(new FitCenter(), new RoundedCorners((int)
(8 * mainActivityRef.get().getResources().getDisplayMetrics().density))) (8 * context.getResources().getDisplayMetrics().density)))
.dontAnimate()) .dontAnimate())
.into(holder.imageView); .into(holder.imageView);

View File

@ -1,4 +1,4 @@
package de.danoeh.antennapod.adapter.itunes; package de.danoeh.antennapod.ui.discovery;
import android.content.Context; import android.content.Context;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
@ -17,11 +17,9 @@ import com.bumptech.glide.request.RequestOptions;
import java.util.List; import java.util.List;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.net.discovery.PodcastSearchResult; import de.danoeh.antennapod.net.discovery.PodcastSearchResult;
public class ItunesAdapter extends ArrayAdapter<PodcastSearchResult> { public class OnlineSearchAdapter extends ArrayAdapter<PodcastSearchResult> {
/** /**
* Related Context * Related Context
*/ */
@ -38,7 +36,7 @@ public class ItunesAdapter extends ArrayAdapter<PodcastSearchResult> {
* @param context Related context * @param context Related context
* @param objects Search result * @param objects Search result
*/ */
public ItunesAdapter(Context context, List<PodcastSearchResult> objects) { public OnlineSearchAdapter(Context context, List<PodcastSearchResult> objects) {
super(context, 0, objects); super(context, 0, objects);
this.data = objects; this.data = objects;
this.context = context; this.context = context;
@ -57,9 +55,8 @@ public class ItunesAdapter extends ArrayAdapter<PodcastSearchResult> {
View view; View view;
//Handle view holder stuff //Handle view holder stuff
if(convertView == null) { if (convertView == null) {
view = ((MainActivity) context).getLayoutInflater() view = View.inflate(context, R.layout.online_search_listitem, null);
.inflate(R.layout.itunes_podcast_listitem, parent, false);
viewHolder = new PodcastViewHolder(view); viewHolder = new PodcastViewHolder(view);
view.setTag(viewHolder); view.setTag(viewHolder);
} else { } else {
@ -116,7 +113,7 @@ public class ItunesAdapter extends ArrayAdapter<PodcastSearchResult> {
* Constructor * Constructor
* @param view GridView cell * @param view GridView cell
*/ */
PodcastViewHolder(View view){ PodcastViewHolder(View view) {
coverView = view.findViewById(R.id.imgvCover); coverView = view.findViewById(R.id.imgvCover);
titleView = view.findViewById(R.id.txtvTitle); titleView = view.findViewById(R.id.txtvTitle);
authorView = view.findViewById(R.id.txtvAuthor); authorView = view.findViewById(R.id.txtvAuthor);

View File

@ -1,7 +1,6 @@
package de.danoeh.antennapod.fragment; package de.danoeh.antennapod.ui.discovery;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -23,13 +22,10 @@ import com.google.android.material.appbar.MaterialToolbar;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.PodcastSearchResult;
import de.danoeh.antennapod.net.discovery.PodcastSearcher; import de.danoeh.antennapod.net.discovery.PodcastSearcher;
import de.danoeh.antennapod.net.discovery.PodcastSearcherRegistry; import de.danoeh.antennapod.net.discovery.PodcastSearcherRegistry;
import de.danoeh.antennapod.ui.appstartintent.OnlineFeedviewActivityStarter;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
public class OnlineSearchFragment extends Fragment { public class OnlineSearchFragment extends Fragment {
@ -41,7 +37,7 @@ public class OnlineSearchFragment extends Fragment {
/** /**
* Adapter responsible with the search results * Adapter responsible with the search results
*/ */
private ItunesAdapter adapter; private OnlineSearchAdapter adapter;
private PodcastSearcher searchProvider; private PodcastSearcher searchProvider;
private GridView gridView; private GridView gridView;
private ProgressBar progressBar; private ProgressBar progressBar;
@ -93,18 +89,16 @@ public class OnlineSearchFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment // 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); gridView = root.findViewById(R.id.gridView);
adapter = new ItunesAdapter(getActivity(), new ArrayList<>()); adapter = new OnlineSearchAdapter(getActivity(), new ArrayList<>());
gridView.setAdapter(adapter); gridView.setAdapter(adapter);
//Show information about the podcast when the list item is clicked //Show information about the podcast when the list item is clicked
gridView.setOnItemClickListener((parent, view1, position, id) -> { gridView.setOnItemClickListener((parent, view1, position, id) -> {
PodcastSearchResult podcast = searchResults.get(position); PodcastSearchResult podcast = searchResults.get(position);
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class); startActivity(new OnlineFeedviewActivityStarter(getContext(), podcast.feedUrl)
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, podcast.feedUrl); .withStartedFromSearch().getIntent());
intent.putExtra(MainActivity.EXTRA_STARTED_FROM_SEARCH, true);
startActivity(intent);
}); });
progressBar = root.findViewById(R.id.progressBar); progressBar = root.findViewById(R.id.progressBar);
txtvError = root.findViewById(R.id.txtvError); txtvError = root.findViewById(R.id.txtvError);

View File

@ -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.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
@ -16,15 +15,13 @@ import android.widget.GridView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.net.discovery.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.storage.database.DBReader; import de.danoeh.antennapod.storage.database.DBReader;
import de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent; import de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent;
import de.danoeh.antennapod.net.discovery.ItunesTopListLoader; import de.danoeh.antennapod.net.discovery.ItunesTopListLoader;
import de.danoeh.antennapod.net.discovery.PodcastSearchResult; 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.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
@ -57,8 +54,10 @@ public class QuickFeedDiscoveryFragment extends Fragment implements AdapterView.
super.onCreateView(inflater, container, savedInstanceState); super.onCreateView(inflater, container, savedInstanceState);
View root = inflater.inflate(R.layout.quick_feed_discovery, container, false); View root = inflater.inflate(R.layout.quick_feed_discovery, container, false);
View discoverMore = root.findViewById(R.id.discover_more); View discoverMore = root.findViewById(R.id.discover_more);
discoverMore.setOnClickListener(v -> discoverMore.setOnClickListener(v -> startActivity(new MainActivityStarter(getContext())
((MainActivity) getActivity()).loadChildFragment(new DiscoveryFragment())); .withFragmentLoaded(DiscoveryFragment.TAG)
.withAddToBackStack()
.getIntent()));
discoverGridLayout = root.findViewById(R.id.discover_grid); discoverGridLayout = root.findViewById(R.id.discover_grid);
errorView = root.findViewById(R.id.discover_error); 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); errorRetry = root.findViewById(R.id.discover_error_retry_btn);
poweredByTextView = root.findViewById(R.id.discover_powered_by_itunes); poweredByTextView = root.findViewById(R.id.discover_powered_by_itunes);
adapter = new FeedDiscoverAdapter((MainActivity) getActivity()); adapter = new FeedDiscoverAdapter(getActivity());
discoverGridLayout.setAdapter(adapter); discoverGridLayout.setAdapter(adapter);
discoverGridLayout.setOnItemClickListener(this); discoverGridLayout.setOnItemClickListener(this);
@ -171,8 +170,6 @@ public class QuickFeedDiscoveryFragment extends Fragment implements AdapterView.
if (TextUtils.isEmpty(podcast.feedUrl)) { if (TextUtils.isEmpty(podcast.feedUrl)) {
return; return;
} }
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class); startActivity(new OnlineFeedviewActivityStarter(getContext(), podcast.feedUrl).getIntent());
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, podcast.feedUrl);
startActivity(intent);
} }
} }

View File

@ -40,7 +40,7 @@
android:paddingTop="@dimen/list_vertical_padding" android:paddingTop="@dimen/list_vertical_padding"
android:stretchMode="columnWidth" android:stretchMode="columnWidth"
android:verticalSpacing="8dp" android:verticalSpacing="8dp"
tools:listitem="@layout/itunes_podcast_listitem" /> tools:listitem="@layout/online_search_listitem" />
<TextView <TextView
android:id="@android:id/empty" android:id="@android:id/empty"

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" 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" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -46,8 +45,8 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
app:layout_columnWeight="1" android:layout_columnWeight="1"
app:layout_rowWeight="1" /> android:layout_rowWeight="1" />
<LinearLayout <LinearLayout
android:id="@+id/discover_error" android:id="@+id/discover_error"