Search in sources :

Example 1 with DashBaseFragment

use of net.osmand.plus.dashboard.DashBaseFragment in project Osmand by osmandapp.

the class TransactionBuilder method getFragmentTransaction.

public FragmentTransaction getFragmentTransaction() {
    FragmentTransaction fragmentTransaction = manager.beginTransaction();
    Collections.sort(fragments);
    for (DashFragmentData dashFragmentData : fragments) {
        DashBaseFragment fragment = (DashBaseFragment) manager.findFragmentByTag(dashFragmentData.tag);
        if (fragment == null) {
            if (dashFragmentData.shouldShowFunction.shouldShow(settings, mapActivity, dashFragmentData.tag)) {
                try {
                    DashBaseFragment newInstance = dashFragmentData.fragmentClass.newInstance();
                    // XXX hardcoded value
                    fragmentTransaction.add(R.id.content, newInstance, dashFragmentData.tag);
                } catch (InstantiationException e) {
                    Log.v(TAG, "");
                    mapActivity.getMyApplication().showToastMessage("Error showing dashboard " + dashFragmentData.tag);
                } catch (IllegalAccessException e) {
                    Log.v(TAG, "");
                    mapActivity.getMyApplication().showToastMessage("Error showing dashboard " + dashFragmentData.tag);
                }
            }
        } else {
            if (!dashFragmentData.shouldShowFunction.shouldShow(settings, mapActivity, dashFragmentData.tag)) {
                fragmentTransaction.remove(fragment);
            } else if (fragment.getView() != null) {
                if (fragment.isHidden()) {
                    fragmentTransaction.show(fragment);
                }
                fragment.onOpenDash();
            }
        }
    }
    return fragmentTransaction;
}
Also used : FragmentTransaction(androidx.fragment.app.FragmentTransaction) DashBaseFragment(net.osmand.plus.dashboard.DashBaseFragment)

Aggregations

FragmentTransaction (androidx.fragment.app.FragmentTransaction)1 DashBaseFragment (net.osmand.plus.dashboard.DashBaseFragment)1