Commit 024e05f5 authored by Schoumi's avatar Schoumi

Add Support for user to choose his history order

Fixes #15
parent 59594741
......@@ -88,10 +88,10 @@ public class Database extends SQLiteOpenHelper {
}
}
public List<Img> getHistory() {
public List<Img> getHistory(boolean descendingOrder) {
List<Img> history = new ArrayList<>();
//ask for history order by date
String orderBy = "date ASC";
String orderBy = descendingOrder ? "date DESC" : "date ASC";
Cursor cursor = getReadableDatabase().query("history", null, null, null, null, null, orderBy);
while(cursor.moveToNext())
{
......
......@@ -20,6 +20,7 @@ package fr.mobdev.goblim.activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
......@@ -27,6 +28,8 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
......@@ -52,6 +55,7 @@ import fr.mobdev.goblim.R;
public class HistoryActivity extends AppCompatActivity {
private List<Long> imagesIdx;
private boolean descendingOrder;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -71,6 +75,15 @@ public class HistoryActivity extends AppCompatActivity {
});
ListView historyList = (ListView) findViewById(R.id.history_list);
SharedPreferences prefs = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE);
if(prefs.getAll().size() == 0) {
descendingOrder = true;
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("order", descendingOrder);
editor.commit();
} else {
descendingOrder = prefs.getBoolean("order",true);
}
updateHistory();
......@@ -96,11 +109,34 @@ public class HistoryActivity extends AppCompatActivity {
updateHistory();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_history, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_change_order) {
SharedPreferences prefs = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE);
descendingOrder = !descendingOrder;
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("order", descendingOrder);
editor.commit();
updateHistory();
return true;
}
return super.onOptionsItemSelected(item);
}
private void updateHistory()
{
ListView historyList = (ListView) findViewById(R.id.history_list);
List<Img> images = Database.getInstance(getApplicationContext()).getHistory();
List<Img> images = Database.getInstance(getApplicationContext()).getHistory(descendingOrder);
if(imagesIdx == null)
imagesIdx = new ArrayList<>();
imagesIdx.clear();
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context="fr.mobdev.goblim.activity.HistoryActivity">
<item android:id="@+id/action_change_order"
android:icon="@drawable/ic_action_sort"
android:title="@string/reorder_history"
app:showAsAction="ifRoom" />
</menu>
......@@ -40,6 +40,7 @@
<string name="uploading_files">Envoi Image </string>
<string name="retry_failed_uploads">Voulez vous retenter l\'envoi des fichiers listés?</string>
<string name="retry_failed_upload">Voulez vous retenter l\'envoi de ce fichier?</string>
<string name="reorder_history">Changer l\'ordre de l\'historique</string>
<string-array name="deleted_days">
<item>Pas de limitation</item>
<item>24 Heures</item>
......
......@@ -40,6 +40,7 @@
<string name="uploading_files">Uploading Image </string>
<string name="retry_failed_uploads">Would you retry upload of listed files?</string>
<string name="retry_failed_upload">Would you retry upload of this file?</string>
<string name="reorder_history">Change history order</string>
<string-array name="deleted_days">
<item>No limitation</item>
<item>24 Hours</item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment