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

Commit be7ebc9c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Convert from Pair<Integer,Integer> to FeedbackIcon"

parents 60e51c5c 68c51fe5
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -573,8 +573,7 @@ public class NotificationViewHierarchyManager implements DynamicPrivacyControlle
                    stack.push(notificationChildren.get(i));
                }
            }
            row.showFeedbackIcon(mAssistantFeedbackController.showFeedbackIndicator(entry),
                    mAssistantFeedbackController.getFeedbackResources(entry));
            row.setFeedbackIcon(mAssistantFeedbackController.getFeedbackIcon(entry));
            row.setLastAudiblyAlertedMs(entry.getLastAudiblyAlertedMs());
        }

+18 −29
Original line number Diff line number Diff line
@@ -24,7 +24,9 @@ import android.app.NotificationManager;
import android.content.Context;
import android.os.Handler;
import android.provider.DeviceConfig;
import android.util.Pair;
import android.util.SparseArray;

import androidx.annotation.Nullable;

import com.android.internal.R;
import com.android.systemui.dagger.SysUISingleton;
@@ -52,6 +54,8 @@ public class AssistantFeedbackController {
    public static final int STATUS_PROMOTED = 3;
    public static final int STATUS_DEMOTED = 4;

    private final SparseArray<FeedbackIcon> mIcons;

    private volatile boolean mFeedbackEnabled;

    private final DeviceConfig.OnPropertiesChangedListener mPropertiesChangedListener =
@@ -76,6 +80,16 @@ public class AssistantFeedbackController {
                ENABLE_NAS_FEEDBACK, false);
        mDeviceConfigProxy.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_SYSTEMUI,
                this::postToHandler, mPropertiesChangedListener);
        // Populate the array of statuses.
        mIcons = new SparseArray<>(4);
        mIcons.set(STATUS_ALERTED, new FeedbackIcon(R.drawable.ic_feedback_alerted,
                R.string.notification_feedback_indicator_alerted));
        mIcons.set(STATUS_SILENCED, new FeedbackIcon(R.drawable.ic_feedback_silenced,
                R.string.notification_feedback_indicator_silenced));
        mIcons.set(STATUS_PROMOTED, new FeedbackIcon(R.drawable.ic_feedback_uprank,
                R.string.notification_feedback_indicator_promoted));
        mIcons.set(STATUS_DEMOTED, new FeedbackIcon(R.drawable.ic_feedback_downrank,
                R.string.notification_feedback_indicator_demoted));
    }

    private void postToHandler(Runnable r) {
@@ -119,41 +133,16 @@ public class AssistantFeedbackController {
        }
    }

    /**
     * Determines whether to show feedback indicator. The feedback indicator will be shown
     * if {@link #isFeedbackEnabled()} is enabled and assistant has changed this notification's rank
     * or importance.
     *
     * @param entry Notification Entry to show feedback for
     */
    public boolean showFeedbackIndicator(NotificationEntry entry) {
        return getFeedbackStatus(entry) != STATUS_UNCHANGED;
    }

    /**
     * Get the feedback indicator image and content description resources according to assistant's
     * changes on this notification's rank or importance.
     *
     * @param entry Notification Entry to show feedback for
     */
    public Pair<Integer, Integer> getFeedbackResources(NotificationEntry entry) {
    @Nullable
    public FeedbackIcon getFeedbackIcon(NotificationEntry entry) {
        int feedbackStatus = getFeedbackStatus(entry);
        switch (feedbackStatus) {
            case STATUS_ALERTED:
                return new Pair(R.drawable.ic_feedback_alerted,
                        R.string.notification_feedback_indicator_alerted);
            case STATUS_SILENCED:
                return new Pair(R.drawable.ic_feedback_silenced,
                        R.string.notification_feedback_indicator_silenced);
            case STATUS_PROMOTED:
                return new Pair(R.drawable.ic_feedback_uprank,
                        R.string.notification_feedback_indicator_promoted);
            case STATUS_DEMOTED:
                return new Pair(R.drawable.ic_feedback_downrank,
                        R.string.notification_feedback_indicator_demoted);
            default:
                return new Pair(0, 0);
        }
        return mIcons.get(feedbackStatus);
    }

    /**
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.statusbar.notification

import android.annotation.DrawableRes
import android.annotation.StringRes

/**
 * The feedback icon to show in the header of a notification.
 * The icon consists of a drawable and a content description to set on the ImageView.
 */
data class FeedbackIcon(
    /** The drawable resource */
    @DrawableRes val iconRes: Int,
    /** The content description string resource */
    @StringRes val contentDescRes: Int
)
 No newline at end of file
+1 −4
Original line number Diff line number Diff line
@@ -64,10 +64,7 @@ class RowAppearanceCoordinator @Inject internal constructor(
        // very first notification and if it's not a child of grouped notifications.
        controller.setSystemExpanded(mAlwaysExpandNonGroupedNotification || entry == entryToExpand)
        // Show/hide the feedback icon
        controller.showFeedbackIcon(
            mAssistantFeedbackController.showFeedbackIndicator(entry),
            mAssistantFeedbackController.getFeedbackResources(entry)
        )
        controller.setFeedbackIcon(mAssistantFeedbackController.getFeedbackIcon(entry))
        // Show the "alerted" bell icon
        controller.setLastAudiblyAlertedMs(entry.lastAudiblyAlertedMs)
    }
+3 −6
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package com.android.systemui.statusbar.notification.collection.render

import android.util.Pair
import com.android.systemui.statusbar.notification.FeedbackIcon

/** A view controller for a notification row */
interface NotifRowController {
@@ -34,9 +34,6 @@ interface NotifRowController {
     */
    fun setLastAudiblyAlertedMs(lastAudiblyAlertedMs: Long)

    /**
     * Sets both whether to show a feedback indicator and which resources to use for the drawable
     * and content description.
     */
    fun showFeedbackIcon(showFeedbackIndicator: Boolean, feedbackResources: Pair<Int, Int>?)
    /** Shows the given feedback icon, or hides the icon if null. */
    fun setFeedbackIcon(icon: FeedbackIcon?)
}
Loading