Search in sources :

Example 1 with DiscoveryDefaultUpdateEvent

use of de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent in project AntennaPod by AntennaPod.

the class DiscoveryFragment method onCreateView.

@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);
    gridView = root.findViewById(R.id.gridView);
    adapter = new ItunesAdapter(getActivity(), new ArrayList<>());
    gridView.setAdapter(adapter);
    Toolbar toolbar = root.findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack());
    // 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) {
            return;
        }
        Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
        intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, podcast.feedUrl);
        startActivity(intent);
    });
    List<String> countryCodeArray = new ArrayList<String>(Arrays.asList(Locale.getISOCountries()));
    HashMap<String, String> countryCodeNames = new HashMap<String, String>();
    for (String code : countryCodeArray) {
        Locale locale = new Locale("", code);
        String countryName = locale.getDisplayCountry();
        if (countryName != null) {
            countryCodeNames.put(code, countryName);
        }
    }
    List<String> countryNamesSort = new ArrayList<String>(countryCodeNames.values());
    Collections.sort(countryNamesSort);
    countryNamesSort.add(0, getResources().getString(R.string.discover_hide));
    Spinner countrySpinner = root.findViewById(R.id.spinner_country);
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this.getContext(), android.R.layout.simple_spinner_item, countryNamesSort);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    countrySpinner.setAdapter(dataAdapter);
    int pos = countryNamesSort.indexOf(countryCodeNames.get(countryCode));
    countrySpinner.setSelection(pos);
    countrySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> countrySpinner, View view, int position, long id) {
            String countryName = (String) countrySpinner.getItemAtPosition(position);
            if (countryName.equals(getResources().getString(R.string.discover_hide))) {
                countryCode = ItunesTopListLoader.DISCOVER_HIDE_FAKE_COUNTRY_CODE;
            } else {
                for (Object o : countryCodeNames.keySet()) {
                    if (countryCodeNames.get(o).equals(countryName)) {
                        countryCode = o.toString();
                        break;
                    }
                }
            }
            prefs.edit().putString(ItunesTopListLoader.PREF_KEY_COUNTRY_CODE, countryCode).apply();
            EventBus.getDefault().post(new DiscoveryDefaultUpdateEvent());
            loadToplist(countryCode);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    progressBar = root.findViewById(R.id.progressBar);
    txtvError = root.findViewById(R.id.txtvError);
    butRetry = root.findViewById(R.id.butRetry);
    txtvEmpty = root.findViewById(android.R.id.empty);
    loadToplist(countryCode);
    return root;
}
Also used : Locale(java.util.Locale) ItunesAdapter(de.danoeh.antennapod.adapter.itunes.ItunesAdapter) HashMap(java.util.HashMap) Spinner(android.widget.Spinner) DiscoveryDefaultUpdateEvent(de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent) ArrayList(java.util.ArrayList) Intent(android.content.Intent) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter) Toolbar(androidx.appcompat.widget.Toolbar) PodcastSearchResult(de.danoeh.antennapod.discovery.PodcastSearchResult)

Aggregations

Intent (android.content.Intent)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 GridView (android.widget.GridView)1 Spinner (android.widget.Spinner)1 TextView (android.widget.TextView)1 Toolbar (androidx.appcompat.widget.Toolbar)1 ItunesAdapter (de.danoeh.antennapod.adapter.itunes.ItunesAdapter)1 PodcastSearchResult (de.danoeh.antennapod.discovery.PodcastSearchResult)1 DiscoveryDefaultUpdateEvent (de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1