Showing more suggestions
This commit is contained in:
parent
fc8aee3ce4
commit
e4fa92b8b9
|
@ -2,6 +2,7 @@ package de.danoeh.antennapod.fragment;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import android.util.Log;
|
||||
|
@ -26,11 +27,12 @@ import java.util.List;
|
|||
|
||||
public class QuickFeedDiscoveryFragment extends Fragment implements AdapterView.OnItemClickListener {
|
||||
private static final String TAG = "FeedDiscoveryFragment";
|
||||
private static final int NUM_SUGGESTIONS = 12;
|
||||
|
||||
private ProgressBar progressBar;
|
||||
private Disposable disposable;
|
||||
private FeedDiscoverAdapter adapter;
|
||||
private GridView subscriptionGridLayout;
|
||||
private GridView discoverGridLayout;
|
||||
private TextView errorTextView;
|
||||
|
||||
@Override
|
||||
|
@ -41,24 +43,31 @@ public class QuickFeedDiscoveryFragment extends Fragment implements AdapterView.
|
|||
discoverMore.setOnClickListener(v ->
|
||||
((MainActivity) getActivity()).loadChildFragment(new ItunesSearchFragment()));
|
||||
|
||||
subscriptionGridLayout = root.findViewById(R.id.discover_grid);
|
||||
discoverGridLayout = root.findViewById(R.id.discover_grid);
|
||||
progressBar = root.findViewById(R.id.discover_progress_bar);
|
||||
errorTextView = root.findViewById(R.id.discover_error);
|
||||
|
||||
adapter = new FeedDiscoverAdapter((MainActivity) getActivity());
|
||||
subscriptionGridLayout.setAdapter(adapter);
|
||||
subscriptionGridLayout.setOnItemClickListener(this);
|
||||
discoverGridLayout.setAdapter(adapter);
|
||||
discoverGridLayout.setOnItemClickListener(this);
|
||||
|
||||
DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
|
||||
float screenWidthDp = displayMetrics.widthPixels / displayMetrics.density;
|
||||
if (screenWidthDp > 600) {
|
||||
discoverGridLayout.setNumColumns(6);
|
||||
} else {
|
||||
discoverGridLayout.setNumColumns(4);
|
||||
}
|
||||
|
||||
// Fill with dummy elements to have a fixed height and
|
||||
// prevent the UI elements below from jumping on slow connections
|
||||
List<PodcastSearchResult> dummies = new ArrayList<>();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (int i = 0; i < NUM_SUGGESTIONS; i++) {
|
||||
dummies.add(PodcastSearchResult.dummy());
|
||||
}
|
||||
|
||||
adapter.updateData(dummies);
|
||||
|
||||
loadToplist();
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
|
@ -72,22 +81,22 @@ public class QuickFeedDiscoveryFragment extends Fragment implements AdapterView.
|
|||
|
||||
private void loadToplist() {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
subscriptionGridLayout.setVisibility(View.INVISIBLE);
|
||||
discoverGridLayout.setVisibility(View.INVISIBLE);
|
||||
errorTextView.setVisibility(View.GONE);
|
||||
|
||||
ItunesTopListLoader loader = new ItunesTopListLoader(getContext());
|
||||
disposable = loader.loadToplist(8)
|
||||
disposable = loader.loadToplist(NUM_SUGGESTIONS)
|
||||
.subscribe(podcasts -> {
|
||||
errorTextView.setVisibility(View.GONE);
|
||||
progressBar.setVisibility(View.GONE);
|
||||
subscriptionGridLayout.setVisibility(View.VISIBLE);
|
||||
discoverGridLayout.setVisibility(View.VISIBLE);
|
||||
adapter.updateData(podcasts);
|
||||
}, error -> {
|
||||
Log.e(TAG, Log.getStackTraceString(error));
|
||||
errorTextView.setText(error.getLocalizedMessage());
|
||||
errorTextView.setVisibility(View.VISIBLE);
|
||||
progressBar.setVisibility(View.GONE);
|
||||
subscriptionGridLayout.setVisibility(View.INVISIBLE);
|
||||
discoverGridLayout.setVisibility(View.INVISIBLE);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue