Search in sources :

Example 1 with GpodnetTag

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

the class TagListFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getListView().setOnItemClickListener((parent, view1, position, id) -> {
        GpodnetTag tag = (GpodnetTag) getListAdapter().getItem(position);
        MainActivity activity = (MainActivity) getActivity();
        activity.loadChildFragment(TagFragment.newInstance(tag));
    });
    startLoadTask();
}
Also used : GpodnetTag(de.danoeh.antennapod.core.gpoddernet.model.GpodnetTag) MainActivity(de.danoeh.antennapod.activity.MainActivity)

Example 2 with GpodnetTag

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

the class GpodnetService method getTopTags.

/**
     * Returns the [count] most used tags.
     */
public List<GpodnetTag> getTopTags(int count) throws GpodnetServiceException {
    URL url;
    try {
        url = new URI(BASE_SCHEME, BASE_HOST, String.format("/api/2/tags/%d.json", count), null).toURL();
    } catch (MalformedURLException | URISyntaxException e) {
        e.printStackTrace();
        throw new GpodnetServiceException(e);
    }
    Request.Builder request = new Request.Builder().url(url);
    String response = executeRequest(request);
    try {
        JSONArray jsonTagList = new JSONArray(response);
        List<GpodnetTag> tagList = new ArrayList<>(jsonTagList.length());
        for (int i = 0; i < jsonTagList.length(); i++) {
            JSONObject jObj = jsonTagList.getJSONObject(i);
            String title = jObj.getString("title");
            String tag = jObj.getString("tag");
            int usage = jObj.getInt("usage");
            tagList.add(new GpodnetTag(title, tag, usage));
        }
        return tagList;
    } catch (JSONException e) {
        e.printStackTrace();
        throw new GpodnetServiceException(e);
    }
}
Also used : GpodnetTag(de.danoeh.antennapod.core.gpoddernet.model.GpodnetTag) MalformedURLException(java.net.MalformedURLException) Request(okhttp3.Request) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) JSONObject(org.json.JSONObject)

Example 3 with GpodnetTag

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

the class TagListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Holder holder;
    GpodnetTag tag = 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_tag_listitem, parent, false);
        holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
        holder.usage = (TextView) convertView.findViewById(R.id.txtvUsage);
        convertView.setTag(holder);
    } else {
        holder = (Holder) convertView.getTag();
    }
    holder.title.setText(tag.getTitle());
    holder.usage.setText(String.valueOf(tag.getUsage()));
    return convertView;
}
Also used : GpodnetTag(de.danoeh.antennapod.core.gpoddernet.model.GpodnetTag) LayoutInflater(android.view.LayoutInflater)

Example 4 with GpodnetTag

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

GpodnetTag (de.danoeh.antennapod.core.gpoddernet.model.GpodnetTag)4 Context (android.content.Context)1 LayoutInflater (android.view.LayoutInflater)1 TextView (android.widget.TextView)1 MainActivity (de.danoeh.antennapod.activity.MainActivity)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 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Request (okhttp3.Request)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1