View source: added searching

pull/214/head
M66B 1 year ago
parent 77b64984e0
commit 3847d059ff

@ -40,6 +40,7 @@ import android.widget.Toast;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.SearchView;
import androidx.constraintlayout.widget.Group;
import androidx.preference.PreferenceManager;
import androidx.webkit.WebSettingsCompat;
@ -66,6 +67,7 @@ public class ActivityCode extends ActivityBase {
private boolean sanitize = false;
private boolean lines = false;
private boolean links = false;
private String searching = null;
private static final int REQUEST_SAVE = 1;
@ -78,6 +80,7 @@ public class ActivityCode extends ActivityBase {
sanitize = savedInstanceState.getBoolean("fair:sanitize");
lines = savedInstanceState.getBoolean("fair:lines");
links = savedInstanceState.getBoolean("fair:links");
searching = savedInstanceState.getString("fair:searching");
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@ -151,6 +154,7 @@ public class ActivityCode extends ActivityBase {
outState.putBoolean("fair:sanitize", sanitize);
outState.putBoolean("fair:lines", lines);
outState.putBoolean("fair:links", links);
outState.putString("fair:searching", searching);
super.onSaveInstanceState(outState);
}
@ -158,6 +162,41 @@ public class ActivityCode extends ActivityBase {
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_code, menu);
final String saved = searching;
final MenuItem menuSearch = menu.findItem(R.id.menu_search);
final SearchView searchView = (SearchView) menuSearch.getActionView();
if (searchView != null)
searchView.setQueryHint(getString(R.string.title_search));
if (searchView != null) {
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
search(query);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
search(newText);
return false;
}
private void search(String query) {
searching = query;
if (wvCode != null)
wvCode.findAllAsync(query);
}
});
if (!TextUtils.isEmpty(saved)) {
menuSearch.expandActionView();
searchView.setQuery(saved, false);
}
}
return true;
}
@ -174,7 +213,6 @@ public class ActivityCode extends ActivityBase {
menu.findItem(R.id.menu_sanitize)
.setVisible(BuildConfig.DEBUG || debug)
.setChecked(sanitize)
.setIcon(sanitize
? R.drawable.twotone_fullscreen_24
: R.drawable.twotone_fullscreen_exit_24)
@ -193,7 +231,7 @@ public class ActivityCode extends ActivityBase {
int itemId = item.getItemId();
if (itemId == R.id.menu_force_light) {
force_light = !force_light;
invalidateOptionsMenu();
item.getIcon().setLevel(force_light ? 1 : 0);
setDarkMode();
return true;
} else if (itemId == R.id.menu_sanitize) {

@ -1,6 +1,13 @@
<?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">
<item
android:id="@+id/menu_search"
android:icon="@drawable/twotone_search_24"
android:title="@string/title_search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="collapseActionView|always" />
<item
android:id="@+id/menu_force_light"
android:icon="@drawable/lightdark"
@ -9,7 +16,6 @@
<item
android:id="@+id/menu_sanitize"
android:checkable="true"
android:icon="@drawable/twotone_fullscreen_exit_24"
android:title="@string/title_legend_show_reformatted"
app:showAsAction="always" />

Loading…
Cancel
Save