diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 34738f4c..3895ce87 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3,7 +3,7 @@
package="org.fox.ttrss"
android:versionCode="4"
android:versionName="0.1.3">
-
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b951c291..84b0632c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -32,4 +32,5 @@
Close article
Share article
Could not decode content (UnsupportedEncodingException)
+ Sort feeds by unread count
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index 9f200274..10cb3cca 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -18,7 +18,9 @@
android:key="theme"
android:defaultValue="THEME_DARK"
android:entries="@array/pref_theme_names"
- android:entryValues="@array/pref_theme_values" android:summary="@string/pref_theme_long"/>
+ android:entryValues="@array/pref_theme_values" android:summary="@string/pref_theme_long"/>
+
+
\ No newline at end of file
diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java
index 9777f9b2..d4480dba 100644
--- a/src/org/fox/ttrss/FeedsFragment.java
+++ b/src/org/fox/ttrss/FeedsFragment.java
@@ -3,6 +3,7 @@ package org.fox.ttrss;
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;
@@ -39,6 +40,28 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
public void onFeedSelected(Feed feed);
}
+ class FeedUnreadComparator implements Comparator {
+
+ @Override
+ public int compare(Feed a, Feed b) {
+ if (a.unread != b.unread)
+ return b.unread - a.unread;
+ else
+ return a.title.compareTo(b.title);
+ }
+
+ }
+
+
+ class FeedTitleComparator implements Comparator {
+
+ @Override
+ public int compare(Feed a, Feed b) {
+ return a.title.compareTo(b.title);
+ }
+
+ }
+
public void showLoading(boolean show) {
View v = getView();
@@ -170,9 +193,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
for (Feed f : feeds)
m_feeds.add(f);
- Collections.sort(m_feeds);
-
- m_adapter.notifyDataSetInvalidated();
+ sortFeeds();
showLoading(false);
}
@@ -260,4 +281,17 @@ public class FeedsFragment extends Fragment implements OnItemClickListener {
return v;
}
}
+
+ public void sortFeeds() {
+ Comparator cmp;
+
+ if (m_prefs.getBoolean("sort_feeds_by_unread", false)) {
+ cmp = new FeedUnreadComparator();
+ } else {
+ cmp = new FeedTitleComparator();
+ }
+
+ Collections.sort(m_feeds, cmp);
+ m_adapter.notifyDataSetInvalidated();
+ }
}
diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java
index f815d974..1c7207bf 100644
--- a/src/org/fox/ttrss/MainActivity.java
+++ b/src/org/fox/ttrss/MainActivity.java
@@ -145,7 +145,14 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
Intent refresh = new Intent(this, MainActivity.class);
startActivity(refresh);
finish();
- }
+ } else {
+ FeedsFragment frag = (FeedsFragment)getSupportFragmentManager().findFragmentById(R.id.feeds_fragment);
+
+ if (frag != null) {
+ frag.sortFeeds();
+ }
+ }
+
}
@Override