mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 03:06:14 +00:00
committed by
Benoit Marty
parent
2b2d86a804
commit
e66efcfc43
+10
@@ -39,6 +39,7 @@ class ShowQrCodeNode(
|
||||
private val callback: Callback = callback()
|
||||
private val showQrCodePresenter: ShowQrCodePresenter = showQrCodePresenterFactory.create(
|
||||
initialData = inputs.data,
|
||||
maxQrCodeRotation = MAX_QR_CODE_ROTATION,
|
||||
)
|
||||
|
||||
@Composable
|
||||
@@ -50,4 +51,13 @@ class ShowQrCodeNode(
|
||||
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
|
||||
class ShowQrCodePresenter(
|
||||
@Assisted private val initialData: String,
|
||||
@Assisted private val maxQrCodeRotation: Int,
|
||||
private val linkNewMobileHandler: LinkNewMobileHandler,
|
||||
) : Presenter<ShowQrCodeState> {
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
fun create(initialData: String): ShowQrCodePresenter
|
||||
fun create(
|
||||
initialData: String,
|
||||
maxQrCodeRotation: Int,
|
||||
): ShowQrCodePresenter
|
||||
}
|
||||
|
||||
private var loadingJob: Job? = null
|
||||
|
||||
@Composable
|
||||
override fun present(): ShowQrCodeState {
|
||||
var qrCodeRotationCounter by remember { mutableIntStateOf(MAX_QR_CODE_ROTATION) }
|
||||
var qrCodeRotationCounter by remember { mutableIntStateOf(maxQrCodeRotation) }
|
||||
val state by produceState(
|
||||
initialValue = ShowQrCodeState(
|
||||
data = AsyncData.Success(initialData),
|
||||
@@ -81,8 +85,4 @@ class ShowQrCodePresenter(
|
||||
|
||||
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(
|
||||
linkNewMobileHandler: LinkNewMobileHandler = LinkNewMobileHandler(FakeMatrixClient()),
|
||||
maxQrCodeRotation: Int = 10,
|
||||
) = ShowQrCodePresenter(
|
||||
initialData = "DATA",
|
||||
maxQrCodeRotation = maxQrCodeRotation,
|
||||
linkNewMobileHandler = linkNewMobileHandler,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user