From 9d80e8acebbf55c423c7a07b1c81c65501bf4ba5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 4 Nov 2014 17:36:13 +0300 Subject: [PATCH] add article sorting dialog for offline mode --- .../java/org/fox/ttrss/FeedsActivity.java | 2 - .../java/org/fox/ttrss/OnlineActivity.java | 2 - .../fox/ttrss/offline/OfflineActivity.java | 10 ++-- .../ttrss/offline/OfflineFeedsActivity.java | 48 ++++++++++++++++++- .../src/main/res/menu/offline_menu.xml | 2 +- 5 files changed, 54 insertions(+), 10 deletions(-) diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java index 39e4ae6f..10c4623b 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/FeedsActivity.java @@ -327,8 +327,6 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe @Override public void onClick(DialogInterface dialog, int which) { - Log.d(TAG, "which:" + which); - switch (which) { case 0: setSortMode("default"); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java index 894920cb..4d4cbc22 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java @@ -1728,8 +1728,6 @@ public class OnlineActivity extends CommonActivity { } public void setSortMode(String sortMode) { - Log.d(TAG, "setSortMode:" + sortMode); - SharedPreferences.Editor editor = m_prefs.edit(); editor.putString("headlines_sort_mode", sortMode); editor.commit(); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineActivity.java index 184937a7..fa0eb1b8 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineActivity.java @@ -824,13 +824,17 @@ public class OfflineActivity extends CommonActivity { editor.commit(); } - /* public String getSortMode() { - return m_prefs.getString("headlines_sort_mode", "default"); + /* public boolean getOldestFirst() { + return getSortMode().equals("oldest_first"); + } + + public String getSortMode() { + return m_prefs.getString("offline_headlines_sort_mode", "default"); } public void setSortMode(String sortMode) { SharedPreferences.Editor editor = m_prefs.edit(); - editor.putString("headlines_sort_mode", sortMode); + editor.putString("offline_headlines_sort_mode", sortMode); editor.commit(); } */ diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineFeedsActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineFeedsActivity.java index d5cc0cde..9337e521 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineFeedsActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineFeedsActivity.java @@ -1,6 +1,9 @@ package org.fox.ttrss.offline; import android.annotation.SuppressLint; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.database.sqlite.SQLiteStatement; @@ -133,10 +136,51 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead //getSupportFragmentManager().popBackStack(); return true; case R.id.headlines_toggle_sort_order: - SharedPreferences.Editor editor = m_prefs.edit(); + /* SharedPreferences.Editor editor = m_prefs.edit(); editor.putBoolean("offline_oldest_first", !m_prefs.getBoolean("offline_oldest_first", false)); editor.commit(); - refresh(); + refresh(); */ + + Dialog dialog = new Dialog(this); + + int selectedIndex = m_prefs.getBoolean("offline_oldest_first", false) ? 1 : 0; + + 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_oldest_first) + }, + selectedIndex, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int which) { + switch (which) { + case 0: + if (true) { + SharedPreferences.Editor editor = m_prefs.edit(); + editor.putBoolean("offline_oldest_first", false); + editor.commit(); + } + break; + case 1: + if (true) { + SharedPreferences.Editor editor = m_prefs.edit(); + editor.putBoolean("offline_oldest_first", true); + editor.commit(); + } + break; + } + dialog.cancel(); + + refresh(); + } + }); + + dialog = builder.create(); + dialog.show(); + return true; case R.id.show_feeds: setUnreadOnly(!getUnreadOnly()); diff --git a/org.fox.ttrss/src/main/res/menu/offline_menu.xml b/org.fox.ttrss/src/main/res/menu/offline_menu.xml index a4731bd9..6f576cdd 100644 --- a/org.fox.ttrss/src/main/res/menu/offline_menu.xml +++ b/org.fox.ttrss/src/main/res/menu/offline_menu.xml @@ -31,7 +31,7 @@ android:title="@string/headlines_select"/>