add preference to sort feeds by unread

This commit is contained in:
Andrew Dolgov 2011-11-26 09:31:14 +03:00
parent a950ebbddb
commit 10672b110f
5 changed files with 50 additions and 6 deletions

View File

@ -3,7 +3,7 @@
package="org.fox.ttrss"
android:versionCode="4"
android:versionName="0.1.3">
<uses-sdk android:minSdkVersion="10" />
<uses-sdk android:minSdkVersion="8" />
<supports-screens android:smallScreens="false" android:normalScreens="false" />
<uses-permission android:name="android.permission.INTERNET" />

View File

@ -32,4 +32,5 @@
<string name="close_article">Close article</string>
<string name="share_article">Share article</string>
<string name="could_not_decode_content">Could not decode content (UnsupportedEncodingException)</string>
<string name="sort_feeds_by_unread">Sort feeds by unread count</string>
</resources>

View File

@ -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"/>
<CheckBoxPreference android:title="@string/sort_feeds_by_unread" android:key="sort_feeds_by_unread"/>
</PreferenceCategory>
</PreferenceScreen>

View File

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

View File

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