diff --git a/src/full/java/com/topjohnwu/magisk/MagiskHideFragment.java b/src/full/java/com/topjohnwu/magisk/MagiskHideFragment.java index 336e63862..679fe89e0 100644 --- a/src/full/java/com/topjohnwu/magisk/MagiskHideFragment.java +++ b/src/full/java/com/topjohnwu/magisk/MagiskHideFragment.java @@ -28,7 +28,6 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber { private ApplicationAdapter appAdapter; private SearchView.OnQueryTextListener searchListener; - private String lastFilter; @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -41,25 +40,22 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_magisk_hide, container, false); unbinder = ButterKnife.bind(this, view); - lastFilter = ""; mSwipeRefreshLayout.setRefreshing(true); mSwipeRefreshLayout.setOnRefreshListener(() -> appAdapter.refresh()); - appAdapter = new ApplicationAdapter(getActivity()); + appAdapter = new ApplicationAdapter(); recyclerView.setAdapter(appAdapter); searchListener = new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { - lastFilter = query; appAdapter.filter(query); return false; } @Override public boolean onQueryTextChange(String newText) { - lastFilter = newText; appAdapter.filter(newText); return false; } @@ -86,7 +82,7 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber { @Override public void onTopicPublished(Topic topic) { mSwipeRefreshLayout.setRefreshing(false); - appAdapter.filter(lastFilter); + appAdapter.filter(null); } @Override diff --git a/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java b/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java index f9efe1777..8cad5b196 100644 --- a/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java +++ b/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java @@ -1,6 +1,5 @@ package com.topjohnwu.magisk.adapters; -import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.support.v7.widget.RecyclerView; @@ -13,11 +12,10 @@ import android.widget.Filter; import android.widget.ImageView; import android.widget.TextView; +import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.asyncs.ParallelTask; import com.topjohnwu.magisk.utils.Const; -import com.topjohnwu.magisk.utils.Topic; -import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.superuser.Shell; import java.util.ArrayList; @@ -30,25 +28,19 @@ import butterknife.ButterKnife; public class ApplicationAdapter extends RecyclerView.Adapter { - private List mOriginalList, mList; - private List mHideList; + private List fullList, showList; + private List hideList; private PackageManager pm; private ApplicationFilter filter; - private Topic magiskHideDone; - public ApplicationAdapter(Context context) { - mOriginalList = mList = Collections.emptyList(); - mHideList = Collections.emptyList(); + public ApplicationAdapter() { + fullList = showList = Collections.emptyList(); + hideList = Collections.emptyList(); filter = new ApplicationFilter(); - pm = context.getPackageManager(); - magiskHideDone = Utils.getMagiskManager(context).magiskHideDone; + pm = MagiskManager.get().getPackageManager(); new LoadApps().exec(); } - private boolean lowercaseContains(CharSequence string, CharSequence nonNullLowercaseSearch) { - return !TextUtils.isEmpty(string) && string.toString().toLowerCase().contains(nonNullLowercaseSearch); - } - @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_app, parent, false); @@ -57,28 +49,28 @@ public class ApplicationAdapter extends RecyclerView.Adapter { if (isChecked) { Shell.Async.su("magiskhide --add " + info.packageName); - mHideList.add(info.packageName); + hideList.add(info.packageName); } else { Shell.Async.su("magiskhide --rm " + info.packageName); - mHideList.remove(info.packageName); + hideList.remove(info.packageName); } }); } @Override public int getItemCount() { - return mList.size(); + return showList.size(); } public void filter(String constraint) { @@ -104,17 +96,21 @@ public class ApplicationAdapter extends RecyclerView.Adapter(); + showList = new ArrayList<>(); String filter = constraint.toString().toLowerCase(); - for (ApplicationInfo info : mOriginalList) { - if (lowercaseContains(info.loadLabel(pm), filter) + for (ApplicationInfo info : fullList) { + if (lowercaseContains(info.loadLabel(pm).toString(), filter) || lowercaseContains(info.packageName, filter)) { - mList.add(info); + showList.add(info); } } } @@ -131,22 +127,32 @@ public class ApplicationAdapter extends RecyclerView.Adapter i = mOriginalList.iterator(); i.hasNext(); ) { + fullList = pm.getInstalledApplications(0); + hideList = Shell.Sync.su("magiskhide --ls"); + for (Iterator i = fullList.iterator(); i.hasNext(); ) { ApplicationInfo info = i.next(); if (Const.HIDE_BLACKLIST.contains(info.packageName) || !info.enabled) { i.remove(); } } - Collections.sort(mOriginalList, (a, b) -> a.loadLabel(pm).toString().toLowerCase() - .compareTo(b.loadLabel(pm).toString().toLowerCase())); - mHideList = Shell.Sync.su("magiskhide --ls"); + Collections.sort(fullList, (a, b) -> { + boolean ah = hideList.contains(a.packageName); + boolean bh = hideList.contains(b.packageName); + if (ah == bh) { + return a.loadLabel(pm).toString().toLowerCase().compareTo( + b.loadLabel(pm).toString().toLowerCase()); + } else if (ah) { + return -1; + } else { + return 1; + } + }); return null; } @Override protected void onPostExecute(Void v) { - magiskHideDone.publish(false); + MagiskManager.get().magiskHideDone.publish(false); } } }