mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
committed by
Benoit Marty
parent
2b2d86a804
commit
e66efcfc43
+10
@@ -39,6 +39,7 @@ class ShowQrCodeNode(
|
|||||||
private val callback: Callback = callback()
|
private val callback: Callback = callback()
|
||||||
private val showQrCodePresenter: ShowQrCodePresenter = showQrCodePresenterFactory.create(
|
private val showQrCodePresenter: ShowQrCodePresenter = showQrCodePresenterFactory.create(
|
||||||
initialData = inputs.data,
|
initialData = inputs.data,
|
||||||
|
maxQrCodeRotation = MAX_QR_CODE_ROTATION,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -50,4 +51,13 @@ class ShowQrCodeNode(
|
|||||||
onBackClick = callback::navigateBack,
|
onBackClick = callback::navigateBack,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/**
|
||||||
|
* Max number of QrCode rotation.
|
||||||
|
* When QrCode is rotated this number of time, a TimeOut error is emitted.
|
||||||
|
* Set to 0 to disable QrCode rotation.
|
||||||
|
*/
|
||||||
|
const val MAX_QR_CODE_ROTATION = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -33,18 +33,22 @@ private val tag = LoggerTag("ShowQrCodePresenter", LoggerTags.linkNewDevice)
|
|||||||
@AssistedInject
|
@AssistedInject
|
||||||
class ShowQrCodePresenter(
|
class ShowQrCodePresenter(
|
||||||
@Assisted private val initialData: String,
|
@Assisted private val initialData: String,
|
||||||
|
@Assisted private val maxQrCodeRotation: Int,
|
||||||
private val linkNewMobileHandler: LinkNewMobileHandler,
|
private val linkNewMobileHandler: LinkNewMobileHandler,
|
||||||
) : Presenter<ShowQrCodeState> {
|
) : Presenter<ShowQrCodeState> {
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
interface Factory {
|
interface Factory {
|
||||||
fun create(initialData: String): ShowQrCodePresenter
|
fun create(
|
||||||
|
initialData: String,
|
||||||
|
maxQrCodeRotation: Int,
|
||||||
|
): ShowQrCodePresenter
|
||||||
}
|
}
|
||||||
|
|
||||||
private var loadingJob: Job? = null
|
private var loadingJob: Job? = null
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
override fun present(): ShowQrCodeState {
|
override fun present(): ShowQrCodeState {
|
||||||
var qrCodeRotationCounter by remember { mutableIntStateOf(MAX_QR_CODE_ROTATION) }
|
var qrCodeRotationCounter by remember { mutableIntStateOf(maxQrCodeRotation) }
|
||||||
val state by produceState(
|
val state by produceState(
|
||||||
initialValue = ShowQrCodeState(
|
initialValue = ShowQrCodeState(
|
||||||
data = AsyncData.Success(initialData),
|
data = AsyncData.Success(initialData),
|
||||||
@@ -81,8 +85,4 @@ class ShowQrCodePresenter(
|
|||||||
|
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val MAX_QR_CODE_ROTATION = 10
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+26
@@ -91,10 +91,36 @@ class ShowQrCodePresenterTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - when handler emits QrRotating, the presenter does not emit anything when rotation is disabled`() = runTest {
|
||||||
|
val linkMobileHandler = FakeLinkMobileHandler(
|
||||||
|
startResult = {},
|
||||||
|
)
|
||||||
|
val matrixClient = FakeMatrixClient(
|
||||||
|
sessionCoroutineScope = backgroundScope,
|
||||||
|
createLinkMobileHandlerResult = { Result.success(linkMobileHandler) },
|
||||||
|
)
|
||||||
|
val linkNewMobileHandler = LinkNewMobileHandler(matrixClient)
|
||||||
|
linkNewMobileHandler.createAndStartNewHandler()
|
||||||
|
createPresenter(
|
||||||
|
linkNewMobileHandler = linkNewMobileHandler,
|
||||||
|
maxQrCodeRotation = 0,
|
||||||
|
).test {
|
||||||
|
awaitItem()
|
||||||
|
linkMobileHandler.emitStep(
|
||||||
|
LinkMobileStep.QrRotating
|
||||||
|
)
|
||||||
|
runCurrent()
|
||||||
|
expectNoEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun createPresenter(
|
private fun createPresenter(
|
||||||
linkNewMobileHandler: LinkNewMobileHandler = LinkNewMobileHandler(FakeMatrixClient()),
|
linkNewMobileHandler: LinkNewMobileHandler = LinkNewMobileHandler(FakeMatrixClient()),
|
||||||
|
maxQrCodeRotation: Int = 10,
|
||||||
) = ShowQrCodePresenter(
|
) = ShowQrCodePresenter(
|
||||||
initialData = "DATA",
|
initialData = "DATA",
|
||||||
|
maxQrCodeRotation = maxQrCodeRotation,
|
||||||
linkNewMobileHandler = linkNewMobileHandler,
|
linkNewMobileHandler = linkNewMobileHandler,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user