Search in sources :

Example 1 with ItunesTopListLoader

use of de.danoeh.antennapod.discovery.ItunesTopListLoader in project AntennaPod by AntennaPod.

the class QuickFeedDiscoveryFragment method loadToplist.

private void loadToplist() {
    progressBar.setVisibility(View.VISIBLE);
    discoverGridLayout.setVisibility(View.INVISIBLE);
    errorView.setVisibility(View.GONE);
    errorRetry.setVisibility(View.INVISIBLE);
    poweredByTextView.setVisibility(View.VISIBLE);
    ItunesTopListLoader loader = new ItunesTopListLoader(getContext());
    SharedPreferences prefs = getActivity().getSharedPreferences(ItunesTopListLoader.PREFS, MODE_PRIVATE);
    String countryCode = prefs.getString(ItunesTopListLoader.PREF_KEY_COUNTRY_CODE, Locale.getDefault().getCountry());
    if (countryCode.equals(ItunesTopListLoader.DISCOVER_HIDE_FAKE_COUNTRY_CODE)) {
        errorTextView.setText(String.format(getResources().getString(R.string.discover_is_hidden), getResources().getString(R.string.discover_hide)));
        errorView.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.GONE);
        discoverGridLayout.setVisibility(View.INVISIBLE);
        errorRetry.setVisibility(View.INVISIBLE);
        poweredByTextView.setVisibility(View.INVISIBLE);
        return;
    }
    disposable = loader.loadToplist(countryCode, NUM_SUGGESTIONS).subscribe(podcasts -> {
        errorView.setVisibility(View.GONE);
        progressBar.setVisibility(View.GONE);
        discoverGridLayout.setVisibility(View.VISIBLE);
        if (podcasts.size() == 0) {
            errorTextView.setText(getResources().getText(R.string.search_status_no_results));
            errorView.setVisibility(View.VISIBLE);
            discoverGridLayout.setVisibility(View.INVISIBLE);
        } else {
            adapter.updateData(podcasts);
        }
    }, error -> {
        Log.e(TAG, Log.getStackTraceString(error));
        errorTextView.setText(error.getLocalizedMessage());
        errorView.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.GONE);
        discoverGridLayout.setVisibility(View.INVISIBLE);
        errorRetry.setVisibility(View.VISIBLE);
    });
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) GridView(android.widget.GridView) ProgressBar(android.widget.ProgressBar) Intent(android.content.Intent) FeedDiscoverAdapter(de.danoeh.antennapod.adapter.FeedDiscoverAdapter) ArrayList(java.util.ArrayList) Locale(java.util.Locale) EventBus(org.greenrobot.eventbus.EventBus) MODE_PRIVATE(android.content.Context.MODE_PRIVATE) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) AdapterView(android.widget.AdapterView) Log(android.util.Log) ItunesTopListLoader(de.danoeh.antennapod.discovery.ItunesTopListLoader) LayoutInflater(android.view.LayoutInflater) R(de.danoeh.antennapod.R) DiscoveryDefaultUpdateEvent(de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent) ThreadMode(org.greenrobot.eventbus.ThreadMode) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) MainActivity(de.danoeh.antennapod.activity.MainActivity) PodcastSearchResult(de.danoeh.antennapod.discovery.PodcastSearchResult) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) TextView(android.widget.TextView) Subscribe(org.greenrobot.eventbus.Subscribe) SharedPreferences(android.content.SharedPreferences) OnlineFeedViewActivity(de.danoeh.antennapod.activity.OnlineFeedViewActivity) SharedPreferences(android.content.SharedPreferences) ItunesTopListLoader(de.danoeh.antennapod.discovery.ItunesTopListLoader)

Example 2 with ItunesTopListLoader

use of de.danoeh.antennapod.discovery.ItunesTopListLoader in project AntennaPod by AntennaPod.

the class DiscoveryFragment method loadToplist.

private void loadToplist(String country) {
    if (disposable != null) {
        disposable.dispose();
    }
    gridView.setVisibility(View.GONE);
    txtvError.setVisibility(View.GONE);
    butRetry.setVisibility(View.GONE);
    txtvEmpty.setVisibility(View.GONE);
    progressBar.setVisibility(View.VISIBLE);
    if (country.equals(ItunesTopListLoader.DISCOVER_HIDE_FAKE_COUNTRY_CODE)) {
        gridView.setVisibility(View.GONE);
        txtvError.setVisibility(View.VISIBLE);
        txtvError.setText(getResources().getString(R.string.discover_is_hidden));
        butRetry.setVisibility(View.GONE);
        txtvEmpty.setVisibility(View.GONE);
        progressBar.setVisibility(View.GONE);
    } else {
        ItunesTopListLoader loader = new ItunesTopListLoader(getContext());
        disposable = loader.loadToplist(country, 25).subscribe(podcasts -> {
            progressBar.setVisibility(View.GONE);
            topList = podcasts;
            updateData(topList);
        }, error -> {
            Log.e(TAG, Log.getStackTraceString(error));
            progressBar.setVisibility(View.GONE);
            txtvError.setText(error.getMessage());
            txtvError.setVisibility(View.VISIBLE);
            butRetry.setOnClickListener(v -> loadToplist(country));
            butRetry.setVisibility(View.VISIBLE);
        });
    }
}
Also used : Arrays(java.util.Arrays) Bundle(android.os.Bundle) GridView(android.widget.GridView) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) ItunesAdapter(de.danoeh.antennapod.adapter.itunes.ItunesAdapter) Intent(android.content.Intent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Locale(java.util.Locale) EventBus(org.greenrobot.eventbus.EventBus) MODE_PRIVATE(android.content.Context.MODE_PRIVATE) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) AdapterView(android.widget.AdapterView) Log(android.util.Log) ItunesTopListLoader(de.danoeh.antennapod.discovery.ItunesTopListLoader) LayoutInflater(android.view.LayoutInflater) R(de.danoeh.antennapod.R) DiscoveryDefaultUpdateEvent(de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) ArrayAdapter(android.widget.ArrayAdapter) PodcastSearchResult(de.danoeh.antennapod.discovery.PodcastSearchResult) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) TextView(android.widget.TextView) SharedPreferences(android.content.SharedPreferences) Toolbar(androidx.appcompat.widget.Toolbar) OnlineFeedViewActivity(de.danoeh.antennapod.activity.OnlineFeedViewActivity) Collections(java.util.Collections) ItunesTopListLoader(de.danoeh.antennapod.discovery.ItunesTopListLoader)

Aggregations

MODE_PRIVATE (android.content.Context.MODE_PRIVATE)2 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 Bundle (android.os.Bundle)2 Log (android.util.Log)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 AdapterView (android.widget.AdapterView)2 Button (android.widget.Button)2 GridView (android.widget.GridView)2 ProgressBar (android.widget.ProgressBar)2 TextView (android.widget.TextView)2 Fragment (androidx.fragment.app.Fragment)2 R (de.danoeh.antennapod.R)2 OnlineFeedViewActivity (de.danoeh.antennapod.activity.OnlineFeedViewActivity)2 ItunesTopListLoader (de.danoeh.antennapod.discovery.ItunesTopListLoader)2 PodcastSearchResult (de.danoeh.antennapod.discovery.PodcastSearchResult)2 DiscoveryDefaultUpdateEvent (de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent)2 Disposable (io.reactivex.disposables.Disposable)2