Search in sources :

Example 1 with GpodnetTag

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

the class TagListFragment method onViewCreated.

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

Example 2 with GpodnetTag

use of de.danoeh.antennapod.net.sync.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 = convertView.findViewById(R.id.txtvTitle);
        holder.usage = 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.net.sync.gpoddernet.model.GpodnetTag) LayoutInflater(android.view.LayoutInflater)

Example 3 with GpodnetTag

use of de.danoeh.antennapod.net.sync.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(baseScheme, null, baseHost, basePort, String.format(Locale.US, "/api/2/tags/%d.json", count), null, 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 jsonObject = jsonTagList.getJSONObject(i);
            String title = jsonObject.getString("title");
            String tag = jsonObject.getString("tag");
            int usage = jsonObject.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.net.sync.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)

Aggregations

GpodnetTag (de.danoeh.antennapod.net.sync.gpoddernet.model.GpodnetTag)3 LayoutInflater (android.view.LayoutInflater)1 MainActivity (de.danoeh.antennapod.activity.MainActivity)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 Request (okhttp3.Request)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1