Search in sources :

Example 1 with TagListAdapter

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

the class TagListFragment method startLoadTask.

private void startLoadTask() {
    cancelLoadTask();
    loadTask = new AsyncTask<Void, Void, List<GpodnetTag>>() {

        private Exception exception;

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

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            setListShown(false);
        }

        @Override
        protected void onPostExecute(List<GpodnetTag> gpodnetTags) {
            super.onPostExecute(gpodnetTags);
            final Context context = getActivity();
            if (context != null) {
                if (gpodnetTags != null) {
                    setListAdapter(new TagListAdapter(context, android.R.layout.simple_list_item_1, gpodnetTags));
                } else if (exception != null) {
                    TextView txtvError = new TextView(getActivity());
                    txtvError.setText(exception.getMessage());
                    getListView().setEmptyView(txtvError);
                }
                setListShown(true);
            }
        }
    };
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
        loadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        loadTask.execute();
    }
}
Also used : Context(android.content.Context) GpodnetServiceException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException) GpodnetTag(de.danoeh.antennapod.core.gpoddernet.model.GpodnetTag) TagListAdapter(de.danoeh.antennapod.adapter.gpodnet.TagListAdapter) GpodnetService(de.danoeh.antennapod.core.gpoddernet.GpodnetService) List(java.util.List) TextView(android.widget.TextView) GpodnetServiceException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException)

Aggregations

Context (android.content.Context)1 TextView (android.widget.TextView)1 TagListAdapter (de.danoeh.antennapod.adapter.gpodnet.TagListAdapter)1 GpodnetService (de.danoeh.antennapod.core.gpoddernet.GpodnetService)1 GpodnetServiceException (de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException)1 GpodnetTag (de.danoeh.antennapod.core.gpoddernet.model.GpodnetTag)1 List (java.util.List)1