Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19470ecc authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Fix issue #6595555: deal better with fragmentless headers.

If you constructed a preference activity whose first header
didn't have a fragment, this would crash in two-pane mode
because it would try to use that header as the initially
selected header but not have a fragment to show.

We need to have a fragment for whatever header we switch to,
so the code now looks for the first header with a fragment
as the initial header.

Also added some error checks to throw more descriptive
exceptions on bad headers -- when there is no header at all
with a fragment, if the app tries to manually switch to a
header without a fragment.

Change-Id: Ia84221fcb2fe5755bb674e0606ac2a1fcde4cdc9
parent b41af58f
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -703,7 +703,13 @@ public abstract class PreferenceActivity extends ListActivity implements
     * show for the initial UI.
     */
    public Header onGetInitialHeader() {
        return mHeaders.get(0);
        for (int i=0; i<mHeaders.size(); i++) {
            Header h = mHeaders.get(i);
            if (h.fragment != null) {
                return h;
            }
        }
        throw new IllegalStateException("Must have at least one header with a fragment");
    }

    /**
@@ -1167,6 +1173,9 @@ public abstract class PreferenceActivity extends ListActivity implements
            getFragmentManager().popBackStack(BACK_STACK_PREFS,
                    FragmentManager.POP_BACK_STACK_INCLUSIVE);
        } else {
            if (header.fragment == null) {
                throw new IllegalStateException("can't switch to header that has no fragment");
            }
            int direction = mHeaders.indexOf(header) - mHeaders.indexOf(mCurHeader);
            switchToHeaderInner(header.fragment, header.fragmentArguments, direction);
            setSelectedHeader(header);