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

Commit d37dcf85 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Changed management to just show all controls" into rvc-dev

parents 31c94a2f 1e3178de
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -70,12 +70,14 @@
            android:layout_height="match_parent"
            android:padding="4dp">

            <TextView
            <Button
                android:id="@+id/other_apps"
                android:visibility="gone"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center_vertical"
                android:text="See other apps"
                android:textAppearance="@style/TextAppearance.Control.Title"
                android:textColor="?android:attr/colorPrimary"
                style="@*android:style/Widget.DeviceDefault.Button.Borderless.Colored"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"/>
@@ -85,6 +87,7 @@
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="Done"
                style="@*android:style/Widget.DeviceDefault.Button.Colored"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"/>
+4 −75
Original line number Diff line number Diff line
@@ -14,87 +14,19 @@
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<androidx.constraintlayout.widget.ConstraintLayout
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/error_message"
        android:id="@+id/status_message"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/controls_management_list_margin"
        android:text="@string/controls_favorite_load_error"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:visibility="gone"
        android:gravity="center_horizontal"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="parent"
        app:layout_constraintBottom_toTopOf="@id/text_favorites"
    />

    <TextView
        android:id="@+id/text_favorites"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/controls_management_list_margin"
        android:text="@string/controls_favorite_header_favorites"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textAllCaps="true"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toTopOf="@id/divider1"
        app:layout_constraintTop_toBottomOf="@id/error_message"
        />

    <View
        android:id="@+id/divider1"
        android:layout_width="match_parent"
        android:layout_height="@dimen/controls_app_divider_height"
        android:layout_gravity="center_horizontal|top"
        android:background="?android:attr/listDivider"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@id/listFavorites"
        app:layout_constraintTop_toBottomOf="@id/text_favorites"
        />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/listFavorites"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="@dimen/controls_management_list_margin"
        android:nestedScrollingEnabled="false"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@id/text_all"
        app:layout_constraintTop_toBottomOf="@id/divider1"/>

    <TextView
        android:id="@+id/text_all"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/controls_management_list_margin"
        android:text="@string/controls_favorite_header_all"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textAllCaps="true"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toTopOf="@id/divider2"
        app:layout_constraintTop_toBottomOf="@id/listFavorites"
        />

    <View
        android:id="@+id/divider2"
        android:layout_width="match_parent"
        android:layout_height="@dimen/controls_app_divider_height"
        android:layout_gravity="center_horizontal|top"
        android:background="?android:attr/listDivider"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@id/listAll"
        app:layout_constraintTop_toBottomOf="@id/text_all"
    />

    <androidx.recyclerview.widget.RecyclerView
@@ -102,9 +34,6 @@
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="@dimen/controls_management_list_margin"
        android:nestedScrollingEnabled="false"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/divider2"/>
        android:nestedScrollingEnabled="false"/>

</androidx.constraintlayout.widget.ConstraintLayout>
 No newline at end of file
</LinearLayout>
 No newline at end of file
+7 −3
Original line number Diff line number Diff line
@@ -2614,8 +2614,8 @@
    <string name="controls_providers_subtitle">Choose an app from which to add controls</string>
    <!-- Number of favorites for controls management screen [CHAR LIMIT=NONE]-->
    <plurals name="controls_number_of_favorites">
        <item quantity="one"><xliff:g id="number" example="1">%s</xliff:g> current favorite.</item>
        <item quantity="other"><xliff:g id="number" example="3">%s</xliff:g> current favorites.</item>
        <item quantity="one"><xliff:g id="number" example="1">%s</xliff:g> control added.</item>
        <item quantity="other"><xliff:g id="number" example="3">%s</xliff:g> controls added.</item>
    </plurals>

    <!-- Controls management controls screen default title [CHAR LIMIT=30] -->
