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

Commit e72ac948 authored by Ned Burns's avatar Ned Burns Committed by Android (Google) Code Review
Browse files

Merge "Revamp view manager logic to support any kind of view"

parents 3bec8f1a 2b699058
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -307,7 +307,7 @@ public class PreparationCoordinator implements Coordinator {
    private void onInflationFinished(NotificationEntry entry) {
        mLogger.logNotifInflated(entry.getKey());
        mInflatingNotifs.remove(entry);
        mViewBarn.registerViewForEntry(entry, entry.getRow());
        mViewBarn.registerViewForEntry(entry, entry.getRowController());
        mInflationStates.put(entry, STATE_INFLATED);
        mNotifInflatingFilter.invalidateList();
    }
+1 −0
Original line number Diff line number Diff line
@@ -136,6 +136,7 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
                                        .expandableNotificationRow(row)
                                        .notificationEntry(entry)
                                        .onExpandClickListener(mPresenter)
                                        .listContainer(mListContainer)
                                        .build();
                        ExpandableNotificationRowController rowController =
                                component.getExpandableNotificationRowController();
+5 −7
Original line number Diff line number Diff line
@@ -29,8 +29,7 @@ import com.android.systemui.statusbar.notification.collection.ShadeListBuilder;
import com.android.systemui.statusbar.notification.collection.coalescer.GroupCoalescer;
import com.android.systemui.statusbar.notification.collection.coordinator.NotifCoordinators;
import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinderImpl;
import com.android.systemui.statusbar.notification.collection.render.NotifViewManager;
import com.android.systemui.statusbar.notification.collection.render.NotifViewManagerBuilder;
import com.android.systemui.statusbar.notification.collection.render.ShadeViewManagerFactory;
import com.android.systemui.statusbar.notification.stack.NotificationListContainer;

import java.io.FileDescriptor;
@@ -51,7 +50,7 @@ public class NotifPipelineInitializer implements Dumpable {
    private final NotifCoordinators mNotifPluggableCoordinators;
    private final NotifInflaterImpl mNotifInflater;
    private final DumpManager mDumpManager;
    private final NotifViewManagerBuilder mNotifViewManagerBuilder;
    private final ShadeViewManagerFactory mShadeViewManagerFactory;
    private final FeatureFlags mFeatureFlags;


@@ -64,7 +63,7 @@ public class NotifPipelineInitializer implements Dumpable {
            NotifCoordinators notifCoordinators,
            NotifInflaterImpl notifInflater,
            DumpManager dumpManager,
            NotifViewManagerBuilder notifViewManagerBuilder,
            ShadeViewManagerFactory shadeViewManagerFactory,
            FeatureFlags featureFlags) {
        mPipelineWrapper = pipelineWrapper;
        mGroupCoalescer = groupCoalescer;
@@ -73,8 +72,8 @@ public class NotifPipelineInitializer implements Dumpable {
        mNotifPluggableCoordinators = notifCoordinators;
        mDumpManager = dumpManager;
        mNotifInflater = notifInflater;
        mShadeViewManagerFactory = shadeViewManagerFactory;
        mFeatureFlags = featureFlags;
        mNotifViewManagerBuilder = notifViewManagerBuilder;
    }

    /** Hooks the new pipeline up to NotificationManager */
@@ -95,8 +94,7 @@ public class NotifPipelineInitializer implements Dumpable {

        // Wire up pipeline
        if (mFeatureFlags.isNewNotifPipelineRenderingEnabled()) {
            NotifViewManager notifViewManager = mNotifViewManagerBuilder.build(listContainer);
            notifViewManager.attach(mListBuilder);
            mShadeViewManagerFactory.create(listContainer).attach(mListBuilder);
        }
        mListBuilder.attach(mNotifCollection);
        mNotifCollection.attach(mGroupCoalescer);
+90 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.collection.render

import android.view.View
import java.lang.RuntimeException
import java.lang.StringBuilder

/**
 * A controller that represents a single unit of addable/removable view(s) in the notification
 * shade. Some nodes are just a single view (such as a header), while some might involve many views
 * (such as a notification row).
 *
 * It's possible for nodes to support having child nodes (for example, some notification rows
 * contain other notification rows). If so, they must implement all of the child-related methods
 * below.
 */
interface NodeController {
    /** A string that uniquely(ish) represents the node in the tree. Used for debugging. */
    val nodeLabel: String

    val view: View

    fun getChildAt(index: Int): View? {
        throw RuntimeException("Not supported")
    }

    fun getChildCount(): Int {
        throw RuntimeException("Not supported")
    }

    fun addChildAt(child: NodeController, index: Int) {
        throw RuntimeException("Not supported")
    }

    fun moveChildTo(child: NodeController, index: Int) {
        throw RuntimeException("Not supported")
    }

    fun removeChild(child: NodeController, isTransfer: Boolean) {
        throw RuntimeException("Not supported")
    }
}

/**
 * Used to specify the tree of [NodeController]s that currently make up the shade.
 */
interface NodeSpec {
    val parent: NodeSpec?
    val controller: NodeController
    val children: List<NodeSpec>
}

class NodeSpecImpl(
    override val parent: NodeSpec?,
    override val controller: NodeController
) : NodeSpec {
    override val children = mutableListOf<NodeSpec>()
}

/**
 * Converts a tree spec to human-readable string, for dumping purposes.
 */
fun treeSpecToStr(tree: NodeSpec): String {
    return StringBuilder().also { treeSpecToStrHelper(tree, it, "") }.toString()
}

private fun treeSpecToStrHelper(tree: NodeSpec, sb: StringBuilder, indent: String) {
    sb.append("${indent}ns{${tree.controller.nodeLabel}")
    if (tree.children.isNotEmpty()) {
        val childIndent = "$indent  "
        for (child in tree.children) {
            treeSpecToStrHelper(child, sb, childIndent)
        }
    }
}
+7 −6
Original line number Diff line number Diff line
@@ -18,18 +18,19 @@ package com.android.systemui.statusbar.notification.collection.render

import android.view.textclassifier.Log
import com.android.systemui.statusbar.notification.collection.ListEntry
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRowController
import javax.inject.Inject
import javax.inject.Singleton

/**
 * The ViewBarn is just a map from [ListEntry] to an instance of an [ExpandableNotificationRow].
 * The ViewBarn is just a map from [ListEntry] to an instance of an
 * [ExpandableNotificationRowController].
 */
@Singleton
class NotifViewBarn @Inject constructor() {
    private val rowMap = mutableMapOf<String, ExpandableNotificationRow>()
    private val rowMap = mutableMapOf<String, ExpandableNotificationRowController>()

    fun requireView(forEntry: ListEntry): ExpandableNotificationRow {
    fun requireView(forEntry: ListEntry): ExpandableNotificationRowController {
        if (DEBUG) {
            Log.d(TAG, "requireView: $forEntry.key")
        }
@@ -41,11 +42,11 @@ class NotifViewBarn @Inject constructor() {
        return li
    }

    fun registerViewForEntry(entry: ListEntry, view: ExpandableNotificationRow) {
    fun registerViewForEntry(entry: ListEntry, controller: ExpandableNotificationRowController) {
        if (DEBUG) {
            Log.d(TAG, "registerViewForEntry: $entry.key")
        }
        rowMap[entry.key] = view
        rowMap[entry.key] = controller
    }

    fun removeViewForEntry(entry: ListEntry) {
Loading