use of org.ethack.orwall.lib.AppRuleComparator in project orWall by EthACKdotOrg.
the class AppFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view;
view = inflater.inflate(R.layout.fragment_tabbed_apps, container, false);
Iptables iptables = new Iptables(getActivity());
// Do we have root access ?
if (RootCommands.rootAccessGiven()) {
view.findViewById(R.id.warn_root).setVisibility(View.GONE);
} else {
view.findViewById(R.id.warn_root).setVisibility(View.VISIBLE);
}
// Hopefully there IS iptables on this deviceā¦
if (Iptables.iptablesExists()) {
view.findViewById(R.id.warn_iptables).setVisibility(View.GONE);
} else {
view.findViewById(R.id.warn_iptables).setVisibility(View.VISIBLE);
}
if (Iptables.initSupported() && !iptables.isInitialized()) {
view.findViewById(R.id.warn_init).setVisibility(View.VISIBLE);
}
ListView listView = (ListView) view.findViewById(R.id.id_enabled_apps);
// Toggle hint layer
boolean hide_hint = Preferences.isHidePressHint(getActivity());
if (hide_hint) {
view.findViewById(R.id.hint_press).setVisibility(View.GONE);
} else {
view.findViewById(R.id.id_hide_hint).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((View) view.getParent()).setVisibility(View.GONE);
Preferences.setHidePressHint(getActivity(), true);
}
});
}
// get enabled apps
NatRules natRules = new NatRules(this.getActivity());
List<AppRule> enabledApps = natRules.getAllRules();
LongSparseArray<AppRule> rulesIndex = new LongSparseArray<>();
for (AppRule app : enabledApps) rulesIndex.put(app.getAppUID(), app);
// get disabled apps (filtered with enabled)
List<AppRule> disabledApps = listDisabledApps(rulesIndex);
// Get special, disabled apps
List<AppRule> specialDisabled = listSpecialApps(rulesIndex);
// Merge both disabled apps
disabledApps.addAll(specialDisabled);
// Sort collection using a dedicated method
Collections.sort(enabledApps, new AppRuleComparator(getActivity().getPackageManager()));
Collections.sort(disabledApps, new AppRuleComparator(getActivity().getPackageManager()));
// merge both collections so that enabled apps are above disabled
enabledApps.addAll(disabledApps);
listView.setAdapter(new AppListAdapter(this.getActivity(), enabledApps));
return view;
}
Aggregations