Rename PipActivity to PipView

This commit is contained in:
Benoit Marty 2024-08-26 17:15:32 +02:00
parent f6e864f520
commit 0d576a9f03
5 changed files with 21 additions and 21 deletions

View file

@ -35,7 +35,7 @@ class PictureInPicturePresenter @Inject constructor(
pipSupportProvider: PipSupportProvider, pipSupportProvider: PipSupportProvider,
) : Presenter<PictureInPictureState> { ) : Presenter<PictureInPictureState> {
private val isPipSupported = pipSupportProvider.isPipSupported() private val isPipSupported = pipSupportProvider.isPipSupported()
private var pipActivity: PipActivity? = null private var pipView: PipView? = null
@Composable @Composable
override fun present(): PictureInPictureState { override fun present(): PictureInPictureState {
@ -72,13 +72,13 @@ class PictureInPicturePresenter @Inject constructor(
) )
} }
fun setPipActivity(pipActivity: PipActivity?) { fun setPipView(pipView: PipView?) {
if (isPipSupported) { if (isPipSupported) {
Timber.tag(loggerTag.value).d("Setting PiP params") Timber.tag(loggerTag.value).d("Setting PiP params")
this.pipActivity = pipActivity this.pipView = pipView
pipActivity?.setPipParams() pipView?.setPipParams()
} else { } else {
Timber.tag(loggerTag.value).d("onCreate: PiP is not supported") Timber.tag(loggerTag.value).d("setPipView: PiP is not supported")
} }
} }
@ -92,11 +92,11 @@ class PictureInPicturePresenter @Inject constructor(
} }
if (pipController == null || pipController.canEnterPip()) { if (pipController == null || pipController.canEnterPip()) {
Timber.tag(loggerTag.value).d("Switch to PiP mode") Timber.tag(loggerTag.value).d("Switch to PiP mode")
pipActivity?.enterPipMode() pipView?.enterPipMode()
?.also { Timber.tag(loggerTag.value).d("Switch to PiP mode result: $it") } ?.also { Timber.tag(loggerTag.value).d("Switch to PiP mode result: $it") }
} else { } else {
Timber.tag(loggerTag.value).w("Cannot enter PiP mode, hangup the call") Timber.tag(loggerTag.value).w("Cannot enter PiP mode, hangup the call")
pipActivity?.hangUp() pipView?.hangUp()
} }
} }
} }

View file

