parent
595947414d
commit
024e05f5ce
10 changed files with 50 additions and 3 deletions
|
@ -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();
|
||||
|
|
BIN
app/src/main/res/drawable-hdpi/ic_action_sort.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_action_sort.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 151 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_sort.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_action_sort.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 105 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_sort.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_action_sort.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 132 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_sort.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_action_sort.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 163 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_action_sort.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_action_sort.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 218 B |
9
app/src/main/res/menu/menu_history.xml
Normal file
9
app/src/main/res/menu/menu_history.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?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>
|
||||
|
|
Loading…
Reference in a new issue