implement support for article sorting modes instead of previous preference options

This commit is contained in:
Andrew Dolgov 2014-11-04 17:27:11 +03:00
parent 7feb9203ab
commit 36c24e5846
7 changed files with 88 additions and 19 deletions

View File

@ -233,7 +233,7 @@ public class ArticlePager extends Fragment {
put("view_mode", m_activity.getViewMode()); put("view_mode", m_activity.getViewMode());
put("skip", String.valueOf(fskip)); put("skip", String.valueOf(fskip));
put("include_nested", "true"); put("include_nested", "true");
put("order_by", m_prefs.getBoolean("oldest_first", false) ? "date_reverse" : ""); put("order_by", m_activity.getSortMode());
if (feed.is_cat) put("is_cat", "true"); if (feed.is_cat) put("is_cat", "true");

View File

@ -2,6 +2,9 @@ package org.fox.ttrss;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
@ -297,10 +300,58 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
//getSupportFragmentManager().popBackStack(); //getSupportFragmentManager().popBackStack();
return true; return true;
case R.id.headlines_toggle_sort_order: case R.id.headlines_toggle_sort_order:
SharedPreferences.Editor editor = m_prefs.edit(); Dialog dialog = new Dialog(this);
editor.putBoolean("oldest_first", !m_prefs.getBoolean("oldest_first", false));
editor.commit(); String sortMode = getSortMode();
int selectedIndex = 0;
if (sortMode.equals("feed_dates")) {
selectedIndex = 1;
} else if (sortMode.equals("date_reverse")) {
selectedIndex = 2;
} else if (sortMode.equals("title")) {
selectedIndex = 3;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(getString(R.string.headlines_sort_articles_title))
.setSingleChoiceItems(
new String[] {
getString(R.string.headlines_sort_default),
getString(R.string.headlines_sort_newest_first),
getString(R.string.headlines_sort_oldest_first),
getString(R.string.headlines_sort_title)
},
selectedIndex, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
Log.d(TAG, "which:" + which);
switch (which) {
case 0:
setSortMode("default");
break;
case 1:
setSortMode("feed_dates");
break;
case 2:
setSortMode("date_reverse");
break;
case 3:
setSortMode("title");
break;
}
dialog.cancel();
refresh(); refresh();
}
});
dialog = builder.create();
dialog.show();
return true; return true;
case R.id.show_feeds: case R.id.show_feeds:
setUnreadOnly(!getUnreadOnly()); setUnreadOnly(!getUnreadOnly());

View File

@ -541,7 +541,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
put("offset", String.valueOf(0)); put("offset", String.valueOf(0));
put("skip", String.valueOf(fskip)); put("skip", String.valueOf(fskip));
put("include_nested", "true"); put("include_nested", "true");
put("order_by", m_prefs.getBoolean("oldest_first", false) ? "date_reverse" : ""); put("order_by", m_activity.getSortMode());
if (isCat) put("is_cat", "true"); if (isCat) put("is_cat", "true");

View File

@ -1723,6 +1723,18 @@ public class OnlineActivity extends CommonActivity {
} }
public String getSortMode() {
return m_prefs.getString("headlines_sort_mode", "default");
}
public void setSortMode(String sortMode) {
Log.d(TAG, "setSortMode:" + sortMode);
SharedPreferences.Editor editor = m_prefs.edit();
editor.putString("headlines_sort_mode", sortMode);
editor.commit();
}
public void setViewMode(String viewMode) { public void setViewMode(String viewMode) {
SharedPreferences.Editor editor = m_prefs.edit(); SharedPreferences.Editor editor = m_prefs.edit();
editor.putString("view_mode", viewMode); editor.putString("view_mode", viewMode);

View File

@ -824,6 +824,16 @@ public class OfflineActivity extends CommonActivity {
editor.commit(); editor.commit();
} }
/* public String getSortMode() {
return m_prefs.getString("headlines_sort_mode", "default");
}
public void setSortMode(String sortMode) {
SharedPreferences.Editor editor = m_prefs.edit();
editor.putString("headlines_sort_mode", sortMode);
editor.commit();
} */
public String getViewMode() { public String getViewMode() {
return m_prefs.getString("offline_view_mode", "adaptive"); return m_prefs.getString("offline_view_mode", "adaptive");
} }

View File

@ -244,5 +244,10 @@
<string name="error_loading_image">Error loading image.</string> <string name="error_loading_image">Error loading image.</string>
<string name="open_parent">Open parent</string> <string name="open_parent">Open parent</string>
<string name="toggle_sort_order">Toggle oldest first</string> <string name="toggle_sort_order">Toggle oldest first</string>
<string name="headlines_sort_default">Default</string>
<string name="headlines_sort_newest_first">Newest first</string>
<string name="headlines_sort_oldest_first">Oldest first</string>
<string name="headlines_sort_title">Title</string>
<string name="headlines_sort_articles_title">Sort articles</string>
</resources> </resources>

View File

@ -104,11 +104,6 @@
android:summary="@string/pref_headlines_full_content_long" android:summary="@string/pref_headlines_full_content_long"
android:title="@string/pref_headlines_full_content" /> --> android:title="@string/pref_headlines_full_content" /> -->
<CheckBoxPreference
android:defaultValue="false"
android:key="oldest_first"
android:summary="@string/requires_api5"
android:title="@string/offline_oldest_first" />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="headlines_mark_read_scroll" android:key="headlines_mark_read_scroll"
@ -171,10 +166,6 @@
android:key="offline_image_cache_enabled" android:key="offline_image_cache_enabled"
android:summary="@string/offline_image_cache_enabled_summary" android:summary="@string/offline_image_cache_enabled_summary"
android:title="@string/offline_image_cache_enabled" /> android:title="@string/offline_image_cache_enabled" />
<CheckBoxPreference
android:defaultValue="false"
android:key="offline_oldest_first"
android:title="@string/offline_oldest_first" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/debugging" > <PreferenceCategory android:title="@string/debugging" >
<CheckBoxPreference <CheckBoxPreference