@@ -2626,6 +2626,10 @@
    <string name="controls_favorite_header_favorites">Favorites</string>
    <!-- Controls management controls screen all header [CHAR LIMIT=50] -->
    <string name="controls_favorite_header_all">All</string>
    <!-- Controls management controls screen error on load message [CHAR LIMIT=50] -->
    <!-- Controls management controls screen error on load message [CHAR LIMIT=60] -->
    <string name="controls_favorite_load_error">The list of all controls could not be loaded.</string>
    <!-- Controls management controls screen header for Other zone [CHAR LIMIT=60] -->
    <string name="controls_favorite_other_zone_header">Other</string>


</resources>
+114 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.controls.management

import android.text.TextUtils
import android.util.ArrayMap
import com.android.systemui.controls.ControlStatus
import com.android.systemui.controls.controller.ControlInfo

/**
 * This model is used to show all controls separated by zones.
 *
 * The model will sort the controls and zones in the following manner:
 *  * The zones will be sorted in a first seen basis
 *  * The controls in each zone will be sorted in a first seen basis.
 *
 * @property controls List of all controls as returned by loading
 * @property initialFavoriteIds sorted ids of favorite controls
 * @property noZoneString text to use as header for all controls that have blank or `null` zone.
 */
class AllModel(
    private val controls: List<ControlStatus>,
    initialFavoriteIds: List<String>,
    private val emptyZoneString: CharSequence
) : ControlsModel {

    override val favorites: List<ControlInfo.Builder>
        get() = favoriteIds.mapNotNull { id ->
            val control = controls.firstOrNull { it.control.controlId == id }?.control
            control?.let {
                ControlInfo.Builder().apply {
                    controlId = it.controlId
                    controlTitle = it.title
                    deviceType = it.deviceType
                }
            }
        }

    private val favoriteIds = initialFavoriteIds.toMutableList()

    override val elements: List<ElementWrapper> = createWrappers(controls)

    override fun changeFavoriteStatus(controlId: String, favorite: Boolean) {
        if (favorite) {
            favoriteIds.add(controlId)
        } else {
            favoriteIds.remove(controlId)
        }
    }

    private fun createWrappers(list: List<ControlStatus>): List<ElementWrapper> {
        val map = list.groupByTo(OrderedMap(ArrayMap<CharSequence, MutableList<ControlStatus>>())) {
            it.control.zone ?: ""
        }
        val output = mutableListOf<ElementWrapper>()
        var emptyZoneValues: Sequence<ControlWrapper>? = null
        for (zoneName in map.orderedKeys) {
            val values = map.getValue(zoneName).asSequence().map { ControlWrapper(it) }
            if (TextUtils.isEmpty(zoneName)) {
                emptyZoneValues = values
            } else {
                output.add(ZoneNameWrapper(zoneName))
                output.addAll(values)
            }
        }
        // Add controls with empty zone at the end
        if (emptyZoneValues != null) {
            if (map.size != 1) {
                output.add(ZoneNameWrapper(emptyZoneString))
            }
            output.addAll(emptyZoneValues)
        }
        return output
    }

    private class OrderedMap<K, V>(private val map: MutableMap<K, V>) : MutableMap<K, V> by map {

        val orderedKeys = mutableListOf<K>()

        override fun put(key: K, value: V): V? {
            if (key !in map) {
                orderedKeys.add(key)
            }
            return map.put(key, value)
        }

        override fun clear() {
            orderedKeys.clear()
            map.clear()
        }

        override fun remove(key: K): V? {
            val removed = map.remove(key)
            if (removed != null) {
                orderedKeys.remove(key)
            }
            return removed
        }
    }
}
 No newline at end of file
+5 −1
Original line number Diff line number Diff line
@@ -116,6 +116,10 @@ class FavoritesRenderer(

    fun renderFavoritesForComponent(component: ComponentName): String {
        val qty = favoriteFunction(component)
        if (qty != 0) {
            return resources.getQuantityString(R.plurals.controls_number_of_favorites, qty, qty)
        } else {
            return ""
        }
    }
}
 No newline at end of file
Loading