Add search to MagiskHide
This commit is contained in:
parent
399c0d337a
commit
e17638bc06
@ -5,16 +5,21 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.SearchView;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.adapters.ApplicationAdapter;
|
import com.topjohnwu.magisk.adapters.ApplicationAdapter;
|
||||||
import com.topjohnwu.magisk.utils.Async;
|
import com.topjohnwu.magisk.utils.Async;
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -28,7 +33,11 @@ public class MagiskHideFragment extends Fragment {
|
|||||||
|
|
||||||
private PackageManager packageManager;
|
private PackageManager packageManager;
|
||||||
private View mView;
|
private View mView;
|
||||||
private ApplicationAdapter appAdapter;
|
private List<ApplicationInfo> listApps = new ArrayList<>(), fListApps = new ArrayList<>();
|
||||||
|
private List<String> hideList = new ArrayList<>();
|
||||||
|
private ApplicationAdapter appAdapter = new ApplicationAdapter(fListApps, hideList);
|
||||||
|
|
||||||
|
private SearchView.OnQueryTextListener searchListener;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
@ -44,36 +53,68 @@ public class MagiskHideFragment extends Fragment {
|
|||||||
new LoadApps().exec();
|
new LoadApps().exec();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
recyclerView.setAdapter(appAdapter);
|
||||||
|
|
||||||
|
searchListener = new SearchView.OnQueryTextListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onQueryTextSubmit(String query) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onQueryTextChange(String newText) {
|
||||||
|
fListApps.clear();
|
||||||
|
for (ApplicationInfo info : listApps) {
|
||||||
|
if (info.loadLabel(packageManager).toString().contains(newText)
|
||||||
|
|| info.packageName.contains(newText)) {
|
||||||
|
fListApps.add(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
appAdapter.notifyDataSetChanged();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
new LoadApps().exec();
|
new LoadApps().exec();
|
||||||
return mView;
|
return mView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
inflater.inflate(R.menu.menu_magiskhide, menu);
|
||||||
|
SearchView search = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.app_search));
|
||||||
|
search.setOnQueryTextListener(searchListener);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
setHasOptionsMenu(true);
|
||||||
mView = this.getView();
|
mView = this.getView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LoadApps extends Async.RootTask<Void, Void, Void> {
|
private class LoadApps extends Async.RootTask<Void, Void, Void> {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
List<ApplicationInfo> listApps = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
|
listApps.clear();
|
||||||
|
hideList.clear();
|
||||||
|
fListApps.clear();
|
||||||
|
listApps.addAll(packageManager.getInstalledApplications(PackageManager.GET_META_DATA));
|
||||||
Collections.sort(listApps, (a, b) -> a.loadLabel(packageManager).toString().toLowerCase()
|
Collections.sort(listApps, (a, b) -> a.loadLabel(packageManager).toString().toLowerCase()
|
||||||
.compareTo(b.loadLabel(packageManager).toString().toLowerCase()));
|
.compareTo(b.loadLabel(packageManager).toString().toLowerCase()));
|
||||||
List<String> hideList = Shell.su(Async.MAGISK_HIDE_PATH + "list");
|
hideList.addAll(Shell.su(Async.MAGISK_HIDE_PATH + "list"));
|
||||||
appAdapter = new ApplicationAdapter(listApps, hideList);
|
fListApps.addAll(listApps);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void aVoid) {
|
protected void onPostExecute(Void aVoid) {
|
||||||
super.onPostExecute(aVoid);
|
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUI() {
|
private void updateUI() {
|
||||||
recyclerView.setAdapter(appAdapter);
|
appAdapter.notifyDataSetChanged();
|
||||||
recyclerView.setVisibility(View.VISIBLE);
|
recyclerView.setVisibility(View.VISIBLE);
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
}
|
}
|
||||||
|
9
app/src/main/res/menu/menu_magiskhide.xml
Normal file
9
app/src/main/res/menu/menu_magiskhide.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?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/app_search"
|
||||||
|
app:actionViewClass="android.widget.SearchView"
|
||||||
|
app:showAsAction="always"/>
|
||||||
|
</menu>
|
Loading…
Reference in New Issue
Block a user