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

Commit 3a05ab65 authored by Aaron Liu's avatar Aaron Liu
Browse files

[User Switcher] Change layout of menu.

Change the layout of the menu in the fullscreen user switcher such that
manage users is in its own partiion. Also add some dividers between the
items.

Fixes: 253609111
Test: I tested by going to the fullscreen user switcher menu on a large
screen device. I have changed the orientation of the activity from
portrait to landscape with the menu open. I have open and closed the
menu repeatedly. I have clicked on all of the options of the menu as
well.

Change-Id: Ib6e74197f4bd6a28f1ae6371189c805ec5fcbf6f
parent 3e2ed2a8
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2022 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
  -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <size android:height="@dimen/bouncer_user_switcher_popup_items_divider_height"/>
    <solid android:color="@color/user_switcher_fullscreen_bg"/>
</shape>
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@
    <dimen name="bouncer_user_switcher_width">248dp</dimen>
    <dimen name="bouncer_user_switcher_popup_header_height">12dp</dimen>
    <dimen name="bouncer_user_switcher_popup_divider_height">4dp</dimen>
    <dimen name="bouncer_user_switcher_popup_items_divider_height">2dp</dimen>
    <dimen name="bouncer_user_switcher_item_padding_vertical">10dp</dimen>
    <dimen name="bouncer_user_switcher_item_padding_horizontal">12dp</dimen>
    <dimen name="bouncer_user_switcher_header_padding_end">44dp</dimen>
+1 −3
Original line number Diff line number Diff line
@@ -36,9 +36,7 @@ class UserSwitcherPopupMenu(
    private var adapter: ListAdapter? = null

    init {
        setBackgroundDrawable(
            res.getDrawable(R.drawable.bouncer_user_switcher_popup_bg, context.getTheme())
        )
        setBackgroundDrawable(null)
        setModal(false)
        setOverlapAnchor(true)
    }
+51 −23
Original line number Diff line number Diff line
@@ -18,12 +18,15 @@
package com.android.systemui.user.ui.binder

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.LinearLayout.SHOW_DIVIDER_MIDDLE
import android.widget.TextView
import androidx.constraintlayout.helper.widget.Flow as FlowWidget
import androidx.core.view.isVisible
@@ -36,6 +39,7 @@ import com.android.systemui.R
import com.android.systemui.classifier.FalsingCollector
import com.android.systemui.user.UserSwitcherPopupMenu
import com.android.systemui.user.UserSwitcherRootView
import com.android.systemui.user.shared.model.UserActionModel
import com.android.systemui.user.ui.viewmodel.UserActionViewModel
import com.android.systemui.user.ui.viewmodel.UserSwitcherViewModel
import com.android.systemui.util.children
@@ -168,15 +172,10 @@ object UserSwitcherViewBinder {
        onDismissed: () -> Unit,
    ): UserSwitcherPopupMenu {
        return UserSwitcherPopupMenu(context).apply {
            this.setDropDownGravity(Gravity.END)
            this.anchorView = anchorView
            setAdapter(adapter)
            setOnDismissListener { onDismissed() }
            setOnItemClickListener { _, _, position, _ ->
                val itemPositionExcludingHeader = position - 1
                adapter.getItem(itemPositionExcludingHeader).onClicked()
                dismiss()
            }

            show()
        }
    }
@@ -186,38 +185,67 @@ object UserSwitcherViewBinder {
        private val layoutInflater: LayoutInflater,
    ) : BaseAdapter() {

        private val items = mutableListOf<UserActionViewModel>()
        private var sections = listOf<List<UserActionViewModel>>()

        override fun getCount(): Int {
            return items.size
            return sections.size
        }

        override fun getItem(position: Int): UserActionViewModel {
            return items[position]
        override fun getItem(position: Int): List<UserActionViewModel> {
            return sections[position]
        }

        override fun getItemId(position: Int): Long {
            return getItem(position).viewKey
            return position.toLong()
        }

        override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
            val section = getItem(position)
            val context = parent.context
            val sectionView =
                convertView as? LinearLayout
                    ?: LinearLayout(context, null).apply {
                        this.orientation = LinearLayout.VERTICAL
                        this.background =
                            parent.resources.getDrawable(
                                R.drawable.bouncer_user_switcher_popup_bg,
                                context.theme
                            )
                        this.showDividers = SHOW_DIVIDER_MIDDLE
                        this.dividerDrawable =
                            context.getDrawable(
                                R.drawable.fullscreen_userswitcher_menu_item_divider
                            )
                    }
            sectionView.removeAllViewsInLayout()

            for (viewModel in section) {
                val view =
                convertView
                    ?: layoutInflater.inflate(
                    layoutInflater.inflate(
                        R.layout.user_switcher_fullscreen_popup_item,
                        parent,
                        false
                        /* parent= */ null
                    )
            val viewModel = getItem(position)
            view.requireViewById<ImageView>(R.id.icon).setImageResource(viewModel.iconResourceId)
                view
                    .requireViewById<ImageView>(R.id.icon)
                    .setImageResource(viewModel.iconResourceId)
                view.requireViewById<TextView>(R.id.text).text =
                    view.resources.getString(viewModel.textResourceId)
            return view
                view.setOnClickListener { viewModel.onClicked() }
                sectionView.addView(view)
            }
            return sectionView
        }

        fun setItems(items: List<UserActionViewModel>) {
            this.items.clear()
            this.items.addAll(items)
            val primarySection =
                items.filter {
                    it.viewKey != UserActionModel.NAVIGATE_TO_USER_MANAGEMENT.ordinal.toLong()
                }
            val secondarySection =
                items.filter {
                    it.viewKey == UserActionModel.NAVIGATE_TO_USER_MANAGEMENT.ordinal.toLong()
                }
            this.sections = listOf(primarySection, secondarySection)
            notifyDataSetChanged()
        }
    }