Gpodder categories shows title instead of tag and additionally the usage
This commit is contained in:
parent
d1d0013c67
commit
596462b7a2
|
@ -0,0 +1,54 @@
|
|||
package de.danoeh.antennapod.adapter.gpodnet;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetTag;
|
||||
|
||||
/**
|
||||
* Adapter for displaying a list of GPodnetPodcast-Objects.
|
||||
*/
|
||||
public class TagListAdapter extends ArrayAdapter<GpodnetTag> {
|
||||
|
||||
public TagListAdapter(Context context, int resource, List<GpodnetTag> objects) {
|
||||
super(context, resource, objects);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
static class Holder {
|
||||
TextView title;
|
||||
TextView usage;
|
||||
}
|
||||
}
|
|
@ -24,11 +24,11 @@ public class TagFragment extends PodcastListFragment {
|
|||
|
||||
private GpodnetTag tag;
|
||||
|
||||
public static TagFragment newInstance(String tagName) {
|
||||
Validate.notNull(tagName);
|
||||
public static TagFragment newInstance(GpodnetTag tag) {
|
||||
Validate.notNull(tag);
|
||||
TagFragment fragment = new TagFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString("tag", tagName);
|
||||
args.putParcelable("tag", tag);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
@ -38,14 +38,14 @@ public class TagFragment extends PodcastListFragment {
|
|||
super.onCreate(savedInstanceState);
|
||||
|
||||
Bundle args = getArguments();
|
||||
Validate.isTrue(args != null && args.getString("tag") != null, "args invalid");
|
||||
tag = new GpodnetTag(args.getString("tag"));
|
||||
Validate.isTrue(args != null && args.getParcelable("tag") != null, "args invalid");
|
||||
tag = args.getParcelable("tag");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
((MainActivity) getActivity()).getMainActivtyActionBar().setTitle(tag.getName());
|
||||
((MainActivity) getActivity()).getMainActivtyActionBar().setTitle(tag.getTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,14 +10,13 @@ import android.view.Menu;
|
|||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.adapter.gpodnet.TagListAdapter;
|
||||
import de.danoeh.antennapod.core.gpoddernet.GpodnetService;
|
||||
import de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException;
|
||||
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetTag;
|
||||
|
@ -67,15 +66,21 @@ public class TagListFragment extends ListFragment {
|
|||
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
String selectedTag = (String) getListAdapter().getItem(position);
|
||||
GpodnetTag tag = (GpodnetTag) getListAdapter().getItem(position);
|
||||
MainActivity activity = (MainActivity) getActivity();
|
||||
activity.loadChildFragment(TagFragment.newInstance(selectedTag));
|
||||
activity.loadChildFragment(TagFragment.newInstance(tag));
|
||||
}
|
||||
});
|
||||
|
||||
startLoadTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
((MainActivity) getActivity()).getMainActivtyActionBar().setTitle(R.string.add_feed_label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
@ -121,11 +126,7 @@ public class TagListFragment extends ListFragment {
|
|||
final Context context = getActivity();
|
||||
if (context != null) {
|
||||
if (gpodnetTags != null) {
|
||||
List<String> tagNames = new ArrayList<String>();
|
||||
for (GpodnetTag tag : gpodnetTags) {
|
||||
tagNames.add(tag.getName());
|
||||
}
|
||||
setListAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, tagNames));
|
||||
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());
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:background="@android:color/darker_gray">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvTitle"
|
||||
style="@style/AntennaPod.TextView.ListItemPrimaryTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/listitem_threeline_horizontalpadding"
|
||||
android:layout_marginTop="@dimen/listitem_threeline_verticalpadding"
|
||||
android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding"
|
||||
android:lines="1"
|
||||
tools:text="Tag Title"
|
||||
tools:background="@android:color/holo_green_dark" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvUsage"
|
||||
style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_marginRight="@dimen/listitem_threeline_horizontalpadding"
|
||||
android:layout_marginTop="@dimen/listitem_threeline_verticalpadding"
|
||||
android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding"
|
||||
tools:text="301"
|
||||
tools:background="@android:color/holo_green_dark"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -172,9 +172,10 @@ public class GpodnetService {
|
|||
jsonTagList.length());
|
||||
for (int i = 0; i < jsonTagList.length(); i++) {
|
||||
JSONObject jObj = jsonTagList.getJSONObject(i);
|
||||
String name = jObj.getString("tag");
|
||||
String title = jObj.getString("title");
|
||||
String tag = jObj.getString("tag");
|
||||
int usage = jObj.getInt("usage");
|
||||
tagList.add(new GpodnetTag(name, usage));
|
||||
tagList.add(new GpodnetTag(title, tag, usage));
|
||||
}
|
||||
return tagList;
|
||||
} catch (JSONException e) {
|
||||
|
@ -194,7 +195,7 @@ public class GpodnetService {
|
|||
|
||||
try {
|
||||
URL url = new URI(BASE_SCHEME, BASE_HOST, String.format(
|
||||
"/api/2/tag/%s/%d.json", tag.getName(), count), null).toURL();
|
||||
"/api/2/tag/%s/%d.json", tag.getTag(), count), null).toURL();
|
||||
Request.Builder request = new Request.Builder().url(url);
|
||||
String response = executeRequest(request);
|
||||
|
||||
|
|
|
@ -1,46 +1,60 @@
|
|||
package de.danoeh.antennapod.core.gpoddernet.model;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.Comparator;
|
||||
public class GpodnetTag implements Parcelable {
|
||||
|
||||
public class GpodnetTag {
|
||||
private final String title;
|
||||
private final String tag;
|
||||
private final int usage;
|
||||
|
||||
private String name;
|
||||
private int usage;
|
||||
public GpodnetTag(String title, String tag, int usage) {
|
||||
Validate.notNull(title);
|
||||
Validate.notNull(tag);
|
||||
|
||||
public GpodnetTag(String name, int usage) {
|
||||
Validate.notNull(name);
|
||||
|
||||
this.name = name;
|
||||
this.title = title;
|
||||
this.tag = tag;
|
||||
this.usage = usage;
|
||||
}
|
||||
|
||||
public GpodnetTag(String name) {
|
||||
super();
|
||||
this.name = name;
|
||||
public static GpodnetTag createFromParcel(Parcel in) {
|
||||
final String title = in.readString();
|
||||
final String tag = in.readString();
|
||||
final int usage = in.readInt();
|
||||
return new GpodnetTag(title, tag, usage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GpodnetTag [name=" + name + ", usage=" + usage + "]";
|
||||
return "GpodnetTag [title="+title+", tag=" + tag + ", usage=" + usage + "]";
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public int getUsage() {
|
||||
return usage;
|
||||
}
|
||||
|
||||
public static class UsageComparator implements Comparator<GpodnetTag> {
|
||||
|
||||
@Override
|
||||
public int compare(GpodnetTag o1, GpodnetTag o2) {
|
||||
return o1.usage - o2.usage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(title);
|
||||
dest.writeString(tag);
|
||||
dest.writeInt(usage);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue