on API 3, sort feeds and categories using order configured in tt-rss
properly unmark Uncategorized on closeCategory()
This commit is contained in:
parent
1945fa6317
commit
14769a4019
@ -11,6 +11,7 @@ public class Feed implements Comparable<Feed>, Parcelable {
|
|||||||
boolean has_icon;
|
boolean has_icon;
|
||||||
int cat_id;
|
int cat_id;
|
||||||
int last_updated;
|
int last_updated;
|
||||||
|
int order_id;
|
||||||
boolean is_cat;
|
boolean is_cat;
|
||||||
|
|
||||||
public Feed(int id, String title, 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(cat_id);
|
||||||
out.writeInt(last_updated);
|
out.writeInt(last_updated);
|
||||||
out.writeInt(is_cat ? 1 : 0);
|
out.writeInt(is_cat ? 1 : 0);
|
||||||
|
out.writeInt(order_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFromParcel(Parcel in) {
|
public void readFromParcel(Parcel in) {
|
||||||
@ -57,6 +59,7 @@ public class Feed implements Comparable<Feed>, Parcelable {
|
|||||||
cat_id = in.readInt();
|
cat_id = in.readInt();
|
||||||
last_updated = in.readInt();
|
last_updated = in.readInt();
|
||||||
is_cat = in.readInt() == 1;
|
is_cat = in.readInt() == 1;
|
||||||
|
order_id = in.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
@ -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
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||||
ContextMenuInfo menuInfo) {
|
ContextMenuInfo menuInfo) {
|
||||||
@ -233,9 +248,13 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
|
|||||||
|
|
||||||
if (m_prefs.getBoolean("sort_feeds_by_unread", false)) {
|
if (m_prefs.getBoolean("sort_feeds_by_unread", false)) {
|
||||||
cmp = new CatUnreadComparator();
|
cmp = new CatUnreadComparator();
|
||||||
|
} else {
|
||||||
|
if (m_onlineServices.getApiLevel() >= 3) {
|
||||||
|
cmp = new CatOrderComparator();
|
||||||
} else {
|
} else {
|
||||||
cmp = new CatTitleComparator();
|
cmp = new CatTitleComparator();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Collections.sort(m_cats, cmp);
|
Collections.sort(m_cats, cmp);
|
||||||
m_adapter.notifyDataSetInvalidated();
|
m_adapter.notifyDataSetInvalidated();
|
||||||
|
@ -7,6 +7,7 @@ public class FeedCategory implements Parcelable {
|
|||||||
int id;
|
int id;
|
||||||
String title;
|
String title;
|
||||||
int unread;
|
int unread;
|
||||||
|
int order_id;
|
||||||
|
|
||||||
public FeedCategory(Parcel in) {
|
public FeedCategory(Parcel in) {
|
||||||
readFromParcel(in);
|
readFromParcel(in);
|
||||||
@ -16,6 +17,7 @@ public class FeedCategory implements Parcelable {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.unread = unread;
|
this.unread = unread;
|
||||||
|
this.order_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -28,12 +30,14 @@ public class FeedCategory implements Parcelable {
|
|||||||
out.writeInt(id);
|
out.writeInt(id);
|
||||||
out.writeString(title);
|
out.writeString(title);
|
||||||
out.writeInt(unread);
|
out.writeInt(unread);
|
||||||
|
out.writeInt(order_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFromParcel(Parcel in) {
|
public void readFromParcel(Parcel in) {
|
||||||
id = in.readInt();
|
id = in.readInt();
|
||||||
title = in.readString();
|
title = in.readString();
|
||||||
unread = in.readInt();
|
unread = in.readInt();
|
||||||
|
order_id = in.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
@ -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
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||||
ContextMenuInfo menuInfo) {
|
ContextMenuInfo menuInfo) {
|
||||||
@ -423,9 +438,13 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
|
|||||||
|
|
||||||
if (m_prefs.getBoolean("sort_feeds_by_unread", false)) {
|
if (m_prefs.getBoolean("sort_feeds_by_unread", false)) {
|
||||||
cmp = new FeedUnreadComparator();
|
cmp = new FeedUnreadComparator();
|
||||||
|
} else {
|
||||||
|
if (m_onlineServices.getApiLevel() >= 3) {
|
||||||
|
cmp = new FeedOrderComparator();
|
||||||
} else {
|
} else {
|
||||||
cmp = new FeedTitleComparator();
|
cmp = new FeedTitleComparator();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Collections.sort(m_feeds, cmp);
|
Collections.sort(m_feeds, cmp);
|
||||||
m_adapter.notifyDataSetInvalidated();
|
m_adapter.notifyDataSetInvalidated();
|
||||||
|
@ -759,7 +759,8 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
|
|||||||
.findFragmentById(R.id.cats_fragment);
|
.findFragmentById(R.id.cats_fragment);
|
||||||
|
|
||||||
if (cf != null) {
|
if (cf != null) {
|
||||||
cf.setSelectedCategoryId(0);
|
// should be nonexistant feed_id (0 is Uncategorized)
|
||||||
|
cf.setSelectedCategoryId(-10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
initMainMenu();
|
initMainMenu();
|
||||||
|
Loading…
Reference in New Issue
Block a user