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-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;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
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;
|
2016-10-22 18:04:58 +00:00
|
|
|
import com.topjohnwu.magisk.utils.Shell;
|
2016-10-22 16:05:34 +00:00
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
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
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
public class MagiskHideFragment extends Fragment {
|
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
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
private PackageManager packageManager;
|
|
|
|
private View mView;
|
|
|
|
private ApplicationAdapter appAdapter;
|
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);
|
|
|
|
new LoadApps().exec();
|
|
|
|
});
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
new LoadApps().exec();
|
|
|
|
return mView;
|
2016-10-22 16:05:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2016-11-07 13:06:18 +00:00
|
|
|
mView = this.getView();
|
2016-10-22 16:05:34 +00:00
|
|
|
}
|
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
private class LoadApps extends Async.RootTask<Void, Void, Void> {
|
2016-10-22 16:05:34 +00:00
|
|
|
@Override
|
2016-11-07 13:06:18 +00:00
|
|
|
protected Void doInBackground(Void... voids) {
|
|
|
|
List<ApplicationInfo> listApps = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
|
|
|
|
Collections.sort(listApps, (a, b) -> a.loadLabel(packageManager).toString().toLowerCase()
|
|
|
|
.compareTo(b.loadLabel(packageManager).toString().toLowerCase()));
|
|
|
|
List<String> hideList = Shell.su(Async.MAGISK_HIDE_PATH + "list");
|
|
|
|
appAdapter = new ApplicationAdapter(listApps, hideList);
|
2016-10-22 16:05:34 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-11-07 13:06:18 +00:00
|
|
|
protected void onPostExecute(Void aVoid) {
|
|
|
|
super.onPostExecute(aVoid);
|
|
|
|
updateUI();
|
2016-10-22 16:05:34 +00:00
|
|
|
}
|
2016-11-07 13:06:18 +00:00
|
|
|
}
|
2016-10-22 16:05:34 +00:00
|
|
|
|
2016-11-07 13:06:18 +00:00
|
|
|
private void updateUI() {
|
|
|
|
recyclerView.setAdapter(appAdapter);
|
|
|
|
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
|
|
|
}
|