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

Commit 6f63fe34 authored by Andre Le's avatar Andre Le
Browse files

QSDetailedView: Remove dialog dependency from the view binders

The screen record and media view binders should not depend on the dialog
to handle the views. They should bind using the container view inside
the dialog instead. Thus, this CL remove the dialog from the view
binders and use the container view instead.

This CL follows the refactor mentioned in
go/al-screen-record-detailed-view.

Bug: b/378514312
Flag: NONE refactor
Test: ScreenRecordPermissionDialogDelegateTest,
SystemCastPermissionDialogDelegateTest,
ShareToAppPermissionDialogDelegateTest
Test: Click on screen record tile in the QS -> verify that screen
recording in single app and entire screen both works

Change-Id: Iec7922e34e2a8cb79353fbb868bbaaefa42ced13
parent baa89426
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -58,7 +58,6 @@ abstract class BaseMediaProjectionPermissionDialogDelegate<T : AlertDialog>(
            hostUid,
            mediaProjectionMetricsLogger,
            defaultSelectedMode,
            dialog,
        )
    }

@@ -79,7 +78,7 @@ abstract class BaseMediaProjectionPermissionDialogDelegate<T : AlertDialog>(
        if (!::viewBinder.isInitialized) {
            viewBinder = createViewBinder()
        }
        viewBinder.bind()
        viewBinder.bind(dialog.requireViewById(R.id.screen_share_permission_dialog))
    }

    private fun updateIcon() {
+11 −11
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.mediaprojection.permission

import android.app.AlertDialog
import android.content.Context
import android.view.LayoutInflater
import android.view.View
@@ -37,8 +36,8 @@ open class BaseMediaProjectionPermissionViewBinder(
    private val hostUid: Int,
    private val mediaProjectionMetricsLogger: MediaProjectionMetricsLogger,
    @ScreenShareMode val defaultSelectedMode: Int = screenShareOptions.first().mode,
    private val dialog: AlertDialog,
) : AdapterView.OnItemSelectedListener {
    protected lateinit var containerView: View
    private lateinit var warning: TextView
    private lateinit var startButton: TextView
    private lateinit var screenShareModeSpinner: Spinner
@@ -54,9 +53,10 @@ open class BaseMediaProjectionPermissionViewBinder(
        }
    }

    open fun bind() {
        warning = dialog.requireViewById(R.id.text_warning)
        startButton = dialog.requireViewById(android.R.id.button1)
    open fun bind(view: View) {
        containerView = view
        warning = containerView.requireViewById(R.id.text_warning)
        startButton = containerView.requireViewById(android.R.id.button1)
        initScreenShareOptions()
        createOptionsView(getOptionsViewLayoutId())
    }
@@ -67,15 +67,15 @@ open class BaseMediaProjectionPermissionViewBinder(
        initScreenShareSpinner()
    }

    /** Sets fields on the dialog that change based on which option is selected. */
    /** Sets fields on the views that change based on which option is selected. */
    private fun setOptionSpecificFields() {
        warning.text = warningText
        startButton.text = startButtonText
    }

    private fun initScreenShareSpinner() {
        val adapter = OptionsAdapter(dialog.context.applicationContext, screenShareOptions)
        screenShareModeSpinner = dialog.requireViewById(R.id.screen_share_mode_options)
        val adapter = OptionsAdapter(containerView.context.applicationContext, screenShareOptions)
        screenShareModeSpinner = containerView.requireViewById(R.id.screen_share_mode_options)
        screenShareModeSpinner.adapter = adapter
        screenShareModeSpinner.onItemSelectedListener = this

@@ -103,10 +103,10 @@ open class BaseMediaProjectionPermissionViewBinder(
    override fun onNothingSelected(parent: AdapterView<*>?) {}

    private val warningText: String
        get() = dialog.context.getString(selectedScreenShareOption.warningText, appName)
        get() = containerView.context.getString(selectedScreenShareOption.warningText, appName)

    private val startButtonText: String
        get() = dialog.context.getString(selectedScreenShareOption.startButtonText)
        get() = containerView.context.getString(selectedScreenShareOption.startButtonText)

    fun setStartButtonOnClickListener(listener: View.OnClickListener?) {
        startButton.setOnClickListener { view ->
@@ -121,7 +121,7 @@ open class BaseMediaProjectionPermissionViewBinder(

    private fun createOptionsView(@LayoutRes layoutId: Int?) {
        if (layoutId == null) return
        val stub = dialog.requireViewById<View>(R.id.options_stub) as ViewStub
        val stub = containerView.requireViewById<View>(R.id.options_stub) as ViewStub
        stub.layoutResource = layoutId
        stub.inflate()
    }
+0 −1
Original line number Diff line number Diff line
@@ -104,7 +104,6 @@ class ScreenRecordPermissionDialogDelegate(
            mediaProjectionMetricsLogger,
            defaultSelectedMode,
            displayManager,
            dialog,
            controller,
            activityStarter,
            userContextProvider,
+9 −11
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.screenrecord

import android.annotation.SuppressLint
import android.app.Activity
import android.app.AlertDialog
import android.app.PendingIntent
import android.content.Intent
import android.hardware.display.DisplayManager
@@ -57,7 +56,6 @@ class ScreenRecordPermissionViewBinder(
    mediaProjectionMetricsLogger: MediaProjectionMetricsLogger,
    @ScreenShareMode defaultSelectedMode: Int,
    displayManager: DisplayManager,
    private val dialog: AlertDialog,
    private val controller: RecordingController,
    private val activityStarter: ActivityStarter,
    private val userContextProvider: UserContextProvider,
@@ -69,15 +67,14 @@ class ScreenRecordPermissionViewBinder(
        hostUid = hostUid,
        mediaProjectionMetricsLogger,
        defaultSelectedMode,
        dialog,
    ) {
    private lateinit var tapsSwitch: Switch
    private lateinit var audioSwitch: Switch
    private lateinit var tapsView: View
    private lateinit var options: Spinner

    override fun bind() {
        super.bind()
    override fun bind(view: View) {
        super.bind(view)
        initRecordOptionsView()
        setStartButtonOnClickListener { startButtonOnClicked() }
    }
@@ -91,7 +88,8 @@ class ScreenRecordPermissionViewBinder(
            )
        }
        if (selectedScreenShareOption.mode == SINGLE_APP) {
            val intent = Intent(dialog.context, MediaProjectionAppSelectorActivity::class.java)
            val intent =
                Intent(containerView.context, MediaProjectionAppSelectorActivity::class.java)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

            // We can't start activity for result here so we use result receiver to get
@@ -116,10 +114,10 @@ class ScreenRecordPermissionViewBinder(

    @SuppressLint("ClickableViewAccessibility")
    private fun initRecordOptionsView() {
        audioSwitch = dialog.requireViewById(R.id.screenrecord_audio_switch)
        tapsSwitch = dialog.requireViewById(R.id.screenrecord_taps_switch)
        audioSwitch = containerView.requireViewById(R.id.screenrecord_audio_switch)
        tapsSwitch = containerView.requireViewById(R.id.screenrecord_taps_switch)

        tapsView = dialog.requireViewById(R.id.show_taps)
        tapsView = containerView.requireViewById(R.id.show_taps)
        updateTapsViewVisibility()

        // Add these listeners so that the switch only responds to movement
@@ -127,10 +125,10 @@ class ScreenRecordPermissionViewBinder(
        audioSwitch.setOnTouchListener { _, event -> event.action == ACTION_MOVE }
        tapsSwitch.setOnTouchListener { _, event -> event.action == ACTION_MOVE }

        options = dialog.requireViewById(R.id.screen_recording_options)
        options = containerView.requireViewById(R.id.screen_recording_options)
        val a: ArrayAdapter<*> =
            ScreenRecordingAdapter(
                dialog.context,
                containerView.context,
                android.R.layout.simple_spinner_dropdown_item,
                MODES,
            )