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

Commit 19056c22 authored by Stanley Wang's avatar Stanley Wang
Browse files

Fix the problem that the "Turn off SIM" dialog will be displayed

when the MobileNetwork page is slid to to top.

- Update the onBindViewHolder method of
  SettingsMainSwitchPreference. The root cause is that the
  onBindViewHolder method reset the visibility state of the
  SwitchBar.

Fix: 190652161
Test: robotest and test MobileNetwork page manually.
Change-Id: If0a75579fd4bf0fe987ce5d11d2f11d10f4bc43c
parent 052ae787
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -82,15 +82,15 @@ public class SettingsMainSwitchPreference extends TwoStatePreference implements
        holder.setDividerAllowedAbove(false);
        holder.setDividerAllowedBelow(false);

        mMainSwitchBar = (SettingsMainSwitchBar) holder.findViewById(R.id.main_switch_bar);
        mMainSwitchBar.show();
        if (mRestrictedHelper != null) {
            mEnforcedAdmin = mRestrictedHelper.checkRestrictionEnforced();
        }
        mMainSwitchBar = (SettingsMainSwitchBar) holder.findViewById(R.id.main_switch_bar);
        if (mIsVisible) {
            mMainSwitchBar.show();
            updateStatus(isChecked());
            registerListenerToSwitchBar();

        if (!mIsVisible) {
        } else {
            mMainSwitchBar.hide();
        }
    }
+26 −0
Original line number Diff line number Diff line
@@ -24,6 +24,10 @@ import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import androidx.preference.PreferenceViewHolder;

import com.android.settings.R;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -39,6 +43,7 @@ public class SettingsMainSwitchPreferenceTest {
    @Mock
    private EnforcedAdmin mEnforcedAdmin;
    private SettingsMainSwitchPreference mPreference;
    private PreferenceViewHolder mHolder;

    @Before
    public void setUp() {
@@ -48,6 +53,9 @@ public class SettingsMainSwitchPreferenceTest {
        mPreference = new SettingsMainSwitchPreference(context);
        ReflectionHelpers.setField(mPreference, "mEnforcedAdmin", mEnforcedAdmin);
        ReflectionHelpers.setField(mPreference, "mMainSwitchBar", switchBar);
        final View rootView = View.inflate(context, R.layout.preference_widget_main_switch,
                null /* parent */);
        mHolder = PreferenceViewHolder.createInstanceForTests(rootView);
    }

    @Test
@@ -60,4 +68,22 @@ public class SettingsMainSwitchPreferenceTest {

        assertThat(restrictedIcon.getVisibility() == View.VISIBLE).isTrue();
    }

    @Test
    public void show_preferenceShouldDisplay() {
        mPreference.show();

        mPreference.onBindViewHolder(mHolder);

        assertThat(mPreference.isShowing()).isTrue();
    }

    @Test
    public void hide_preferenceShouldNotDisplay() {
        mPreference.hide();

        mPreference.onBindViewHolder(mHolder);

        assertThat(mPreference.isShowing()).isFalse();
    }
}