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

Commit ce555ef9 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Format NotificationSectionsManager.kt

Flag: EXEMPT just ktfmt
Test: presubmit
Change-Id: I109a8c0d3da834a3c11110f5d9f61bee5a30f398
parent 7fda7b66
Loading
Loading
Loading
Loading
+63 −56
Original line number Diff line number Diff line
@@ -40,7 +40,9 @@ import javax.inject.Inject
 *
 * TODO: Move remaining sections logic from NSSL into this class.
 */
class NotificationSectionsManager @Inject internal constructor(
class NotificationSectionsManager
@Inject
internal constructor(
    private val configurationController: ConfigurationController,
    private val keyguardMediaController: KeyguardMediaController,
    private val sectionsFeatureManager: NotificationSectionsFeatureManager,
@@ -52,7 +54,8 @@ class NotificationSectionsManager @Inject internal constructor(
    @SilentHeader private val silentHeaderController: SectionHeaderController
) : SectionProvider {

    private val configurationListener = object : ConfigurationController.ConfigurationListener {
    private val configurationListener =
        object : ConfigurationController.ConfigurationListener {
            override fun onLocaleListChanged() {
                reinflateViews()
            }
@@ -91,13 +94,12 @@ class NotificationSectionsManager @Inject internal constructor(
    }

    fun createSectionsForBuckets(): Array<NotificationSection> =
            sectionsFeatureManager.getNotificationBuckets()
        sectionsFeatureManager
            .getNotificationBuckets()
            .map { NotificationSection(parent, it) }
            .toTypedArray()

    /**
     * Reinflates the entire notification header, including all decoration views.
     */
    /** Reinflates the entire notification header, including all decoration views. */
    fun reinflateViews() {
        silentHeaderController.reinflateView(parent)
        alertingHeaderController.reinflateView(parent)
@@ -115,7 +117,8 @@ class NotificationSectionsManager @Inject internal constructor(
            view === incomingHeaderView ||
            getBucket(view) != getBucket(previous)

    private fun getBucket(view: View?): Int? = when {
    private fun getBucket(view: View?): Int? =
        when {
            view === silentHeaderView -> BUCKET_SILENT
            view === incomingHeaderView -> BUCKET_HEADS_UP
            view === mediaControlsView -> BUCKET_MEDIA_CONTROLS
@@ -127,21 +130,20 @@ class NotificationSectionsManager @Inject internal constructor(

    private sealed class SectionBounds {

        data class Many(
            val first: ExpandableView,
            val last: ExpandableView
        ) : SectionBounds()
        data class Many(val first: ExpandableView, val last: ExpandableView) : SectionBounds()

        data class One(val lone: ExpandableView) : SectionBounds()
        object None : SectionBounds()

        fun addNotif(notif: ExpandableView): SectionBounds = when (this) {
        fun addNotif(notif: ExpandableView): SectionBounds =
            when (this) {
                is None -> One(notif)
                is One -> Many(lone, notif)
                is Many -> copy(last = notif)
            }

        fun updateSection(section: NotificationSection): Boolean = when (this) {
        fun updateSection(section: NotificationSection): Boolean =
            when (this) {
                is None -> section.setFirstAndLastVisibleChildren(null, null)
                is One -> section.setFirstAndLastVisibleChildren(lone, lone)
                is Many -> section.setFirstAndLastVisibleChildren(first, last)
@@ -167,7 +169,9 @@ class NotificationSectionsManager @Inject internal constructor(
        children: List<ExpandableView>
    ): Boolean {
        // Create mapping of bucket to section
        val sectionBounds = children.asSequence()
        val sectionBounds =
            children
                .asSequence()
                // Group children by bucket
                .groupingBy {
                    getBucket(it)
@@ -185,7 +189,8 @@ class NotificationSectionsManager @Inject internal constructor(
        val oldLastChildren = sections.mapNotNull { it.lastVisibleChild }.toSet().toMutableSet()

        // Update each section with the associated boundary, tracking if there was a change
        val changed = sections.fold(false) { changed, section ->
        val changed =
            sections.fold(false) { changed, section ->
                val bounds = sectionBounds[section.bucket] ?: SectionBounds.None
                val isSectionChanged = bounds.updateSection(section)
                isSectionChanged || changed
@@ -229,12 +234,14 @@ class NotificationSectionsManager @Inject internal constructor(
    private fun logSections(sections: Array<NotificationSection>) {
        for (i in sections.indices) {
            val s = sections[i]
            val fs = when (val first = s.firstVisibleChild) {
            val fs =
                when (val first = s.firstVisibleChild) {
                    null -> "(null)"
                    is ExpandableNotificationRow -> first.entry.key
                    else -> Integer.toHexString(System.identityHashCode(first))
                }
            val ls = when (val last = s.lastVisibleChild) {
            val ls =
                when (val last = s.lastVisibleChild) {
                    null -> "(null)"
                    is ExpandableNotificationRow -> last.entry.key
                    else -> Integer.toHexString(System.identityHashCode(last))