Search in sources :

Example 1 with ItunesAdapter

use of de.danoeh.antennapod.adapter.itunes.ItunesAdapter in project AntennaPod by AntennaPod.

the class ItunesSearchFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View root = inflater.inflate(R.layout.fragment_itunes_search, container, false);
    gridView = (GridView) root.findViewById(R.id.gridView);
    adapter = new ItunesAdapter(getActivity(), new ArrayList<>());
    gridView.setAdapter(adapter);
    //Show information about the podcast when the list item is clicked
    gridView.setOnItemClickListener((parent, view1, position, id) -> {
        Podcast podcast = searchResults.get(position);
        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);
            subscription = Observable.create((Observable.OnSubscribe<String>) subscriber -> {
                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");
                        subscriber.onNext(feedUrl);
                    } else {
                        String prefix = getString(R.string.error_msg_prefix);
                        subscriber.onError(new IOException(prefix + response));
                    }
                } catch (IOException | JSONException e) {
                    subscriber.onError(e);
                }
                subscriber.onCompleted();
            }).subscribeOn(Schedulers.newThread()).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();
            });
        }
    });
    progressBar = (ProgressBar) root.findViewById(R.id.progressBar);
    txtvError = (TextView) root.findViewById(R.id.txtvError);
    butRetry = (Button) root.findViewById(R.id.butRetry);
    txtvEmpty = (TextView) root.findViewById(android.R.id.empty);
    loadToplist();
    return root;
}
Also used : Bundle(android.os.Bundle) GridView(android.widget.GridView) ProgressBar(android.widget.ProgressBar) SearchView(android.support.v7.widget.SearchView) ItunesAdapter(de.danoeh.antennapod.adapter.itunes.ItunesAdapter) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Observable(rx.Observable) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) MenuItemUtils(de.danoeh.antennapod.menuhandler.MenuItemUtils) MenuInflater(android.view.MenuInflater) Locale(java.util.Locale) Menu(android.view.Menu) Schedulers(rx.schedulers.Schedulers) View(android.view.View) Button(android.widget.Button) Response(okhttp3.Response) AntennapodHttpClient(de.danoeh.antennapod.core.service.download.AntennapodHttpClient) Log(android.util.Log) Request(okhttp3.Request) LayoutInflater(android.view.LayoutInflater) R(de.danoeh.antennapod.R) MenuItemCompat(android.support.v4.view.MenuItemCompat) Fragment(android.support.v4.app.Fragment) ClientConfig(de.danoeh.antennapod.core.ClientConfig) IOException(java.io.IOException) ViewGroup(android.view.ViewGroup) URLEncoder(java.net.URLEncoder) List(java.util.List) TextView(android.widget.TextView) OkHttpClient(okhttp3.OkHttpClient) Podcast(de.danoeh.antennapod.adapter.itunes.ItunesAdapter.Podcast) OnlineFeedViewActivity(de.danoeh.antennapod.activity.OnlineFeedViewActivity) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Subscription(rx.Subscription) JSONArray(org.json.JSONArray) ItunesAdapter(de.danoeh.antennapod.adapter.itunes.ItunesAdapter) OnlineFeedViewActivity(de.danoeh.antennapod.activity.OnlineFeedViewActivity) OkHttpClient(okhttp3.OkHttpClient) ArrayList(java.util.ArrayList) Podcast(de.danoeh.antennapod.adapter.itunes.ItunesAdapter.Podcast) Request(okhttp3.Request) Intent(android.content.Intent) IOException(java.io.IOException) GridView(android.widget.GridView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) TextView(android.widget.TextView) Observable(rx.Observable) Response(okhttp3.Response) JSONObject(org.json.JSONObject)

Example 2 with ItunesAdapter

use of de.danoeh.antennapod.adapter.itunes.ItunesAdapter in project AntennaPod by AntennaPod.

the class FyydSearchFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View root = inflater.inflate(R.layout.fragment_itunes_search, container, false);
    gridView = (GridView) root.findViewById(R.id.gridView);
    adapter = new ItunesAdapter(getActivity(), new ArrayList<>());
    gridView.setAdapter(adapter);
    //Show information about the podcast when the list item is clicked
    gridView.setOnItemClickListener((parent, view1, position, id) -> {
        Podcast podcast = searchResults.get(position);
        Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
        intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, podcast.feedUrl);
        intent.putExtra(OnlineFeedViewActivity.ARG_TITLE, podcast.title);
        startActivity(intent);
    });
    progressBar = (ProgressBar) root.findViewById(R.id.progressBar);
    txtvError = (TextView) root.findViewById(R.id.txtvError);
    butRetry = (Button) root.findViewById(R.id.butRetry);
    txtvEmpty = (TextView) root.findViewById(android.R.id.empty);
    return root;
}
Also used : ItunesAdapter(de.danoeh.antennapod.adapter.itunes.ItunesAdapter) ArrayList(java.util.ArrayList) Podcast(de.danoeh.antennapod.adapter.itunes.ItunesAdapter.Podcast) Intent(android.content.Intent) GridView(android.widget.GridView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) TextView(android.widget.TextView)

Example 3 with ItunesAdapter

use of de.danoeh.antennapod.adapter.itunes.ItunesAdapter 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)

Example 4 with ItunesAdapter

use of de.danoeh.antennapod.adapter.itunes.ItunesAdapter in project AntennaPod by AntennaPod.

the class OnlineSearchFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View root = inflater.inflate(R.layout.fragment_itunes_search, container, false);
    root.findViewById(R.id.spinner_country).setVisibility(INVISIBLE);
    gridView = root.findViewById(R.id.gridView);
    adapter = new ItunesAdapter(getActivity(), new ArrayList<>());
    gridView.setAdapter(adapter);
    // Show information about the podcast when the list item is clicked
    gridView.setOnItemClickListener((parent, view1, position, id) -> {
        PodcastSearchResult podcast = searchResults.get(position);
        Intent intent = new Intent(getActivity(), OnlineFeedViewActivity.class);
        intent.putExtra(OnlineFeedViewActivity.ARG_FEEDURL, podcast.feedUrl);
        intent.putExtra(MainActivity.EXTRA_STARTED_FROM_SEARCH, true);
        startActivity(intent);
    });
    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);
    TextView txtvPoweredBy = root.findViewById(R.id.search_powered_by);
    txtvPoweredBy.setText(getString(R.string.search_powered_by, searchProvider.getName()));
    setupToolbar(root.findViewById(R.id.toolbar));
    gridView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (scrollState == SCROLL_STATE_TOUCH_SCROLL) {
                InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        }
    });
    return root;
}
Also used : ItunesAdapter(de.danoeh.antennapod.adapter.itunes.ItunesAdapter) ArrayList(java.util.ArrayList) AbsListView(android.widget.AbsListView) Intent(android.content.Intent) TextView(android.widget.TextView) InputMethodManager(android.view.inputmethod.InputMethodManager) GridView(android.widget.GridView) View(android.view.View) AbsListView(android.widget.AbsListView) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) PodcastSearchResult(de.danoeh.antennapod.discovery.PodcastSearchResult)

Aggregations

Intent (android.content.Intent)4 View (android.view.View)4 GridView (android.widget.GridView)4 TextView (android.widget.TextView)4 ItunesAdapter (de.danoeh.antennapod.adapter.itunes.ItunesAdapter)4 ArrayList (java.util.ArrayList)4 SearchView (android.support.v7.widget.SearchView)2 Podcast (de.danoeh.antennapod.adapter.itunes.ItunesAdapter.Podcast)2 PodcastSearchResult (de.danoeh.antennapod.discovery.PodcastSearchResult)2 Locale (java.util.Locale)2 Bundle (android.os.Bundle)1 Fragment (android.support.v4.app.Fragment)1 MenuItemCompat (android.support.v4.view.MenuItemCompat)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 ViewGroup (android.view.ViewGroup)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1