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

Automatically select the first loaded account when signing in (#899)

This commit is contained in:
Evgenii Kozlov 2020-09-22 19:38:06 +02:00 committed by GitHub
parent 95d0fb1bf2
commit 6f30ecdca4
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 45 deletions

View file

@ -2,6 +2,10 @@
## Version 0.0.48
### New features 🚀
* Automatically select the first loaded account when signing in (#869)
### Design & UX 🔳
* Indent aware scroll-and-move (#820)

View file

@ -6,7 +6,18 @@
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/gradient_rectangle">
<TextView
android:layout_marginStart="24dp"
android:layout_marginTop="56dp"
android:textColor="@color/white"
android:id="@+id/header"
style="@style/AuthHeaderStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/fetching_your_account" />
<androidx.cardview.widget.CardView
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"

View file

@ -125,7 +125,7 @@ Do the computation of an expensive paragraph of text on a background thread:
<string name="pickit_drive">Drive file was selected</string>
<string name="pickit_file_selected">File was selected from unknown provider</string>
<string name="pickit_local_file">Local file was selected</string>
<string name="pickit_waiting">Waiting to receive file...</string>
<string name="pickit_waiting">Waiting to receive file</string>
<string name="profile_wallpaper">Wallpaper</string>
<string name="content_desc_wallpaper">Wallpaper icon</string>
<string name="content_desc_key">Keychain icon</string>
@ -141,5 +141,6 @@ Do the computation of an expensive paragraph of text on a background thread:
<string name="telegram_app">https://t.me/joinchat/BsRYeRURhKcXDOyDA7_NLw</string>
<string name="telegram_web">http://www.telegram.me/joinchat/BsRYeRURhKcXDOyDA7_NLw</string>
<string name="fetching_your_account">Fetching your account…</string>
</resources>

View file

@ -20,8 +20,7 @@ class SelectAccountViewModel(
private val observeAccounts: ObserveAccounts
) : ViewModel(), SupportNavigation<EventWrapper<AppNavigation.Command>> {
override val navigation: MutableLiveData<EventWrapper<AppNavigation.Command>> =
MutableLiveData()
override val navigation = MutableLiveData<EventWrapper<AppNavigation.Command>>()
val state by lazy { MutableLiveData<List<SelectAccountView>>() }
@ -35,7 +34,10 @@ class SelectAccountViewModel(
init {
startObservingAccounts()
startLoadingAccount()
startDispatchingAccumulatedAccounts()
}
private fun startDispatchingAccumulatedAccounts() {
accounts
.onEach { result ->
state.postValue(
@ -66,12 +68,16 @@ class SelectAccountViewModel(
private fun startObservingAccounts() {
viewModelScope.launch {
observeAccounts.build().collect { account ->
accountChannel.send(account)
observeAccounts.build().take(1).collect { account ->
onFirstAccountLoaded(account.id)
}
}
}
private fun onFirstAccountLoaded(id: String) {
navigation.postValue(EventWrapper(AppNavigation.Command.SetupSelectedAccountScreen(id)))
}
fun onProfileClicked(id: String) {
navigation.postValue(EventWrapper(AppNavigation.Command.SetupSelectedAccountScreen(id)))
}

View file

@ -2,21 +2,14 @@ package com.agileburo.anytype.presentation.auth
import MockDataFactory
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.viewModelScope
import com.agileburo.anytype.domain.auth.interactor.ObserveAccounts
import com.agileburo.anytype.domain.auth.interactor.StartLoadingAccounts
import com.agileburo.anytype.domain.auth.model.Account
import com.agileburo.anytype.domain.base.Either
import com.agileburo.anytype.presentation.auth.account.SelectAccountViewModel
import com.agileburo.anytype.presentation.auth.model.SelectAccountView
import com.agileburo.anytype.presentation.util.CoroutinesTestRule
import com.jraska.livedata.test
import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.doAnswer
import com.nhaarman.mockitokotlin2.doReturn
import com.nhaarman.mockitokotlin2.stub
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.test.runBlockingTest
@ -25,7 +18,6 @@ import org.junit.Rule
import org.junit.Test
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.mockito.MockitoDebugger
class SelectAccountViewModelTest {
@ -56,7 +48,7 @@ class SelectAccountViewModelTest {
}
@Test
fun `should emit one account without image`() = runBlockingTest {
fun `should not emit one account without image`() = runBlockingTest {
val account = Account(
id = MockDataFactory.randomUuid(),
@ -74,21 +66,11 @@ class SelectAccountViewModelTest {
vm = buildViewModel()
vm.state.test()
.assertValue(
listOf(
SelectAccountView.AccountView(
id = account.id,
name = account.name,
image = account.avatar
)
)
)
.assertHistorySize(1)
vm.state.test().assertNoValue()
}
@Test
fun `should emit list with two accounts without images`() = runBlockingTest {
fun `should not emit list with two accounts without images`() = runBlockingTest {
val firstAccount = Account(
id = MockDataFactory.randomUuid(),
@ -109,30 +91,12 @@ class SelectAccountViewModelTest {
emit(secondAccount)
}
val blob = ByteArray(0)
val response = Either.Right(blob)
observeAccounts.stub {
onBlocking { build() } doReturn accounts
}
vm = buildViewModel()
vm.state.test()
.assertValue(
listOf(
SelectAccountView.AccountView(
id = firstAccount.id,
name = firstAccount.name
),
SelectAccountView.AccountView(
id = secondAccount.id,
name = secondAccount.name
)
)
)
.assertHistorySize(1)
vm.state.test().assertNoValue()
}
}