@ -16,7 +16,7 @@
package io.element.android.features.call.impl.pip package io.element.android.features.call.impl.pip
interface PipActivity { interface PipView {
fun setPipParams() fun setPipParams()
fun enterPipMode(): Boolean fun enterPipMode(): Boolean
fun hangUp() fun hangUp()

View file

@ -48,7 +48,7 @@ import io.element.android.features.call.impl.di.CallBindings
import io.element.android.features.call.impl.pip.PictureInPictureEvents import io.element.android.features.call.impl.pip.PictureInPictureEvents
import io.element.android.features.call.impl.pip.PictureInPicturePresenter import io.element.android.features.call.impl.pip.PictureInPicturePresenter
import io.element.android.features.call.impl.pip.PictureInPictureState import io.element.android.features.call.impl.pip.PictureInPictureState
import io.element.android.features.call.impl.pip.PipActivity import io.element.android.features.call.impl.pip.PipView
import io.element.android.features.call.impl.services.CallForegroundService import io.element.android.features.call.impl.services.CallForegroundService
import io.element.android.features.call.impl.utils.CallIntentDataParser import io.element.android.features.call.impl.utils.CallIntentDataParser
import io.element.android.libraries.architecture.bindings import io.element.android.libraries.architecture.bindings
@ -60,7 +60,7 @@ import javax.inject.Inject
class ElementCallActivity : class ElementCallActivity :
AppCompatActivity(), AppCompatActivity(),
CallScreenNavigator, CallScreenNavigator,
PipActivity { PipView {
@Inject lateinit var callIntentDataParser: CallIntentDataParser @Inject lateinit var callIntentDataParser: CallIntentDataParser
@Inject lateinit var presenterFactory: CallScreenPresenter.Factory @Inject lateinit var presenterFactory: CallScreenPresenter.Factory
@Inject lateinit var appPreferencesStore: AppPreferencesStore @Inject lateinit var appPreferencesStore: AppPreferencesStore
@ -101,7 +101,7 @@ class ElementCallActivity :
updateUiMode(resources.configuration) updateUiMode(resources.configuration)
} }
pictureInPicturePresenter.setPipActivity(this) pictureInPicturePresenter.setPipView(this)
audioManager = getSystemService(AUDIO_SERVICE) as AudioManager audioManager = getSystemService(AUDIO_SERVICE) as AudioManager
requestAudioFocus() requestAudioFocus()
@ -177,7 +177,7 @@ class ElementCallActivity :
super.onDestroy() super.onDestroy()
releaseAudioFocus() releaseAudioFocus()
CallForegroundService.stop(this) CallForegroundService.stop(this)
pictureInPicturePresenter.setPipActivity(null) pictureInPicturePresenter.setPipView(null)
} }
override fun finish() { override fun finish() {

View file

@ -18,11 +18,11 @@ package io.element.android.features.call.impl.pip
import io.element.android.tests.testutils.lambda.lambdaError import io.element.android.tests.testutils.lambda.lambdaError
class FakePipActivity( class FakePipView(
private val setPipParamsResult: () -> Unit = { lambdaError() }, private val setPipParamsResult: () -> Unit = { lambdaError() },
private val enterPipModeResult: () -> Boolean = { lambdaError() }, private val enterPipModeResult: () -> Boolean = { lambdaError() },
private val handUpResult: () -> Unit = { lambdaError() } private val handUpResult: () -> Unit = { lambdaError() }
) : PipActivity { ) : PipView {
override fun setPipParams() = setPipParamsResult() override fun setPipParams() = setPipParamsResult()
override fun enterPipMode(): Boolean = enterPipModeResult() override fun enterPipMode(): Boolean = enterPipModeResult()
override fun hangUp() = handUpResult() override fun hangUp() = handUpResult()

View file

@ -34,14 +34,14 @@ class PictureInPicturePresenterTest {
val initialState = awaitItem() val initialState = awaitItem()
assertThat(initialState.supportPip).isFalse() assertThat(initialState.supportPip).isFalse()
} }
presenter.setPipActivity(null) presenter.setPipView(null)
} }
@Test @Test
fun `when pip is supported, the state value supportPip is true`() = runTest { fun `when pip is supported, the state value supportPip is true`() = runTest {
val presenter = createPictureInPicturePresenter( val presenter = createPictureInPicturePresenter(
supportPip = true, supportPip = true,
pipActivity = FakePipActivity(setPipParamsResult = { }), pipView = FakePipView(setPipParamsResult = { }),
) )
moleculeFlow(RecompositionMode.Immediate) { moleculeFlow(RecompositionMode.Immediate) {
presenter.present() presenter.present()
@ -56,7 +56,7 @@ class PictureInPicturePresenterTest {
val enterPipModeResult = lambdaRecorder<Boolean> { true } val enterPipModeResult = lambdaRecorder<Boolean> { true }
val presenter = createPictureInPicturePresenter( val presenter = createPictureInPicturePresenter(
supportPip = true, supportPip = true,
pipActivity = FakePipActivity( pipView = FakePipView(
setPipParamsResult = { }, setPipParamsResult = { },
enterPipModeResult = enterPipModeResult, enterPipModeResult = enterPipModeResult,
), ),
@ -83,7 +83,7 @@ class PictureInPicturePresenterTest {
val handUpResult = lambdaRecorder<Unit> { } val handUpResult = lambdaRecorder<Unit> { }
val presenter = createPictureInPicturePresenter( val presenter = createPictureInPicturePresenter(
supportPip = true, supportPip = true,
pipActivity = FakePipActivity( pipView = FakePipView(
setPipParamsResult = { }, setPipParamsResult = { },
handUpResult = handUpResult handUpResult = handUpResult
), ),
@ -105,7 +105,7 @@ class PictureInPicturePresenterTest {
val exitPipResult = lambdaRecorder<Unit> { } val exitPipResult = lambdaRecorder<Unit> { }
val presenter = createPictureInPicturePresenter( val presenter = createPictureInPicturePresenter(
supportPip = true, supportPip = true,
pipActivity = FakePipActivity( pipView = FakePipView(
setPipParamsResult = { }, setPipParamsResult = { },
enterPipModeResult = enterPipModeResult enterPipModeResult = enterPipModeResult
), ),
@ -141,12 +141,12 @@ class PictureInPicturePresenterTest {
private fun createPictureInPicturePresenter( private fun createPictureInPicturePresenter(
supportPip: Boolean = true, supportPip: Boolean = true,
pipActivity: PipActivity? = FakePipActivity() pipView: PipView? = FakePipView()
): PictureInPicturePresenter { ): PictureInPicturePresenter {
return PictureInPicturePresenter( return PictureInPicturePresenter(
pipSupportProvider = FakePipSupportProvider(supportPip), pipSupportProvider = FakePipSupportProvider(supportPip),
).apply { ).apply {
setPipActivity(pipActivity) setPipView(pipView)
} }
} }
} }