Added clear log menu

This commit is contained in:
M66B 2016-01-05 22:53:22 +01:00
parent 26b2eaf546
commit 352c4df292
4 changed files with 38 additions and 3 deletions

View File

@ -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);
}

View File

@ -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();
}
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_clear"
android:title="@string/menu_clear" />
</menu>

View File

@ -24,6 +24,8 @@ These issues are caused by bugs in Android, or in the software provided by the m
<string name="menu_support">Support</string>
<string name="menu_about">About</string>
<string name="menu_clear">Clear</string>
<string name="setting_defaults">Defaults</string>
<string name="setting_whitelist_wifi">Block Wi-Fi</string>
<string name="setting_whitelist_other">Block mobile</string>