mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
Tech | Remove legacy (#2126)
This commit is contained in:
parent
7846ea2b5f
commit
b181c74e54
31 changed files with 1 additions and 1548 deletions
|
@ -75,13 +75,6 @@ class ComponentManager(private val main: MainComponent) {
|
|||
.build()
|
||||
}
|
||||
|
||||
val profileComponent = Component {
|
||||
main
|
||||
.profileComponentBuilder()
|
||||
.profileModule(ProfileModule)
|
||||
.build()
|
||||
}
|
||||
|
||||
val debugSettingsComponent = Component {
|
||||
main
|
||||
.debugSettingsBuilder()
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
package com.anytypeio.anytype.di.feature
|
||||
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_utils.di.scope.PerScreen
|
||||
import com.anytypeio.anytype.domain.auth.interactor.GetCurrentAccount
|
||||
import com.anytypeio.anytype.domain.auth.interactor.GetLibraryVersion
|
||||
import com.anytypeio.anytype.domain.auth.interactor.Logout
|
||||
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.presentation.profile.ProfileViewModelFactory
|
||||
import com.anytypeio.anytype.ui.profile.ProfileFragment
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.Subcomponent
|
||||
|
||||
|
||||
@Subcomponent(
|
||||
modules = [ProfileModule::class]
|
||||
)
|
||||
@PerScreen
|
||||
interface ProfileSubComponent {
|
||||
|
||||
@Subcomponent.Builder
|
||||
interface Builder {
|
||||
fun profileModule(module: ProfileModule): Builder
|
||||
fun build(): ProfileSubComponent
|
||||
}
|
||||
|
||||
fun inject(fragment: ProfileFragment)
|
||||
}
|
||||
|
||||
@Module
|
||||
object ProfileModule {
|
||||
|
||||
@JvmStatic
|
||||
@Provides
|
||||
@PerScreen
|
||||
fun provideProfileViewModelFactory(
|
||||
logout: Logout,
|
||||
getCurrentAccount: GetCurrentAccount,
|
||||
analytics: Analytics,
|
||||
getLibraryVersion: GetLibraryVersion
|
||||
): ProfileViewModelFactory = ProfileViewModelFactory(
|
||||
logout = logout,
|
||||
getCurrentAccount = getCurrentAccount,
|
||||
analytics = analytics,
|
||||
getLibraryVersion = getLibraryVersion
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
@Provides
|
||||
@PerScreen
|
||||
fun provideLogoutUseCase(
|
||||
repository: AuthRepository
|
||||
): Logout = Logout(repository)
|
||||
|
||||
@JvmStatic
|
||||
@Provides
|
||||
@PerScreen
|
||||
fun provideGetAccountUseCase(
|
||||
repo: BlockRepository,
|
||||
builder: UrlBuilder
|
||||
): GetCurrentAccount = GetCurrentAccount(repo = repo, builder = builder)
|
||||
|
||||
@JvmStatic
|
||||
@Provides
|
||||
@PerScreen
|
||||
fun provideGetVersion(
|
||||
repo: AuthRepository
|
||||
): GetLibraryVersion = GetLibraryVersion(repo)
|
||||
}
|
|
@ -22,7 +22,6 @@ import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
|||
import com.anytypeio.anytype.domain.config.FlavourConfigProvider
|
||||
import com.anytypeio.anytype.domain.config.InfrastructureRepository
|
||||
import com.anytypeio.anytype.domain.config.UserSettingsRepository
|
||||
import com.anytypeio.anytype.domain.database.repo.DatabaseRepository
|
||||
import com.anytypeio.anytype.domain.device.PathProvider
|
||||
import com.anytypeio.anytype.domain.misc.AppActionManager
|
||||
import com.anytypeio.anytype.domain.objects.DefaultObjectStore
|
||||
|
@ -237,11 +236,6 @@ object DataModule {
|
|||
@Singleton
|
||||
fun provideMiddlewareService(): MiddlewareService = MiddlewareServiceImplementation()
|
||||
|
||||
@JvmStatic
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideDatabaseRepo(): DatabaseRepository = DatabaseDataRepository()
|
||||
|
||||
@JvmStatic
|
||||
@Provides
|
||||
@Singleton
|
||||
|
|
|
@ -28,7 +28,6 @@ interface MainComponent {
|
|||
fun inject(app: AndroidApplication)
|
||||
|
||||
fun authComponentBuilder(): AuthSubComponent.Builder
|
||||
fun profileComponentBuilder(): ProfileSubComponent.Builder
|
||||
fun splashComponentBuilder(): SplashSubComponent.Builder
|
||||
fun homeDashboardComponentBuilder(): HomeDashboardSubComponent.Builder
|
||||
fun editorComponentBuilder(): EditorSubComponent.Builder
|
||||
|
|
|
@ -1,116 +0,0 @@
|
|||
package com.anytypeio.anytype.ui.profile
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.anytypeio.anytype.BuildConfig
|
||||
import com.anytypeio.anytype.R
|
||||
import com.anytypeio.anytype.core_ui.extensions.avatarColor
|
||||
import com.anytypeio.anytype.core_utils.ext.firstDigitByHash
|
||||
import com.anytypeio.anytype.core_utils.ext.invisible
|
||||
import com.anytypeio.anytype.core_utils.ext.toast
|
||||
import com.anytypeio.anytype.core_utils.ext.visible
|
||||
import com.anytypeio.anytype.core_utils.ui.ViewState
|
||||
import com.anytypeio.anytype.databinding.FragmentProfileBinding
|
||||
import com.anytypeio.anytype.di.common.componentManager
|
||||
import com.anytypeio.anytype.presentation.profile.ProfileView
|
||||
import com.anytypeio.anytype.presentation.profile.ProfileViewModel
|
||||
import com.anytypeio.anytype.presentation.profile.ProfileViewModelFactory
|
||||
import com.anytypeio.anytype.ui.base.ViewStateFragment
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@Deprecated("To be deleted")
|
||||
class ProfileFragment : ViewStateFragment<ViewState<ProfileView>, FragmentProfileBinding>(R.layout.fragment_profile) {
|
||||
|
||||
@Inject
|
||||
lateinit var factory: ProfileViewModelFactory
|
||||
private val vm by viewModels<ProfileViewModel> { factory }
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
vm.state.observe(viewLifecycleOwner, this)
|
||||
vm.version.observe(viewLifecycleOwner) { version(it) }
|
||||
vm.navigation.observe(viewLifecycleOwner, navObserver)
|
||||
binding.backButtonContainer.setOnClickListener { vm.onBackButtonClicked() }
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
vm.isLoggingOut.collect { isLoggingOut ->
|
||||
if (isLoggingOut)
|
||||
binding.logoutProgressBar.visible()
|
||||
else
|
||||
binding.logoutProgressBar.invisible()
|
||||
}
|
||||
}
|
||||
}
|
||||
vm.onViewCreated()
|
||||
}
|
||||
|
||||
override fun render(state: ViewState<ProfileView>) {
|
||||
when (state) {
|
||||
is ViewState.Init -> {
|
||||
with(binding) {
|
||||
wallpaperText.setOnClickListener {
|
||||
findNavController().navigate(R.id.wallpaperSetScreen)
|
||||
}
|
||||
logoutButton.setOnClickListener { vm.onLogoutClicked() }
|
||||
pinCodeText.setOnClickListener {
|
||||
vm.onPinCodeClicked()
|
||||
toast("Coming soon...")
|
||||
}
|
||||
keychainPhrase.setOnClickListener { vm.onKeyChainPhraseClicked() }
|
||||
backButton.setOnClickListener { vm.onBackButtonClicked() }
|
||||
profileCardContainer.setOnClickListener { vm.onProfileCardClicked() }
|
||||
userSettingsText.setOnClickListener { vm.onUserSettingsClicked() }
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
with(debugSettingsButton) {
|
||||
visible()
|
||||
setOnClickListener { vm.onDebugSettingsClicked() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
is ViewState.Success -> {
|
||||
binding.name.text = state.data.name
|
||||
val pos = state.data.name.firstDigitByHash()
|
||||
binding.avatar.bind(
|
||||
name = state.data.name,
|
||||
color = requireContext().avatarColor(pos)
|
||||
)
|
||||
state.data.avatar?.let { binding.avatar.icon(it) }
|
||||
}
|
||||
is ViewState.Error -> {}
|
||||
ViewState.Loading -> {}
|
||||
}
|
||||
}
|
||||
|
||||
private fun version(version: String) {
|
||||
if (version.isEmpty()) {
|
||||
binding.tvVersion.text = "Android v${BuildConfig.VERSION_NAME}-alpha"
|
||||
} else {
|
||||
binding.tvVersion.text = "Android v${BuildConfig.VERSION_NAME}-alpha ($version)"
|
||||
}
|
||||
}
|
||||
|
||||
override fun injectDependencies() {
|
||||
componentManager().profileComponent.get().inject(this)
|
||||
}
|
||||
|
||||
override fun releaseDependencies() {
|
||||
componentManager().profileComponent.release()
|
||||
}
|
||||
|
||||
override fun inflateBinding(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?
|
||||
): FragmentProfileBinding = FragmentProfileBinding.inflate(
|
||||
inflater, container, false
|
||||
)
|
||||
}
|
|
@ -1,10 +1,7 @@
|
|||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:context=".ui.database.modals.ModalsNavFragment">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
</FrameLayout>
|
|
@ -1,326 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="none"
|
||||
tools:context=".ui.profile.ProfileFragment">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/backButtonContainer"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="@dimen/dp_12"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/backButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:contentDescription="@string/content_description_back_button_icon"
|
||||
android:src="@drawable/ic_profile_back" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/profileCardView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:visibility="invisible"
|
||||
app:cardCornerRadius="12dp"
|
||||
app:cardElevation="0dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/backButtonContainer">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/profileCardContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.anytypeio.anytype.core_ui.widgets.AvatarWidget
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:background="@drawable/circle_solid_default"
|
||||
android:contentDescription="@string/description_profile_picture"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:text_size="34sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:ellipsize="end"
|
||||
android:fontFamily="@font/graphik_semibold"
|
||||
android:maxLines="3"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="28sp"
|
||||
app:layout_constraintEnd_toStartOf="@+id/ivArrowForward"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/avatar"
|
||||
tools:text="Anton Pronkin" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="3dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginBottom="15dp"
|
||||
android:fontFamily="@font/inter_regular"
|
||||
android:text="@string/your_page"
|
||||
android:textColor="#ACA996"
|
||||
android:textSize="15sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/name" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivArrowForward"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/name"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/name"
|
||||
app:srcCompat="@drawable/ic_profile_forward" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/actionsCardView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
app:cardBackgroundColor="@color/background_primary"
|
||||
app:cardCornerRadius="12dp"
|
||||
app:cardElevation="0dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/profileCardView">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icWallpaper"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:contentDescription="@string/content_desc_wallpaper"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/ic_wallpaper" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/wallpaperText"
|
||||
style="@style/ProfileItem"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:drawableEnd="@drawable/ic_profile_forward"
|
||||
android:text="@string/profile_wallpaper"
|
||||
android:textColor="@color/text_primary"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/icWallpaper"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/icWallpaper"
|
||||
app:layout_constraintTop_toTopOf="@+id/icWallpaper" />
|
||||
|
||||
<View
|
||||
android:id="@+id/firstDivider"
|
||||
style="@style/ProfileItemDivider"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/default_divider_height"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/icWallpaper" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/keyIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:contentDescription="@string/content_desc_key"
|
||||
android:src="@drawable/ic_key"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/firstDivider" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/keychainPhrase"
|
||||
style="@style/ProfileItem"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:drawableEnd="@drawable/ic_profile_forward"
|
||||
android:text="@string/keychain_phrase"
|
||||
android:textColor="@color/text_primary"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/keyIcon"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/keyIcon"
|
||||
app:layout_constraintTop_toTopOf="@+id/keyIcon" />
|
||||
|
||||
<View
|
||||
android:id="@+id/secondDivider"
|
||||
style="@style/ProfileItemDivider"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/default_divider_height"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/keyIcon" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/pinIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="31dp"
|
||||
android:contentDescription="@string/content_desc_pin"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/secondDivider"
|
||||
app:srcCompat="@drawable/ic_pin_code" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pinCodeText"
|
||||
style="@style/ProfileItem"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:drawableEnd="@drawable/ic_profile_forward"
|
||||
android:text="@string/pin_code"
|
||||
android:textColor="@color/text_primary"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/pinIcon"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/pinIcon"
|
||||
app:layout_constraintTop_toTopOf="@+id/pinIcon" />
|
||||
|
||||
<View
|
||||
android:id="@+id/thirdDivider"
|
||||
style="@style/ProfileItemDivider"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/default_divider_height"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/pinIcon" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/userSettingsIcon"
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="28dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="31dp"
|
||||
android:contentDescription="@string/content_desc_pin"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/thirdDivider"
|
||||
app:srcCompat="@drawable/ic_other_settings" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/userSettingsText"
|
||||
style="@style/ProfileItem"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:drawableEnd="@drawable/ic_profile_forward"
|
||||
android:text="@string/other_settings"
|
||||
android:textColor="@color/text_primary"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/userSettingsIcon"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/userSettingsIcon"
|
||||
app:layout_constraintTop_toTopOf="@+id/userSettingsIcon" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/logoutButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
app:cardBackgroundColor="@color/background_primary"
|
||||
app:cardCornerRadius="12dp"
|
||||
app:cardElevation="0dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/actionsCardView">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:fontFamily="@font/inter_regular"
|
||||
android:text="@string/log_out"
|
||||
android:textColor="@color/anytype_text_red"
|
||||
android:textSize="17sp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/logoutProgressBar"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:theme="@style/GreyProgressBar"
|
||||
android:visibility="invisible"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvVersion"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:fontFamily="monospace"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="11sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/debugSettingsButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:padding="16dp"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/ic_debug_settings"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -1,29 +0,0 @@
|
|||
package com.anytypeio.anytype.data.auth.repo
|
||||
|
||||
import com.anytypeio.anytype.domain.database.DatabaseMock
|
||||
import com.anytypeio.anytype.domain.database.model.DatabaseView
|
||||
import com.anytypeio.anytype.domain.database.model.ViewType
|
||||
import com.anytypeio.anytype.domain.database.repo.DatabaseRepository
|
||||
|
||||
class DatabaseDataRepository : DatabaseRepository {
|
||||
|
||||
private var db: DatabaseView
|
||||
|
||||
init {
|
||||
db = DatabaseMock.getDatabaseView(DatabaseMock.ID)
|
||||
}
|
||||
|
||||
override fun getDatabase(id: String): DatabaseView = db
|
||||
|
||||
override fun updateDatabase(databse: DatabaseView) {
|
||||
db = databse
|
||||
}
|
||||
|
||||
override fun updateViewType(type: ViewType) {
|
||||
db.let {
|
||||
val list = it.content.displays
|
||||
list[0] = list.first().copy(type = type)
|
||||
db = it.copy(content = it.content.copy(displays = list))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database
|
||||
|
||||
import com.anytypeio.anytype.domain.database.model.Contact
|
||||
import com.anytypeio.anytype.domain.database.model.Tag
|
||||
|
||||
object ContactsMock {
|
||||
|
||||
val CONTACTS = listOf(
|
||||
Contact(
|
||||
id = "kfgonk;lmkmvkld8",
|
||||
name = "Fred Scott",
|
||||
date = 1571328513000,
|
||||
tags = listOf(
|
||||
Tag(
|
||||
"777",
|
||||
"Family"
|
||||
)
|
||||
),
|
||||
icon = ""
|
||||
),
|
||||
Contact(
|
||||
id = "bjcbdjdfb",
|
||||
name = "Tomas Hale",
|
||||
date = 1492387200000,
|
||||
tags = listOf(
|
||||
Tag("333", "Team"),
|
||||
Tag("111", "Core")
|
||||
),
|
||||
icon = ""
|
||||
),
|
||||
Contact(
|
||||
id = "sadfsdas",
|
||||
name = "Anton Lurie",
|
||||
date = 1574351513000,
|
||||
tags = listOf(
|
||||
Tag("333", "Team"),
|
||||
Tag("222", "Design")
|
||||
),
|
||||
icon = ""
|
||||
),
|
||||
Contact(
|
||||
id = "hfjhfgjkshjdh",
|
||||
name = "Anna Lee",
|
||||
date = 1571328513000,
|
||||
tags = listOf(
|
||||
Tag("333", "Team"),
|
||||
Tag("555", "Product")
|
||||
),
|
||||
icon = ""
|
||||
),
|
||||
Contact(
|
||||
id = "zfjh3hjdh",
|
||||
name = "Neil Keaton",
|
||||
date = 1571328513000,
|
||||
tags = listOf(
|
||||
Tag("777", "Family")
|
||||
),
|
||||
icon = ""
|
||||
),
|
||||
Contact(
|
||||
id = "dshjfhskdh",
|
||||
name = "Greg Phillips",
|
||||
date = 1571328513000,
|
||||
tags = listOf(
|
||||
Tag("333", "Team"),
|
||||
Tag(
|
||||
"444",
|
||||
"Programming"
|
||||
)
|
||||
),
|
||||
icon = ""
|
||||
),
|
||||
Contact(
|
||||
id = "sadwcdweew",
|
||||
name = "Roman Blum",
|
||||
date = 1571328513000,
|
||||
tags = listOf(
|
||||
Tag("333", "Team"),
|
||||
Tag(
|
||||
"444",
|
||||
"Programming"
|
||||
)
|
||||
),
|
||||
icon = ""
|
||||
)
|
||||
)
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database
|
||||
|
||||
import com.anytypeio.anytype.domain.database.model.*
|
||||
|
||||
object DatabaseMock {
|
||||
|
||||
const val ID = "343253"
|
||||
|
||||
fun getDatabaseView(id: String): DatabaseView {
|
||||
|
||||
val details = listOf(
|
||||
Detail.Number(id = "21", name = "Id", show = true),
|
||||
Detail.Title(id = "22", name = "Name", show = true),
|
||||
Detail.Email(id = "24", name = "E-mail", show = true),
|
||||
Detail.Date(id = "25", name = "Date", show = true),
|
||||
Detail.Select(
|
||||
id = "26",
|
||||
name = "Select",
|
||||
select = setOf("select1", "select2", "select3"),
|
||||
show = true
|
||||
),
|
||||
Detail.Multiple(
|
||||
id = "27",
|
||||
name = "Multiple",
|
||||
multiSelect = setOf(
|
||||
"multiple1",
|
||||
"multiple2",
|
||||
"multiple3",
|
||||
"multiple4",
|
||||
"multiple5"
|
||||
),
|
||||
show = true
|
||||
),
|
||||
Detail.Person(
|
||||
id = "38",
|
||||
name = "Account",
|
||||
accounts = setOf(
|
||||
Value(name = "Gennadiy Gusarov"),
|
||||
Value(name = "Eduard Streltsov")
|
||||
),
|
||||
show = false
|
||||
),
|
||||
Detail.File(id = "49", name = "File", show = true),
|
||||
Detail.Bool(id = "510", name = "Bool", show = true),
|
||||
Detail.Link(id = "711", name = "Link", show = true),
|
||||
Detail.Phone(id = "3312", name = "Phone", show = true),
|
||||
Detail.Text(id = "213", name = "Phone", show = true),
|
||||
Detail.Text(id = "214", name = "Phone", show = true),
|
||||
Detail.Text(id = "215", name = "Phone", show = true),
|
||||
Detail.Text(id = "216", name = "Phone", show = true),
|
||||
Detail.Text(id = "217", name = "Phone", show = true),
|
||||
Detail.Text(id = "218", name = "Phone", show = true),
|
||||
Detail.Text(id = "219", name = "Phone", show = true),
|
||||
Detail.Text(id = "220", name = "Phone", show = true)
|
||||
)
|
||||
|
||||
val data1: HashMap<String, Any> = hashMapOf(
|
||||
"1" to "1",
|
||||
"2" to "Valentin Ivanov",
|
||||
"4" to "ivanov@gmail.com",
|
||||
"5" to 1420200661,
|
||||
"6" to "select1",
|
||||
"11" to "httpto//anytype.io",
|
||||
"12" to "+7 (1234) 5678910",
|
||||
"7" to arrayOf("value1", "value2", "value3"),
|
||||
"10" to true,
|
||||
"8" to { "name" to "Eduard Streltsov" }
|
||||
)
|
||||
|
||||
val data2: HashMap<String, Any> = hashMapOf(
|
||||
"1" to "2",
|
||||
"2" to "Eduard Streltsov",
|
||||
"4" to "streltsov@gmail.com",
|
||||
"5" to 1420200661,
|
||||
"6" to "select2",
|
||||
"11" to "ftp://anytype.io"
|
||||
)
|
||||
|
||||
val data3: HashMap<String, Any> = hashMapOf(
|
||||
"1" to "3",
|
||||
"2" to "Gennadiy Gusarov",
|
||||
"4" to "gusarov@gmail.com",
|
||||
"5" to 1420200662,
|
||||
"6" to "select3",
|
||||
"11" to "telnet://anytype.io"
|
||||
)
|
||||
|
||||
val data4: HashMap<String, Any> = hashMapOf(
|
||||
"1" to "4",
|
||||
"2" to "Georgiy Zharkov",
|
||||
"4" to "zharkov@gmail.com",
|
||||
"5" to 1420200662,
|
||||
"6" to "select4",
|
||||
"11" to "https://anytype.io"
|
||||
)
|
||||
|
||||
val data5: HashMap<String, Any> = hashMapOf(
|
||||
"1" to "5",
|
||||
"2" to "Pyotr Petrov",
|
||||
"4" to "ppetrov@gmail.com",
|
||||
"5" to 1420200663,
|
||||
"6" to "select5"
|
||||
)
|
||||
|
||||
val data = listOf(data1, data2, data3, data4, data5)
|
||||
|
||||
val views = mutableListOf(
|
||||
Display(
|
||||
id = "1",
|
||||
type = ViewType.LIST,
|
||||
name = "Нобелевские лауреаты 2019",
|
||||
filters = listOf(
|
||||
Filter(
|
||||
detailId = "1",
|
||||
value = "",
|
||||
condition = FilterTypeCondition.NONE,
|
||||
equality = FilterTypeEquality.EQUAL
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
val contentDatabaseView = ContentDatabaseView(
|
||||
data = data,
|
||||
details = details,
|
||||
databaseId = ID,
|
||||
displays = views
|
||||
)
|
||||
|
||||
if (id == contentDatabaseView.databaseId) {
|
||||
return DatabaseView(content = contentDatabaseView)
|
||||
} else {
|
||||
throw RuntimeException("Wrong Id")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database
|
||||
|
||||
import com.anytypeio.anytype.domain.database.model.*
|
||||
|
||||
const val ALL_ID = "-2"
|
||||
const val PLUS_ID = "-1"
|
||||
|
||||
object FilterMock {
|
||||
|
||||
val FILTER_ALL = Filter(
|
||||
detailId = ALL_ID,
|
||||
condition = FilterTypeCondition.NONE,
|
||||
equality = FilterTypeEquality.EQUAL,
|
||||
value = "All"
|
||||
)
|
||||
|
||||
// val FILTER_PLUS = Filter(
|
||||
// propertyId = PLUS_ID,
|
||||
// condition = FilterTypeCondition.NONE,
|
||||
// equality = FilterTypeEquality.EQUAL,
|
||||
// value = "Plus"
|
||||
// )
|
||||
|
||||
var filters = mutableListOf(
|
||||
Filter(
|
||||
detailId = "333",
|
||||
condition = FilterTypeCondition.NONE,
|
||||
equality = FilterTypeEquality.EQUAL,
|
||||
value = "Team"
|
||||
),
|
||||
Filter(
|
||||
detailId = "777",
|
||||
condition = FilterTypeCondition.NONE,
|
||||
equality = FilterTypeEquality.EQUAL,
|
||||
value = "Family"
|
||||
),
|
||||
// Filter(
|
||||
// propertyId = "333",
|
||||
// condition = FilterTypeCondition.NONE,
|
||||
// equality = FilterTypeEquality.EQUAL,
|
||||
// value = "Product"
|
||||
// ),
|
||||
// Filter(
|
||||
// propertyId = "555",
|
||||
// condition = FilterTypeCondition.NONE,
|
||||
// equality = FilterTypeEquality.EQUAL,
|
||||
// value = "Android"
|
||||
// ),
|
||||
Filter(
|
||||
detailId = "888",
|
||||
condition = FilterTypeCondition.NONE,
|
||||
equality = FilterTypeEquality.EQUAL,
|
||||
value = "New"
|
||||
)
|
||||
)
|
||||
|
||||
val groups = mutableListOf(
|
||||
Group(
|
||||
details = listOf(
|
||||
Detail.File(id = "9", name = "File", show = true),
|
||||
Detail.Bool(id = "10", name = "Bool", show = true),
|
||||
Detail.Link(id = "11", name = "Link", show = true),
|
||||
Detail.Phone(id = "12", name = "Phone", show = true)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.FilterMock
|
||||
import com.anytypeio.anytype.domain.database.model.Filter
|
||||
|
||||
class AddFilter : BaseUseCase<Unit, AddFilter.Params>() {
|
||||
|
||||
override suspend fun run(params: Params): Either<Throwable, Unit> = try {
|
||||
FilterMock.filters.add(params.filter)
|
||||
Either.Right(Unit)
|
||||
} catch (e: Throwable) {
|
||||
Either.Left(e)
|
||||
}
|
||||
|
||||
data class Params(val filter: Filter)
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.model.Display
|
||||
import com.anytypeio.anytype.domain.database.model.ViewType
|
||||
import com.anytypeio.anytype.domain.database.repo.DatabaseRepository
|
||||
|
||||
class CreateDisplayView(
|
||||
private val databaseRepo: DatabaseRepository
|
||||
) : BaseUseCase<Display, CreateDisplayView.Params>() {
|
||||
|
||||
override suspend fun run(params: Params): Either<Throwable, Display> {
|
||||
val displayView = Display(
|
||||
//todo update id
|
||||
id = "-1",
|
||||
name = params.name,
|
||||
type = params.type
|
||||
)
|
||||
return Either.Right(displayView)
|
||||
}
|
||||
|
||||
data class Params(val name: String, val type: ViewType)
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.repo.DatabaseRepository
|
||||
|
||||
class DeleteDatabase(
|
||||
private val databaseRepo: DatabaseRepository
|
||||
) : BaseUseCase<String, DeleteDatabase.Params>() {
|
||||
|
||||
override suspend fun run(params: Params): Either<Throwable, String> = try {
|
||||
Either.Right("Delete database with id:${params.id}, name:{${params.name}}")
|
||||
} catch (e: Throwable) {
|
||||
Either.Left(e)
|
||||
}
|
||||
|
||||
data class Params(val id: String, val name: String)
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.model.Detail
|
||||
import com.anytypeio.anytype.domain.database.repo.DatabaseRepository
|
||||
|
||||
class DeleteDetail(
|
||||
private val databaseRepo: DatabaseRepository
|
||||
) : BaseUseCase<Unit, DeleteDetail.Params>() {
|
||||
|
||||
override suspend fun run(params: Params): Either<Throwable, Unit> = try {
|
||||
databaseRepo.getDatabase(params.databaseId).let {
|
||||
val details = it.content.details
|
||||
|
||||
val index = getDetailIndex(details, params.detailId)
|
||||
if (index == -1) {
|
||||
Either.Left(DeleteDetailError())
|
||||
} else {
|
||||
databaseRepo.updateDatabase(
|
||||
it.copy(
|
||||
content = it.content.copy(
|
||||
details = details.toMutableList().apply {
|
||||
removeAt(index)
|
||||
})
|
||||
)
|
||||
)
|
||||
Either.Right(Unit)
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e: Throwable) {
|
||||
Either.Left(e)
|
||||
}
|
||||
|
||||
private fun getDetailIndex(details: List<Detail>, id: String): Int =
|
||||
details.indexOfFirst { it.id == id }
|
||||
|
||||
class Params(val databaseId: String, val detailId: String)
|
||||
class DeleteDetailError: Throwable()
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.repo.DatabaseRepository
|
||||
|
||||
class DuplicateDatabase(
|
||||
private val databaseRepo: DatabaseRepository
|
||||
) : BaseUseCase<String, DuplicateDatabase.Params>() {
|
||||
|
||||
override suspend fun run(params: Params): Either<Throwable, String> = try {
|
||||
Either.Right("Duplicate database with id:${params.id}, name:{${params.name}}")
|
||||
} catch (e: Throwable) {
|
||||
Either.Left(e)
|
||||
}
|
||||
|
||||
data class Params(val id: String, val name: String)
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.model.Detail
|
||||
import com.anytypeio.anytype.domain.database.repo.DatabaseRepository
|
||||
import java.util.*
|
||||
|
||||
class DuplicateDetail(
|
||||
private val databaseRepo: DatabaseRepository
|
||||
) : BaseUseCase<Unit, DuplicateDetail.Params>() {
|
||||
|
||||
override suspend fun run(params: Params): Either<Throwable, Unit> = try {
|
||||
databaseRepo.getDatabase(params.databaseId).let {
|
||||
val details = it.content.details
|
||||
|
||||
val index = getDetailIndex(details, params.detailId)
|
||||
if (index == -1) {
|
||||
Either.Left(DuplicateDetailError())
|
||||
} else {
|
||||
val detail: Detail = details[index]
|
||||
|
||||
databaseRepo.updateDatabase(
|
||||
it.copy(
|
||||
content = it.content.copy(
|
||||
details = details.toMutableList().apply {
|
||||
add(duplicate(detail))
|
||||
})
|
||||
)
|
||||
)
|
||||
Either.Right(Unit)
|
||||
}
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
Either.Left(e)
|
||||
}
|
||||
|
||||
private fun getDetailIndex(details: List<Detail>, id: String): Int =
|
||||
details.indexOfFirst { it.id == id }
|
||||
|
||||
private fun duplicate(detail: Detail): Detail =
|
||||
when (detail) {
|
||||
is Detail.Title -> detail.copy(id = UUID.randomUUID().toString())
|
||||
is Detail.Text -> detail.copy(id = UUID.randomUUID().toString())
|
||||
is Detail.Number -> detail.copy(id = UUID.randomUUID().toString())
|
||||
is Detail.Date -> detail.copy(id = UUID.randomUUID().toString())
|
||||
is Detail.Select -> detail.copy(id = UUID.randomUUID().toString())
|
||||
is Detail.Multiple -> detail.copy(id = UUID.randomUUID().toString())
|
||||
is Detail.Person -> detail.copy(id = UUID.randomUUID().toString())
|
||||
is Detail.File -> detail.copy(id = UUID.randomUUID().toString())
|
||||
is Detail.Bool -> detail.copy(id = UUID.randomUUID().toString())
|
||||
is Detail.Link -> detail.copy(id = UUID.randomUUID().toString())
|
||||
is Detail.Email -> detail.copy(id = UUID.randomUUID().toString())
|
||||
is Detail.Phone -> detail.copy(id = UUID.randomUUID().toString())
|
||||
}
|
||||
|
||||
class Params(val databaseId: String, val detailId: String)
|
||||
class DuplicateDetailError : Throwable()
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.model.Contact
|
||||
import com.anytypeio.anytype.domain.database.ContactsMock
|
||||
|
||||
class GetContact : BaseUseCase<Contact, GetContact.Params>() {
|
||||
|
||||
override suspend fun run(params: Params): Either<Throwable, Contact> = try {
|
||||
ContactsMock.CONTACTS.find {
|
||||
it.id == params.contactId
|
||||
}.let {
|
||||
if (it == null) {
|
||||
Either.Left(Throwable("Error getting contact by id=${params.contactId}"))
|
||||
} else {
|
||||
Either.Right(it)
|
||||
}
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
Either.Left(e)
|
||||
}
|
||||
|
||||
class Params(
|
||||
val contactId: String
|
||||
)
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.model.Contact
|
||||
import com.anytypeio.anytype.domain.database.ContactsMock
|
||||
|
||||
class GetContacts : BaseUseCase<List<Contact>, BaseUseCase.None>() {
|
||||
|
||||
override suspend fun run(params: None): Either<Throwable, List<Contact>> = try {
|
||||
Either.Right(ContactsMock.CONTACTS)
|
||||
} catch (e: Throwable) {
|
||||
Either.Left(e)
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.DatabaseMock
|
||||
import com.anytypeio.anytype.domain.database.model.DatabaseView
|
||||
import com.anytypeio.anytype.domain.database.repo.DatabaseRepository
|
||||
|
||||
class GetDatabase(
|
||||
private val databaseRepo: DatabaseRepository
|
||||
) : BaseUseCase<DatabaseView, GetDatabase.Params>() {
|
||||
|
||||
override suspend fun run(params: Params): Either<Throwable, DatabaseView> = try {
|
||||
databaseRepo.getDatabase(params.id).let {
|
||||
Either.Right(it)
|
||||
}
|
||||
|
||||
} catch (e: Throwable) {
|
||||
Either.Left(e)
|
||||
}
|
||||
|
||||
class Params(val id: String)
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.FilterMock
|
||||
import com.anytypeio.anytype.domain.database.model.Filter
|
||||
|
||||
class GetFilters : BaseUseCase<List<Filter>, BaseUseCase.None>() {
|
||||
|
||||
override suspend fun run(params: None): Either<Throwable, List<Filter>> = try {
|
||||
Either.Right(addDefaultFilters(FilterMock.filters.toMutableList()))
|
||||
} catch (e: Throwable) {
|
||||
Either.Left(e)
|
||||
}
|
||||
|
||||
private fun addDefaultFilters(filters: MutableList<Filter>): List<Filter> {
|
||||
filters.add(0, FilterMock.FILTER_ALL)
|
||||
return filters
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.FilterMock
|
||||
import com.anytypeio.anytype.domain.database.model.Group
|
||||
|
||||
class GetGroups : BaseUseCase<List<Group>, BaseUseCase.None>() {
|
||||
|
||||
override suspend fun run(params: None): Either<Throwable, List<Group>> = try {
|
||||
Either.Right(FilterMock.groups)
|
||||
} catch (e: Throwable) {
|
||||
Either.Left(e)
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.model.Detail
|
||||
import com.anytypeio.anytype.domain.database.repo.DatabaseRepository
|
||||
|
||||
class HideDetail(
|
||||
private val databaseRepo: DatabaseRepository
|
||||
) : BaseUseCase<Unit, HideDetail.Params>() {
|
||||
|
||||
override suspend fun run(params: Params): Either<Throwable, Unit> = try {
|
||||
databaseRepo.getDatabase(params.databaseId).let {
|
||||
val details = it.content.details
|
||||
|
||||
val index = getDetailIndex(details, params.detailId)
|
||||
if (index == -1) {
|
||||
Either.Left(HideDetailError())
|
||||
} else {
|
||||
|
||||
val detail: Detail = details[index]
|
||||
databaseRepo.updateDatabase(
|
||||
it.copy(
|
||||
content = it.content.copy(
|
||||
details = details.toMutableList().apply {
|
||||
set(index, changeShow(detail))
|
||||
})
|
||||
)
|
||||
)
|
||||
Either.Right(Unit)
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e: Throwable) {
|
||||
Either.Left(e)
|
||||
}
|
||||
|
||||
private fun getDetailIndex(details: List<Detail>, id: String): Int =
|
||||
details.indexOfFirst { it.id == id }
|
||||
|
||||
private fun changeShow(detail: Detail): Detail =
|
||||
when (detail) {
|
||||
is Detail.Title -> detail.copy(show = !detail.show)
|
||||
is Detail.Text -> detail.copy(show = !detail.show)
|
||||
is Detail.Number -> detail.copy(show = !detail.show)
|
||||
is Detail.Date -> detail.copy(show = !detail.show)
|
||||
is Detail.Select -> detail.copy(show = !detail.show)
|
||||
is Detail.Multiple -> detail.copy(show = !detail.show)
|
||||
is Detail.Person -> detail.copy(show = !detail.show)
|
||||
is Detail.File -> detail.copy(show = !detail.show)
|
||||
is Detail.Bool -> detail.copy(show = !detail.show)
|
||||
is Detail.Link -> detail.copy(show = !detail.show)
|
||||
is Detail.Email -> detail.copy(show = !detail.show)
|
||||
is Detail.Phone -> detail.copy(show = !detail.show)
|
||||
}
|
||||
|
||||
class Params(val databaseId: String, val detailId: String)
|
||||
class HideDetailError : Throwable()
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.repo.DatabaseRepository
|
||||
|
||||
/**
|
||||
* Created by Konstantin Ivanov
|
||||
* email : ki@agileburo.com
|
||||
* on 2019-12-19.
|
||||
*/
|
||||
class SwapDetails(
|
||||
private val databaseRepo: DatabaseRepository
|
||||
) : BaseUseCase<Unit, SwapDetails.Params>() {
|
||||
|
||||
override suspend fun run(params: Params): Either<Throwable, Unit> = try {
|
||||
|
||||
databaseRepo.getDatabase(params.databaseId).let {
|
||||
val updatedDetails = it.content.details.toMutableList()
|
||||
updatedDetails.swap(params.from, params.to)
|
||||
databaseRepo.updateDatabase(
|
||||
it.copy(
|
||||
content = it.content.copy(
|
||||
details = updatedDetails.toList()
|
||||
)
|
||||
)
|
||||
)
|
||||
Either.Right(Unit)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
Either.Left(e)
|
||||
}
|
||||
|
||||
data class Params(val from: Int, val to: Int, val databaseId: String)
|
||||
}
|
||||
|
||||
fun <T> MutableList<T>.swap(index1: Int, index2: Int) {
|
||||
val tmp = this[index1] // 'this' corresponds to the list
|
||||
this[index1] = this[index2]
|
||||
this[index2] = tmp
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.database.model.ViewType
|
||||
import com.anytypeio.anytype.domain.database.repo.DatabaseRepository
|
||||
import java.lang.Exception
|
||||
|
||||
class SwitchDisplayView(
|
||||
private val databaseRepo: DatabaseRepository
|
||||
) : BaseUseCase<String, SwitchDisplayView.Params>() {
|
||||
|
||||
override suspend fun run(params: Params): Either<Throwable, String> = try {
|
||||
databaseRepo.updateViewType(params.type)
|
||||
Either.Right("Switch display view with id:${params.id} to type:${params.type}")
|
||||
} catch (e: Throwable) {
|
||||
Either.Left(e)
|
||||
}
|
||||
|
||||
data class Params(val id: String, val type: ViewType)
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.model
|
||||
|
||||
data class Contact(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val date: Long,
|
||||
val icon: String?,
|
||||
val tags: List<Tag> = emptyList()
|
||||
)
|
||||
|
||||
data class Tag(
|
||||
val id: String,
|
||||
val name: String
|
||||
)
|
|
@ -1,43 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.model
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
@Deprecated("Legacy")
|
||||
enum class ViewType : Serializable { GRID, BOARD, GALLERY, LIST }
|
||||
@Deprecated("Legacy")
|
||||
enum class FilterTypeCondition { NONE, AND, OR }
|
||||
@Deprecated("Legacy")
|
||||
enum class FilterTypeEquality { EQUAL, NOT_EQUAL, IN, NOT_IN, GREATER, LESSER, LIKE, NOT_LIKE }
|
||||
|
||||
@Deprecated("Legacy")
|
||||
data class Filter(
|
||||
val detailId: String,
|
||||
val condition: FilterTypeCondition,
|
||||
val equality: FilterTypeEquality,
|
||||
val value: Any
|
||||
)
|
||||
|
||||
@Deprecated("Legacy")
|
||||
data class Group(
|
||||
val details: List<Detail>
|
||||
)
|
||||
|
||||
@Deprecated("Legacy")
|
||||
data class Display(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val type: ViewType,
|
||||
val filters: List<Filter> = emptyList(),
|
||||
val groups: List<Group> = emptyList()
|
||||
)
|
||||
|
||||
@Deprecated("Legacy")
|
||||
data class ContentDatabaseView(
|
||||
val databaseId: String,
|
||||
val details: List<Detail>,
|
||||
val displays: MutableList<Display>,
|
||||
val data: List<HashMap<String, Any>>
|
||||
)
|
||||
|
||||
@Deprecated("Legacy")
|
||||
data class DatabaseView(val content: ContentDatabaseView)
|
|
@ -1,90 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.model
|
||||
|
||||
sealed class Detail(open val id: String) {
|
||||
|
||||
data class Title(
|
||||
override val id: String,
|
||||
val name: String,
|
||||
val show: Boolean
|
||||
) : Detail(id)
|
||||
|
||||
data class Text(
|
||||
override val id: String,
|
||||
val name: String,
|
||||
val show: Boolean
|
||||
) : Detail(id)
|
||||
|
||||
data class Number(
|
||||
override val id: String,
|
||||
val name: String,
|
||||
val show: Boolean
|
||||
) :
|
||||
Detail(id)
|
||||
|
||||
data class Date(
|
||||
override val id: String,
|
||||
val name: String,
|
||||
val show: Boolean
|
||||
) : Detail(id)
|
||||
|
||||
data class Select(
|
||||
override val id: String,
|
||||
val name: String,
|
||||
val select: Set<String> = emptySet(),
|
||||
val show: Boolean
|
||||
) :
|
||||
Detail(id)
|
||||
|
||||
data class Multiple(
|
||||
override val id: String,
|
||||
val name: String,
|
||||
val multiSelect: Set<String> = emptySet(),
|
||||
val show: Boolean
|
||||
) : Detail(id)
|
||||
|
||||
data class Person(
|
||||
override val id: String,
|
||||
val name: String,
|
||||
val accounts: Set<Value>,
|
||||
val show: Boolean
|
||||
) :
|
||||
Detail(id)
|
||||
|
||||
data class File(
|
||||
override val id: String,
|
||||
val name: String,
|
||||
val show: Boolean
|
||||
) :
|
||||
Detail(id)
|
||||
|
||||
data class Bool(
|
||||
override val id: String,
|
||||
val name: String,
|
||||
val show: Boolean
|
||||
) :
|
||||
Detail(id)
|
||||
|
||||
data class Link(
|
||||
override val id: String,
|
||||
val name: String,
|
||||
val show: Boolean
|
||||
) :
|
||||
Detail(id)
|
||||
|
||||
data class Email(
|
||||
override val id: String,
|
||||
val name: String,
|
||||
val show: Boolean
|
||||
) :
|
||||
Detail(id)
|
||||
|
||||
data class Phone
|
||||
(
|
||||
override val id: String,
|
||||
val name: String,
|
||||
val show: Boolean
|
||||
) :
|
||||
Detail(id)
|
||||
}
|
||||
|
||||
data class Value(val name: String)
|
|
@ -1,10 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.repo
|
||||
|
||||
import com.anytypeio.anytype.domain.database.model.DatabaseView
|
||||
import com.anytypeio.anytype.domain.database.model.ViewType
|
||||
|
||||
interface DatabaseRepository {
|
||||
fun getDatabase(id: String): DatabaseView
|
||||
fun updateDatabase(databse: DatabaseView)
|
||||
fun updateViewType(type: ViewType)
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.core_models.CoroutineTestRule
|
||||
import com.anytypeio.anytype.domain.database.model.ContentDatabaseView
|
||||
import com.anytypeio.anytype.domain.database.model.DatabaseView
|
||||
import com.anytypeio.anytype.domain.database.model.Detail
|
||||
import com.anytypeio.anytype.domain.database.repo.DatabaseRepository
|
||||
import com.nhaarman.mockitokotlin2.doReturn
|
||||
import com.nhaarman.mockitokotlin2.stub
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class DeleteDetailTest {
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
@get:Rule
|
||||
var rule = CoroutineTestRule()
|
||||
|
||||
@Mock
|
||||
lateinit var databaseRepo: DatabaseRepository
|
||||
lateinit var deleteDetail: DeleteDetail
|
||||
|
||||
private val db = DatabaseView(
|
||||
content = ContentDatabaseView(
|
||||
databaseId = "213",
|
||||
displays = mutableListOf(),
|
||||
details = listOf(
|
||||
Detail.Date(id = "423", show = true, name = "Birthday"),
|
||||
Detail.Email(id = "544", show = true, name = "Cowokers email"),
|
||||
Detail.Text(id = "888", show = true, name = "Surnames")
|
||||
),
|
||||
data = listOf()
|
||||
)
|
||||
)
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
deleteDetail = DeleteDetail(databaseRepo)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should delete database detail with id`() = runBlocking {
|
||||
val databaseId = "213"
|
||||
val detailId = "423"
|
||||
|
||||
databaseRepo.stub {
|
||||
onBlocking { getDatabase(databaseId) } doReturn db
|
||||
}
|
||||
|
||||
val result =
|
||||
deleteDetail.run(DeleteDetail.Params(databaseId = databaseId, detailId = detailId))
|
||||
|
||||
assertEquals(Either.Right(Unit), result)
|
||||
}
|
||||
|
||||
// @Test
|
||||
// fun `should return error when try to delete wrong detail`() = runBlocking {
|
||||
// val databaseId = "213"
|
||||
// val detailId = "424"
|
||||
//
|
||||
// databaseRepo.stub {
|
||||
// onBlocking { getDatabase(databaseId) } doReturn db
|
||||
// }
|
||||
//
|
||||
// val result =
|
||||
// deleteDetail.run(DeleteDetail.Params(databaseId = databaseId, detailId = detailId))
|
||||
//
|
||||
// Assert.assertEquals(Either.Left(DeleteDetail.DeleteDetailError()), result)
|
||||
// }
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package com.anytypeio.anytype.domain.database.interactor
|
||||
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.core_models.CoroutineTestRule
|
||||
import com.anytypeio.anytype.domain.database.model.ContentDatabaseView
|
||||
import com.anytypeio.anytype.domain.database.model.DatabaseView
|
||||
import com.anytypeio.anytype.domain.database.model.Detail
|
||||
import com.anytypeio.anytype.domain.database.repo.DatabaseRepository
|
||||
import com.nhaarman.mockitokotlin2.doReturn
|
||||
import com.nhaarman.mockitokotlin2.stub
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class HideDetailTest {
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
@get:Rule
|
||||
var rule = CoroutineTestRule()
|
||||
|
||||
@Mock
|
||||
lateinit var databaseRepo: DatabaseRepository
|
||||
lateinit var hideDetail: HideDetail
|
||||
|
||||
private val db = DatabaseView(
|
||||
content = ContentDatabaseView(
|
||||
databaseId = "213",
|
||||
displays = mutableListOf(),
|
||||
details = listOf(
|
||||
Detail.Date(id = "423", show = true, name = "Birthday"),
|
||||
Detail.Email(id = "544", show = true, name = "Cowokers email"),
|
||||
Detail.Text(id = "888", show = true, name = "Surnames")
|
||||
),
|
||||
data = listOf()
|
||||
)
|
||||
)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
hideDetail = HideDetail(databaseRepo)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should hide detail with id`() = runBlocking {
|
||||
val databaseId = "213"
|
||||
val detailId = "423"
|
||||
|
||||
databaseRepo.stub {
|
||||
onBlocking { getDatabase(databaseId) } doReturn db
|
||||
}
|
||||
|
||||
val result =
|
||||
hideDetail.run(HideDetail.Params(databaseId = databaseId, detailId = detailId))
|
||||
|
||||
assertEquals(Either.Right(Unit), result)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue