From 201dce1474e667afac8ad8e8eb06c60306d4f7ea Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 24 Mar 2013 19:50:44 +0400 Subject: sort categories, remove duplicate files --- src/org/fox/ttrss/share/FeedCategory.java | 58 -------------------------- src/org/fox/ttrss/share/FeedCategoryList.java | 52 ----------------------- src/org/fox/ttrss/share/SubscribeActivity.java | 29 +++++++++++++ 3 files changed, 29 insertions(+), 110 deletions(-) delete mode 100644 src/org/fox/ttrss/share/FeedCategory.java delete mode 100644 src/org/fox/ttrss/share/FeedCategoryList.java diff --git a/src/org/fox/ttrss/share/FeedCategory.java b/src/org/fox/ttrss/share/FeedCategory.java deleted file mode 100644 index aae1ce62..00000000 --- a/src/org/fox/ttrss/share/FeedCategory.java +++ /dev/null @@ -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]; - } - }; -} diff --git a/src/org/fox/ttrss/share/FeedCategoryList.java b/src/org/fox/ttrss/share/FeedCategoryList.java deleted file mode 100644 index 26270b18..00000000 --- a/src/org/fox/ttrss/share/FeedCategoryList.java +++ /dev/null @@ -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 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]; - } - }; - } diff --git a/src/org/fox/ttrss/share/SubscribeActivity.java b/src/org/fox/ttrss/share/SubscribeActivity.java index b69500ef..eb9ed66d 100644 --- a/src/org/fox/ttrss/share/SubscribeActivity.java +++ b/src/org/fox/ttrss/share/SubscribeActivity.java @@ -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 { + + @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 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); -- cgit v1.2.3