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

Commit 9d894145 authored by arangelov's avatar arangelov
Browse files

Restore share sheet height when toggling dark mode

This CL does the following changes:
- Save and restore the resolver drawer layout height.
This is necessary because when we toggle darkmode,
we don't go through handleLayoutChange, thus we don't
recalculate the height the standard way.
- Disables saving state for the viewpager.
This is necessary, because the content is
incorrectly restored afterwards. It's better to
reload it instead.
- Saves and restores the last selected tab. This is
necessary because with the viewpager state saving
disabled, it defaults to the first tab.

I considered updating the configChanges attribute in
the manifest to include dark mode toggling, but it
gave unsatisfactory result - the share sheet only
partially became dark.

Test: manual
Test: atest ChooserActivityTest
Test: atest ResolverActivityTest
Fixes: 154526324
Change-Id: I99e159ea7ca413f8acbc0429a43ce5aba32a1b28
parent 4ae27323
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -146,6 +146,7 @@ public class ResolverActivity extends Activity implements

    private static final String TAG = "ResolverActivity";
    private static final boolean DEBUG = false;
    private static final String LAST_SHOWN_TAB_KEY = "last_shown_tab_key";

    private boolean mRegistered;

@@ -843,10 +844,20 @@ public class ResolverActivity extends Activity implements
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        ViewPager viewPager = findViewById(R.id.profile_pager);
        outState.putInt(LAST_SHOWN_TAB_KEY, viewPager.getCurrentItem());
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        resetButtonBar();
        ViewPager viewPager = findViewById(R.id.profile_pager);
        viewPager.setCurrentItem(savedInstanceState.getInt(LAST_SHOWN_TAB_KEY));
        mMultiProfilePagerAdapter.clearInactiveProfileCache();
    }

    private boolean isHttpSchemeAndViewAction(Intent intent) {
@@ -1585,6 +1596,7 @@ public class ResolverActivity extends Activity implements
        TabHost tabHost = findViewById(R.id.profile_tabhost);
        tabHost.setup();
        ViewPager viewPager = findViewById(R.id.profile_pager);
        viewPager.setSaveEnabled(false);
        TabHost.TabSpec tabSpec = tabHost.newTabSpec(TAB_TAG_PERSONAL)
                .setContent(R.id.profile_pager)
                .setIndicator(getString(R.string.resolver_personal_tab));
+5 −0
Original line number Diff line number Diff line
@@ -1084,6 +1084,7 @@ public class ResolverDrawerLayout extends ViewGroup {
    protected Parcelable onSaveInstanceState() {
        final SavedState ss = new SavedState(super.onSaveInstanceState());
        ss.open = mCollapsibleHeight > 0 && mCollapseOffset == 0;
        ss.mCollapsibleHeightReserved = mCollapsibleHeightReserved;
        return ss;
    }

@@ -1092,6 +1093,7 @@ public class ResolverDrawerLayout extends ViewGroup {
        final SavedState ss = (SavedState) state;
        super.onRestoreInstanceState(ss.getSuperState());
        mOpenOnLayout = ss.open;
        mCollapsibleHeightReserved = ss.mCollapsibleHeightReserved;
    }

    public static class LayoutParams extends MarginLayoutParams {
@@ -1142,6 +1144,7 @@ public class ResolverDrawerLayout extends ViewGroup {

    static class SavedState extends BaseSavedState {
        boolean open;
        private int mCollapsibleHeightReserved;

        SavedState(Parcelable superState) {
            super(superState);
@@ -1150,12 +1153,14 @@ public class ResolverDrawerLayout extends ViewGroup {
        private SavedState(Parcel in) {
            super(in);
            open = in.readInt() != 0;
            mCollapsibleHeightReserved = in.readInt();
        }

        @Override
        public void writeToParcel(Parcel out, int flags) {
            super.writeToParcel(out, flags);
            out.writeInt(open ? 1 : 0);
            out.writeInt(mCollapsibleHeightReserved);
        }

        public static final Parcelable.Creator<SavedState> CREATOR =