mirror of
https://github.com/M66B/NetGuard.git
synced 2025-03-15 08:29:02 +00:00
Revert "Experimental: letter category search"
This reverts commit 7b56dd05d3
.
It is ugly and doesn't support non latin character sets
This commit is contained in:
parent
7b56dd05d3
commit
0ded9aa91e
4 changed files with 9 additions and 101 deletions
|
@ -42,7 +42,6 @@ import android.support.v7.widget.LinearLayoutManager;
|
|||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -68,7 +67,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
private ImageView ivInteractive;
|
||||
private ImageView ivNetwork;
|
||||
private ImageView ivMetered;
|
||||
private LinearLayout llSearch = null;
|
||||
private SwipeRefreshLayout swipeRefresh;
|
||||
private RuleAdapter adapter = null;
|
||||
private MenuItem menuSearch = null;
|
||||
|
@ -167,35 +165,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
|
||||
tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);
|
||||
|
||||
// Lexicographic filtering
|
||||
llSearch = (LinearLayout) findViewById(R.id.llSearch);
|
||||
final Button btnA = (Button) findViewById(R.id.btnA);
|
||||
final Button btnG = (Button) findViewById(R.id.btnG);
|
||||
final Button btnM = (Button) findViewById(R.id.btnM);
|
||||
final Button btnS = (Button) findViewById(R.id.btnS);
|
||||
|
||||
View.OnClickListener lexicographic = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (adapter != null)
|
||||
if (view == btnA)
|
||||
adapter.getFilter().filter("^[a-f].*$");
|
||||
else if (view == btnG)
|
||||
adapter.getFilter().filter("^[g-l].*$");
|
||||
else if (view == btnM)
|
||||
adapter.getFilter().filter("^[m-r].*$");
|
||||
else if (view == btnS)
|
||||
adapter.getFilter().filter("^[s-z|\\W].*$");
|
||||
if (menuSearch != null)
|
||||
MenuItemCompat.collapseActionView(menuSearch);
|
||||
}
|
||||
};
|
||||
|
||||
btnA.setOnClickListener(lexicographic);
|
||||
btnG.setOnClickListener(lexicographic);
|
||||
btnM.setOnClickListener(lexicographic);
|
||||
btnS.setOnClickListener(lexicographic);
|
||||
|
||||
// Application list
|
||||
RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
|
||||
rvApplication.setHasFixedSize(true);
|
||||
|
@ -439,10 +408,8 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
@Override
|
||||
protected void onPostExecute(List<Rule> result) {
|
||||
if (running) {
|
||||
if (adapter != null) {
|
||||
if (adapter != null)
|
||||
adapter.set(result);
|
||||
adapter.getFilter().filter(null);
|
||||
}
|
||||
if (menuSearch != null)
|
||||
MenuItemCompat.collapseActionView(menuSearch);
|
||||
if (swipeRefresh != null) {
|
||||
|
@ -462,34 +429,26 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
// Search
|
||||
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 + ".*$");
|
||||
if (llSearch != null)
|
||||
llSearch.setVisibility(TextUtils.isEmpty(query) ? View.VISIBLE : View.GONE);
|
||||
adapter.getFilter().filter(query);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if (adapter != null)
|
||||
adapter.getFilter().filter("^.*" + newText + ".*$");
|
||||
if (llSearch != null)
|
||||
llSearch.setVisibility(TextUtils.isEmpty(newText) ? View.VISIBLE : View.GONE);
|
||||
adapter.getFilter().filter(newText);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
|
||||
@Override
|
||||
public boolean onClose() {
|
||||
if (adapter != null)
|
||||
adapter.getFilter().filter(null);
|
||||
if (llSearch != null)
|
||||
llSearch.setVisibility(View.VISIBLE);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -47,7 +47,6 @@ import com.squareup.picasso.Picasso;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> implements Filterable {
|
||||
private static final String TAG = "NetGuard.Adapter";
|
||||
|
@ -359,13 +358,12 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
|
|||
if (query == null)
|
||||
listResult.addAll(listAll);
|
||||
else {
|
||||
boolean lexicographic = ((String) query).startsWith("^[");
|
||||
Pattern regex = Pattern.compile((String) query, Pattern.CASE_INSENSITIVE);
|
||||
query = query.toString().toLowerCase();
|
||||
for (Rule rule : listAll)
|
||||
if ((!lexicographic && regex.matcher(rule.info.packageName).matches()) ||
|
||||
(rule.name != null && regex.matcher(rule.name).matches()) ||
|
||||
(debuggable && !lexicographic && rule.info.applicationInfo != null &&
|
||||
regex.matcher(Integer.toString(rule.info.applicationInfo.uid)).matches()))
|
||||
if (rule.info.packageName.toLowerCase().contains(query) ||
|
||||
(rule.name != null && rule.name.toLowerCase().contains(query)) ||
|
||||
(debuggable && rule.info.applicationInfo != null &&
|
||||
Integer.toString(rule.info.applicationInfo.uid).contains(query)))
|
||||
listResult.add(rule);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,54 +21,10 @@
|
|||
android:textColor="@color/colorAccent"
|
||||
android:visibility="gone" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/llSearch"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnA"
|
||||
style="@style/smallButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:backgroundTint="@color/colorPrimary"
|
||||
android:text="A-F" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnG"
|
||||
style="@style/smallButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:backgroundTint="@color/colorPrimary"
|
||||
android:text="G-L" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnM"
|
||||
style="@style/smallButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:backgroundTint="@color/colorPrimary"
|
||||
android:text="M-R" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnS"
|
||||
style="@style/smallButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:backgroundTint="@color/colorPrimary"
|
||||
android:text="S-Z" />
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipeRefresh"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="4dp">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/rvApplication"
|
||||
|
|
|
@ -13,9 +13,4 @@
|
|||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<item name="android:windowDisablePreview">true</item>
|
||||
</style>
|
||||
|
||||
<style name="smallButton" parent="android:Widget.Button.Small">
|
||||
<item name="android:minHeight">0dp</item>
|
||||
<item name="android:minWidth">0dp</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Reference in a new issue