From 14769a40191078d96c8637cdede508c470595885 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 8 Mar 2012 18:29:27 +0300 Subject: [PATCH] on API 3, sort feeds and categories using order configured in tt-rss properly unmark Uncategorized on closeCategory() --- src/org/fox/ttrss/Feed.java | 3 +++ src/org/fox/ttrss/FeedCategoriesFragment.java | 23 +++++++++++++++++-- src/org/fox/ttrss/FeedCategory.java | 4 ++++ src/org/fox/ttrss/FeedsFragment.java | 23 +++++++++++++++++-- src/org/fox/ttrss/MainActivity.java | 3 ++- 5 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/org/fox/ttrss/Feed.java b/src/org/fox/ttrss/Feed.java index 0582d406..1f0af4cc 100644 --- a/src/org/fox/ttrss/Feed.java +++ b/src/org/fox/ttrss/Feed.java @@ -11,6 +11,7 @@ public class Feed implements Comparable, Parcelable { boolean has_icon; int cat_id; int last_updated; + int order_id; boolean is_cat; public Feed(int id, String title, boolean is_cat) { @@ -46,6 +47,7 @@ public class Feed implements Comparable, Parcelable { out.writeInt(cat_id); out.writeInt(last_updated); out.writeInt(is_cat ? 1 : 0); + out.writeInt(order_id); } public void readFromParcel(Parcel in) { @@ -57,6 +59,7 @@ public class Feed implements Comparable, Parcelable { cat_id = in.readInt(); last_updated = in.readInt(); is_cat = in.readInt() == 1; + order_id = in.readInt(); } @SuppressWarnings("rawtypes") diff --git a/src/org/fox/ttrss/FeedCategoriesFragment.java b/src/org/fox/ttrss/FeedCategoriesFragment.java index 4b7873d7..3f17eb60 100644 --- a/src/org/fox/ttrss/FeedCategoriesFragment.java +++ b/src/org/fox/ttrss/FeedCategoriesFragment.java @@ -63,7 +63,22 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe } } - + + class CatOrderComparator implements Comparator { + + @Override + public int compare(FeedCategory a, FeedCategory b) { + if (a.id >= 0 && b.id >= 0) + if (a.order_id != 0 && b.order_id != 0) + return a.order_id - b.order_id; + else + return a.title.compareTo(b.title); + else + return a.id - b.id; + } + + } + @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { @@ -234,7 +249,11 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe if (m_prefs.getBoolean("sort_feeds_by_unread", false)) { cmp = new CatUnreadComparator(); } else { - cmp = new CatTitleComparator(); + if (m_onlineServices.getApiLevel() >= 3) { + cmp = new CatOrderComparator(); + } else { + cmp = new CatTitleComparator(); + } } Collections.sort(m_cats, cmp); diff --git a/src/org/fox/ttrss/FeedCategory.java b/src/org/fox/ttrss/FeedCategory.java index 43d78869..48c3b554 100644 --- a/src/org/fox/ttrss/FeedCategory.java +++ b/src/org/fox/ttrss/FeedCategory.java @@ -7,6 +7,7 @@ public class FeedCategory implements Parcelable { int id; String title; int unread; + int order_id; public FeedCategory(Parcel in) { readFromParcel(in); @@ -16,6 +17,7 @@ public class FeedCategory implements Parcelable { this.id = id; this.title = title; this.unread = unread; + this.order_id = 0; } @Override @@ -28,12 +30,14 @@ public class FeedCategory implements Parcelable { 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") diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index 07682586..836a5b0c 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -92,7 +92,22 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh } } - + + class FeedOrderComparator implements Comparator { + + @Override + public int compare(Feed a, Feed b) { + if (a.id >= 0 && b.id >= 0) + if (a.order_id != 0 && b.order_id != 0) + return a.order_id - b.order_id; + else + return a.title.compareTo(b.title); + else + return a.id - b.id; + } + + } + @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { @@ -424,7 +439,11 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh if (m_prefs.getBoolean("sort_feeds_by_unread", false)) { cmp = new FeedUnreadComparator(); } else { - cmp = new FeedTitleComparator(); + if (m_onlineServices.getApiLevel() >= 3) { + cmp = new FeedOrderComparator(); + } else { + cmp = new FeedTitleComparator(); + } } Collections.sort(m_feeds, cmp); diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index 52ec8f31..d8143242 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -759,7 +759,8 @@ public class MainActivity extends FragmentActivity implements OnlineServices { .findFragmentById(R.id.cats_fragment); if (cf != null) { - cf.setSelectedCategoryId(0); + // should be nonexistant feed_id (0 is Uncategorized) + cf.setSelectedCategoryId(-10000); } initMainMenu();