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

Commit 36ac9b3a authored by Michael W's avatar Michael W
Browse files

Tiles: SystemProfiles: Adapt behaviour

* Opening the detail view should enable profiles
* Disabling the switch should also close the details
* The tile's title should just be "System profiles"
  when disabled, we also don't say "Wifi off" on wifi tile
* Set dualTarget to true so the tile indicates expandability

Change-Id: I4eb463bc84ad78fcabb8acef1829c990ab04f19b
parent cc0c2d39
Loading
Loading
Loading
Loading
+1 −2
Original line number Original line Diff line number Diff line
@@ -57,12 +57,11 @@
    <string name="accessibility_quick_settings_sync_changed_on">Sync turned on.</string>
    <string name="accessibility_quick_settings_sync_changed_on">Sync turned on.</string>


    <!-- System Profiles QS tile -->
    <!-- System Profiles QS tile -->
    <string name="quick_settings_profiles_label">System profiles</string>
    <string name="accessibility_quick_settings_profiles_off">Profiles off.</string>
    <string name="accessibility_quick_settings_profiles_off">Profiles off.</string>
    <string name="accessibility_quick_settings_profiles">Profile: <xliff:g id="profile" example="Default">%s</xliff:g>.</string>
    <string name="accessibility_quick_settings_profiles">Profile: <xliff:g id="profile" example="Default">%s</xliff:g>.</string>
    <string name="accessibility_quick_settings_profiles_changed_off">Profiles turned off.</string>
    <string name="accessibility_quick_settings_profiles_changed_off">Profiles turned off.</string>
    <string name="accessibility_quick_settings_profiles_changed">Profile changed to <xliff:g id="profile" example="Default">%s</xliff:g>.</string>
    <string name="accessibility_quick_settings_profiles_changed">Profile changed to <xliff:g id="profile" example="Default">%s</xliff:g>.</string>
    <string name="quick_settings_profiles_off">Profiles off.</string>
    <string name="quick_settings_profiles">System profiles</string>


    <!-- USB tethering QS tile -->
    <!-- USB tethering QS tile -->
    <string name="quick_settings_usb_tether_label">USB tethering</string>
    <string name="quick_settings_usb_tether_label">USB tethering</string>
+39 −33
Original line number Original line Diff line number Diff line
@@ -83,7 +83,7 @@ public class ProfilesTile extends QSTileImpl<State> {


    @Override
    @Override
    public CharSequence getTileLabel() {
    public CharSequence getTileLabel() {
        return mContext.getString(R.string.quick_settings_profiles);
        return mContext.getString(R.string.quick_settings_profiles_label);
    }
    }


    @Override
    @Override
@@ -93,11 +93,19 @@ public class ProfilesTile extends QSTileImpl<State> {


    @Override
    @Override
    protected void handleClick() {
    protected void handleClick() {
        setProfilesEnabled(!profilesEnabled());
    }

    @Override
    protected void handleSecondaryClick() {
        if (mKeyguardMonitor.isSecure() && mKeyguardMonitor.isShowing()) {
        if (mKeyguardMonitor.isSecure() && mKeyguardMonitor.isShowing()) {
            mActivityStarter.postQSRunnableDismissingKeyguard(() ->
            mActivityStarter.postQSRunnableDismissingKeyguard(() -> {
                showDetail(true));
                setProfilesEnabled(true);
                showDetail(true);
            });
            return;
            return;
        }
        }
        setProfilesEnabled(true);
        showDetail(true);
        showDetail(true);
    }
    }


@@ -115,10 +123,11 @@ public class ProfilesTile extends QSTileImpl<State> {
                    R.string.accessibility_quick_settings_profiles, state.label);
                    R.string.accessibility_quick_settings_profiles, state.label);
        } else {
        } else {
            state.icon = ResourceIcon.get(R.drawable.ic_qs_profiles_off);
            state.icon = ResourceIcon.get(R.drawable.ic_qs_profiles_off);
            state.label = mContext.getString(R.string.quick_settings_profiles_off);
            state.label = mContext.getString(R.string.quick_settings_profiles_label);
            state.contentDescription = mContext.getString(
            state.contentDescription = mContext.getString(
                    R.string.accessibility_quick_settings_profiles_off);
                    R.string.accessibility_quick_settings_profiles_off);
        }
        }
        state.dualTarget = true;
    }
    }


    @Override
    @Override
