mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-1082 Shortcuts | Fix | Setting up shortcuts on home screen (#3022)
DROID-1082 Shortcuts | Fix | Setting up shortcuts on home screen
This commit is contained in:
parent
a6b639cc85
commit
49cfae9411
21 changed files with 188 additions and 175 deletions
|
@ -34,6 +34,11 @@ class DefaultAppActionManager(val context: Context) : AppActionManager {
|
|||
.build()
|
||||
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
|
||||
}
|
||||
is AppActionManager.Action.ClearAll -> {
|
||||
val shortcuts = ShortcutManagerCompat.getDynamicShortcuts(context).map { it.id }
|
||||
ShortcutManagerCompat.removeLongLivedShortcuts(context, shortcuts)
|
||||
ShortcutManagerCompat.removeAllDynamicShortcuts(context)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Error while setting up an app action: $action")
|
||||
|
|
|
@ -58,6 +58,7 @@ import com.anytypeio.anytype.di.feature.StartLoginModule
|
|||
import com.anytypeio.anytype.di.feature.TextBlockIconPickerModule
|
||||
import com.anytypeio.anytype.di.feature.ViewerFilterModule
|
||||
import com.anytypeio.anytype.di.feature.ViewerSortModule
|
||||
import com.anytypeio.anytype.di.feature.auth.DaggerDeletedAccountComponent
|
||||
import com.anytypeio.anytype.di.feature.auth.DeletedAccountModule
|
||||
import com.anytypeio.anytype.di.feature.cover.UnsplashModule
|
||||
import com.anytypeio.anytype.di.feature.home.DaggerHomeScreenComponent
|
||||
|
@ -105,10 +106,6 @@ class ComponentManager(
|
|||
main.authComponentBuilder().authModule(AuthModule).build()
|
||||
}
|
||||
|
||||
val deletedAccountComponent = Component {
|
||||
main.deletedAccountBuilder().module(DeletedAccountModule).build()
|
||||
}
|
||||
|
||||
val startLoginComponent = Component {
|
||||
authComponent
|
||||
.get()
|
||||
|
@ -839,6 +836,12 @@ class ComponentManager(
|
|||
.create(findComponentDependencies())
|
||||
}
|
||||
|
||||
val deletedAccountComponent = Component {
|
||||
DaggerDeletedAccountComponent
|
||||
.factory()
|
||||
.create(findComponentDependencies())
|
||||
}
|
||||
|
||||
class Component<T>(private val builder: () -> T) {
|
||||
|
||||
private var instance: T? = null
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.anytypeio.anytype.analytics.base.Analytics
|
|||
import com.anytypeio.anytype.core_utils.di.scope.PerScreen
|
||||
import com.anytypeio.anytype.domain.account.AccountStatusChannel
|
||||
import com.anytypeio.anytype.domain.account.InterceptAccountStatus
|
||||
import com.anytypeio.anytype.domain.auth.interactor.CheckAuthorizationStatus
|
||||
import com.anytypeio.anytype.domain.auth.interactor.Logout
|
||||
import com.anytypeio.anytype.domain.auth.interactor.ResumeAccount
|
||||
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
|
||||
|
@ -53,7 +54,8 @@ object MainEntryModule {
|
|||
interceptAccountStatus: InterceptAccountStatus,
|
||||
logout: Logout,
|
||||
relationsSubscriptionManager: RelationsSubscriptionManager,
|
||||
objectTypesSubscriptionManager: ObjectTypesSubscriptionManager
|
||||
objectTypesSubscriptionManager: ObjectTypesSubscriptionManager,
|
||||
checkAuthorizationStatus: CheckAuthorizationStatus
|
||||
): MainViewModelFactory = MainViewModelFactory(
|
||||
resumeAccount = resumeAccount,
|
||||
analytics = analytics,
|
||||
|
@ -62,7 +64,8 @@ object MainEntryModule {
|
|||
interceptAccountStatus = interceptAccountStatus,
|
||||
logout = logout,
|
||||
relationsSubscriptionManager = relationsSubscriptionManager,
|
||||
objectTypesSubscriptionManager = objectTypesSubscriptionManager
|
||||
objectTypesSubscriptionManager = objectTypesSubscriptionManager,
|
||||
checkAuthorizationStatus = checkAuthorizationStatus
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
|
@ -129,4 +132,11 @@ object MainEntryModule {
|
|||
provider,
|
||||
dispatchers
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
@PerScreen
|
||||
@Provides
|
||||
fun provideCheckAuthStatus(
|
||||
repo: AuthRepository
|
||||
): CheckAuthorizationStatus = CheckAuthorizationStatus(repo)
|
||||
}
|
|
@ -17,7 +17,6 @@ import com.anytypeio.anytype.domain.config.UserSettingsRepository
|
|||
import com.anytypeio.anytype.domain.device.PathProvider
|
||||
import com.anytypeio.anytype.domain.launch.GetDefaultPageType
|
||||
import com.anytypeio.anytype.domain.launch.SetDefaultEditorType
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.page.CreateObject
|
||||
import com.anytypeio.anytype.domain.search.ObjectTypesSubscriptionManager
|
||||
|
@ -162,7 +161,6 @@ interface SplashDependencies : ComponentDependencies {
|
|||
fun workspaceManager(): WorkspaceManager
|
||||
fun urlBuilder(): UrlBuilder
|
||||
fun analytics(): Analytics
|
||||
fun appActionManager(): AppActionManager
|
||||
fun relationsSubscriptionManager(): RelationsSubscriptionManager
|
||||
fun objectTypesSubscriptionManager(): ObjectTypesSubscriptionManager
|
||||
fun authRepository(): AuthRepository
|
||||
|
|
|
@ -1,28 +1,38 @@
|
|||
package com.anytypeio.anytype.di.feature.auth
|
||||
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_utils.di.scope.PerScreen
|
||||
import com.anytypeio.anytype.di.common.ComponentDependencies
|
||||
import com.anytypeio.anytype.domain.account.DateHelper
|
||||
import com.anytypeio.anytype.domain.account.RestoreAccount
|
||||
import com.anytypeio.anytype.domain.auth.interactor.Logout
|
||||
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
|
||||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.search.RelationsSubscriptionManager
|
||||
import com.anytypeio.anytype.ext.DefaultDateHelper
|
||||
import com.anytypeio.anytype.presentation.auth.account.DeletedAccountViewModel
|
||||
import com.anytypeio.anytype.ui.auth.account.DeletedAccountFragment
|
||||
import dagger.Binds
|
||||
import dagger.Component
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.Subcomponent
|
||||
|
||||
@Subcomponent(modules = [DeletedAccountModule::class])
|
||||
@Component(
|
||||
dependencies = [DeletedAccountDependencies::class],
|
||||
modules = [
|
||||
DeletedAccountModule::class,
|
||||
DeletedAccountModule.Declarations::class
|
||||
]
|
||||
)
|
||||
@PerScreen
|
||||
interface DeletedAccountSubcomponent {
|
||||
@Subcomponent.Builder
|
||||
interface Builder {
|
||||
fun module(module: DeletedAccountModule): Builder
|
||||
fun build(): DeletedAccountSubcomponent
|
||||
interface DeletedAccountComponent {
|
||||
|
||||
@Component.Factory
|
||||
interface Factory {
|
||||
fun create(dependencies: DeletedAccountDependencies): DeletedAccountComponent
|
||||
}
|
||||
|
||||
fun inject(fragment: DeletedAccountFragment)
|
||||
|
@ -30,22 +40,6 @@ interface DeletedAccountSubcomponent {
|
|||
|
||||
@Module
|
||||
object DeletedAccountModule {
|
||||
@JvmStatic
|
||||
@Provides
|
||||
@PerScreen
|
||||
fun provideViewModelFactory(
|
||||
restoreAccount: RestoreAccount,
|
||||
logout: Logout,
|
||||
helper: DateHelper,
|
||||
analytics: Analytics,
|
||||
relationsSubscriptionManager: RelationsSubscriptionManager
|
||||
): DeletedAccountViewModel.Factory = DeletedAccountViewModel.Factory(
|
||||
restoreAccount = restoreAccount,
|
||||
logout = logout,
|
||||
helper = helper,
|
||||
analytics = analytics,
|
||||
relationsSubscriptionManager = relationsSubscriptionManager
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
@Provides
|
||||
|
@ -75,4 +69,24 @@ object DeletedAccountModule {
|
|||
@Provides
|
||||
@PerScreen
|
||||
fun provideDateHelper(): DateHelper = DefaultDateHelper()
|
||||
|
||||
@Module
|
||||
interface Declarations {
|
||||
|
||||
@PerScreen
|
||||
@Binds
|
||||
fun bindViewModelFactory(
|
||||
factory: DeletedAccountViewModel.Factory
|
||||
): ViewModelProvider.Factory
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
interface DeletedAccountDependencies : ComponentDependencies {
|
||||
fun analytics(): Analytics
|
||||
fun appActionManager(): AppActionManager
|
||||
fun relationsSubscriptionManager(): RelationsSubscriptionManager
|
||||
fun dispatchers(): AppCoroutineDispatchers
|
||||
fun configStorage(): ConfigStorage
|
||||
fun authRepository(): AuthRepository
|
||||
}
|
|
@ -18,6 +18,7 @@ import com.anytypeio.anytype.domain.event.interactor.EventChannel
|
|||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.launch.GetDefaultPageType
|
||||
import com.anytypeio.anytype.domain.library.StorelessSubscriptionContainer
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.`object`.GetObject
|
||||
import com.anytypeio.anytype.domain.`object`.OpenObject
|
||||
|
@ -259,4 +260,5 @@ interface HomeScreenDependencies : ComponentDependencies {
|
|||
fun analytics(): Analytics
|
||||
fun eventChannel(): EventChannel
|
||||
fun dispatchers(): AppCoroutineDispatchers
|
||||
fun appActionManager(): AppActionManager
|
||||
}
|
|
@ -6,6 +6,7 @@ import com.anytypeio.anytype.domain.auth.interactor.Logout
|
|||
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
|
||||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.search.RelationsSubscriptionManager
|
||||
import com.anytypeio.anytype.ui.settings.LogoutWarningFragment
|
||||
import com.anytypeio.anytype.ui_settings.account.LogoutWarningViewModel
|
||||
|
@ -35,11 +36,13 @@ object LogoutWarningModule {
|
|||
fun provideViewModelFactory(
|
||||
logout: Logout,
|
||||
analytics: Analytics,
|
||||
relationsSubscriptionManager: RelationsSubscriptionManager
|
||||
relationsSubscriptionManager: RelationsSubscriptionManager,
|
||||
appActionManager: AppActionManager
|
||||
): LogoutWarningViewModel.Factory = LogoutWarningViewModel.Factory(
|
||||
logout = logout,
|
||||
analytics = analytics,
|
||||
relationsSubscriptionManager = relationsSubscriptionManager
|
||||
relationsSubscriptionManager = relationsSubscriptionManager,
|
||||
appActionManager = appActionManager
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
|
|
|
@ -19,7 +19,7 @@ import com.anytypeio.anytype.di.feature.ObjectTypeChangeSubComponent
|
|||
import com.anytypeio.anytype.di.feature.OtherSettingsSubComponent
|
||||
import com.anytypeio.anytype.di.feature.PageNavigationSubComponent
|
||||
import com.anytypeio.anytype.di.feature.SplashDependencies
|
||||
import com.anytypeio.anytype.di.feature.auth.DeletedAccountSubcomponent
|
||||
import com.anytypeio.anytype.di.feature.auth.DeletedAccountDependencies
|
||||
import com.anytypeio.anytype.di.feature.home.HomeScreenDependencies
|
||||
import com.anytypeio.anytype.di.feature.library.LibraryDependencies
|
||||
import com.anytypeio.anytype.di.feature.relations.RelationCreateFromLibraryDependencies
|
||||
|
@ -71,7 +71,8 @@ interface MainComponent :
|
|||
TypeEditDependencies,
|
||||
RelationCreateFromLibraryDependencies,
|
||||
RelationEditDependencies,
|
||||
SplashDependencies {
|
||||
SplashDependencies,
|
||||
DeletedAccountDependencies {
|
||||
fun inject(app: AndroidApplication)
|
||||
|
||||
fun editorComponentBuilder(): EditorSubComponent.Builder
|
||||
|
@ -92,8 +93,6 @@ interface MainComponent :
|
|||
//region Auth
|
||||
|
||||
fun authComponentBuilder(): AuthSubComponent.Builder
|
||||
fun deletedAccountBuilder(): DeletedAccountSubcomponent.Builder
|
||||
|
||||
//endregion
|
||||
|
||||
//region Settings
|
||||
|
@ -162,4 +161,9 @@ private abstract class ComponentDependenciesModule private constructor() {
|
|||
@ComponentDependenciesKey(SplashDependencies::class)
|
||||
abstract fun provideSplashDependencies(component: MainComponent): ComponentDependencies
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ComponentDependenciesKey(DeletedAccountDependencies::class)
|
||||
abstract fun provideDeletedAccountDependencies(component: MainComponent): ComponentDependencies
|
||||
|
||||
}
|
|
@ -76,7 +76,7 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), AppNavigation.Pr
|
|||
}
|
||||
launch {
|
||||
vm.commands.collect { command ->
|
||||
when(command) {
|
||||
when (command) {
|
||||
is Command.ShowDeletedAccountScreen -> {
|
||||
navigator.deletedAccountScreen(
|
||||
deadline = command.deadline
|
||||
|
@ -85,6 +85,15 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), AppNavigation.Pr
|
|||
is Command.LogoutDueToAccountDeletion -> {
|
||||
navigator.logout()
|
||||
}
|
||||
is Command.OpenCreateNewType -> {
|
||||
findNavController(R.id.fragment)
|
||||
.navigate(
|
||||
R.id.action_global_createObjectFragment,
|
||||
bundleOf(
|
||||
CreateObjectFragment.TYPE_KEY to command.type
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,16 +123,8 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), AppNavigation.Pr
|
|||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
if (intent != null && intent.action == Intent.ACTION_VIEW) {
|
||||
val bundle = intent.extras
|
||||
if (bundle != null) {
|
||||
val type = bundle.getString(DefaultAppActionManager.ACTION_CREATE_NEW_TYPE_KEY)
|
||||
if (type != null) {
|
||||
findNavController(R.id.fragment)
|
||||
.navigate(
|
||||
R.id.action_global_createObjectFragment,
|
||||
bundleOf(CreateObjectFragment.TYPE_KEY to type)
|
||||
)
|
||||
}
|
||||
intent.extras?.getString(DefaultAppActionManager.ACTION_CREATE_NEW_TYPE_KEY)?.let {
|
||||
vm.onIntentCreateObject(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,5 +8,6 @@ interface AppActionManager {
|
|||
|
||||
sealed class Action {
|
||||
data class CreateNew(val type: Id, val name: String) : Action()
|
||||
object ClearAll: Action()
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
org.gradle.parallel=true
|
||||
org.gradle.caching=true
|
||||
org.gradle.jvmargs=-Xmx3072m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
org.gradle.jvmargs=-Xmx3072m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
org.gradle.configureondemand=true
|
||||
|
||||
android.useAndroidX=true
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.anytypeio.anytype.domain.account.RestoreAccount
|
|||
import com.anytypeio.anytype.domain.auth.interactor.Logout
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Interactor
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.search.RelationsSubscriptionManager
|
||||
import com.anytypeio.anytype.presentation.common.BaseViewModel
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
|
@ -21,6 +22,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import java.math.RoundingMode
|
||||
import javax.inject.Inject
|
||||
import kotlin.time.DurationUnit.DAYS
|
||||
import kotlin.time.DurationUnit.MILLISECONDS
|
||||
import kotlin.time.toDuration
|
||||
|
@ -30,7 +32,8 @@ class DeletedAccountViewModel(
|
|||
private val logout: Logout,
|
||||
private val dateHelper: DateHelper,
|
||||
private val analytics: Analytics,
|
||||
private val relationsSubscriptionManager: RelationsSubscriptionManager
|
||||
private val relationsSubscriptionManager: RelationsSubscriptionManager,
|
||||
private val appActionManager: AppActionManager
|
||||
) : BaseViewModel() {
|
||||
|
||||
val commands = MutableSharedFlow<Command>(replay = 0)
|
||||
|
@ -103,6 +106,10 @@ class DeletedAccountViewModel(
|
|||
proceedWithLoggingOut()
|
||||
}
|
||||
|
||||
private fun clearShortcuts() {
|
||||
appActionManager.setup(AppActionManager.Action.ClearAll)
|
||||
}
|
||||
|
||||
private fun proceedWithLoggingOut() {
|
||||
if (!isLoggingOut.value) {
|
||||
viewModelScope.launch {
|
||||
|
@ -115,6 +122,7 @@ class DeletedAccountViewModel(
|
|||
isLoggingOut.value = true
|
||||
}
|
||||
is Interactor.Status.Success -> {
|
||||
clearShortcuts()
|
||||
isLoggingOut.value = false
|
||||
relationsSubscriptionManager.onStop()
|
||||
commands.emit(Command.Logout)
|
||||
|
@ -134,12 +142,13 @@ class DeletedAccountViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
class Factory(
|
||||
class Factory @Inject constructor(
|
||||
private val restoreAccount: RestoreAccount,
|
||||
private val logout: Logout,
|
||||
private val helper: DateHelper,
|
||||
private val analytics: Analytics,
|
||||
private val relationsSubscriptionManager: RelationsSubscriptionManager
|
||||
private val relationsSubscriptionManager: RelationsSubscriptionManager,
|
||||
private val appActionManager: AppActionManager
|
||||
) : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
|
@ -148,7 +157,8 @@ class DeletedAccountViewModel(
|
|||
logout = logout,
|
||||
dateHelper = helper,
|
||||
analytics = analytics,
|
||||
relationsSubscriptionManager = relationsSubscriptionManager
|
||||
relationsSubscriptionManager = relationsSubscriptionManager,
|
||||
appActionManager = appActionManager
|
||||
) as T
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.anytypeio.anytype.core_models.Payload
|
|||
import com.anytypeio.anytype.core_models.Position
|
||||
import com.anytypeio.anytype.core_models.WidgetLayout
|
||||
import com.anytypeio.anytype.core_models.ext.process
|
||||
import com.anytypeio.anytype.core_utils.ext.letNotNull
|
||||
import com.anytypeio.anytype.core_utils.ext.replace
|
||||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
import com.anytypeio.anytype.domain.base.Resultat
|
||||
|
@ -21,7 +22,9 @@ import com.anytypeio.anytype.domain.bin.EmptyBin
|
|||
import com.anytypeio.anytype.domain.block.interactor.Move
|
||||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.launch.GetDefaultPageType
|
||||
import com.anytypeio.anytype.domain.library.StorelessSubscriptionContainer
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.misc.Reducer
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.`object`.GetObject
|
||||
|
@ -86,6 +89,8 @@ class HomeScreenViewModel(
|
|||
private val move: Move,
|
||||
private val emptyBin: EmptyBin,
|
||||
private val unsubscriber: Unsubscriber,
|
||||
private val getDefaultPageType: GetDefaultPageType,
|
||||
private val appActionManager: AppActionManager
|
||||
) : NavigationViewModel<HomeScreenViewModel.Navigation>(),
|
||||
Reducer<ObjectView, Payload>,
|
||||
WidgetActiveViewStateHolder by widgetActiveViewStateHolder,
|
||||
|
@ -223,6 +228,7 @@ class HomeScreenViewModel(
|
|||
}
|
||||
|
||||
proceedWithDispatches()
|
||||
setupShortcuts()
|
||||
}
|
||||
|
||||
private fun proceedWithOpeningWidgetObject(widgetObject: Id) {
|
||||
|
@ -693,6 +699,26 @@ class HomeScreenViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
private fun setupShortcuts() {
|
||||
viewModelScope.launch {
|
||||
getDefaultPageType.execute(Unit).fold(
|
||||
onSuccess = {
|
||||
Pair(it.name, it.type).letNotNull { name, type ->
|
||||
appActionManager.setup(
|
||||
AppActionManager.Action.CreateNew(
|
||||
type = type,
|
||||
name = name
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
onFailure = {
|
||||
Timber.d("Error while setting up app shortcuts")
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Navigation {
|
||||
data class OpenObject(val ctx: Id) : Navigation()
|
||||
data class OpenSet(val ctx: Id) : Navigation()
|
||||
|
@ -719,7 +745,9 @@ class HomeScreenViewModel(
|
|||
private val getObject: GetObject,
|
||||
private val move: Move,
|
||||
private val emptyBin: EmptyBin,
|
||||
private val unsubscriber: Unsubscriber
|
||||
private val unsubscriber: Unsubscriber,
|
||||
private val getDefaultPageType: GetDefaultPageType,
|
||||
private val appActionManager: AppActionManager
|
||||
) : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T = HomeScreenViewModel(
|
||||
|
@ -742,7 +770,9 @@ class HomeScreenViewModel(
|
|||
urlBuilder = urlBuilder,
|
||||
move = move,
|
||||
emptyBin = emptyBin,
|
||||
unsubscriber = unsubscriber
|
||||
unsubscriber = unsubscriber,
|
||||
getDefaultPageType = getDefaultPageType,
|
||||
appActionManager = appActionManager
|
||||
) as T
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,13 @@ import com.anytypeio.anytype.analytics.base.Analytics
|
|||
import com.anytypeio.anytype.analytics.base.updateUserProperties
|
||||
import com.anytypeio.anytype.analytics.props.UserProperty
|
||||
import com.anytypeio.anytype.core_models.AccountStatus
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Wallpaper
|
||||
import com.anytypeio.anytype.domain.account.InterceptAccountStatus
|
||||
import com.anytypeio.anytype.domain.auth.interactor.CheckAuthorizationStatus
|
||||
import com.anytypeio.anytype.domain.auth.interactor.Logout
|
||||
import com.anytypeio.anytype.domain.auth.interactor.ResumeAccount
|
||||
import com.anytypeio.anytype.domain.auth.model.AuthStatus
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Interactor
|
||||
import com.anytypeio.anytype.domain.search.ObjectTypesSubscriptionManager
|
||||
|
@ -30,7 +33,8 @@ class MainViewModel(
|
|||
private val interceptAccountStatus: InterceptAccountStatus,
|
||||
private val logout: Logout,
|
||||
private val relationsSubscriptionManager: RelationsSubscriptionManager,
|
||||
private val objectTypesSubscriptionManager: ObjectTypesSubscriptionManager
|
||||
private val objectTypesSubscriptionManager: ObjectTypesSubscriptionManager,
|
||||
private val checkAuthorizationStatus: CheckAuthorizationStatus,
|
||||
) : ViewModel() {
|
||||
|
||||
val wallpaper = MutableStateFlow<Wallpaper>(Wallpaper.Default)
|
||||
|
@ -112,8 +116,23 @@ class MainViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
fun onIntentCreateObject(type: Id) {
|
||||
viewModelScope.launch {
|
||||
checkAuthorizationStatus(Unit).process(
|
||||
failure = { e -> Timber.e(e, "Error while checking auth status") },
|
||||
success = { status ->
|
||||
if (status == AuthStatus.AUTHORIZED) {
|
||||
commands.emit(Command.OpenCreateNewType(type))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Command {
|
||||
data class ShowDeletedAccountScreen(val deadline: Long) : Command()
|
||||
object LogoutDueToAccountDeletion : Command()
|
||||
|
||||
class OpenCreateNewType(val type: Id) : Command()
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.domain.account.InterceptAccountStatus
|
||||
import com.anytypeio.anytype.domain.auth.interactor.CheckAuthorizationStatus
|
||||
import com.anytypeio.anytype.domain.auth.interactor.Logout
|
||||
import com.anytypeio.anytype.domain.auth.interactor.ResumeAccount
|
||||
import com.anytypeio.anytype.domain.search.ObjectTypesSubscriptionManager
|
||||
|
@ -19,8 +20,9 @@ class MainViewModelFactory(
|
|||
private val interceptAccountStatus: InterceptAccountStatus,
|
||||
private val logout: Logout,
|
||||
private val relationsSubscriptionManager: RelationsSubscriptionManager,
|
||||
private val objectTypesSubscriptionManager: ObjectTypesSubscriptionManager
|
||||
) : ViewModelProvider.Factory {
|
||||
private val objectTypesSubscriptionManager: ObjectTypesSubscriptionManager,
|
||||
private val checkAuthorizationStatus: CheckAuthorizationStatus,
|
||||
) : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(
|
||||
modelClass: Class<T>
|
||||
|
@ -32,6 +34,7 @@ class MainViewModelFactory(
|
|||
interceptAccountStatus = interceptAccountStatus,
|
||||
logout = logout,
|
||||
relationsSubscriptionManager = relationsSubscriptionManager,
|
||||
objectTypesSubscriptionManager = objectTypesSubscriptionManager
|
||||
objectTypesSubscriptionManager = objectTypesSubscriptionManager,
|
||||
checkAuthorizationStatus = checkAuthorizationStatus
|
||||
) as T
|
||||
}
|
|
@ -40,9 +40,7 @@ class SplashViewModel(
|
|||
private val launchWallet: LaunchWallet,
|
||||
private val launchAccount: LaunchAccount,
|
||||
private val getLastOpenedObject: GetLastOpenedObject,
|
||||
private val getDefaultPageType: GetDefaultPageType,
|
||||
private val createObject: CreateObject,
|
||||
private val appActionManager: AppActionManager,
|
||||
private val relationsSubscriptionManager: RelationsSubscriptionManager,
|
||||
private val objectTypesSubscriptionManager: ObjectTypesSubscriptionManager
|
||||
) : ViewModel() {
|
||||
|
@ -101,7 +99,7 @@ class SplashViewModel(
|
|||
val props = Props.empty()
|
||||
sendEvent(startTime, openAccount, props)
|
||||
proceedWithGlobalSubscriptions()
|
||||
setupShortcutsAndStartApp()
|
||||
commands.emit(Command.CheckAppStartIntent)
|
||||
},
|
||||
failure = { e ->
|
||||
Timber.e(e, "Error while launching account")
|
||||
|
@ -111,27 +109,6 @@ class SplashViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
private fun setupShortcutsAndStartApp() {
|
||||
viewModelScope.launch {
|
||||
getDefaultPageType.execute(Unit).fold(
|
||||
onSuccess = {
|
||||
Pair(it.name, it.type).letNotNull { name, type ->
|
||||
appActionManager.setup(
|
||||
AppActionManager.Action.CreateNew(
|
||||
type = type,
|
||||
name = name
|
||||
)
|
||||
)
|
||||
}
|
||||
commands.emit(Command.CheckAppStartIntent)
|
||||
},
|
||||
onFailure = {
|
||||
commands.emit(Command.CheckAppStartIntent)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun proceedWithGlobalSubscriptions() {
|
||||
relationsSubscriptionManager.onStart()
|
||||
objectTypesSubscriptionManager.onStart()
|
||||
|
|
|
@ -26,8 +26,6 @@ class SplashViewModelFactory @Inject constructor(
|
|||
private val launchWallet: LaunchWallet,
|
||||
private val analytics: Analytics,
|
||||
private val getLastOpenedObject: GetLastOpenedObject,
|
||||
private val getDefaultPageType: GetDefaultPageType,
|
||||
private val appActionManager: AppActionManager,
|
||||
private val createObject: CreateObject,
|
||||
private val relationsSubscriptionManager: RelationsSubscriptionManager,
|
||||
private val objectTypesSubscriptionManager: ObjectTypesSubscriptionManager
|
||||
|
@ -41,8 +39,6 @@ class SplashViewModelFactory @Inject constructor(
|
|||
launchWallet = launchWallet,
|
||||
analytics = analytics,
|
||||
getLastOpenedObject = getLastOpenedObject,
|
||||
getDefaultPageType = getDefaultPageType,
|
||||
appActionManager = appActionManager,
|
||||
createObject = createObject,
|
||||
relationsSubscriptionManager = relationsSubscriptionManager,
|
||||
objectTypesSubscriptionManager = objectTypesSubscriptionManager
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.anytypeio.anytype.domain.auth.interactor.Logout
|
|||
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
|
||||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.search.RelationsSubscriptionManager
|
||||
import com.anytypeio.anytype.presentation.auth.account.DeletedAccountViewModel
|
||||
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
|
||||
|
@ -50,6 +51,9 @@ class DeleteAccountViewModelTest {
|
|||
@Mock
|
||||
lateinit var analytics: Analytics
|
||||
|
||||
@Mock
|
||||
lateinit var appActionManager: AppActionManager
|
||||
|
||||
@Mock
|
||||
private lateinit var relationsSubscriptionManager: RelationsSubscriptionManager
|
||||
|
||||
|
@ -75,7 +79,8 @@ class DeleteAccountViewModelTest {
|
|||
logout = logout,
|
||||
dateHelper = helper,
|
||||
analytics = analytics,
|
||||
relationsSubscriptionManager = relationsSubscriptionManager
|
||||
relationsSubscriptionManager = relationsSubscriptionManager,
|
||||
appActionManager = appActionManager
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -23,9 +23,11 @@ import com.anytypeio.anytype.domain.block.interactor.Move
|
|||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.config.Gateway
|
||||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.launch.GetDefaultPageType
|
||||
import com.anytypeio.anytype.domain.library.StoreSearchByIdsParams
|
||||
import com.anytypeio.anytype.domain.library.StoreSearchParams
|
||||
import com.anytypeio.anytype.domain.library.StorelessSubscriptionContainer
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.`object`.GetObject
|
||||
import com.anytypeio.anytype.domain.`object`.OpenObject
|
||||
|
@ -121,6 +123,12 @@ class HomeScreenViewModelTest {
|
|||
@Mock
|
||||
lateinit var unsubscriber: Unsubscriber
|
||||
|
||||
@Mock
|
||||
lateinit var getDefaultPageType: GetDefaultPageType
|
||||
|
||||
@Mock
|
||||
lateinit var appActionManager: AppActionManager
|
||||
|
||||
@Mock
|
||||
lateinit var gateway: Gateway
|
||||
|
||||
|
@ -1836,7 +1844,9 @@ class HomeScreenViewModelTest {
|
|||
urlBuilder = urlBuilder,
|
||||
move = move,
|
||||
emptyBin = emptyBin,
|
||||
unsubscriber = unsubscriber
|
||||
unsubscriber = unsubscriber,
|
||||
getDefaultPageType = getDefaultPageType,
|
||||
appActionManager = appActionManager
|
||||
)
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.anytypeio.anytype.presentation.splash
|
|||
|
||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_models.ObjectTypeIds
|
||||
import com.anytypeio.anytype.domain.auth.interactor.CheckAuthorizationStatus
|
||||
import com.anytypeio.anytype.domain.auth.interactor.GetLastOpenedObject
|
||||
import com.anytypeio.anytype.domain.auth.interactor.LaunchAccount
|
||||
|
@ -10,24 +9,19 @@ import com.anytypeio.anytype.domain.auth.interactor.LaunchWallet
|
|||
import com.anytypeio.anytype.domain.auth.model.AuthStatus
|
||||
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.base.Resultat
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import com.anytypeio.anytype.domain.launch.GetDefaultPageType
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.page.CreateObject
|
||||
import com.anytypeio.anytype.domain.search.ObjectTypesSubscriptionManager
|
||||
import com.anytypeio.anytype.domain.search.RelationsSubscriptionManager
|
||||
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.mockito.kotlin.any
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.doThrow
|
||||
import org.mockito.kotlin.eq
|
||||
import org.mockito.kotlin.stub
|
||||
import org.mockito.kotlin.times
|
||||
|
@ -65,12 +59,6 @@ class SplashViewModelTest {
|
|||
@Mock
|
||||
lateinit var createObject: CreateObject
|
||||
|
||||
@Mock
|
||||
lateinit var appActionManager: AppActionManager
|
||||
|
||||
@Mock
|
||||
private lateinit var getDefaultPageType: GetDefaultPageType
|
||||
|
||||
@Mock
|
||||
private lateinit var relationsSubscriptionManager: RelationsSubscriptionManager
|
||||
|
||||
|
@ -95,9 +83,7 @@ class SplashViewModelTest {
|
|||
launchWallet = launchWallet,
|
||||
analytics = analytics,
|
||||
getLastOpenedObject = getLastOpenedObject,
|
||||
getDefaultPageType = getDefaultPageType,
|
||||
createObject = createObject,
|
||||
appActionManager = appActionManager,
|
||||
relationsSubscriptionManager = relationsSubscriptionManager,
|
||||
objectTypesSubscriptionManager = objectTypesSubscriptionManager
|
||||
)
|
||||
|
@ -122,63 +108,6 @@ class SplashViewModelTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Ignore("https://github.com/mockito/mockito-kotlin/issues/456")
|
||||
@Test
|
||||
fun `should invoke checkAuthorizationStatus when getDefaultPageType on error `() {
|
||||
val status = AuthStatus.AUTHORIZED
|
||||
val response = Either.Right(status)
|
||||
|
||||
stubCheckAuthStatus(response)
|
||||
stubLaunchWallet()
|
||||
stubLaunchAccount()
|
||||
stubGetLastOpenedObject()
|
||||
getDefaultPageType.stub {
|
||||
onBlocking { execute(Unit) } doThrow Exception("error")
|
||||
}
|
||||
|
||||
initViewModel()
|
||||
|
||||
runBlocking {
|
||||
verify(getDefaultPageType, times(1)).execute(any())
|
||||
verify(checkAuthorizationStatus, times(1)).invoke(any())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should invoke checkAuthorizationStatus when getDefaultPageType is object type `() {
|
||||
val status = AuthStatus.AUTHORIZED
|
||||
val response = Either.Right(status)
|
||||
|
||||
stubCheckAuthStatus(response)
|
||||
stubLaunchWallet()
|
||||
stubLaunchAccount()
|
||||
stubGetLastOpenedObject()
|
||||
stubGetDefaultObjectType(type = ObjectTypeIds.PAGE)
|
||||
|
||||
initViewModel()
|
||||
|
||||
runBlocking {
|
||||
verify(getDefaultPageType, times(1)).execute(any())
|
||||
verify(checkAuthorizationStatus, times(1)).invoke(any())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should not invoke checkAuthorizationStatus when getDefaultPageType is null`() {
|
||||
val status = AuthStatus.AUTHORIZED
|
||||
val response = Either.Right(status)
|
||||
|
||||
stubCheckAuthStatus(response)
|
||||
stubLaunchWallet()
|
||||
stubLaunchAccount()
|
||||
stubGetLastOpenedObject()
|
||||
stubGetDefaultObjectType(type = null)
|
||||
|
||||
runBlocking {
|
||||
verify(checkAuthorizationStatus, times(0)).invoke(any())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should start launching wallet if user is authorized`() {
|
||||
|
||||
|
@ -190,7 +119,6 @@ class SplashViewModelTest {
|
|||
stubLaunchWallet()
|
||||
stubLaunchAccount()
|
||||
stubGetLastOpenedObject()
|
||||
stubGetDefaultObjectType(type = ObjectTypeIds.PAGE)
|
||||
|
||||
initViewModel()
|
||||
|
||||
|
@ -210,7 +138,6 @@ class SplashViewModelTest {
|
|||
stubLaunchWallet()
|
||||
stubLaunchAccount()
|
||||
stubGetLastOpenedObject()
|
||||
stubGetDefaultObjectType(type = ObjectTypeIds.PAGE)
|
||||
|
||||
initViewModel()
|
||||
|
||||
|
@ -248,14 +175,4 @@ class SplashViewModelTest {
|
|||
}
|
||||
}
|
||||
|
||||
private fun stubGetDefaultObjectType(type: String? = null, name: String? = null) {
|
||||
getDefaultPageType.stub {
|
||||
onBlocking { execute(Unit) } doReturn Resultat.success(
|
||||
GetDefaultPageType.Response(
|
||||
type,
|
||||
name
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ import com.anytypeio.anytype.analytics.base.sendEvent
|
|||
import com.anytypeio.anytype.analytics.props.Props
|
||||
import com.anytypeio.anytype.domain.auth.interactor.Logout
|
||||
import com.anytypeio.anytype.domain.base.Interactor
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.search.RelationsSubscriptionManager
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
@ -19,7 +20,8 @@ import timber.log.Timber
|
|||
class LogoutWarningViewModel(
|
||||
private val logout: Logout,
|
||||
private val analytics: Analytics,
|
||||
private val relationsSubscriptionManager: RelationsSubscriptionManager
|
||||
private val relationsSubscriptionManager: RelationsSubscriptionManager,
|
||||
private val appActionManager: AppActionManager
|
||||
) : ViewModel() {
|
||||
|
||||
val commands = MutableSharedFlow<Command>(replay = 0)
|
||||
|
@ -45,6 +47,7 @@ class LogoutWarningViewModel(
|
|||
)
|
||||
)
|
||||
)
|
||||
appActionManager.setup(AppActionManager.Action.ClearAll)
|
||||
relationsSubscriptionManager.onStop()
|
||||
isLoggingOut.value = false
|
||||
commands.emit(Command.Logout)
|
||||
|
@ -71,14 +74,16 @@ class LogoutWarningViewModel(
|
|||
class Factory(
|
||||
private val logout: Logout,
|
||||
private val analytics: Analytics,
|
||||
private val relationsSubscriptionManager: RelationsSubscriptionManager
|
||||
private val relationsSubscriptionManager: RelationsSubscriptionManager,
|
||||
private val appActionManager: AppActionManager
|
||||
) : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return LogoutWarningViewModel(
|
||||
logout = logout,
|
||||
analytics = analytics,
|
||||
relationsSubscriptionManager = relationsSubscriptionManager
|
||||
relationsSubscriptionManager = relationsSubscriptionManager,
|
||||
appActionManager = appActionManager
|
||||
) as T
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue