Search in sources :

Example 1 with GpodnetPodcast

use of de.danoeh.antennapod.core.gpoddernet.model.GpodnetPodcast in project AntennaPod by AntennaPod.

the class PodcastListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Holder holder;
    GpodnetPodcast podcast = getItem(position);
    // Inflate Layout
    if (convertView == null) {
        holder = new Holder();
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.gpodnet_podcast_listitem, parent, false);
        holder.image = (ImageView) convertView.findViewById(R.id.imgvCover);
        holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
        holder.subscribers = (TextView) convertView.findViewById(R.id.txtvSubscribers);
        holder.url = (TextView) convertView.findViewById(R.id.txtvUrl);
        convertView.setTag(holder);
    } else {
        holder = (Holder) convertView.getTag();
    }
    if (StringUtils.isNotBlank(podcast.getLogoUrl())) {
        Glide.with(convertView.getContext()).load(podcast.getLogoUrl()).placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate().into(holder.image);
    }
    holder.title.setText(podcast.getTitle());
    holder.subscribers.setText(String.valueOf(podcast.getSubscribers()));
    holder.url.setText(podcast.getUrl());
    return convertView;
}
Also used : GpodnetPodcast(de.danoeh.antennapod.core.gpoddernet.model.GpodnetPodcast) LayoutInflater(android.view.LayoutInflater)

Example 2 with GpodnetPodcast

use of de.danoeh.antennapod.core.gpoddernet.model.GpodnetPodcast 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)

Example 3 with GpodnetPodcast

use of de.danoeh.antennapod.core.gpoddernet.model.GpodnetPodcast in project AntennaPod by AntennaPod.

the class PodcastListFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.gpodnet_podcast_list, container, false);
    gridView = (GridView) root.findViewById(R.id.gridView);
    progressBar = (ProgressBar) root.findViewById(R.id.progressBar);
    txtvError = (TextView) root.findViewById(R.id.txtvError);
    butRetry = (Button) root.findViewById(R.id.butRetry);
    gridView.setOnItemClickListener((parent, view, position, id) -> onPodcastSelected((GpodnetPodcast) gridView.getAdapter().getItem(position)));
    butRetry.setOnClickListener(v -> loadData());
    loadData();
    return root;
}
Also used : GpodnetPodcast(de.danoeh.antennapod.core.gpoddernet.model.GpodnetPodcast) GridView(android.widget.GridView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) TextView(android.widget.TextView)

Example 4 with GpodnetPodcast

use of de.danoeh.antennapod.core.gpoddernet.model.GpodnetPodcast in project AntennaPod by AntennaPod.

the class GpodnetService method readPodcastFromJSONObject.

private GpodnetPodcast readPodcastFromJSONObject(JSONObject object) throws JSONException {
    String url = object.getString("url");
    String title;
    Object titleObj = object.opt("title");
    if (titleObj != null && titleObj instanceof String) {
        title = (String) titleObj;
    } else {
        title = url;
    }
    String description;
    Object descriptionObj = object.opt("description");
    if (descriptionObj != null && descriptionObj instanceof String) {
        description = (String) descriptionObj;
    } else {
        description = "";
    }
    int subscribers = object.getInt("subscribers");
    Object logoUrlObj = object.opt("logo_url");
    String logoUrl = (logoUrlObj instanceof String) ? (String) logoUrlObj : null;
    if (logoUrl == null) {
        Object scaledLogoUrl = object.opt("scaled_logo_url");
        if (scaledLogoUrl != null && scaledLogoUrl instanceof String) {
            logoUrl = (String) scaledLogoUrl;
        }
    }
    String website = null;
    Object websiteObj = object.opt("website");
    if (websiteObj != null && websiteObj instanceof String) {
        website = (String) websiteObj;
    }
    String mygpoLink = object.getString("mygpo_link");
    return new GpodnetPodcast(url, title, description, subscribers, logoUrl, website, mygpoLink);
}
Also used : GpodnetPodcast(de.danoeh.antennapod.core.gpoddernet.model.GpodnetPodcast) JSONObject(org.json.JSONObject)

Aggregations

GpodnetPodcast (de.danoeh.antennapod.core.gpoddernet.model.GpodnetPodcast)4 Context (android.content.Context)1 AsyncTask (android.os.AsyncTask)1 SearchView (android.support.v7.widget.SearchView)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 GridView (android.widget.GridView)1 TextView (android.widget.TextView)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 List (java.util.List)1 JSONObject (org.json.JSONObject)1