@@ -131,6 +140,11 @@ public class ProfilesTile extends QSTileImpl<State> {
        }
        }
    }
    }


    private void setProfilesEnabled(Boolean enabled) {
        LineageSettings.System.putInt(mContext.getContentResolver(),
                LineageSettings.System.SYSTEM_PROFILES_ENABLED, enabled ? 1 : 0);
    }

    private boolean profilesEnabled() {
    private boolean profilesEnabled() {
        return LineageSettings.System.getInt(mContext.getContentResolver(),
        return LineageSettings.System.getInt(mContext.getContentResolver(),
                LineageSettings.System.SYSTEM_PROFILES_ENABLED, 1) == 1;
                LineageSettings.System.SYSTEM_PROFILES_ENABLED, 1) == 1;
@@ -184,8 +198,9 @@ public class ProfilesTile extends QSTileImpl<State> {


        @Override
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            CheckedTextView label = convertView != null
            CheckedTextView label = (CheckedTextView) inflater.inflate(
                    ? (CheckedTextView) convertView
                    : (CheckedTextView) LayoutInflater.from(mContext).inflate(
                            android.R.layout.simple_list_item_single_choice, parent, false);
                            android.R.layout.simple_list_item_single_choice, parent, false);


            Profile p = getItem(position);
            Profile p = getItem(position);
@@ -211,13 +226,12 @@ public class ProfilesTile extends QSTileImpl<State> {


        @Override
        @Override
        public CharSequence getTitle() {
        public CharSequence getTitle() {
            return mContext.getString(R.string.quick_settings_profiles);
            return mContext.getString(R.string.quick_settings_profiles_label);
        }
        }


        @Override
        @Override
        public Boolean getToggleState() {
        public Boolean getToggleState() {
            boolean enabled = profilesEnabled();
            return profilesEnabled();
            return enabled;
        }
        }


        @Override
        @Override
@@ -235,17 +249,13 @@ public class ProfilesTile extends QSTileImpl<State> {
            list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
            list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
            list.setOnItemClickListener(this);
            list.setOnItemClickListener(this);


            mDetails.setEmptyState(R.drawable.ic_qs_profiles_off,
            buildProfilesList();
                    R.string.quick_settings_profiles_off);

            rebuildProfilesList(profilesEnabled());


            return mDetails;
            return mDetails;
        }
        }


        private void rebuildProfilesList(boolean populate) {
        private void buildProfilesList() {
            mProfilesList.clear();
            mProfilesList.clear();
            if (populate) {
            int selected = -1;
            int selected = -1;


            final Profile[] profiles = mProfileManager.getProfiles();
            final Profile[] profiles = mProfileManager.getProfiles();
@@ -259,7 +269,6 @@ public class ProfilesTile extends QSTileImpl<State> {
                }
                }
            }
            }
            mDetails.getListView().setItemChecked(selected, true);
            mDetails.getListView().setItemChecked(selected, true);
            }
            mAdapter.notifyDataSetChanged();
            mAdapter.notifyDataSetChanged();
        }
        }


@@ -270,11 +279,8 @@ public class ProfilesTile extends QSTileImpl<State> {


        @Override
        @Override
        public void setToggleState(boolean state) {
        public void setToggleState(boolean state) {
            LineageSettings.System.putInt(mContext.getContentResolver(),
            setProfilesEnabled(state);
                    LineageSettings.System.SYSTEM_PROFILES_ENABLED, state ? 1 : 0);
            showDetail(false);

            fireToggleStateChanged(state);
            rebuildProfilesList(state);
        }
        }


        @Override
        @Override