2016-10-22 16:05:34 +00:00
|
|
|
package com.topjohnwu.magisk;
|
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
import android.app.Fragment;
|
2016-10-22 16:05:34 +00:00
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.annotation.Nullable;
|
2016-11-11 13:45:03 +00:00
|
|
|
import android.support.v4.view.MenuItemCompat;
|
2016-11-07 13:06:18 +00:00
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
|
import android.support.v7.widget.RecyclerView;
|
2016-10-22 16:05:34 +00:00
|
|
|
import android.view.LayoutInflater;
|
2016-11-11 13:45:03 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
2016-10-22 16:05:34 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2016-11-11 13:45:03 +00:00
|
|
|
import android.widget.SearchView;
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2016-11-07 16:09:08 +00:00
|
|
|
import com.topjohnwu.magisk.adapters.ApplicationAdapter;
|
2016-11-07 13:06:18 +00:00
|
|
|
import com.topjohnwu.magisk.utils.Async;
|
2017-01-06 16:29:53 +00:00
|
|
|
import com.topjohnwu.magisk.utils.CallbackHandler;
|
|
|
|
import com.topjohnwu.magisk.utils.Logger;
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2016-11-11 13:45:03 +00:00
|
|
|
import java.util.ArrayList;
|
2017-01-06 16:29:53 +00:00
|
|
|
import java.util.Arrays;
|
2016-10-22 16:05:34 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
2016-10-22 18:04:58 +00:00
|
|
|
|
2017-01-06 16:29:53 +00:00
|
|
|
public class MagiskHideFragment extends Fragment implements CallbackHandler.EventListener {
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
|
|
|
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2017-01-06 16:29:53 +00:00
|
|
|
public static List<ApplicationInfo> listApps, fListApps = new ArrayList<>();
|
|
|
|
public static List<String> hideList = new ArrayList<>();
|
|
|
|
// Don't show in list...
|
|
|
|
public static final List<String> blacklist = Arrays.asList(
|
|
|
|
"android",
|
|
|
|
"com.topjohnwu.magisk",
|
|
|
|
"com.google.android.gms",
|
|
|
|
"com.google.android.apps.walletnfcrel",
|
|
|
|
"com.nianticlabs.pokemongo"
|
|
|
|
);
|
|
|
|
public static CallbackHandler.Event packageLoadDone = new CallbackHandler.Event();
|
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
private PackageManager packageManager;
|
|
|
|
private View mView;
|
2016-11-11 13:45:03 +00:00
|
|
|
private ApplicationAdapter appAdapter = new ApplicationAdapter(fListApps, hideList);
|
|
|
|
|
|
|
|
private SearchView.OnQueryTextListener searchListener;
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
@Nullable
|
2016-10-22 16:05:34 +00:00
|
|
|
@Override
|
2016-11-07 13:06:18 +00:00
|
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
mView = inflater.inflate(R.layout.magisk_hide_fragment, container, false);
|
|
|
|
ButterKnife.bind(this, mView);
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
packageManager = getActivity().getPackageManager();
|
|
|
|
|
|
|
|
mSwipeRefreshLayout.setRefreshing(true);
|
|
|
|
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
|
|
|
recyclerView.setVisibility(View.GONE);
|
2017-01-06 16:29:53 +00:00
|
|
|
new Async.LoadApps(packageManager).exec();
|
2016-11-07 13:06:18 +00:00
|
|
|
});
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2017-01-06 16:29:53 +00:00
|
|
|
recyclerView.setAdapter(appAdapter);
|
2016-11-11 13:45:03 +00:00
|
|
|
|
|
|
|
searchListener = new SearchView.OnQueryTextListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextSubmit(String query) {
|
2017-01-06 16:29:53 +00:00
|
|
|
new FilterApps().exec(query);
|
2016-11-11 13:45:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextChange(String newText) {
|
2016-11-20 10:49:09 +00:00
|
|
|
new FilterApps().exec(newText);
|
2016-11-11 13:45:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
return mView;
|
2016-10-22 16:05:34 +00:00
|
|
|
}
|
|
|
|
|
2016-11-11 13:45:03 +00:00
|
|
|
@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);
|
|
|
|
}
|
|
|
|
|
2016-10-22 16:05:34 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2016-11-11 13:45:03 +00:00
|
|
|
setHasOptionsMenu(true);
|
2016-11-07 13:06:18 +00:00
|
|
|
mView = this.getView();
|
2016-12-24 19:05:22 +00:00
|
|
|
getActivity().setTitle(R.string.magiskhide);
|
2017-01-06 16:29:53 +00:00
|
|
|
CallbackHandler.register(packageLoadDone, this);
|
|
|
|
if (packageLoadDone.isTriggered) {
|
|
|
|
onTrigger(packageLoadDone);
|
|
|
|
}
|
2016-10-22 16:05:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 16:29:53 +00:00
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
CallbackHandler.unRegister(packageLoadDone, this);
|
|
|
|
}
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2017-01-06 16:29:53 +00:00
|
|
|
@Override
|
|
|
|
public void onTrigger(CallbackHandler.Event event) {
|
|
|
|
Logger.dev("MagiskHideFragment: UI refresh");
|
|
|
|
updateUI();
|
2016-11-07 13:06:18 +00:00
|
|
|
}
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2016-11-20 10:49:09 +00:00
|
|
|
private class FilterApps extends Async.NormalTask<String, Void, Void> {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(String... strings) {
|
|
|
|
String newText = strings[0];
|
|
|
|
fListApps.clear();
|
|
|
|
for (ApplicationInfo info : listApps) {
|
|
|
|
if (info.loadLabel(packageManager).toString().toLowerCase().contains(newText.toLowerCase())
|
|
|
|
|| info.packageName.toLowerCase().contains(newText.toLowerCase())) {
|
|
|
|
fListApps.add(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void v) {
|
|
|
|
appAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
private void updateUI() {
|
2016-11-11 13:45:03 +00:00
|
|
|
appAdapter.notifyDataSetChanged();
|
2016-11-07 13:06:18 +00:00
|
|
|
recyclerView.setVisibility(View.VISIBLE);
|
|
|
|
mSwipeRefreshLayout.setRefreshing(false);
|
2016-10-22 16:05:34 +00:00
|
|
|
}
|
2016-11-07 13:06:18 +00:00
|
|
|
|
2016-10-22 16:05:34 +00:00
|
|
|
}
|