mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
implement searching in local-help
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:label="@string/app_name" />
|
||||
android:label="@string/app_name"
|
||||
android:includeInGlobalSearch="false" />
|
||||
|
||||
@@ -12,6 +12,8 @@ import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
@@ -23,6 +25,8 @@ import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
public class LocalHelpActivity extends PassphraseRequiredActionBarActivity
|
||||
implements SearchView.OnQueryTextListener,
|
||||
WebView.FindListener
|
||||
{
|
||||
private WebView webView;
|
||||
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
||||
@@ -84,6 +88,7 @@ public class LocalHelpActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
});
|
||||
webView.loadUrl("file:///android_asset/" + helpPath.replace("LANG", helpLang));
|
||||
webView.setFindListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,10 +109,49 @@ public class LocalHelpActivity extends PassphraseRequiredActionBarActivity
|
||||
menu.clear();
|
||||
|
||||
inflater.inflate(R.menu.local_help, menu);
|
||||
|
||||
MenuItem searchItem = menu.findItem(R.id.menu_search_localhelp);
|
||||
SearchView searchView = (SearchView) searchItem.getActionView();
|
||||
searchView.setOnQueryTextListener(this);
|
||||
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
private String lastQuery = "";
|
||||
private Toast lastToast = null;
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
webView.findNext(true);
|
||||
return true; // action handled by listener
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String query) {
|
||||
String normQuery = query.trim();
|
||||
lastQuery = normQuery;
|
||||
if (lastToast!=null) {
|
||||
lastToast.cancel();
|
||||
lastToast = null;
|
||||
}
|
||||
webView.findAllAsync(normQuery);
|
||||
return true; // action handled by listener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFindResultReceived (int activeMatchOrdinal, int numberOfMatches, boolean isDoneCounting)
|
||||
{
|
||||
if (isDoneCounting && numberOfMatches==0 && !lastQuery.isEmpty()) {
|
||||
String msg = getString(R.string.search_no_result_for_x, lastQuery);
|
||||
if (lastToast!=null) {
|
||||
lastToast.cancel();
|
||||
}
|
||||
lastToast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
|
||||
lastToast.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
super.onOptionsItemSelected(item);
|
||||
|
||||
Reference in New Issue
Block a user