add article sorting dialog for offline mode

This commit is contained in:
Andrew Dolgov 2014-11-04 17:36:13 +03:00
parent 36c24e5846
commit 9d80e8aceb
5 changed files with 54 additions and 10 deletions

View File

@ -327,8 +327,6 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
@Override @Override
public void onClick(DialogInterface dialog, public void onClick(DialogInterface dialog,
int which) { int which) {
Log.d(TAG, "which:" + which);
switch (which) { switch (which) {
case 0: case 0:
setSortMode("default"); setSortMode("default");

View File

@ -1728,8 +1728,6 @@ public class OnlineActivity extends CommonActivity {
} }
public void setSortMode(String sortMode) { public void setSortMode(String sortMode) {
Log.d(TAG, "setSortMode:" + sortMode);
SharedPreferences.Editor editor = m_prefs.edit(); SharedPreferences.Editor editor = m_prefs.edit();
editor.putString("headlines_sort_mode", sortMode); editor.putString("headlines_sort_mode", sortMode);
editor.commit(); editor.commit();

View File

@ -824,13 +824,17 @@ public class OfflineActivity extends CommonActivity {
editor.commit(); editor.commit();
} }
/* public String getSortMode() { /* public boolean getOldestFirst() {
return m_prefs.getString("headlines_sort_mode", "default"); return getSortMode().equals("oldest_first");
}
public String getSortMode() {
return m_prefs.getString("offline_headlines_sort_mode", "default");
} }
public void setSortMode(String sortMode) { public void setSortMode(String sortMode) {
SharedPreferences.Editor editor = m_prefs.edit(); SharedPreferences.Editor editor = m_prefs.edit();
editor.putString("headlines_sort_mode", sortMode); editor.putString("offline_headlines_sort_mode", sortMode);
editor.commit(); editor.commit();
} */ } */

View File

@ -1,6 +1,9 @@
package org.fox.ttrss.offline; package org.fox.ttrss.offline;
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.database.sqlite.SQLiteStatement; import android.database.sqlite.SQLiteStatement;
@ -133,10 +136,51 @@ public class OfflineFeedsActivity extends OfflineActivity implements OfflineHead
//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(); /* SharedPreferences.Editor editor = m_prefs.edit();
editor.putBoolean("offline_oldest_first", !m_prefs.getBoolean("offline_oldest_first", false)); editor.putBoolean("offline_oldest_first", !m_prefs.getBoolean("offline_oldest_first", false));
editor.commit(); editor.commit();
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(); 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

@ -31,7 +31,7 @@
android:title="@string/headlines_select"/> android:title="@string/headlines_select"/>
<item <item
android:id="@+id/toggle_sort_order" android:id="@+id/headlines_toggle_sort_order"
android:icon="@drawable/ic_action_sort_by_size" android:icon="@drawable/ic_action_sort_by_size"
app:showAsAction="ifRoom" app:showAsAction="ifRoom"
android:title="@string/toggle_sort_order"/> android:title="@string/toggle_sort_order"/>