[Media TTT] Update chip states to not require otherDeviceName if they
don't need it. Define a #getChipTextString method instead. Bug: 203800643 Bug: 203800347 Test: verify all states still trigger via adb Test: media.taptotransfer tests Change-Id: Iba8a67a0a8affc4857fafdaf1880b920db0a3fe1
This commit is contained in:
@@ -16,8 +16,8 @@
|
||||
|
||||
package com.android.systemui.media.taptotransfer.sender
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.annotation.StringRes
|
||||
import com.android.systemui.R
|
||||
import com.android.systemui.media.taptotransfer.common.MediaTttChipState
|
||||
|
||||
@@ -27,91 +27,89 @@ import com.android.systemui.media.taptotransfer.common.MediaTttChipState
|
||||
*
|
||||
* This is a sealed class where each subclass represents a specific chip state. Each subclass can
|
||||
* contain additional information that is necessary for only that state.
|
||||
*
|
||||
* @property chipText a string resource for the text that the chip should display.
|
||||
* @property otherDeviceName the name of the other device involved in the transfer.
|
||||
*/
|
||||
sealed class ChipStateSender(
|
||||
appIconDrawable: Drawable,
|
||||
appIconContentDescription: String,
|
||||
@StringRes internal val chipText: Int,
|
||||
internal val otherDeviceName: String,
|
||||
) : MediaTttChipState(appIconDrawable, appIconContentDescription)
|
||||
appIconContentDescription: String
|
||||
) : MediaTttChipState(appIconDrawable, appIconContentDescription) {
|
||||
/** Returns a fully-formed string with the text that the chip should display. */
|
||||
abstract fun getChipTextString(context: Context): String
|
||||
}
|
||||
|
||||
/**
|
||||
* A state representing that the two devices are close but not close enough to *start* a cast to
|
||||
* the receiver device. The chip will instruct the user to move closer in order to initiate the
|
||||
* transfer to the receiver.
|
||||
*
|
||||
* @property otherDeviceName the name of the other device involved in the transfer.
|
||||
*/
|
||||
class MoveCloserToStartCast(
|
||||
appIconDrawable: Drawable,
|
||||
appIconContentDescription: String,
|
||||
otherDeviceName: String,
|
||||
) : ChipStateSender(
|
||||
appIconDrawable,
|
||||
appIconContentDescription,
|
||||
R.string.media_move_closer_to_start_cast,
|
||||
otherDeviceName
|
||||
)
|
||||
private val otherDeviceName: String,
|
||||
) : ChipStateSender(appIconDrawable, appIconContentDescription) {
|
||||
override fun getChipTextString(context: Context): String {
|
||||
return context.getString(R.string.media_move_closer_to_start_cast, otherDeviceName)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A state representing that the two devices are close but not close enough to *end* a cast that's
|
||||
* currently occurring the receiver device. The chip will instruct the user to move closer in order
|
||||
* to initiate the transfer from the receiver and back onto this device (the original sender).
|
||||
*
|
||||
* @property otherDeviceName the name of the other device involved in the transfer.
|
||||
*/
|
||||
class MoveCloserToEndCast(
|
||||
appIconDrawable: Drawable,
|
||||
appIconContentDescription: String,
|
||||
otherDeviceName: String,
|
||||
) : ChipStateSender(
|
||||
appIconDrawable,
|
||||
appIconContentDescription,
|
||||
R.string.media_move_closer_to_end_cast,
|
||||
otherDeviceName
|
||||
)
|
||||
private val otherDeviceName: String,
|
||||
) : ChipStateSender(appIconDrawable, appIconContentDescription) {
|
||||
override fun getChipTextString(context: Context): String {
|
||||
return context.getString(R.string.media_move_closer_to_end_cast, otherDeviceName)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A state representing that a transfer to the receiver device has been initiated (but not
|
||||
* completed).
|
||||
*
|
||||
* @property otherDeviceName the name of the other device involved in the transfer.
|
||||
*/
|
||||
class TransferToReceiverTriggered(
|
||||
appIconDrawable: Drawable,
|
||||
appIconContentDescription: String,
|
||||
otherDeviceName: String
|
||||
) : ChipStateSender(
|
||||
appIconDrawable,
|
||||
appIconContentDescription,
|
||||
R.string.media_transfer_playing,
|
||||
otherDeviceName
|
||||
)
|
||||
private val otherDeviceName: String
|
||||
) : ChipStateSender(appIconDrawable, appIconContentDescription) {
|
||||
override fun getChipTextString(context: Context): String {
|
||||
return context.getString(R.string.media_transfer_playing, otherDeviceName)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A state representing that a transfer has been successfully completed.
|
||||
*
|
||||
* @property otherDeviceName the name of the other device involved in the transfer.
|
||||
* @property undoRunnable if present, the runnable that should be run to undo the transfer. We will
|
||||
* show an Undo button on the chip if this runnable is present.
|
||||
*/
|
||||
class TransferSucceeded(
|
||||
appIconDrawable: Drawable,
|
||||
appIconContentDescription: String,
|
||||
otherDeviceName: String,
|
||||
private val otherDeviceName: String,
|
||||
val undoRunnable: Runnable? = null
|
||||
) : ChipStateSender(appIconDrawable,
|
||||
appIconContentDescription,
|
||||
R.string.media_transfer_playing,
|
||||
otherDeviceName
|
||||
)
|
||||
) : ChipStateSender(appIconDrawable, appIconContentDescription) {
|
||||
override fun getChipTextString(context: Context): String {
|
||||
return context.getString(R.string.media_transfer_playing, otherDeviceName)
|
||||
}
|
||||
}
|
||||
|
||||
/** A state representing that a transfer has failed. */
|
||||
class TransferFailed(
|
||||
appIconDrawable: Drawable,
|
||||
appIconContentDescription: String,
|
||||
// TODO(b/211493953): The failed chip doesn't need [otherDeviceName] so we may want to remove
|
||||
// [otherDeviceName] from the superclass [ChipStateSender].
|
||||
otherDeviceName: String,
|
||||
) : ChipStateSender(
|
||||
appIconDrawable,
|
||||
appIconContentDescription,
|
||||
R.string.media_transfer_failed,
|
||||
otherDeviceName
|
||||
)
|
||||
appIconContentDescription: String
|
||||
) : ChipStateSender(appIconDrawable, appIconContentDescription) {
|
||||
override fun getChipTextString(context: Context): String {
|
||||
return context.getString(R.string.media_transfer_failed)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class MediaTttChipControllerSender @Inject constructor(
|
||||
|
||||
// Text
|
||||
currentChipView.requireViewById<TextView>(R.id.text).apply {
|
||||
text = context.getString(chipState.chipText, chipState.otherDeviceName)
|
||||
text = chipState.getChipTextString(context)
|
||||
}
|
||||
|
||||
// Loading
|
||||
|
||||
@@ -53,7 +53,7 @@ class MediaTttSenderService @Inject constructor(
|
||||
override fun transferFailed(
|
||||
mediaInfo: MediaRoute2Info, otherDeviceInfo: DeviceInfo
|
||||
) {
|
||||
this@MediaTttSenderService.transferFailed(mediaInfo, otherDeviceInfo)
|
||||
this@MediaTttSenderService.transferFailed(mediaInfo)
|
||||
}
|
||||
|
||||
override fun transferToReceiverTriggered(
|
||||
@@ -91,11 +91,10 @@ class MediaTttSenderService @Inject constructor(
|
||||
controller.displayChip(chipState)
|
||||
}
|
||||
|
||||
private fun transferFailed(mediaInfo: MediaRoute2Info, otherDeviceInfo: DeviceInfo) {
|
||||
private fun transferFailed(mediaInfo: MediaRoute2Info) {
|
||||
val chipState = TransferFailed(
|
||||
appIconDrawable = fakeAppIconDrawable,
|
||||
appIconContentDescription = mediaInfo.name.toString(),
|
||||
otherDeviceName = otherDeviceInfo.name
|
||||
appIconContentDescription = mediaInfo.name.toString()
|
||||
)
|
||||
controller.displayChip(chipState)
|
||||
}
|
||||
|
||||
@@ -53,12 +53,13 @@ class MediaTttChipControllerSenderTest : SysuiTestCase() {
|
||||
|
||||
@Test
|
||||
fun moveCloserToStartCast_appIcon_deviceName_noLoadingIcon_noUndo_noFailureIcon() {
|
||||
controllerSender.displayChip(moveCloserToStartCast())
|
||||
val state = moveCloserToStartCast()
|
||||
controllerSender.displayChip(state)
|
||||
|
||||
val chipView = getChipView()
|
||||
assertThat(chipView.getAppIconView().drawable).isEqualTo(appIconDrawable)
|
||||
assertThat(chipView.getAppIconView().contentDescription).isEqualTo(APP_ICON_CONTENT_DESC)
|
||||
assertThat(chipView.getChipText()).contains(DEVICE_NAME)
|
||||
assertThat(chipView.getChipText()).isEqualTo(state.getChipTextString(context))
|
||||
assertThat(chipView.getLoadingIconVisibility()).isEqualTo(View.GONE)
|
||||
assertThat(chipView.getUndoButton().visibility).isEqualTo(View.GONE)
|
||||
assertThat(chipView.getFailureIcon().visibility).isEqualTo(View.GONE)
|
||||
@@ -66,12 +67,13 @@ class MediaTttChipControllerSenderTest : SysuiTestCase() {
|
||||
|
||||
@Test
|
||||
fun moveCloserToEndCast_appIcon_deviceName_noLoadingIcon_noUndo_noFailureIcon() {
|
||||
controllerSender.displayChip(moveCloserToEndCast())
|
||||
val state = moveCloserToEndCast()
|
||||
controllerSender.displayChip(state)
|
||||
|
||||
val chipView = getChipView()
|
||||
assertThat(chipView.getAppIconView().drawable).isEqualTo(appIconDrawable)
|
||||
assertThat(chipView.getAppIconView().contentDescription).isEqualTo(APP_ICON_CONTENT_DESC)
|
||||
assertThat(chipView.getChipText()).contains(DEVICE_NAME)
|
||||
assertThat(chipView.getChipText()).isEqualTo(state.getChipTextString(context))
|
||||
assertThat(chipView.getLoadingIconVisibility()).isEqualTo(View.GONE)
|
||||
assertThat(chipView.getUndoButton().visibility).isEqualTo(View.GONE)
|
||||
assertThat(chipView.getFailureIcon().visibility).isEqualTo(View.GONE)
|
||||
@@ -79,12 +81,13 @@ class MediaTttChipControllerSenderTest : SysuiTestCase() {
|
||||
|
||||
@Test
|
||||
fun transferToReceiverTriggered_appIcon_loadingIcon_noUndo_noFailureIcon() {
|
||||
controllerSender.displayChip(transferToReceiverTriggered())
|
||||
val state = transferToReceiverTriggered()
|
||||
controllerSender.displayChip(state)
|
||||
|
||||
val chipView = getChipView()
|
||||
assertThat(chipView.getAppIconView().drawable).isEqualTo(appIconDrawable)
|
||||
assertThat(chipView.getAppIconView().contentDescription).isEqualTo(APP_ICON_CONTENT_DESC)
|
||||
assertThat(chipView.getChipText()).contains(DEVICE_NAME)
|
||||
assertThat(chipView.getChipText()).isEqualTo(state.getChipTextString(context))
|
||||
assertThat(chipView.getLoadingIconVisibility()).isEqualTo(View.VISIBLE)
|
||||
assertThat(chipView.getUndoButton().visibility).isEqualTo(View.GONE)
|
||||
assertThat(chipView.getFailureIcon().visibility).isEqualTo(View.GONE)
|
||||
@@ -92,12 +95,13 @@ class MediaTttChipControllerSenderTest : SysuiTestCase() {
|
||||
|
||||
@Test
|
||||
fun transferSucceeded_appIcon_deviceName_noLoadingIcon_noFailureIcon() {
|
||||
controllerSender.displayChip(transferSucceeded())
|
||||
val state = transferSucceeded()
|
||||
controllerSender.displayChip(state)
|
||||
|
||||
val chipView = getChipView()
|
||||
assertThat(chipView.getAppIconView().drawable).isEqualTo(appIconDrawable)
|
||||
assertThat(chipView.getAppIconView().contentDescription).isEqualTo(APP_ICON_CONTENT_DESC)
|
||||
assertThat(chipView.getChipText()).contains(DEVICE_NAME)
|
||||
assertThat(chipView.getChipText()).isEqualTo(state.getChipTextString(context))
|
||||
assertThat(chipView.getLoadingIconVisibility()).isEqualTo(View.GONE)
|
||||
assertThat(chipView.getFailureIcon().visibility).isEqualTo(View.GONE)
|
||||
}
|
||||
@@ -132,12 +136,13 @@ class MediaTttChipControllerSenderTest : SysuiTestCase() {
|
||||
|
||||
@Test
|
||||
fun transferFailed_appIcon_noDeviceName_noLoadingIcon_noUndo_failureIcon() {
|
||||
controllerSender.displayChip(transferFailed())
|
||||
val state = transferFailed()
|
||||
controllerSender.displayChip(state)
|
||||
|
||||
val chipView = getChipView()
|
||||
assertThat(chipView.getAppIconView().drawable).isEqualTo(appIconDrawable)
|
||||
assertThat(chipView.getAppIconView().contentDescription).isEqualTo(APP_ICON_CONTENT_DESC)
|
||||
assertThat(chipView.getChipText()).doesNotContain(DEVICE_NAME)
|
||||
assertThat(chipView.getChipText()).isEqualTo(state.getChipTextString(context))
|
||||
assertThat(chipView.getLoadingIconVisibility()).isEqualTo(View.GONE)
|
||||
assertThat(chipView.getUndoButton().visibility).isEqualTo(View.GONE)
|
||||
assertThat(chipView.getFailureIcon().visibility).isEqualTo(View.VISIBLE)
|
||||
@@ -219,8 +224,7 @@ class MediaTttChipControllerSenderTest : SysuiTestCase() {
|
||||
) = TransferSucceeded(appIconDrawable, APP_ICON_CONTENT_DESC, DEVICE_NAME, undoRunnable)
|
||||
|
||||
/** Helper method providing default parameters to not clutter up the tests. */
|
||||
private fun transferFailed() =
|
||||
TransferFailed(appIconDrawable, APP_ICON_CONTENT_DESC, DEVICE_NAME)
|
||||
private fun transferFailed() = TransferFailed(appIconDrawable, APP_ICON_CONTENT_DESC)
|
||||
}
|
||||
|
||||
private const val DEVICE_NAME = "My Tablet"
|
||||
|
||||
@@ -44,7 +44,7 @@ class MediaTttSenderServiceTest : SysuiTestCase() {
|
||||
verify(controller).displayChip(capture(chipStateCaptor))
|
||||
|
||||
val chipState = chipStateCaptor.value!!
|
||||
assertThat(chipState.otherDeviceName).isEqualTo(name)
|
||||
assertThat(chipState.getChipTextString(context)).contains(name)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,7 +56,7 @@ class MediaTttSenderServiceTest : SysuiTestCase() {
|
||||
verify(controller).displayChip(capture(chipStateCaptor))
|
||||
|
||||
val chipState = chipStateCaptor.value!!
|
||||
assertThat(chipState.otherDeviceName).isEqualTo(name)
|
||||
assertThat(chipState.getChipTextString(context)).contains(name)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,7 +68,7 @@ class MediaTttSenderServiceTest : SysuiTestCase() {
|
||||
verify(controller).displayChip(capture(chipStateCaptor))
|
||||
|
||||
val chipState = chipStateCaptor.value!!
|
||||
assertThat(chipState.otherDeviceName).isEqualTo(name)
|
||||
assertThat(chipState.getChipTextString(context)).contains(name)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user