mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Create function to limit code duplication.
This commit is contained in:
+7
-9
@@ -46,11 +46,15 @@ class LinkNewDesktopHandler(
|
|||||||
private var timerJob: Job? = null
|
private var timerJob: Job? = null
|
||||||
private var handler: LinkDesktopHandler? = null
|
private var handler: LinkDesktopHandler? = null
|
||||||
|
|
||||||
fun createNewHandler() {
|
private fun resetJobs() {
|
||||||
currentJob?.cancel()
|
currentJob?.cancel()
|
||||||
currentJob = null
|
currentJob = null
|
||||||
timerJob?.cancel()
|
timerJob?.cancel()
|
||||||
timerJob = null
|
timerJob = null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createNewHandler() {
|
||||||
|
resetJobs()
|
||||||
handler = matrixClient.createLinkDesktopHandler().getOrNull()
|
handler = matrixClient.createLinkDesktopHandler().getOrNull()
|
||||||
timerJob = sessionScope.launch {
|
timerJob = sessionScope.launch {
|
||||||
delay(2.minutes)
|
delay(2.minutes)
|
||||||
@@ -59,20 +63,14 @@ class LinkNewDesktopHandler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun reset() {
|
fun reset() {
|
||||||
currentJob?.cancel()
|
resetJobs()
|
||||||
currentJob = null
|
|
||||||
timerJob?.cancel()
|
|
||||||
timerJob = null
|
|
||||||
sessionScope.launch {
|
sessionScope.launch {
|
||||||
linkDesktopStepFlow.emit(LinkDesktopStep.Uninitialized)
|
linkDesktopStepFlow.emit(LinkDesktopStep.Uninitialized)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onScannedCode(data: ByteArray) {
|
fun onScannedCode(data: ByteArray) {
|
||||||
currentJob?.cancel()
|
resetJobs()
|
||||||
currentJob = null
|
|
||||||
timerJob?.cancel()
|
|
||||||
timerJob = null
|
|
||||||
val currentHandler = handler
|
val currentHandler = handler
|
||||||
if (currentHandler == null) {
|
if (currentHandler == null) {
|
||||||
Timber.tag(loggerTag.value).e("onScannedCode: Handler is not initialized. Call createNewHandler() first.")
|
Timber.tag(loggerTag.value).e("onScannedCode: Handler is not initialized. Call createNewHandler() first.")
|
||||||
|
|||||||
Reference in New Issue
Block a user