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();
}
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);
}
}
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;
}
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();
}
}
Aggregations