Search in sources :

Example 1 with AppRuleComparator

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;
}
Also used : LongSparseArray(android.support.v4.util.LongSparseArray) Iptables(org.ethack.orwall.lib.Iptables) View(android.view.View) ListView(android.widget.ListView) AppRuleComparator(org.ethack.orwall.lib.AppRuleComparator) NatRules(org.ethack.orwall.lib.NatRules) ListView(android.widget.ListView) AppRule(org.ethack.orwall.lib.AppRule) AppListAdapter(org.ethack.orwall.adapter.AppListAdapter)

Aggregations

LongSparseArray (android.support.v4.util.LongSparseArray)1 View (android.view.View)1 ListView (android.widget.ListView)1 AppListAdapter (org.ethack.orwall.adapter.AppListAdapter)1 AppRule (org.ethack.orwall.lib.AppRule)1 AppRuleComparator (org.ethack.orwall.lib.AppRuleComparator)1 Iptables (org.ethack.orwall.lib.Iptables)1 NatRules (org.ethack.orwall.lib.NatRules)1