Updated on 2026-08-14
This commit is contained in:
commit
e77d58c8cc
130 changed files with 4126 additions and 3296 deletions
|
|
@ -6,6 +6,7 @@ import com.tangem.core.decompose.ui.UiMessageSender
|
|||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.*
|
||||
import javax.annotation.OverridingMethodsMustInvokeSuper
|
||||
|
||||
/**
|
||||
* Abstract class for a component's model.
|
||||
|
|
@ -29,6 +30,7 @@ abstract class Model : InstanceKeeper.Instance {
|
|||
CoroutineScope(context = dispatchers.mainImmediate + SupervisorJob())
|
||||
}
|
||||
|
||||
@OverridingMethodsMustInvokeSuper
|
||||
override fun onDestroy() {
|
||||
runCatching { modelScope.cancel() }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
/* Core */
|
||||
implementation(projects.core.decompose)
|
||||
|
||||
/* Libs - AndroidX */
|
||||
implementation(deps.lifecycle.runtime.ktx)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package com.tangem.core.deeplink
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
// TODO: Add tests
|
||||
/**
|
||||
|
|
@ -21,17 +19,11 @@ interface DeepLinksRegistry {
|
|||
|
||||
/**
|
||||
* Registers the given [deepLink].
|
||||
*
|
||||
* @see registerWithLifecycle
|
||||
* @see registerWithViewModel
|
||||
*/
|
||||
fun register(deepLink: DeepLink)
|
||||
|
||||
/**
|
||||
* Registers the given [deepLinks].
|
||||
*
|
||||
* @see registerWithLifecycle
|
||||
* @see registerWithViewModel
|
||||
*/
|
||||
fun register(deepLinks: Collection<DeepLink>)
|
||||
|
||||
|
|
@ -50,17 +42,6 @@ interface DeepLinksRegistry {
|
|||
* */
|
||||
fun unregisterByIds(ids: Collection<String>)
|
||||
|
||||
/**
|
||||
* Registers the [deepLinks] when the [owner] is resumed and ensures that they are unregistered when the [owner] is
|
||||
* stopped.
|
||||
*/
|
||||
fun registerWithLifecycle(owner: LifecycleOwner, deepLinks: Collection<DeepLink>)
|
||||
|
||||
/**
|
||||
* Registers the [deepLinks] and ensures that they are unregistered when the [ViewModel] is closed.
|
||||
*/
|
||||
fun registerWithViewModel(viewModel: ViewModel, deepLinks: Collection<DeepLink>)
|
||||
|
||||
/**
|
||||
* Triggers run last launched [Intent] with deeplink handlers that can handle delayed deeplink
|
||||
* after handle [Intent] clear that and second time no intent will be handled
|
||||
|
|
|
|||
|
|
@ -3,11 +3,8 @@ package com.tangem.core.deeplink.impl
|
|||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.tangem.core.deeplink.DeepLink
|
||||
import com.tangem.core.deeplink.DeepLinksRegistry
|
||||
import com.tangem.core.deeplink.utils.DeepLinksLifecycleObserver
|
||||
import timber.log.Timber
|
||||
|
||||
internal class DefaultDeepLinksRegistry : DeepLinksRegistry {
|
||||
|
|
@ -103,19 +100,6 @@ internal class DefaultDeepLinksRegistry : DeepLinksRegistry {
|
|||
)
|
||||
}
|
||||
|
||||
override fun registerWithLifecycle(owner: LifecycleOwner, deepLinks: Collection<DeepLink>) {
|
||||
val observer = DeepLinksLifecycleObserver(deepLinksRegistry = this, deepLinks)
|
||||
owner.lifecycle.addObserver(observer)
|
||||
}
|
||||
|
||||
override fun registerWithViewModel(viewModel: ViewModel, deepLinks: Collection<DeepLink>) {
|
||||
viewModel.addCloseable {
|
||||
unregister(deepLinks)
|
||||
}
|
||||
|
||||
register(deepLinks)
|
||||
}
|
||||
|
||||
override fun triggerDelayedDeeplink() {
|
||||
if (lastIntent != null) {
|
||||
val intent = lastIntent
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.tangem.core.deeplink.utils
|
||||
|
||||
import com.arkivanov.essenty.lifecycle.subscribe
|
||||
import com.tangem.core.decompose.context.AppComponentContext
|
||||
import com.tangem.core.deeplink.DeepLink
|
||||
import com.tangem.core.deeplink.DeepLinksRegistry
|
||||
|
||||
fun AppComponentContext.registerDeepLinks(registry: DeepLinksRegistry, vararg deepLinks: DeepLink) {
|
||||
registerDeepLinks(registry, deepLinks.toList())
|
||||
}
|
||||
|
||||
fun AppComponentContext.registerDeepLinks(registry: DeepLinksRegistry, deepLinks: Collection<DeepLink>) {
|
||||
lifecycle.subscribe(
|
||||
onCreate = {
|
||||
registry.register(deepLinks)
|
||||
},
|
||||
onDestroy = {
|
||||
registry.unregister(deepLinks)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
package com.tangem.core.deeplink.utils
|
||||
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import com.tangem.core.deeplink.DeepLink
|
||||
import com.tangem.core.deeplink.DeepLinksRegistry
|
||||
|
||||
internal class DeepLinksLifecycleObserver(
|
||||
private val deepLinksRegistry: DeepLinksRegistry,
|
||||
private val deepLinks: Collection<DeepLink>,
|
||||
) : DefaultLifecycleObserver {
|
||||
|
||||
override fun onResume(owner: LifecycleOwner) {
|
||||
deepLinksRegistry.register(deepLinks)
|
||||
}
|
||||
|
||||
override fun onPause(owner: LifecycleOwner) {
|
||||
deepLinksRegistry.unregister(deepLinks)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue