Updated on 2026-08-14
This commit is contained in:
parent
69aeaf5776
commit
e38a822f0b
10 changed files with 50 additions and 80 deletions
|
|
@ -39,6 +39,7 @@ dependencies {
|
|||
implementation(projects.core.featuretoggles)
|
||||
implementation(projects.core.ui)
|
||||
implementation(projects.core.utils)
|
||||
implementation(projects.core.navigation)
|
||||
|
||||
/** Feature Apis */
|
||||
implementation(projects.features.tester.api)
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
package com.tangem.feature.tester
|
||||
|
||||
import android.app.Activity
|
||||
|
||||
/**
|
||||
* Wraps the main activity class to avoid type erasure issues during injection.
|
||||
*
|
||||
* @property clazz activity class
|
||||
*/
|
||||
class ActivityClassWrapper(
|
||||
val clazz: Class<out Activity>,
|
||||
)
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package com.tangem.feature.tester.apprestarter
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.tangem.feature.tester.ActivityClassWrapper
|
||||
import com.tangem.features.tester.api.AppRestarter
|
||||
|
||||
/**
|
||||
* Entity that kills the process and restarts the main activity
|
||||
* @property context Activity context
|
||||
*/
|
||||
internal class DefaultAppRestarter(
|
||||
private val context: Context,
|
||||
private val activityClassWrapper: ActivityClassWrapper,
|
||||
) : AppRestarter {
|
||||
|
||||
override fun restart() {
|
||||
if (context !is Activity) return
|
||||
|
||||
context.finish()
|
||||
context.startActivity(
|
||||
Intent(context, activityClassWrapper.clazz).apply { flags = Intent.FLAG_ACTIVITY_CLEAR_TOP },
|
||||
)
|
||||
Runtime.getRuntime().exit(0)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package com.tangem.feature.tester.di
|
||||
|
||||
import android.content.Context
|
||||
import com.tangem.feature.tester.ActivityClassWrapper
|
||||
import com.tangem.feature.tester.apprestarter.DefaultAppRestarter
|
||||
import com.tangem.features.tester.api.AppRestarter
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.components.ActivityComponent
|
||||
import dagger.hilt.android.qualifiers.ActivityContext
|
||||
import dagger.hilt.android.scopes.ActivityScoped
|
||||
|
||||
@Module
|
||||
@InstallIn(ActivityComponent::class)
|
||||
internal object RestarterModule {
|
||||
|
||||
@Provides
|
||||
@ActivityScoped
|
||||
fun provideAppRestarter(
|
||||
@ActivityContext context: Context,
|
||||
activityClassWrapper: ActivityClassWrapper,
|
||||
): AppRestarter {
|
||||
return DefaultAppRestarter(context, activityClassWrapper)
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
|||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.tangem.core.navigation.finisher.AppFinisher
|
||||
import com.tangem.core.ui.UiDependencies
|
||||
import com.tangem.core.ui.components.SystemBarsEffect
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
|
|
@ -18,7 +19,6 @@ import com.tangem.feature.tester.presentation.menu.state.TesterMenuContentState
|
|||
import com.tangem.feature.tester.presentation.menu.ui.TesterMenuScreen
|
||||
import com.tangem.feature.tester.presentation.navigation.InnerTesterRouter
|
||||
import com.tangem.feature.tester.presentation.navigation.TesterScreen
|
||||
import com.tangem.features.tester.api.AppRestarter
|
||||
import com.tangem.features.tester.api.TesterRouter
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
|
@ -35,7 +35,7 @@ internal class TesterActivity : ComposeActivity() {
|
|||
lateinit var testerRouter: TesterRouter
|
||||
|
||||
@Inject
|
||||
lateinit var appRestarter: AppRestarter
|
||||
lateinit var appFinisher: AppFinisher
|
||||
|
||||
private val innerTesterRouter: InnerTesterRouter
|
||||
get() = requireNotNull(testerRouter as? InnerTesterRouter) {
|
||||
|
|
@ -70,7 +70,7 @@ internal class TesterActivity : ComposeActivity() {
|
|||
|
||||
composable(route = TesterScreen.FEATURE_TOGGLES.name) {
|
||||
val viewModel = hiltViewModel<FeatureTogglesViewModel>().apply {
|
||||
setupInteractions(innerTesterRouter, appRestarter)
|
||||
setupInteractions(innerTesterRouter, appFinisher)
|
||||
}
|
||||
|
||||
FeatureTogglesScreen(state = viewModel.uiState)
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import com.tangem.core.featuretoggle.manager.FeatureTogglesManager
|
||||
import com.tangem.core.featuretoggle.manager.MutableFeatureTogglesManager
|
||||
import com.tangem.core.navigation.finisher.AppFinisher
|
||||
import com.tangem.feature.tester.presentation.featuretoggles.models.TesterFeatureToggle
|
||||
import com.tangem.feature.tester.presentation.featuretoggles.state.FeatureTogglesContentState
|
||||
import com.tangem.feature.tester.presentation.navigation.InnerTesterRouter
|
||||
import com.tangem.features.tester.api.AppRestarter
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -40,10 +40,10 @@ internal class FeatureTogglesViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
/** Setup navigation state property by router [router] and provides app restart method by [appRestarter] */
|
||||
fun setupInteractions(router: InnerTesterRouter, appRestarter: AppRestarter) {
|
||||
fun setupInteractions(router: InnerTesterRouter, appFinisher: AppFinisher) {
|
||||
uiState = uiState.copy(
|
||||
onBackClick = router::back,
|
||||
onApplyChangesClick = appRestarter::restart,
|
||||
onApplyChangesClick = appFinisher::restart,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue