Search in sources :

Example 1 with PodcastListAdapter

use of de.danoeh.antennapod.adapter.gpodnet.PodcastListAdapter in project AntennaPod by AntennaPod.

the class PodcastListFragment method loadData.

protected final void loadData() {
    AsyncTask<Void, Void, List<GpodnetPodcast>> loaderTask = new AsyncTask<Void, Void, List<GpodnetPodcast>>() {

        volatile Exception exception = null;

        @Override
        protected List<GpodnetPodcast> doInBackground(Void... params) {
            GpodnetService service = null;
            try {
                service = new GpodnetService();
                return loadPodcastData(service);
            } catch (GpodnetServiceException e) {
                exception = e;
                e.printStackTrace();
                return null;
            } finally {
                if (service != null) {
                    service.shutdown();
                }
            }
        }

        @Override
        protected void onPostExecute(List<GpodnetPodcast> gpodnetPodcasts) {
            super.onPostExecute(gpodnetPodcasts);
            final Context context = getActivity();
            if (context != null && gpodnetPodcasts != null && gpodnetPodcasts.size() > 0) {
                PodcastListAdapter listAdapter = new PodcastListAdapter(context, 0, gpodnetPodcasts);
                gridView.setAdapter(listAdapter);
                listAdapter.notifyDataSetChanged();
                progressBar.setVisibility(View.GONE);
                gridView.setVisibility(View.VISIBLE);
                txtvError.setVisibility(View.GONE);
                butRetry.setVisibility(View.GONE);
            } else if (context != null && gpodnetPodcasts != null) {
                gridView.setVisibility(View.GONE);
                progressBar.setVisibility(View.GONE);
                txtvError.setText(getString(R.string.search_status_no_results));
                txtvError.setVisibility(View.VISIBLE);
                butRetry.setVisibility(View.GONE);
            } else if (context != null) {
                gridView.setVisibility(View.GONE);
                progressBar.setVisibility(View.GONE);
                txtvError.setText(getString(R.string.error_msg_prefix) + exception.getMessage());
                txtvError.setVisibility(View.VISIBLE);
                butRetry.setVisibility(View.VISIBLE);
            }
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            gridView.setVisibility(View.GONE);
            progressBar.setVisibility(View.VISIBLE);
            txtvError.setVisibility(View.GONE);
            butRetry.setVisibility(View.GONE);
        }
    };
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
        loaderTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        loaderTask.execute();
    }
}
Also used : GpodnetPodcast(de.danoeh.antennapod.core.gpoddernet.model.GpodnetPodcast) Context(android.content.Context) GpodnetServiceException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException) GpodnetService(de.danoeh.antennapod.core.gpoddernet.GpodnetService) AsyncTask(android.os.AsyncTask) List(java.util.List) PodcastListAdapter(de.danoeh.antennapod.adapter.gpodnet.PodcastListAdapter) GpodnetServiceException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException)

Aggregations

Context (android.content.Context)1 AsyncTask (android.os.AsyncTask)1 PodcastListAdapter (de.danoeh.antennapod.adapter.gpodnet.PodcastListAdapter)1 GpodnetService (de.danoeh.antennapod.core.gpoddernet.GpodnetService)1 GpodnetServiceException (de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException)1 GpodnetPodcast (de.danoeh.antennapod.core.gpoddernet.model.GpodnetPodcast)1 List (java.util.List)1