Added search IP/uid to traffic log

Refs #235
This commit is contained in:
M66B 2016-01-26 21:20:16 +01:00
parent 8c624fe0c0
commit caf0ca574d
3 changed files with 66 additions and 2 deletions

View File

@ -28,7 +28,9 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
@ -36,6 +38,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.FilterQueryProvider;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.Toast;
@ -54,6 +57,8 @@ public class ActivityLog extends AppCompatActivity {
private ListView lvLog;
private LogAdapter adapter;
private MenuItem menuSearch = null;
private DatabaseHelper dh;
private boolean live;
private boolean resolve;
@ -68,7 +73,13 @@ public class ActivityLog extends AppCompatActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.changeCursor(dh.getLog());
if (adapter != null) {
adapter.changeCursor(dh.getLog());
if (menuSearch != null && menuSearch.isActionViewExpanded()) {
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuSearch);
adapter.getFilter().filter(searchView.getQuery().toString());
}
}
}
});
}
@ -90,6 +101,12 @@ public class ActivityLog extends AppCompatActivity {
dh = new DatabaseHelper(this);
adapter = new LogAdapter(this, dh.getLog(), resolve);
adapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
return dh.searchLog(constraint.toString());
}
});
lvLog.setAdapter(adapter);
try {
@ -209,6 +226,33 @@ public class ActivityLog extends AppCompatActivity {
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.log, menu);
menuSearch = menu.findItem(R.id.menu_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuSearch);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (adapter != null)
adapter.getFilter().filter(query);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
if (adapter != null)
adapter.getFilter().filter(newText);
return true;
}
});
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
if (adapter != null)
adapter.getFilter().filter(null);
return true;
}
});
return true;
}
@ -259,6 +303,11 @@ public class ActivityLog extends AppCompatActivity {
resolve = item.isChecked();
prefs.edit().putBoolean("resolve", resolve).apply();
adapter = new LogAdapter(this, dh.getLog(), resolve);
adapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
return dh.searchLog(constraint.toString());
}
});
lvLog.setAdapter(adapter);
return true;

View File

@ -188,6 +188,14 @@ public class DatabaseHelper extends SQLiteOpenHelper {
return db.rawQuery(query, new String[]{});
}
public Cursor searchLog(String find) {
SQLiteDatabase db = this.getReadableDatabase();
String query = "SELECT ID AS _id, * FROM log";
query += " WHERE saddr LIKE ? OR daddr LIKE ? OR uid LIKE ?";
query += " ORDER BY time DESC";
return db.rawQuery(query, new String[]{"%" + find + "%", "%" + find + "%", "%" + find + "%"});
}
public static void addLogChangedListener(LogChangedListener listener) {
logChangedListeners.add(listener);
}

View File

@ -1,5 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:netguard="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_search"
android:icon="@drawable/ic_search_white_24dp"
android:title="@string/menu_search"
netguard:actionViewClass="android.support.v7.widget.SearchView"
netguard:showAsAction="always|collapseActionView" />
<item
android:id="@+id/menu_log_enabled"
android:checkable="true"