From 352c4df292b231ea5a7226a555c05617e20f3e7b Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 5 Jan 2016 22:53:22 +0100 Subject: [PATCH] Added clear log menu --- .../java/eu/faircode/netguard/ActivityLog.java | 15 ++++++++++++++- .../eu/faircode/netguard/DatabaseHelper.java | 18 ++++++++++++++++-- app/src/main/res/menu/log.xml | 6 ++++++ app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/menu/log.xml diff --git a/app/src/main/java/eu/faircode/netguard/ActivityLog.java b/app/src/main/java/eu/faircode/netguard/ActivityLog.java index 3c8f390b..ade36f97 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivityLog.java +++ b/app/src/main/java/eu/faircode/netguard/ActivityLog.java @@ -22,6 +22,8 @@ package eu.faircode.netguard; import android.app.Activity; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.widget.ListView; @@ -31,7 +33,7 @@ public class ActivityLog extends AppCompatActivity { private DatabaseHelper.LogChangedListener listener = new DatabaseHelper.LogChangedListener() { @Override - public void onAdded() { + public void onChanged() { runOnUiThread(new Runnable() { @Override public void run() { @@ -67,11 +69,22 @@ public class ActivityLog extends AppCompatActivity { super.onDestroy(); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.log, menu); + + return true; + } + public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish(); return true; + case R.id.menu_clear: + dh.clear(); + return true; } return super.onOptionsItemSelected(item); } diff --git a/app/src/main/java/eu/faircode/netguard/DatabaseHelper.java b/app/src/main/java/eu/faircode/netguard/DatabaseHelper.java index 2dd16006..03a6670f 100644 --- a/app/src/main/java/eu/faircode/netguard/DatabaseHelper.java +++ b/app/src/main/java/eu/faircode/netguard/DatabaseHelper.java @@ -74,7 +74,21 @@ public class DatabaseHelper extends SQLiteOpenHelper { for (LogChangedListener listener : logChangedListeners) try { - listener.onAdded(); + listener.onChanged(); + } catch (Throwable ex) { + Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); + } + + return this; + } + + public DatabaseHelper clear() { + SQLiteDatabase db = this.getReadableDatabase(); + db.delete("log", null, new String[]{}); + + for (LogChangedListener listener : logChangedListeners) + try { + listener.onChanged(); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } @@ -98,6 +112,6 @@ public class DatabaseHelper extends SQLiteOpenHelper { } public interface LogChangedListener { - void onAdded(); + void onChanged(); } } diff --git a/app/src/main/res/menu/log.xml b/app/src/main/res/menu/log.xml new file mode 100644 index 00000000..684ca5b3 --- /dev/null +++ b/app/src/main/res/menu/log.xml @@ -0,0 +1,6 @@ + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cfe4dd3a..9e3bb91b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -24,6 +24,8 @@ These issues are caused by bugs in Android, or in the software provided by the m Support About + Clear + Defaults Block Wi-Fi Block mobile