Merge pull request #3282 from ByteHamster/add-feed-page-redesign
Add feed page redesign
This commit is contained in:
commit
0e1cac9098
|
@ -0,0 +1,76 @@
|
|||
package de.danoeh.antennapod.adapter;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.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<>();
|
||||
|
||||
public FeedDiscoverAdapter(MainActivity mainActivity) {
|
||||
this.mainActivityRef = new WeakReference<>(mainActivity);
|
||||
}
|
||||
|
||||
public void updateData(List<PodcastSearchResult> newData) {
|
||||
data.clear();
|
||||
data.addAll(newData);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PodcastSearchResult getItem(int position) {
|
||||
return data.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
Holder holder;
|
||||
|
||||
if (convertView == null) {
|
||||
convertView = View.inflate(mainActivityRef.get(), R.layout.quick_feed_discovery_item, null);
|
||||
holder = new Holder();
|
||||
holder.imageView = convertView.findViewById(R.id.discovery_cover);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (Holder) convertView.getTag();
|
||||
}
|
||||
|
||||
|
||||
final PodcastSearchResult podcast = getItem(position);
|
||||
Glide.with(mainActivityRef.get())
|
||||
.load(podcast.imageUrl)
|
||||
.apply(new RequestOptions()
|
||||
.placeholder(R.color.light_gray)
|
||||
.fitCenter()
|
||||
.dontAnimate())
|
||||
.into(holder.imageView);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
static class Holder {
|
||||
ImageView imageView;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package de.danoeh.antennapod.discovery;
|
||||
|
||||
import android.content.Context;
|
||||
import de.danoeh.antennapod.R;
|
||||
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;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ItunesTopListLoader {
|
||||
private final Context context;
|
||||
|
||||
public ItunesTopListLoader(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Single<List<PodcastSearchResult>> loadToplist(int limit) {
|
||||
return Single.create((SingleOnSubscribe<List<PodcastSearchResult>>) emitter -> {
|
||||
String lang = Locale.getDefault().getLanguage();
|
||||
OkHttpClient client = AntennapodHttpClient.getHttpClient();
|
||||
String feedString;
|
||||
try {
|
||||
try {
|
||||
feedString = getTopListFeed(client, lang, limit);
|
||||
} catch (IOException e) {
|
||||
feedString = getTopListFeed(client, "us", limit);
|
||||
}
|
||||
List<PodcastSearchResult> podcasts = parseFeed(feedString);
|
||||
emitter.onSuccess(podcasts);
|
||||
} catch (IOException | JSONException e) {
|
||||
emitter.onError(e);
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public Single<String> getFeedUrl(PodcastSearchResult podcast) {
|
||||
if (!podcast.feedUrl.contains("itunes.apple.com")) {
|
||||
return Single.just(podcast.feedUrl)
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
return Single.create((SingleOnSubscribe<String>) emitter -> {
|
||||
OkHttpClient client = AntennapodHttpClient.getHttpClient();
|
||||
Request.Builder httpReq = new Request.Builder()
|
||||
.url(podcast.feedUrl)
|
||||
.header("User-Agent", ClientConfig.USER_AGENT);
|
||||
try {
|
||||
Response response = client.newCall(httpReq.build()).execute();
|
||||
if (response.isSuccessful()) {
|
||||
String resultString = response.body().string();
|
||||
JSONObject result = new JSONObject(resultString);
|
||||
JSONObject results = result.getJSONArray("results").getJSONObject(0);
|
||||
String feedUrl = results.getString("feedUrl");
|
||||
emitter.onSuccess(feedUrl);
|
||||
} else {
|
||||
String prefix = context.getString(R.string.error_msg_prefix);
|
||||
emitter.onError(new IOException(prefix + response));
|
||||
}
|
||||
} catch (IOException | JSONException e) {
|
||||
emitter.onError(e);
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
private String getTopListFeed(OkHttpClient client, String language, int limit) throws IOException {
|
||||
String url = "https://itunes.apple.com/%s/rss/toppodcasts/limit="+limit+"/explicit=true/json";
|
||||
Request.Builder httpReq = new Request.Builder()
|
||||
.header("User-Agent", ClientConfig.USER_AGENT)
|
||||
.url(String.format(url, language));
|
||||
|
||||
try (Response response = client.newCall(httpReq.build()).execute()) {
|
||||
if (response.isSuccessful()) {
|
||||
return response.body().string();
|
||||
}
|
||||
String prefix = context.getString(R.string.error_msg_prefix);
|
||||
throw new IOException(prefix + response);
|
||||
}
|
||||
}
|
||||
|
||||
private List<PodcastSearchResult> parseFeed(String jsonString) throws JSONException {
|
||||
JSONObject result = new JSONObject(jsonString);
|
||||
JSONObject feed = result.getJSONObject("feed");
|
||||
JSONArray entries = feed.getJSONArray("entry");
|
||||
|
||||
List<PodcastSearchResult> results = new ArrayList<>();
|
||||
for (int i=0; i < entries.length(); i++) {
|
||||
JSONObject json = entries.getJSONObject(i);
|
||||
results.add(PodcastSearchResult.fromItunesToplist(json));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,13 +2,20 @@ package de.danoeh.antennapod.fragment;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.activity.OnlineFeedViewActivity;
|
||||
|
@ -27,11 +34,28 @@ public class AddFeedFragment extends Fragment {
|
|||
*/
|
||||
private static final String ARG_FEED_URL = "feedurl";
|
||||
|
||||
private EditText combinedFeedSearchBox;
|
||||
private MainActivity activity;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
View root = inflater.inflate(R.layout.addfeed, container, false);
|
||||
|
||||
activity = (MainActivity) getActivity();
|
||||
activity.getSupportActionBar().setTitle(R.string.add_feed_label);
|
||||
|
||||
setupAdvancedSearchButtons(root);
|
||||
setupSeachBox(root);
|
||||
|
||||
View butOpmlImport = root.findViewById(R.id.btn_opml_import);
|
||||
butOpmlImport.setOnClickListener(v -> startActivity(new Intent(getActivity(),
|
||||
OpmlImportFromPathActivity.class)));
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private void setupSeachBox(View root) {
|
||||
final EditText etxtFeedurl = root.findViewById(R.id.etxtFeedurl);
|
||||
|
||||
Bundle args = getArguments();
|
||||
|
@ -39,35 +63,69 @@ public class AddFeedFragment extends Fragment {
|
|||
etxtFeedurl.setText(args.getString(ARG_FEED_URL));
|
||||
}
|
||||
|
||||
Button butSearchITunes = root.findViewById(R.id.butSearchItunes);
|
||||
Button butBrowserGpoddernet = root.findViewById(R.id.butBrowseGpoddernet);
|
||||
Button butSearchFyyd = root.findViewById(R.id.butSearchFyyd);
|
||||
Button butSearchCombined = root.findViewById(R.id.butSearchCombined);
|
||||
Button butOpmlImport = root.findViewById(R.id.butOpmlImport);
|
||||
Button butConfirm = root.findViewById(R.id.butConfirm);
|
||||
|
||||
final MainActivity activity = (MainActivity) getActivity();
|
||||
activity.getSupportActionBar().setTitle(R.string.add_feed_label);
|
||||
|
||||
butSearchITunes.setOnClickListener(v -> activity.loadChildFragment(new ItunesSearchFragment()));
|
||||
|
||||
butBrowserGpoddernet.setOnClickListener(v -> activity.loadChildFragment(new GpodnetMainFragment()));
|
||||
|
||||
butSearchFyyd.setOnClickListener(v -> activity.loadChildFragment(new FyydSearchFragment()));
|
||||
|
||||
butSearchCombined.setOnClickListener(v -> activity.loadChildFragment(new CombinedSearchFragment()));
|
||||
|
||||
butOpmlImport.setOnClickListener(v -> startActivity(new Intent(getActivity(),
|
||||
OpmlImportFromPathActivity.class)));
|
||||
|
||||
butConfirm.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
|
||||
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, etxtFeedurl.getText().toString());
|
||||
intent.putExtra(OnlineFeedViewActivity.ARG_TITLE, getString(R.string.add_feed_label));
|
||||
startActivity(intent);
|
||||
Button butConfirmAddUrl = root.findViewById(R.id.butConfirm);
|
||||
butConfirmAddUrl.setOnClickListener(v -> {
|
||||
addUrl(etxtFeedurl.getText().toString());
|
||||
});
|
||||
|
||||
return root;
|
||||
combinedFeedSearchBox = root.findViewById(R.id.combinedFeedSearchBox);
|
||||
combinedFeedSearchBox.setOnEditorActionListener((v, actionId, event) -> {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
performSearch();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
private void setupAdvancedSearchButtons(View root) {
|
||||
View butAdvancedSearch = root.findViewById(R.id.advanced_search);
|
||||
registerForContextMenu(butAdvancedSearch);
|
||||
butAdvancedSearch.setOnClickListener(v -> butAdvancedSearch.showContextMenu());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
getActivity().getMenuInflater().inflate(R.menu.advanced_search, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.search_fyyd:
|
||||
activity.loadChildFragment(new FyydSearchFragment());
|
||||
return true;
|
||||
case R.id.search_gpodder:
|
||||
activity.loadChildFragment(new GpodnetMainFragment());
|
||||
return true;
|
||||
case R.id.search_itunes:
|
||||
activity.loadChildFragment(new ItunesSearchFragment());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void addUrl(String url) {
|
||||
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
|
||||
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, url);
|
||||
intent.putExtra(OnlineFeedViewActivity.ARG_TITLE, getString(R.string.add_feed_label));
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void performSearch() {
|
||||
String query = combinedFeedSearchBox.getText().toString();
|
||||
|
||||
if (query.startsWith("http")) {
|
||||
addUrl(query);
|
||||
return;
|
||||
}
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(CombinedSearchFragment.ARGUMENT_QUERY, query);
|
||||
CombinedSearchFragment fragment = new CombinedSearchFragment();
|
||||
fragment.setArguments(bundle);
|
||||
activity.loadChildFragment(fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.List;
|
|||
public class CombinedSearchFragment extends Fragment {
|
||||
|
||||
private static final String TAG = "CombinedSearchFragment";
|
||||
public static final String ARGUMENT_QUERY = "query";
|
||||
|
||||
/**
|
||||
* Adapter responsible with the search results
|
||||
|
@ -128,6 +129,10 @@ public class CombinedSearchFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
MenuItemCompat.expandActionView(searchItem);
|
||||
|
||||
if (getArguments() != null && getArguments().getString(ARGUMENT_QUERY, null) != null) {
|
||||
sv.setQuery(getArguments().getString(ARGUMENT_QUERY, null), true);
|
||||
}
|
||||
}
|
||||
|
||||
private void search(String query) {
|
||||
|
|
|
@ -21,6 +21,7 @@ import android.widget.TextView;
|
|||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
|
||||
import de.danoeh.antennapod.discovery.ItunesPodcastSearcher;
|
||||
import de.danoeh.antennapod.discovery.ItunesTopListLoader;
|
||||
import de.danoeh.antennapod.discovery.PodcastSearchResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
@ -114,60 +115,30 @@ public class ItunesSearchFragment extends Fragment {
|
|||
//Show information about the podcast when the list item is clicked
|
||||
gridView.setOnItemClickListener((parent, view1, position, id) -> {
|
||||
PodcastSearchResult podcast = searchResults.get(position);
|
||||
if(podcast.feedUrl == null) {
|
||||
if (podcast.feedUrl == null) {
|
||||
return;
|
||||
}
|
||||
if (!podcast.feedUrl.contains("itunes.apple.com")) {
|
||||
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
|
||||
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, podcast.feedUrl);
|
||||
intent.putExtra(OnlineFeedViewActivity.ARG_TITLE, "iTunes");
|
||||
startActivity(intent);
|
||||
} else {
|
||||
gridView.setVisibility(View.GONE);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
disposable = Single.create((SingleOnSubscribe<String>) emitter -> {
|
||||
OkHttpClient client = AntennapodHttpClient.getHttpClient();
|
||||
Request.Builder httpReq = new Request.Builder()
|
||||
.url(podcast.feedUrl)
|
||||
.header("User-Agent", ClientConfig.USER_AGENT);
|
||||
try {
|
||||
Response response = client.newCall(httpReq.build()).execute();
|
||||
if (response.isSuccessful()) {
|
||||
String resultString = response.body().string();
|
||||
JSONObject result = new JSONObject(resultString);
|
||||
JSONObject results = result.getJSONArray("results").getJSONObject(0);
|
||||
String feedUrl = results.getString("feedUrl");
|
||||
emitter.onSuccess(feedUrl);
|
||||
} else {
|
||||
String prefix = getString(R.string.error_msg_prefix);
|
||||
emitter.onError(new IOException(prefix + response));
|
||||
}
|
||||
} catch (IOException | JSONException e) {
|
||||
if (!disposable.isDisposed()) {
|
||||
emitter.onError(e);
|
||||
}
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(feedUrl -> {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
gridView.setVisibility(View.VISIBLE);
|
||||
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
|
||||
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, feedUrl);
|
||||
intent.putExtra(OnlineFeedViewActivity.ARG_TITLE, "iTunes");
|
||||
startActivity(intent);
|
||||
}, error -> {
|
||||
Log.e(TAG, Log.getStackTraceString(error));
|
||||
progressBar.setVisibility(View.GONE);
|
||||
gridView.setVisibility(View.VISIBLE);
|
||||
String prefix = getString(R.string.error_msg_prefix);
|
||||
new MaterialDialog.Builder(getActivity())
|
||||
.content(prefix + " " + error.getMessage())
|
||||
.neutralText(android.R.string.ok)
|
||||
.show();
|
||||
});
|
||||
}
|
||||
gridView.setVisibility(View.GONE);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
ItunesTopListLoader loader = new ItunesTopListLoader(getContext());
|
||||
disposable = loader.getFeedUrl(podcast)
|
||||
.subscribe(feedUrl -> {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
gridView.setVisibility(View.VISIBLE);
|
||||
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
|
||||
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, feedUrl);
|
||||
intent.putExtra(OnlineFeedViewActivity.ARG_TITLE, "iTunes");
|
||||
startActivity(intent);
|
||||
}, error -> {
|
||||
Log.e(TAG, Log.getStackTraceString(error));
|
||||
progressBar.setVisibility(View.GONE);
|
||||
gridView.setVisibility(View.VISIBLE);
|
||||
String prefix = getString(R.string.error_msg_prefix);
|
||||
new MaterialDialog.Builder(getActivity())
|
||||
.content(prefix + " " + error.getMessage())
|
||||
.neutralText(android.R.string.ok)
|
||||
.show();
|
||||
});
|
||||
});
|
||||
progressBar = root.findViewById(R.id.progressBar);
|
||||
txtvError = root.findViewById(R.id.txtvError);
|
||||
|
@ -235,26 +206,9 @@ public class ItunesSearchFragment extends Fragment {
|
|||
butRetry.setVisibility(View.GONE);
|
||||
txtvEmpty.setVisibility(View.GONE);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
disposable = Single.create((SingleOnSubscribe<List<PodcastSearchResult>>) emitter -> {
|
||||
String lang = Locale.getDefault().getLanguage();
|
||||
OkHttpClient client = AntennapodHttpClient.getHttpClient();
|
||||
String feedString;
|
||||
try {
|
||||
try {
|
||||
feedString = getTopListFeed(client, lang);
|
||||
} catch (IOException e) {
|
||||
feedString = getTopListFeed(client, "us");
|
||||
}
|
||||
List<PodcastSearchResult> podcasts = parseFeed(feedString);
|
||||
emitter.onSuccess(podcasts);
|
||||
} catch (IOException | JSONException e) {
|
||||
if (!disposable.isDisposed()) {
|
||||
emitter.onError(e);
|
||||
}
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
||||
ItunesTopListLoader loader = new ItunesTopListLoader(getContext());
|
||||
disposable = loader.loadToplist(25)
|
||||
.subscribe(podcasts -> {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
topList = podcasts;
|
||||
|
@ -269,35 +223,6 @@ public class ItunesSearchFragment extends Fragment {
|
|||
});
|
||||
}
|
||||
|
||||
private String getTopListFeed(OkHttpClient client, String language) throws IOException {
|
||||
String url = "https://itunes.apple.com/%s/rss/toppodcasts/limit=25/explicit=true/json";
|
||||
Request.Builder httpReq = new Request.Builder()
|
||||
.header("User-Agent", ClientConfig.USER_AGENT)
|
||||
.url(String.format(url, language));
|
||||
|
||||
try (Response response = client.newCall(httpReq.build()).execute()) {
|
||||
if (response.isSuccessful()) {
|
||||
return response.body().string();
|
||||
}
|
||||
String prefix = getString(R.string.error_msg_prefix);
|
||||
throw new IOException(prefix + response);
|
||||
}
|
||||
}
|
||||
|
||||
private List<PodcastSearchResult> parseFeed(String jsonString) throws JSONException {
|
||||
JSONObject result = new JSONObject(jsonString);
|
||||
JSONObject feed = result.getJSONObject("feed");
|
||||
JSONArray entries = feed.getJSONArray("entry");
|
||||
|
||||
List<PodcastSearchResult> results = new ArrayList<>();
|
||||
for (int i=0; i < entries.length(); i++) {
|
||||
JSONObject json = entries.getJSONObject(i);
|
||||
results.add(PodcastSearchResult.fromItunesToplist(json));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private void search(String query) {
|
||||
if (disposable != null) {
|
||||
disposable.dispose();
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
package de.danoeh.antennapod.fragment;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ProgressBar;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
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.discovery.ItunesTopListLoader;
|
||||
import de.danoeh.antennapod.discovery.PodcastSearchResult;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
|
||||
public class QuickFeedDiscoveryFragment extends Fragment implements AdapterView.OnItemClickListener {
|
||||
private static final String TAG = "FeedDiscoveryFragment";
|
||||
|
||||
private ProgressBar progressBar;
|
||||
private Disposable disposable;
|
||||
private FeedDiscoverAdapter adapter;
|
||||
private GridView subscriptionGridLayout;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
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 ItunesSearchFragment()));
|
||||
subscriptionGridLayout = root.findViewById(R.id.discover_grid);
|
||||
|
||||
progressBar = root.findViewById(R.id.discover_progress_bar);
|
||||
adapter = new FeedDiscoverAdapter((MainActivity) getActivity());
|
||||
subscriptionGridLayout.setAdapter(adapter);
|
||||
subscriptionGridLayout.setOnItemClickListener(this);
|
||||
|
||||
loadToplist();
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (disposable != null) {
|
||||
disposable.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadToplist() {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
subscriptionGridLayout.setVisibility(View.GONE);
|
||||
|
||||
ItunesTopListLoader loader = new ItunesTopListLoader(getContext());
|
||||
disposable = loader.loadToplist(8)
|
||||
.subscribe(podcasts -> {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
subscriptionGridLayout.setVisibility(View.VISIBLE);
|
||||
adapter.updateData(podcasts);
|
||||
}, error -> {
|
||||
Log.e(TAG, Log.getStackTraceString(error));
|
||||
progressBar.setVisibility(View.GONE);
|
||||
subscriptionGridLayout.setVisibility(View.VISIBLE);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
|
||||
PodcastSearchResult podcast = adapter.getItem(position);
|
||||
if (podcast.feedUrl == null) {
|
||||
return;
|
||||
}
|
||||
view.setAlpha(0.5f);
|
||||
ItunesTopListLoader loader = new ItunesTopListLoader(getContext());
|
||||
disposable = loader.getFeedUrl(podcast)
|
||||
.subscribe(feedUrl -> {
|
||||
view.setAlpha(1f);
|
||||
Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
|
||||
intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, feedUrl);
|
||||
intent.putExtra(OnlineFeedViewActivity.ARG_TITLE, getString(R.string.add_feed_label));
|
||||
startActivity(intent);
|
||||
}, error -> {
|
||||
Log.e(TAG, Log.getStackTraceString(error));
|
||||
view.setAlpha(1f);
|
||||
String prefix = getString(R.string.error_msg_prefix);
|
||||
new MaterialDialog.Builder(getActivity())
|
||||
.content(prefix + " " + error.getMessage())
|
||||
.neutralText(android.R.string.ok)
|
||||
.show();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package de.danoeh.antennapod.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.GridView;
|
||||
|
||||
/**
|
||||
* Source: https://stackoverflow.com/a/46350213/
|
||||
*/
|
||||
public class WrappingGridView extends GridView {
|
||||
|
||||
public WrappingGridView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public WrappingGridView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public WrappingGridView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int heightSpec = heightMeasureSpec;
|
||||
if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
|
||||
// The great Android "hackatlon", the love, the magic.
|
||||
// The two leftmost bits in the height measure spec have
|
||||
// a special meaning, hence we can't use them to describe height.
|
||||
heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
|
||||
}
|
||||
super.onMeasure(widthMeasureSpec, heightSpec);
|
||||
}
|
||||
}
|
|
@ -1,105 +1,172 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical">
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingTop="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvPodcastDirectories"
|
||||
style="@style/AntennaPod.TextView.Heading"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/podcastdirectories_label"/>
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvPodcastDirectoriesDescr"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/podcastdirectories_descr"
|
||||
android:textSize="@dimen/text_size_medium"/>
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardCornerRadius="4dp"
|
||||
android:elevation="16dp"
|
||||
android:layout_margin="8dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/butSearchCombined"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="Search all providers"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/butSearchItunes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/search_itunes_label"/>
|
||||
<ImageView
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="match_parent"
|
||||
android:contentDescription="@string/search_podcast_hint"
|
||||
app:srcCompat="?attr/action_search"
|
||||
android:scaleType="center"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/butSearchFyyd"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/search_fyyd_label"/>
|
||||
<EditText
|
||||
android:id="@+id/combinedFeedSearchBox"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:inputType="text"
|
||||
android:imeOptions="actionSearch"
|
||||
android:importantForAutofill="no"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:hint="@string/search_podcast_hint"
|
||||
android:background="@null"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/butBrowseGpoddernet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/browse_gpoddernet_label"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View style="@style/Divider"/>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvFeedurl"
|
||||
style="@style/AntennaPod.TextView.Heading"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/txtvfeedurl_label"/>
|
||||
<fragment
|
||||
android:id="@+id/quickFeedDiscovery"
|
||||
android:name="de.danoeh.antennapod.fragment.QuickFeedDiscoveryFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etxtFeedurl"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:cursorVisible="true"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:hint="@string/etxtFeedurlHint"
|
||||
android:inputType="textUri"/>
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardCornerRadius="4dp"
|
||||
android:elevation="8dp"
|
||||
android:layout_margin="8dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/butConfirm"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/confirm_label"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<View style="@style/Divider"/>
|
||||
<TextView
|
||||
android:id="@+id/txtvFeedurl"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/txtvfeedurl_label"
|
||||
android:textSize="18sp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textColor="?android:attr/textColorPrimary"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvOpmlImport"
|
||||
style="@style/AntennaPod.TextView.Heading"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/opml_import_label"/>
|
||||
<EditText
|
||||
android:id="@+id/etxtFeedurl"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:cursorVisible="true"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:hint="@string/etxtFeedurlHint"
|
||||
android:inputType="textUri"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvOpmlImportExpl"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/opml_import_txtv_button_lable"
|
||||
android:textSize="@dimen/text_size_medium"/>
|
||||
<Button
|
||||
android:id="@+id/butConfirm"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/confirm_label"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/butOpmlImport"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="@string/opml_import_label"/>
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardCornerRadius="4dp"
|
||||
android:elevation="8dp"
|
||||
android:layout_margin="8dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/advanced_search"
|
||||
android:layout_width="96dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_horizontal"
|
||||
android:padding="16dp"
|
||||
android:background="?android:attr/selectableItemBackground">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="match_parent"
|
||||
android:contentDescription="@string/advanced_search"
|
||||
app:srcCompat="?attr/action_search"
|
||||
android:scaleType="center"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:tint="?android:attr/textColorPrimary"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/advanced_search"
|
||||
android:textAlignment="center"
|
||||
android:textColor="?android:attr/textColorPrimary"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/btn_opml_import"
|
||||
android:layout_width="96dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_horizontal"
|
||||
android:padding="16dp"
|
||||
android:background="?android:attr/selectableItemBackground">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="match_parent"
|
||||
android:contentDescription="@string/opml_import_label"
|
||||
app:srcCompat="?attr/av_download"
|
||||
android:scaleType="center"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:tint="?android:attr/textColorPrimary"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/opml_import_label"
|
||||
android:textAlignment="center"
|
||||
android:textColor="?android:attr/textColorPrimary"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.CardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardCornerRadius="4dp"
|
||||
android:elevation="16dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/discover"
|
||||
android:textSize="18sp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textColor="?android:attr/textColorPrimary"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/discover_more"
|
||||
android:gravity="end"
|
||||
android:textAlignment="viewEnd"
|
||||
android:textSize="18sp"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:layout_weight="1"
|
||||
android:id="@+id/discover_more"
|
||||
android:textColor="@color/antennapod_blue"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<de.danoeh.antennapod.view.WrappingGridView
|
||||
android:id="@+id/discover_grid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:numColumns="4"
|
||||
app:layout_columnWeight="1"
|
||||
app:layout_rowWeight="1"
|
||||
android:horizontalSpacing="4dp"
|
||||
android:verticalSpacing="4dp"
|
||||
android:scrollbars="none"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_gravity="center_horizontal"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/discover_progress_bar"
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="30dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<de.danoeh.antennapod.view.SquareImageView
|
||||
android:id="@+id/discovery_cover"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:foreground="?android:attr/selectableItemBackground"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/search_itunes"
|
||||
android:title="@string/search_itunes_label" />
|
||||
<item
|
||||
android:id="@+id/search_gpodder"
|
||||
android:title="@string/browse_gpoddernet_label" />
|
||||
<item
|
||||
android:id="@+id/search_fyyd"
|
||||
android:title="@string/search_fyyd_label" />
|
||||
|
||||
</menu>
|
|
@ -122,6 +122,8 @@
|
|||
<string name="podcastdirectories_label">Find Podcast in Directory</string>
|
||||
<string name="podcastdirectories_descr">For new podcasts, you can search iTunes or fyyd, or browse gpodder.net by name, category or popularity.</string>
|
||||
<string name="browse_gpoddernet_label">Browse gpodder.net</string>
|
||||
<string name="discover">Discover</string>
|
||||
<string name="discover_more">more »</string>
|
||||
|
||||
<!-- Actions on feeds -->
|
||||
<string name="mark_all_read_label">Mark all as played</string>
|
||||
|
@ -658,10 +660,13 @@
|
|||
<!-- AntennaPodSP -->
|
||||
<string name="sp_apps_importing_feeds_msg">Importing subscriptions from single-purpose apps…</string>
|
||||
|
||||
<!-- Add podcast fragment -->
|
||||
<string name="search_podcast_hint">Search podcast…</string>
|
||||
<string name="search_itunes_label">Search iTunes</string>
|
||||
<string name="filter">Filter</string>
|
||||
|
||||
<string name="search_fyyd_label">Search fyyd</string>
|
||||
<string name="advanced_search">Advanced search</string>
|
||||
|
||||
<string name="filter">Filter</string>
|
||||
|
||||
<!-- Episodes apply actions -->
|
||||
<string name="all_label">All</string>
|
||||
|
|
Loading…
Reference in New Issue