1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

add splash screen logic

This commit is contained in:
Konstantin Ivanov 2019-10-29 14:19:44 +00:00 committed by Evgenii Kozlov
parent c86534ba1a
commit f3ea279263
35 changed files with 448 additions and 162 deletions

View file

@ -64,6 +64,13 @@ class ComponentManager(private val main: MainComponent) {
.build()
}
val splashLoginComponent = Component {
main
.splashComponentBuilder()
.module(SplashModule())
.build()
}
val keychainPhraseComponent = Component {
main
.keychainPhraseComponentBuilder()

View file

@ -0,0 +1,43 @@
package com.agileburo.anytype.di.feature
import com.agileburo.anytype.core_utils.di.scope.PerScreen
import com.agileburo.anytype.domain.auth.interactor.CheckAuthorizationStatus
import com.agileburo.anytype.domain.auth.repo.AuthRepository
import com.agileburo.anytype.presentation.splash.SplashViewModelFactory
import com.agileburo.anytype.ui.splash.SplashFragment
import dagger.Module
import dagger.Provides
import dagger.Subcomponent
/**
* Created by Konstantin Ivanov
* email : ki@agileburo.com
* on 2019-10-21.
*/
@PerScreen
@Subcomponent(modules = [SplashModule::class])
interface SplashSubComponent {
@Subcomponent.Builder
interface Builder {
fun build(): SplashSubComponent
fun module(module: SplashModule): Builder
}
fun inject(fragment: SplashFragment)
}
@Module
class SplashModule {
@PerScreen
@Provides
fun provideSplashViewModelFactory(checkAuthorizationStatus: CheckAuthorizationStatus) =
SplashViewModelFactory(checkAuthorizationStatus)
@PerScreen
@Provides
fun provideCheckAuthorizationStatus(authRepository: AuthRepository) =
CheckAuthorizationStatus(authRepository)
}

View file

@ -4,6 +4,7 @@ import com.agileburo.anytype.di.feature.AuthSubComponent
import com.agileburo.anytype.di.feature.DesktopSubComponent
import com.agileburo.anytype.di.feature.KeychainPhraseSubComponent
import com.agileburo.anytype.di.feature.ProfileSubComponent
import com.agileburo.anytype.di.feature.SplashSubComponent
import dagger.Component
import javax.inject.Singleton
@ -17,6 +18,7 @@ import javax.inject.Singleton
interface MainComponent {
fun authComponentBuilder(): AuthSubComponent.Builder
fun profileComponentBuilder(): ProfileSubComponent.Builder
fun splashComponentBuilder(): SplashSubComponent.Builder
fun keychainPhraseComponentBuilder(): KeychainPhraseSubComponent.Builder
fun desktopComponentBuilder(): DesktopSubComponent.Builder
}

View file

@ -10,8 +10,20 @@ class Navigator : AppNavigation {
private var navController: NavController? = null
override fun startSplashFromDesktop() {
navController?.navigate(R.id.action_profileScreen_to_splashFragment)
}
override fun startDesktopFromSplash() {
navController?.navigate(R.id.action_splashScreen_to_desktopScreen)
}
override fun startDesktopFromLogin() {
navController?.navigate(R.id.action_global_desktopScreen)
}
override fun startLogin() {
navController?.navigate(R.id.action_open_start_login)
navController?.navigate(R.id.action_splashFragment_to_login_nav)
}
override fun createProfile() {
@ -34,9 +46,7 @@ class Navigator : AppNavigation {
navController?.navigate(R.id.action_select_account)
}
override fun workspace() {
navController?.navigate(R.id.action_open_desktop_screen)
}
override fun workspace() {}
override fun openProfile() {
navController?.navigate(R.id.action_open_profile)
@ -47,7 +57,8 @@ class Navigator : AppNavigation {
}
override fun openKeychainScreen() {
navController?.navigate(R.id.action_open_keychain)
//todo Добавить переход на этот экран в nav_graph
//navController?.navigate(R.id.action_open_keychain)
}
override fun setupSelectedAccount(id: String) {

View file

@ -20,6 +20,10 @@ abstract class NavigationFragment(
val navigation = (requireActivity() as AppNavigation.Provider).nav()
when (command) {
is Command.StartSplashFromDesktop -> navigation.startSplashFromDesktop()
is Command.StartDesktopFromLogin -> navigation.startDesktopFromLogin()
is Command.StartDesktopFromSplash -> navigation.startDesktopFromSplash()
is Command.OpenStartLoginScreen -> navigation.startLogin()
is Command.OpenCreateProfile -> navigation.createProfile()
is Command.ChoosePinCodeScreen -> navigation.choosePinCode()

View file

@ -0,0 +1,42 @@
package com.agileburo.anytype.ui.splash
import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProviders
import com.agileburo.anytype.R
import com.agileburo.anytype.di.common.componentManager
import com.agileburo.anytype.presentation.splash.SplashViewModel
import com.agileburo.anytype.presentation.splash.SplashViewModelFactory
import com.agileburo.anytype.ui.base.NavigationFragment
import javax.inject.Inject
/**
* Created by Konstantin Ivanov
* email : ki@agileburo.com
* on 2019-10-21.
*/
class SplashFragment : NavigationFragment(R.layout.fragment_splash) {
@Inject
lateinit var factory: SplashViewModelFactory
private val vm by lazy {
ViewModelProviders
.of(this, factory)
.get(SplashViewModel::class.java)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
vm.navigation.observe(this, navObserver)
vm.onViewCreated()
}
override fun injectDependencies() {
componentManager().splashLoginComponent.get().inject(this)
}
override fun releaseDependencies() {
componentManager().splashLoginComponent.release()
}
}

View file

@ -17,7 +17,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:duration="300"
android:fromXDelta="-100%"
android:fromYDelta="0%"
android:toXDelta="0%"

View file

@ -17,7 +17,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="700"
android:duration="300"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"

View file

@ -17,7 +17,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="700"
android:duration="300"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="-100%"

View file

@ -17,7 +17,7 @@
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:duration="300"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="100%"

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F7F5F0">
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:srcCompat="@drawable/anytype_logo" />
</FrameLayout>

View file

@ -3,128 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_navigation"
app:startDestination="@id/startLoginScreen">
<fragment
android:id="@+id/startLoginScreen"
android:name="com.agileburo.anytype.ui.auth.StartLoginFragment"
android:label="StartLoginFragment"
tools:layout="@layout/fragment_start_login">
<action
android:id="@+id/action_open_sign_in"
app:destination="@id/keychainLoginScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
<action
android:id="@+id/action_open_sign_up"
app:destination="@id/createAccountScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/createAccountScreen"
android:name="com.agileburo.anytype.ui.auth.account.CreateAccountFragment"
android:label="StartLoginFragment"
tools:layout="@layout/fragment_create_account">
<action
android:id="@+id/action_setup_new_account"
app:destination="@id/setupNewAccountScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/setupNewAccountScreen"
android:name="com.agileburo.anytype.ui.auth.account.SetupNewAccountFragment"
android:label="SetupAccount"
tools:layout="@layout/fragment_setup_new_account">
<action
android:id="@+id/action_open_congratulation_screen"
app:destination="@id/congratulationScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/keychainLoginScreen"
android:name="com.agileburo.anytype.ui.auth.KeychainLoginFragment"
android:label="KeychainLogin"
tools:layout="@layout/fragment_keychain_login">
<action
android:id="@+id/action_select_account"
app:destination="@id/selectAccountScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/selectAccountScreen"
android:name="com.agileburo.anytype.ui.auth.account.SelectAccountFragment"
android:label="ChooseProfileScreen"
tools:layout="@layout/fragment_select_account">
<action
android:id="@+id/action_setup_selected_account"
app:destination="@id/setupSelectedAccountScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/setupSelectedAccountScreen"
android:name="com.agileburo.anytype.ui.auth.account.SetupSelectedAccountFragment"
android:label="SetupAccount"
tools:layout="@layout/fragment_setup_selected_account">
<action
android:id="@+id/action_open_congratulation_screen"
app:destination="@id/congratulationScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
<argument
android:name="selected_account_id"
android:defaultValue="0"
app:argType="integer"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/choosePinCodeScreen"
android:name="com.agileburo.anytype.feature_login.ui.login.presentation.ui.pin.ChoosePinCodeFragment"
android:label="StartLoginFragment"
tools:layout="@layout/fragment_choose_pin_code" />
<fragment
android:id="@+id/confirmPinCodeScreen"
android:name="com.agileburo.anytype.feature_login.ui.login.presentation.ui.pin.ConfirmPinCodeFragment"
android:label="StartLoginFragment"
tools:layout="@layout/fragment_confirm_pin_code" />
<fragment
android:id="@+id/congratulationScreen"
android:name="com.agileburo.anytype.ui.auth.CongratulationFragment"
android:label="StartLoginFragment"
tools:layout="@layout/fragment_congratulation">
<action
android:id="@+id/action_open_desktop_screen"
app:destination="@id/desktopScreen" />
</fragment>
app:startDestination="@id/splashScreen">
<fragment
android:id="@+id/desktopScreen"
@ -132,12 +11,12 @@
android:label="DesktopFragment"
tools:layout="@layout/fragment_desktop">
<action
android:id="@+id/action_open_profile"
app:destination="@id/profileScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
app:popExitAnim="@anim/slide_out_right"
android:id="@+id/action_open_profile"
app:destination="@id/profileScreen" />
</fragment>
<fragment
@ -146,18 +25,168 @@
android:label="ProfileScreen"
tools:layout="@layout/fragment_profile">
<action
android:id="@+id/action_open_start_login"
app:destination="@id/startLoginScreen"
app:enterAnim="@anim/fade_in"
app:exitAnim="@anim/fade_out" />
<action
android:id="@+id/action_open_keychain"
app:destination="@id/keychainDialog" />
android:id="@+id/action_profileScreen_to_splashFragment"
app:destination="@+id/main_navigation"
app:popUpTo="@+id/main_navigation"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/splashScreen"
android:name="com.agileburo.anytype.ui.splash.SplashFragment"
android:label="SplashFragment"
tools:layout="@layout/fragment_splash">
<action
android:id="@+id/action_splashScreen_to_desktopScreen"
app:destination="@id/desktopScreen"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@+id/splashScreen"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_splashFragment_to_login_nav"
app:destination="@id/login_nav"
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim"
app:popUpTo="@+id/splashScreen"
app:popUpToInclusive="true" />
</fragment>
<navigation
android:id="@+id/login_nav"
app:startDestination="@id/startLoginScreen" >
<fragment
android:id="@+id/selectAccountScreen"
android:name="com.agileburo.anytype.ui.auth.account.SelectAccountFragment"
android:label="ChooseProfileScreen"
tools:layout="@layout/fragment_select_account">
<action
android:id="@+id/action_setup_selected_account"
app:destination="@id/setupSelectedAccountScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:popUpTo="@+id/startLoginScreen"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/setupNewAccountScreen"
android:name="com.agileburo.anytype.ui.auth.account.SetupNewAccountFragment"
android:label="SetupAccount"
tools:layout="@layout/fragment_setup_new_account">
<action
android:id="@+id/action_open_congratulation_screen"
app:destination="@id/congratulationScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popUpTo="@+id/startLoginScreen"
app:popUpToInclusive="true" />
</fragment>
<dialog
android:id="@+id/keychainDialog"
android:name="com.agileburo.anytype.ui.profile.KeychainPhraseDialog"
tools:layout="@layout/dialog_keychain_phrase" />
<fragment
android:id="@+id/keychainLoginScreen"
android:name="com.agileburo.anytype.ui.auth.KeychainLoginFragment"
android:label="KeychainLogin"
tools:layout="@layout/fragment_keychain_login">
<action
android:id="@+id/action_select_account"
app:destination="@id/selectAccountScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/createAccountScreen"
android:name="com.agileburo.anytype.ui.auth.account.CreateAccountFragment"
android:label="StartLoginFragment"
tools:layout="@layout/fragment_create_account">
<action
android:id="@+id/action_setup_new_account"
app:destination="@id/setupNewAccountScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:popUpTo="@+id/startLoginScreen"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/congratulationScreen"
android:name="com.agileburo.anytype.ui.auth.CongratulationFragment"
android:label="StartLoginFragment"
tools:layout="@layout/fragment_congratulation"/>
<fragment
android:id="@+id/setupSelectedAccountScreen"
android:name="com.agileburo.anytype.ui.auth.account.SetupSelectedAccountFragment"
android:label="SetupAccount"
tools:layout="@layout/fragment_setup_selected_account">
<action
android:id="@+id/action_open_congratulation_screen"
app:destination="@id/congratulationScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:popUpTo="@+id/startLoginScreen"
app:popUpToInclusive="true" />
<argument
android:name="selected_account_id"
android:defaultValue="0"
app:argType="integer"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<fragment
android:id="@+id/startLoginScreen"
android:name="com.agileburo.anytype.ui.auth.StartLoginFragment"
android:label="StartLoginFragment"
tools:layout="@layout/fragment_start_login">
<action
android:id="@+id/action_open_sign_in"
app:destination="@id/keychainLoginScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:popUpToInclusive="false" />
<action
android:id="@+id/action_open_sign_up"
app:destination="@id/createAccountScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
</fragment>
<action
android:id="@+id/action_global_desktopScreen"
app:destination="@+id/desktopScreen"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:popUpTo="@+id/login_nav"
app:popUpToInclusive="true" />
<fragment
android:id="@+id/choosePinCodeScreen"
android:name="com.agileburo.anytype.feature_login.ui.login.presentation.ui.pin.ChoosePinCodeFragment"
android:label="StartLoginFragment"
tools:layout="@layout/fragment_choose_pin_code" />
<fragment
android:id="@+id/confirmPinCodeScreen"
android:name="com.agileburo.anytype.feature_login.ui.login.presentation.ui.pin.ConfirmPinCodeFragment"
android:label="StartLoginFragment"
tools:layout="@layout/fragment_confirm_pin_code" />
<dialog
android:id="@+id/keychainDialog"
android:name="com.agileburo.anytype.ui.profile.KeychainPhraseDialog"
tools:layout="@layout/dialog_keychain_phrase" />
</navigation>
</navigation>

View file

@ -3,6 +3,7 @@ package com.agileburo.anytype.core_utils.ext
import android.content.Context
import android.net.Uri
import android.provider.MediaStore
import timber.log.Timber
fun Context.dimen(res: Int): Float {
return resources
@ -30,4 +31,6 @@ fun Uri.parsePath(context: Context): String {
}
return result ?: throw IllegalStateException("Cold not get real path")
}
}
fun Throwable.timber() = Timber.e("Get error : ${this.message}")

View file

@ -8,4 +8,5 @@ interface AuthCache {
suspend fun getMnemonic(): String
suspend fun getAccount(): AccountEntity
suspend fun logout()
suspend fun getAccounts(): List<AccountEntity>
}

View file

@ -48,5 +48,8 @@ class AuthCacheDataStore(private val cache: AuthCache) : AuthDataStore {
cache.logout()
}
override suspend fun getStoredAccounts(): List<AccountEntity> =
cache.getAccounts()
override suspend fun getAccount() = cache.getAccount()
}

View file

@ -53,4 +53,7 @@ class AuthDataRepository(
override suspend fun logout() {
factory.cache.logout()
}
override suspend fun getAvailableAccounts(): List<Account> =
factory.cache.getStoredAccounts().map { it.toDomain() }
}

View file

@ -20,4 +20,5 @@ interface AuthDataStore {
suspend fun getMnemonic(): String
suspend fun logout()
suspend fun getStoredAccounts(): List<AccountEntity>
}

View file

@ -50,6 +50,10 @@ class AuthRemoteDataStore(
throw UnsupportedOperationException()
}
override suspend fun getStoredAccounts(): List<AccountEntity> {
throw UnsupportedOperationException("not implemented")
}
override suspend fun getAccount(): AccountEntity {
throw UnsupportedOperationException()
}

View file

@ -19,7 +19,7 @@ ext {
// Architecture Components
lifecycle_version = '2.1.0'
navigation_version = '2.1.0'
navigation_version = '2.2.0-rc01'
// Third party libraries
glide_version = '4.9.0'

View file

@ -0,0 +1,27 @@
package com.agileburo.anytype.domain.auth.interactor
import com.agileburo.anytype.domain.auth.model.AuthStatus
import com.agileburo.anytype.domain.auth.repo.AuthRepository
import com.agileburo.anytype.domain.base.BaseUseCase
import com.agileburo.anytype.domain.base.Either
/**
* Created by Konstantin Ivanov
* email : ki@agileburo.com
* on 2019-10-21.
*/
class CheckAuthorizationStatus(
private val repository: AuthRepository
) : BaseUseCase<AuthStatus, Unit>() {
override suspend fun run(params: Unit) = try {
repository.getAvailableAccounts().let { accounts ->
if (accounts.isNotEmpty())
Either.Right(AuthStatus.AUTHORIZED)
else
Either.Right(AuthStatus.UNAUTHORIZED)
}
} catch (e: Throwable) {
Either.Left(e)
}
}

View file

@ -0,0 +1,5 @@
package com.agileburo.anytype.domain.auth.model
enum class AuthStatus {
AUTHORIZED, UNAUTHORIZED
}

View file

@ -20,4 +20,6 @@ interface AuthRepository {
suspend fun getMnemonic(): String
suspend fun logout()
suspend fun getAvailableAccounts(): List<Account>
}

View file

@ -1,4 +1,5 @@
#Tue Oct 22 17:14:40 MSK 2019
#Wed Oct 23 20:41:38 MSK 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

1
lib-middleware/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

View file

@ -1,11 +1,14 @@
package com.agileburo.anytype.common
object Config {
const val DATABASE_NAME = "AnytypeDatabase"
const val ACCOUNT_TABLE_NAME = "Accounts"
const val CLEAR_ACCOUNT_TABLE =
"DELETE FROM $ACCOUNT_TABLE_NAME"
const val GET_ACCOUNTS = "SELECT * FROM $ACCOUNT_TABLE_NAME"
const val CLEAR_ACCOUNT_TABLE = "DELETE FROM $ACCOUNT_TABLE_NAME"
const val QUERY_LAST_ACCOUNT =
"SELECT * FROM $ACCOUNT_TABLE_NAME ORDER BY timestamp DESC LIMIT 1"

View file

@ -13,4 +13,7 @@ abstract class AccountDao : BaseDao<AccountTable> {
@Query(Config.QUERY_LAST_ACCOUNT)
abstract suspend fun lastAccount(): List<AccountTable>
@Query(Config.GET_ACCOUNTS)
abstract suspend fun getAccounts(): List<AccountTable>
}

View file

@ -1,11 +0,0 @@
package com.agileburo.anytype.mapper
import com.agileburo.anytype.data.auth.model.AccountEntity
import com.agileburo.anytype.model.AccountTable
fun AccountTable.toEntity(): AccountEntity {
return AccountEntity(
id = id,
name = name
)
}

View file

@ -0,0 +1,24 @@
package com.agileburo.anytype.mapper
import com.agileburo.anytype.data.auth.model.AccountEntity
import com.agileburo.anytype.model.AccountTable
/**
* Created by Konstantin Ivanov
* email : ki@agileburo.com
* on 2019-10-22.
*/
fun AccountTable.toEntity(): AccountEntity =
AccountEntity(
id = this.id,
name = this.name
)
//Todo исправить timestamp
fun AccountEntity.toTable(): AccountTable =
AccountTable(
id = this.id,
name = this.name,
timestamp = 0
)

View file

@ -45,6 +45,11 @@ class DefaultAuthCache(
prefs.edit().putString(MNEMONIC_KEY, null).apply()
}
override suspend fun getAccounts(): List<AccountEntity> =
db.accountDao()
.getAccounts()
.map { it.toEntity() }
companion object {
const val MNEMONIC_KEY = "mnemonic"
}

View file

@ -11,6 +11,6 @@ class CongratulationViewModel : ViewModel(), SupportNavigation<Event<AppNavigati
override val navigation: MutableLiveData<Event<AppNavigation.Command>> = MutableLiveData()
fun onStartClicked() {
navigation.postValue(Event(AppNavigation.Command.WorkspaceScreen))
navigation.postValue(Event(AppNavigation.Command.StartDesktopFromLogin))
}
}

View file

@ -13,6 +13,9 @@ interface AppNavigation {
fun workspace()
fun openProfile()
fun openDocument(id: String)
fun startDesktopFromSplash()
fun startDesktopFromLogin()
fun startSplashFromDesktop()
fun openKeychainScreen()
sealed class Command {
@ -30,6 +33,9 @@ interface AppNavigation {
object OpenProfile : Command()
object OpenKeychainScreen : Command()
object OpenPinCodeScreen : Command()
object StartDesktopFromSplash : Command()
object StartDesktopFromLogin : Command()
object StartSplashFromDesktop : Command()
}
interface Provider {

View file

@ -32,7 +32,7 @@ class ProfileViewModel(
Timber.e(e, "Error while logging out")
},
fnR = {
navigation.postValue(Event(AppNavigation.Command.OpenStartLoginScreen))
navigation.postValue(Event(AppNavigation.Command.StartSplashFromDesktop))
}
)
}

View file

@ -0,0 +1,35 @@
package com.agileburo.anytype.presentation.splash
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.agileburo.anytype.core_utils.common.Event
import com.agileburo.anytype.domain.auth.interactor.CheckAuthorizationStatus
import com.agileburo.anytype.domain.auth.model.AuthStatus
import com.agileburo.anytype.presentation.navigation.AppNavigation
import timber.log.Timber
/**
* Created by Konstantin Ivanov
* email : ki@agileburo.com
* on 2019-10-21.
*/
class SplashViewModel(private val checkAuthorizationStatus: CheckAuthorizationStatus) : ViewModel() {
val navigation: MutableLiveData<Event<AppNavigation.Command>> = MutableLiveData()
fun onViewCreated() {
checkAuthorizationStatus.invoke(viewModelScope, Unit) {
it.either(
fnL = { e -> Timber.e(e, "Error while checking auth status") },
fnR = ::proceedWithAuthStatus
)
}
}
private fun proceedWithAuthStatus(status: AuthStatus) =
if (status == AuthStatus.UNAUTHORIZED)
navigation.postValue(Event(AppNavigation.Command.OpenStartLoginScreen))
else
navigation.postValue(Event(AppNavigation.Command.StartDesktopFromSplash))
}

View file

@ -0,0 +1,18 @@
package com.agileburo.anytype.presentation.splash
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.agileburo.anytype.domain.auth.interactor.CheckAuthorizationStatus
/**
* Created by Konstantin Ivanov
* email : ki@agileburo.com
* on 2019-10-21.
*/
class SplashViewModelFactory(private val checkAuthorizationStatus: CheckAuthorizationStatus) :
ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T =
SplashViewModel(checkAuthorizationStatus) as T
}