sort categories, remove duplicate files

This commit is contained in:
Andrew Dolgov 2013-03-24 19:50:44 +04:00
parent ad12b2b945
commit 201dce1474
3 changed files with 29 additions and 110 deletions

View File

@ -1,58 +0,0 @@
package org.fox.ttrss.share;
import android.os.Parcel;
import android.os.Parcelable;
public class FeedCategory implements Parcelable {
public int id;
public String title;
public int unread;
public int order_id;
public FeedCategory(Parcel in) {
readFromParcel(in);
}
public FeedCategory(int id, String title, int unread) {
this.id = id;
this.title = title;
this.unread = unread;
this.order_id = 0;
}
public FeedCategory() {
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(id);
out.writeString(title);
out.writeInt(unread);
out.writeInt(order_id);
}
public void readFromParcel(Parcel in) {
id = in.readInt();
title = in.readString();
unread = in.readInt();
order_id = in.readInt();
}
@SuppressWarnings("rawtypes")
public static final Parcelable.Creator CREATOR =
new Parcelable.Creator() {
public FeedCategory createFromParcel(Parcel in) {
return new FeedCategory(in);
}
public FeedCategory[] newArray(int size) {
return new FeedCategory[size];
}
};
}

View File

@ -1,52 +0,0 @@
package org.fox.ttrss.share;
import java.util.ArrayList;
import android.os.Parcel;
import android.os.Parcelable;
@SuppressWarnings("serial")
public class FeedCategoryList extends ArrayList<FeedCategory> implements Parcelable {
public FeedCategoryList() { }
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(this.size());
for (FeedCategory feed : this) {
out.writeParcelable(feed, flags);
}
}
public void readFromParcel(Parcel in) {
int length = in.readInt();
for (int i = 0; i < length; i++) {
FeedCategory feed = in.readParcelable(FeedCategory.class.getClassLoader());
this.add(feed);
}
}
public FeedCategoryList(Parcel in) {
readFromParcel(in);
}
@SuppressWarnings("rawtypes")
public static final Parcelable.Creator CREATOR =
new Parcelable.Creator() {
public FeedCategoryList createFromParcel(Parcel in) {
return new FeedCategoryList(in);
}
public FeedCategoryList[] newArray(int size) {
return new FeedCategoryList[size];
}
};
}

View File

@ -2,11 +2,15 @@ package org.fox.ttrss.share;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import org.fox.ttrss.ApiRequest;
import org.fox.ttrss.ApiRequest.ApiError;
import org.fox.ttrss.types.FeedCategory;
import org.fox.ttrss.types.FeedCategoryList;
import org.fox.ttrss.R;
import android.content.Context;
@ -34,6 +38,29 @@ public class SubscribeActivity extends CommonShareActivity {
private static final int REQ_CATS = 1;
private static final int REQ_POST = 2;
class CatTitleComparator implements Comparator<FeedCategory> {
@Override
public int compare(FeedCategory a, FeedCategory b) {
if (a.id >= 0 && b.id >= 0)
return a.title.compareTo(b.title);
else
return a.id - b.id;
}
}
public void sortCats() {
Comparator<FeedCategory> cmp = new CatTitleComparator();
Collections.sort(m_cats, cmp);
try {
m_adapter.notifyDataSetChanged();
} catch (NullPointerException e) {
// adapter missing
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -204,6 +231,8 @@ public class SubscribeActivity extends CommonShareActivity {
m_cats.add(c);
}
sortCats();
m_adapter.notifyDataSetChanged();
toast(R.string.category_list_updated);