on API 3, sort feeds and categories using order configured in tt-rss

properly unmark Uncategorized on closeCategory()
This commit is contained in:
Andrew Dolgov 2012-03-08 18:29:27 +03:00
parent 1945fa6317
commit 14769a4019
5 changed files with 51 additions and 5 deletions

View File

@ -11,6 +11,7 @@ public class Feed implements Comparable<Feed>, 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<Feed>, 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<Feed>, Parcelable {
cat_id = in.readInt();
last_updated = in.readInt();
is_cat = in.readInt() == 1;
order_id = in.readInt();
}
@SuppressWarnings("rawtypes")

View File

@ -64,6 +64,21 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
}
class CatOrderComparator implements Comparator<FeedCategory> {
@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) {
@ -233,9 +248,13 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
if (m_prefs.getBoolean("sort_feeds_by_unread", false)) {
cmp = new CatUnreadComparator();
} else {
if (m_onlineServices.getApiLevel() >= 3) {
cmp = new CatOrderComparator();
} else {
cmp = new CatTitleComparator();
}
}
Collections.sort(m_cats, cmp);
m_adapter.notifyDataSetInvalidated();

View File

@ -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")

View File

@ -93,6 +93,21 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
}
class FeedOrderComparator implements Comparator<Feed> {
@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) {
@ -423,9 +438,13 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
if (m_prefs.getBoolean("sort_feeds_by_unread", false)) {
cmp = new FeedUnreadComparator();
} else {
if (m_onlineServices.getApiLevel() >= 3) {
cmp = new FeedOrderComparator();
} else {
cmp = new FeedTitleComparator();
}
}
Collections.sort(m_feeds, cmp);
m_adapter.notifyDataSetInvalidated();

View File

@ -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();