Update policy list when resuming the superuser fragment.

Closes #414
This commit is contained in:
darken 2018-07-28 14:11:24 +02:00 committed by John Wu
parent e0cd224831
commit 5cb3e5937f

View File

@ -22,6 +22,8 @@ import butterknife.Unbinder;
public class SuperuserFragment extends Fragment { public class SuperuserFragment extends Fragment {
private Unbinder unbinder; private Unbinder unbinder;
private PackageManager pm;
private MagiskManager mm;
@BindView(R.id.recyclerView) RecyclerView recyclerView; @BindView(R.id.recyclerView) RecyclerView recyclerView;
@BindView(R.id.empty_rv) TextView emptyRv; @BindView(R.id.empty_rv) TextView emptyRv;
@ -31,20 +33,8 @@ public class SuperuserFragment extends Fragment {
View view = inflater.inflate(R.layout.fragment_superuser, container, false); View view = inflater.inflate(R.layout.fragment_superuser, container, false);
unbinder = ButterKnife.bind(this, view); unbinder = ButterKnife.bind(this, view);
PackageManager pm = getActivity().getPackageManager(); pm = getActivity().getPackageManager();
MagiskManager mm = getApplication(); mm = getApplication();
List<Policy> policyList = mm.mDB.getPolicyList(pm);
if (policyList.size() == 0) {
emptyRv.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
} else {
recyclerView.setAdapter(new PolicyAdapter(policyList, mm.mDB, pm));
emptyRv.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
return view; return view;
} }
@ -54,10 +44,29 @@ public class SuperuserFragment extends Fragment {
getActivity().setTitle(getString(R.string.superuser)); getActivity().setTitle(getString(R.string.superuser));
} }
@Override
public void onResume() {
super.onResume();
displayPolicyList();
}
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
unbinder.unbind(); unbinder.unbind();
} }
private void displayPolicyList() {
List<Policy> policyList = mm.mDB.getPolicyList(pm);
if (policyList.size() == 0) {
emptyRv.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
} else {
recyclerView.setAdapter(new PolicyAdapter(policyList, mm.mDB, pm));
emptyRv.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
}
} }