diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cde7ae261..154694c7ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,12 @@ # Change log for Android @Anytype app. -## Version 0.4.5 (WIP) +## Version 0.5.0 (WIP) ### New features & enhancements 🚀 * App | Reminding our users about saving the mnemonic phrase (#1982) * App | Offload your files from device (#1990) +* App | Wallpapers (#1995) ### Fixes & tech 🚒 diff --git a/app/src/main/java/com/anytypeio/anytype/device/DefaultGradientCollectionProvider.kt b/app/src/main/java/com/anytypeio/anytype/device/DefaultGradientCollectionProvider.kt index 8ae335c8f9..f1854337aa 100644 --- a/app/src/main/java/com/anytypeio/anytype/device/DefaultGradientCollectionProvider.kt +++ b/app/src/main/java/com/anytypeio/anytype/device/DefaultGradientCollectionProvider.kt @@ -6,6 +6,13 @@ import com.anytypeio.anytype.presentation.editor.cover.CoverGradient class DefaultGradientCollectionProvider : GradientCollectionProvider { override fun provide(): List = listOf( - CoverGradient.YELLOW, CoverGradient.RED, CoverGradient.BLUE, CoverGradient.TEAL + CoverGradient.YELLOW, + CoverGradient.RED, + CoverGradient.BLUE, + CoverGradient.TEAL, + CoverGradient.PINK_ORANGE, + CoverGradient.BLUE_PINK, + CoverGradient.GREEN_ORANGE, + CoverGradient.SKY ) } \ No newline at end of file diff --git a/app/src/main/java/com/anytypeio/anytype/di/common/ComponentManager.kt b/app/src/main/java/com/anytypeio/anytype/di/common/ComponentManager.kt index 680d9747ee..cca7991e9c 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/common/ComponentManager.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/common/ComponentManager.kt @@ -9,6 +9,7 @@ import com.anytypeio.anytype.di.feature.sets.PickConditionModule import com.anytypeio.anytype.di.feature.sets.SelectFilterRelationModule import com.anytypeio.anytype.di.feature.sets.viewer.ViewerCardSizeSelectModule import com.anytypeio.anytype.di.feature.sets.viewer.ViewerImagePreviewSelectModule +import com.anytypeio.anytype.di.feature.wallpaper.WallpaperSelectModule import com.anytypeio.anytype.di.main.MainComponent class ComponentManager(private val main: MainComponent) { @@ -106,6 +107,13 @@ class ComponentManager(private val main: MainComponent) { .build() } + val wallpaperSelectComponent = Component { + main + .wallpaperSelectComponent() + .module(WallpaperSelectModule) + .build() + } + val editorComponent = ComponentMap { main .editorComponentBuilder() diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/MainEntryDI.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/MainEntryDI.kt index e1195a8adb..8ba6f91b23 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/feature/MainEntryDI.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/MainEntryDI.kt @@ -5,7 +5,10 @@ import com.anytypeio.anytype.core_utils.di.scope.PerScreen import com.anytypeio.anytype.domain.auth.interactor.LaunchAccount import com.anytypeio.anytype.domain.auth.repo.AuthRepository import com.anytypeio.anytype.domain.config.FlavourConfigProvider +import com.anytypeio.anytype.domain.config.UserSettingsRepository import com.anytypeio.anytype.domain.device.PathProvider +import com.anytypeio.anytype.domain.wallpaper.ObserveWallpaper +import com.anytypeio.anytype.domain.wallpaper.RestoreWallpaper import com.anytypeio.anytype.presentation.main.MainViewModelFactory import com.anytypeio.anytype.ui.main.MainActivity import dagger.Module @@ -34,8 +37,15 @@ object MainEntryModule { @Provides fun provideMainViewModelFactory( launchAccount: LaunchAccount, - analytics: Analytics - ): MainViewModelFactory = MainViewModelFactory(launchAccount, analytics) + analytics: Analytics, + observeWallpaper: ObserveWallpaper, + restoreWallpaper: RestoreWallpaper + ): MainViewModelFactory = MainViewModelFactory( + launchAccount = launchAccount, + analytics = analytics, + observeWallpaper = observeWallpaper, + restoreWallpaper = restoreWallpaper + ) @JvmStatic @PerScreen @@ -50,4 +60,16 @@ object MainEntryModule { context = Dispatchers.Main, flavourConfigProvider = flavourConfigProvider ) + + @JvmStatic + @PerScreen + @Provides + fun provideObserveWallpaperUseCase() : ObserveWallpaper = ObserveWallpaper() + + @JvmStatic + @PerScreen + @Provides + fun provideRestoreWallpaperUseCase( + repo: UserSettingsRepository + ) : RestoreWallpaper = RestoreWallpaper(repo) } \ No newline at end of file diff --git a/app/src/main/java/com/anytypeio/anytype/di/feature/wallpaper/WallpaperSelectDI.kt b/app/src/main/java/com/anytypeio/anytype/di/feature/wallpaper/WallpaperSelectDI.kt new file mode 100644 index 0000000000..8081cc6ccc --- /dev/null +++ b/app/src/main/java/com/anytypeio/anytype/di/feature/wallpaper/WallpaperSelectDI.kt @@ -0,0 +1,43 @@ +package com.anytypeio.anytype.di.feature.wallpaper + +import com.anytypeio.anytype.core_utils.di.scope.PerScreen +import com.anytypeio.anytype.domain.config.UserSettingsRepository +import com.anytypeio.anytype.domain.wallpaper.SetWallpaper +import com.anytypeio.anytype.presentation.wallpaper.WallpaperSelectViewModel +import com.anytypeio.anytype.ui.dashboard.WallpaperSelectFragment +import dagger.Module +import dagger.Provides +import dagger.Subcomponent + +@Subcomponent( + modules = [WallpaperSelectModule::class] +) +@PerScreen +interface WallpaperSelectSubComponent { + + @Subcomponent.Builder + interface Builder { + fun module(module: WallpaperSelectModule): Builder + fun build(): WallpaperSelectSubComponent + } + + fun inject(fragment: WallpaperSelectFragment) +} + +@Module +object WallpaperSelectModule { + + @JvmStatic + @Provides + @PerScreen + fun provideViewModelFactory( + setWallpaper: SetWallpaper + ): WallpaperSelectViewModel.Factory = WallpaperSelectViewModel.Factory( + setWallpaper = setWallpaper + ) + + @JvmStatic + @Provides + @PerScreen + fun provideSetWallpaper(repo: UserSettingsRepository) : SetWallpaper = SetWallpaper(repo) +} \ No newline at end of file diff --git a/app/src/main/java/com/anytypeio/anytype/di/main/MainComponent.kt b/app/src/main/java/com/anytypeio/anytype/di/main/MainComponent.kt index de60de0276..60318bb70d 100644 --- a/app/src/main/java/com/anytypeio/anytype/di/main/MainComponent.kt +++ b/app/src/main/java/com/anytypeio/anytype/di/main/MainComponent.kt @@ -2,6 +2,7 @@ package com.anytypeio.anytype.di.main import com.anytypeio.anytype.app.AndroidApplication import com.anytypeio.anytype.di.feature.* +import com.anytypeio.anytype.di.feature.wallpaper.WallpaperSelectSubComponent import dagger.Component import javax.inject.Singleton @@ -43,4 +44,5 @@ interface MainComponent { fun objectSetComponentBuilder(): ObjectSetSubComponent.Builder fun otherSettingsComponentBuilder(): OtherSettingsSubComponent.Builder fun objectTypeChangeComponent(): ObjectTypeChangeSubComponent.Builder + fun wallpaperSelectComponent(): WallpaperSelectSubComponent.Builder } \ No newline at end of file diff --git a/app/src/main/java/com/anytypeio/anytype/ui/dashboard/WallpaperSelectFragment.kt b/app/src/main/java/com/anytypeio/anytype/ui/dashboard/WallpaperSelectFragment.kt new file mode 100644 index 0000000000..67f5a0be4d --- /dev/null +++ b/app/src/main/java/com/anytypeio/anytype/ui/dashboard/WallpaperSelectFragment.kt @@ -0,0 +1,89 @@ +package com.anytypeio.anytype.ui.dashboard + +import android.graphics.Rect +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.viewModels +import androidx.lifecycle.lifecycleScope +import androidx.recyclerview.widget.GridLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.anytypeio.anytype.R +import com.anytypeio.anytype.core_ui.features.wallpaper.WallpaperSelectAdapter +import com.anytypeio.anytype.core_utils.ext.dimen +import com.anytypeio.anytype.core_utils.ext.subscribe +import com.anytypeio.anytype.core_utils.ui.BaseBottomSheetFragment +import com.anytypeio.anytype.di.common.componentManager +import com.anytypeio.anytype.presentation.wallpaper.WallpaperSelectViewModel +import kotlinx.android.synthetic.main.fragment_wallpaper_select.* +import javax.inject.Inject + +class WallpaperSelectFragment : BaseBottomSheetFragment() { + + @Inject + lateinit var factory: WallpaperSelectViewModel.Factory + + private val vm by viewModels { factory } + + private val wallpaperSelectAdapter by lazy { + WallpaperSelectAdapter { vm.onWallpaperSelected(it) } + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? = inflater.inflate(R.layout.fragment_wallpaper_select, container, false) + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val spacing = requireContext().dimen(R.dimen.cover_gallery_item_spacing).toInt() + wallpaperRecycler.apply { + adapter = wallpaperSelectAdapter + layoutManager = GridLayoutManager(context, 3).apply { + spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { + override fun getSpanSize(position: Int): Int { + return when (wallpaperSelectAdapter.getItemViewType(position)) { + R.layout.item_wallpaper_select_section -> 3 + else -> 1 + } + } + } + } + addItemDecoration( + object : RecyclerView.ItemDecoration() { + override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) { + val position = parent.getChildAdapterPosition(view) + val holder = parent.findViewHolderForLayoutPosition(position) + if (holder !is WallpaperSelectAdapter.SectionViewHolder) { + outRect.left = spacing + outRect.right = spacing + outRect.top = spacing * 2 + outRect.bottom = 0 + } + // Drawing space at the bottom of the two last wallpapers. TODO refact. + if (position == state.itemCount - 2) { + outRect.bottom = spacing * 2 + } + if (position == state.itemCount - 1) { + outRect.bottom = spacing * 2 + } + } + } + ) + } + with(lifecycleScope) { + subscribe(vm.state) { wallpaperSelectAdapter.update(it) } + subscribe(vm.isDismissed) { isDismissed -> if (isDismissed) dismiss() } + } + } + + override fun injectDependencies() { + componentManager().wallpaperSelectComponent.get().inject(this) + } + + override fun releaseDependencies() { + componentManager().wallpaperSelectComponent.release() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/anytypeio/anytype/ui/main/MainActivity.kt b/app/src/main/java/com/anytypeio/anytype/ui/main/MainActivity.kt index b6fb4e96c1..b2cbdf52ae 100644 --- a/app/src/main/java/com/anytypeio/anytype/ui/main/MainActivity.kt +++ b/app/src/main/java/com/anytypeio/anytype/ui/main/MainActivity.kt @@ -1,16 +1,23 @@ package com.anytypeio.anytype.ui.main import android.content.Context +import android.graphics.Color import android.os.Bundle import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.lifecycleScope import androidx.navigation.findNavController import com.anytypeio.anytype.R +import com.anytypeio.anytype.core_models.Wallpaper +import com.anytypeio.anytype.core_utils.ext.subscribe import com.anytypeio.anytype.di.common.componentManager import com.anytypeio.anytype.navigation.Navigator +import com.anytypeio.anytype.presentation.editor.cover.CoverGradient import com.anytypeio.anytype.presentation.main.MainViewModel import com.anytypeio.anytype.presentation.main.MainViewModelFactory import com.anytypeio.anytype.presentation.navigation.AppNavigation +import com.anytypeio.anytype.presentation.wallpaper.WallpaperColor +import kotlinx.android.synthetic.main.activity_main.* import javax.inject.Inject class MainActivity : AppCompatActivity(R.layout.activity_main), AppNavigation.Provider { @@ -29,6 +36,38 @@ class MainActivity : AppCompatActivity(R.layout.activity_main), AppNavigation.Pr super.onCreate(savedInstanceState) inject() if (savedInstanceState != null) vm.onRestore() + with(lifecycleScope) { + subscribe(vm.wallpaper) { wallpaper -> setWallpaper(wallpaper) } + } + } + + private fun setWallpaper(wallpaper: Wallpaper) { + when (wallpaper) { + is Wallpaper.Gradient -> { + when(wallpaper.code) { + CoverGradient.YELLOW -> fragment.setBackgroundResource(R.drawable.cover_gradient_yellow) + CoverGradient.RED -> fragment.setBackgroundResource(R.drawable.cover_gradient_red) + CoverGradient.BLUE -> fragment.setBackgroundResource(R.drawable.cover_gradient_blue) + CoverGradient.TEAL -> fragment.setBackgroundResource(R.drawable.cover_gradient_teal) + CoverGradient.PINK_ORANGE -> fragment.setBackgroundResource(R.drawable.wallpaper_gradient_1) + CoverGradient.BLUE_PINK -> fragment.setBackgroundResource(R.drawable.wallpaper_gradient_2) + CoverGradient.GREEN_ORANGE -> fragment.setBackgroundResource(R.drawable.wallpaper_gradient_3) + CoverGradient.SKY -> fragment.setBackgroundResource(R.drawable.wallpaper_gradient_4) + } + } + is Wallpaper.Default -> { + fragment.setBackgroundResource(R.color.default_dashboard_background_color) + } + is Wallpaper.Color -> { + val color = WallpaperColor.values().find { it.code == wallpaper.code } + if (color != null) { + fragment.setBackgroundColor(Color.parseColor(color.hex)) + } + } + is Wallpaper.Image -> { + fragment.setBackgroundResource(R.color.default_dashboard_background_color) + } + } } override fun onResume() { diff --git a/app/src/main/java/com/anytypeio/anytype/ui/profile/ProfileFragment.kt b/app/src/main/java/com/anytypeio/anytype/ui/profile/ProfileFragment.kt index 217df364f9..a47cf6b5ec 100644 --- a/app/src/main/java/com/anytypeio/anytype/ui/profile/ProfileFragment.kt +++ b/app/src/main/java/com/anytypeio/anytype/ui/profile/ProfileFragment.kt @@ -4,6 +4,7 @@ import android.os.Bundle import android.view.View import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope +import androidx.navigation.fragment.findNavController import com.anytypeio.anytype.BuildConfig import com.anytypeio.anytype.R import com.anytypeio.anytype.core_ui.extensions.avatarColor @@ -50,8 +51,7 @@ class ProfileFragment : ViewStateFragment>(R.layout.fragm when (state) { is ViewState.Init -> { wallpaperText.setOnClickListener { - vm.onWallpaperClicked() - toast("Coming soon...") + findNavController().navigate(R.id.wallpaperSetFragment) } logoutButton.setOnClickListener { vm.onLogoutClicked() } pinCodeText.setOnClickListener { diff --git a/app/src/main/java/com/anytypeio/anytype/ui/sets/ObjectSetFragment.kt b/app/src/main/java/com/anytypeio/anytype/ui/sets/ObjectSetFragment.kt index 1a5371e0c7..d8ade3aabd 100644 --- a/app/src/main/java/com/anytypeio/anytype/ui/sets/ObjectSetFragment.kt +++ b/app/src/main/java/com/anytypeio/anytype/ui/sets/ObjectSetFragment.kt @@ -418,6 +418,10 @@ open class ObjectSetFragment : CoverGradient.RED -> setBackgroundResource(com.anytypeio.anytype.core_ui.R.drawable.cover_gradient_red) CoverGradient.BLUE -> setBackgroundResource(com.anytypeio.anytype.core_ui.R.drawable.cover_gradient_blue) CoverGradient.TEAL -> setBackgroundResource(com.anytypeio.anytype.core_ui.R.drawable.cover_gradient_teal) + CoverGradient.PINK_ORANGE -> setBackgroundResource(com.anytypeio.anytype.core_ui.R.drawable.wallpaper_gradient_1) + CoverGradient.BLUE_PINK -> setBackgroundResource(com.anytypeio.anytype.core_ui.R.drawable.wallpaper_gradient_2) + CoverGradient.GREEN_ORANGE -> setBackgroundResource(com.anytypeio.anytype.core_ui.R.drawable.wallpaper_gradient_3) + CoverGradient.SKY -> setBackgroundResource(com.anytypeio.anytype.core_ui.R.drawable.wallpaper_gradient_4) } } container.updatePadding(top = 0) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 77d4cc7f8d..eaba4fcdb9 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,6 +6,7 @@ android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="@color/default_dashboard_background_color" app:defaultNavHost="true" app:navGraph="@navigation/graph" tools:context=".ui.main.MainActivity" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_create_account.xml b/app/src/main/res/layout/fragment_create_account.xml index 4e5a87bdd1..e38d7b8970 100644 --- a/app/src/main/res/layout/fragment_create_account.xml +++ b/app/src/main/res/layout/fragment_create_account.xml @@ -2,8 +2,7 @@ + android:layout_height="match_parent"> + android:layout_height="match_parent"> @@ -36,7 +37,9 @@ android:layout_height="wrap_content" android:layout_marginTop="32dp" android:background="@color/white" + android:fontFamily="@font/inter_regular" android:text="Debug Local Store" + android:textAllCaps="false" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/btnSync" /> diff --git a/app/src/main/res/layout/fragment_invitation.xml b/app/src/main/res/layout/fragment_invitation.xml index 31253d1736..2a1b98b2e5 100644 --- a/app/src/main/res/layout/fragment_invitation.xml +++ b/app/src/main/res/layout/fragment_invitation.xml @@ -2,8 +2,7 @@ + android:layout_height="match_parent"> + android:layout_height="match_parent"> + android:layout_height="match_parent"> + xmlns:tools="http://schemas.android.com/tools"> + android:layout_height="match_parent"> + android:layout_height="match_parent"> + android:layout_height="match_parent"> + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/graph.xml b/app/src/main/res/navigation/graph.xml index c5e1561d4d..3a20ae0af1 100644 --- a/app/src/main/res/navigation/graph.xml +++ b/app/src/main/res/navigation/graph.xml @@ -425,8 +425,12 @@ android:id="@+id/userSettingsFragment" android:name="com.anytypeio.anytype.ui.settings.OtherSettingsFragment" android:label="fragment_user_settings" - tools:layout="@layout/fragment_user_settings" > - + tools:layout="@layout/fragment_user_settings"/> + + app:attributeName="alpha" + app:customFloatValue="1.0" /> + app:attributeName="alpha" + app:customFloatValue="0.0" /> setBackgroundResource(R.drawable.cover_gradient_red) CoverGradient.BLUE -> setBackgroundResource(R.drawable.cover_gradient_blue) CoverGradient.TEAL -> setBackgroundResource(R.drawable.cover_gradient_teal) + CoverGradient.PINK_ORANGE -> setBackgroundResource(R.drawable.wallpaper_gradient_1) + CoverGradient.BLUE_PINK -> setBackgroundResource(R.drawable.wallpaper_gradient_2) + CoverGradient.GREEN_ORANGE -> setBackgroundResource(R.drawable.wallpaper_gradient_3) + CoverGradient.SKY -> setBackgroundResource(R.drawable.wallpaper_gradient_4) } visible() } diff --git a/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/modal/DocCoverGalleryAdapter.kt b/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/modal/DocCoverGalleryAdapter.kt index 967b8e6778..b9699d4d34 100644 --- a/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/modal/DocCoverGalleryAdapter.kt +++ b/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/editor/modal/DocCoverGalleryAdapter.kt @@ -118,6 +118,10 @@ class DocCoverGalleryAdapter( CoverGradient.RED -> setBackgroundResource(R.drawable.cover_gradient_red) CoverGradient.BLUE -> setBackgroundResource(R.drawable.cover_gradient_blue) CoverGradient.TEAL -> setBackgroundResource(R.drawable.cover_gradient_teal) + CoverGradient.PINK_ORANGE -> setBackgroundResource(R.drawable.wallpaper_gradient_1) + CoverGradient.BLUE_PINK -> setBackgroundResource(R.drawable.wallpaper_gradient_2) + CoverGradient.GREEN_ORANGE -> setBackgroundResource(R.drawable.wallpaper_gradient_3) + CoverGradient.SKY -> setBackgroundResource(R.drawable.wallpaper_gradient_4) } } } diff --git a/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/wallpaper/WallpaperSelectAdapter.kt b/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/wallpaper/WallpaperSelectAdapter.kt new file mode 100644 index 0000000000..2bc6fc23ca --- /dev/null +++ b/core-ui/src/main/java/com/anytypeio/anytype/core_ui/features/wallpaper/WallpaperSelectAdapter.kt @@ -0,0 +1,146 @@ +package com.anytypeio.anytype.core_ui.features.wallpaper + +import android.graphics.Color +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.anytypeio.anytype.core_ui.R +import com.anytypeio.anytype.core_ui.extensions.tint +import com.anytypeio.anytype.presentation.editor.cover.CoverGradient +import com.anytypeio.anytype.presentation.wallpaper.WallpaperColor +import com.anytypeio.anytype.presentation.wallpaper.WallpaperSelectView +import com.anytypeio.anytype.presentation.wallpaper.WallpaperView +import kotlinx.android.synthetic.main.item_wallpaper_select_section.view.* + +class WallpaperSelectAdapter( + val onWallpaperSelected: (WallpaperView) -> Unit +) : RecyclerView.Adapter() { + + private var items: List = emptyList() + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH = when (viewType) { + R.layout.item_wallpaper_select_section -> SectionViewHolder(parent) + R.layout.item_wallpaper_select_gradient -> GradientViewHolder(parent).apply { + itemView.setOnClickListener { + val pos = bindingAdapterPosition + if (pos != RecyclerView.NO_POSITION) { + val item = items[pos] + if (item is WallpaperSelectView.Wallpaper) + onWallpaperSelected(item.item) + } + } + } + R.layout.item_wallpaper_select_solid_color -> SolidColorViewHolder(parent).apply { + itemView.setOnClickListener { + val pos = bindingAdapterPosition + if (pos != RecyclerView.NO_POSITION) { + val item = items[pos] + if (item is WallpaperSelectView.Wallpaper) + onWallpaperSelected(item.item) + } + } + } + else -> throw IllegalStateException("Unexpected view type: $viewType") + } + + override fun onBindViewHolder(holder: VH, position: Int) { + when (holder) { + is GradientViewHolder -> { + val item = items[position] + check(item is WallpaperSelectView.Wallpaper) + holder.bind(item) + } + is SolidColorViewHolder -> { + val item = items[position] + check(item is WallpaperSelectView.Wallpaper) + holder.bind(item) + } + is SectionViewHolder -> { + val item = items[position] + check(item is WallpaperSelectView.Section) + holder.bind(item) + } + } + } + + override fun getItemCount(): Int = items.size + + override fun getItemViewType(position: Int): Int = when (val view = items[position]) { + is WallpaperSelectView.Section -> R.layout.item_wallpaper_select_section + is WallpaperSelectView.Wallpaper -> { + if (view.item is WallpaperView.SolidColor) + R.layout.item_wallpaper_select_solid_color + else + R.layout.item_wallpaper_select_gradient + } + } + + fun update(views: List) { + items = views + notifyDataSetChanged() + } + + sealed class VH(view: View) : RecyclerView.ViewHolder(view) + + class SectionViewHolder(parent: ViewGroup) : VH( + LayoutInflater.from(parent.context).inflate( + R.layout.item_wallpaper_select_section, + parent, + false + ) + ) { + fun bind(item: WallpaperSelectView.Section) = with(itemView) { + when (item) { + WallpaperSelectView.Section.Gradient -> { + tvSectionName.setText(R.string.cover_gradients) + } + WallpaperSelectView.Section.SolidColor -> { + tvSectionName.setText(R.string.cover_color_solid) + } + } + } + } + + class SolidColorViewHolder(parent: ViewGroup) : VH( + LayoutInflater.from(parent.context).inflate( + R.layout.item_wallpaper_select_solid_color, + parent, + false + ) + ) { + fun bind(wallpaper: WallpaperSelectView.Wallpaper) = with(itemView) { + val item = wallpaper.item + check(item is WallpaperView.SolidColor) + val color = WallpaperColor.values().find { it.code == item.code } + if (color != null ) { + itemView.tint(Color.parseColor(color.hex)) + } else { + itemView.tint(Color.WHITE) + } + } + } + + class GradientViewHolder(parent: ViewGroup) : VH( + LayoutInflater.from(parent.context).inflate( + R.layout.item_wallpaper_select_gradient, + parent, + false + ) + ) { + fun bind(item: WallpaperSelectView.Wallpaper) = with(itemView) { + val wallpaper = item.item + check(wallpaper is WallpaperView.Gradient) + when (wallpaper.code) { + CoverGradient.YELLOW -> setBackgroundResource(R.drawable.cover_gradient_yellow) + CoverGradient.RED -> setBackgroundResource(R.drawable.cover_gradient_red) + CoverGradient.BLUE -> setBackgroundResource(R.drawable.cover_gradient_blue) + CoverGradient.TEAL -> setBackgroundResource(R.drawable.cover_gradient_teal) + CoverGradient.PINK_ORANGE -> setBackgroundResource(R.drawable.wallpaper_gradient_1) + CoverGradient.BLUE_PINK -> setBackgroundResource(R.drawable.wallpaper_gradient_2) + CoverGradient.GREEN_ORANGE -> setBackgroundResource(R.drawable.wallpaper_gradient_3) + CoverGradient.SKY -> setBackgroundResource(R.drawable.wallpaper_gradient_4) + } + } + } +} \ No newline at end of file diff --git a/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_blue.xml b/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_blue.xml index 6dc4f3c50b..c9855e2e89 100644 --- a/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_blue.xml +++ b/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_blue.xml @@ -2,7 +2,7 @@ \ No newline at end of file diff --git a/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_red.xml b/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_red.xml index 243decc694..d48820ac85 100644 --- a/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_red.xml +++ b/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_red.xml @@ -2,7 +2,7 @@ \ No newline at end of file diff --git a/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_teal.xml b/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_teal.xml index 1226d07f4b..055229fdb1 100644 --- a/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_teal.xml +++ b/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_teal.xml @@ -2,7 +2,7 @@ \ No newline at end of file diff --git a/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_yellow.xml b/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_yellow.xml index c07e7b37a2..4dbaf85ef7 100644 --- a/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_yellow.xml +++ b/core-ui/src/main/res/drawable-xxxhdpi/cover_gradient_yellow.xml @@ -2,7 +2,7 @@ \ No newline at end of file diff --git a/core-ui/src/main/res/drawable/wallpaper_gradient_1.xml b/core-ui/src/main/res/drawable/wallpaper_gradient_1.xml new file mode 100644 index 0000000000..fbcb68cb1e --- /dev/null +++ b/core-ui/src/main/res/drawable/wallpaper_gradient_1.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/core-ui/src/main/res/drawable/wallpaper_gradient_2.xml b/core-ui/src/main/res/drawable/wallpaper_gradient_2.xml new file mode 100644 index 0000000000..80109c6768 --- /dev/null +++ b/core-ui/src/main/res/drawable/wallpaper_gradient_2.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/core-ui/src/main/res/drawable/wallpaper_gradient_3.xml b/core-ui/src/main/res/drawable/wallpaper_gradient_3.xml new file mode 100644 index 0000000000..4e6cf98c1a --- /dev/null +++ b/core-ui/src/main/res/drawable/wallpaper_gradient_3.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/core-ui/src/main/res/drawable/wallpaper_gradient_4.xml b/core-ui/src/main/res/drawable/wallpaper_gradient_4.xml new file mode 100644 index 0000000000..3a57d7f755 --- /dev/null +++ b/core-ui/src/main/res/drawable/wallpaper_gradient_4.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/core-ui/src/main/res/layout/item_wallpaper_select_gradient.xml b/core-ui/src/main/res/layout/item_wallpaper_select_gradient.xml new file mode 100644 index 0000000000..64b966361b --- /dev/null +++ b/core-ui/src/main/res/layout/item_wallpaper_select_gradient.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/core-ui/src/main/res/layout/item_wallpaper_select_section.xml b/core-ui/src/main/res/layout/item_wallpaper_select_section.xml new file mode 100644 index 0000000000..a04c746d47 --- /dev/null +++ b/core-ui/src/main/res/layout/item_wallpaper_select_section.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/core-ui/src/main/res/layout/item_wallpaper_select_solid_color.xml b/core-ui/src/main/res/layout/item_wallpaper_select_solid_color.xml new file mode 100644 index 0000000000..562be45445 --- /dev/null +++ b/core-ui/src/main/res/layout/item_wallpaper_select_solid_color.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/core-ui/src/main/res/values/dimens.xml b/core-ui/src/main/res/values/dimens.xml index 4ec6ae0987..c03e4067dd 100644 --- a/core-ui/src/main/res/values/dimens.xml +++ b/core-ui/src/main/res/values/dimens.xml @@ -201,5 +201,6 @@ 14dp 12sp 11sp + 208dp \ No newline at end of file diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/UserSettingsCache.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/UserSettingsCache.kt index 9f16f1fa60..a7997c9a33 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/UserSettingsCache.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/UserSettingsCache.kt @@ -1,6 +1,10 @@ package com.anytypeio.anytype.data.auth.repo +import com.anytypeio.anytype.core_models.Wallpaper + interface UserSettingsCache { suspend fun setDefaultObjectType(type: String, name: String) suspend fun getDefaultObjectType(): Pair + suspend fun setWallpaper(wallpaper: Wallpaper) + suspend fun getWallpaper() : Wallpaper } \ No newline at end of file diff --git a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/UserSettingsDataRepository.kt b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/UserSettingsDataRepository.kt index 32cb6a2a60..41c38668d0 100644 --- a/data/src/main/java/com/anytypeio/anytype/data/auth/repo/UserSettingsDataRepository.kt +++ b/data/src/main/java/com/anytypeio/anytype/data/auth/repo/UserSettingsDataRepository.kt @@ -1,9 +1,16 @@ package com.anytypeio.anytype.data.auth.repo +import com.anytypeio.anytype.core_models.Wallpaper import com.anytypeio.anytype.domain.config.UserSettingsRepository class UserSettingsDataRepository(private val cache: UserSettingsCache) : UserSettingsRepository { + override suspend fun setWallpaper(wallpaper: Wallpaper) { + cache.setWallpaper(wallpaper) + } + + override suspend fun getWallpaper(): Wallpaper = cache.getWallpaper() + override suspend fun setDefaultObjectType(type: String, name: String) { cache.setDefaultObjectType(type, name) } diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/config/UserSettingsRepository.kt b/domain/src/main/java/com/anytypeio/anytype/domain/config/UserSettingsRepository.kt index 22c2735b96..e37bac7dd5 100644 --- a/domain/src/main/java/com/anytypeio/anytype/domain/config/UserSettingsRepository.kt +++ b/domain/src/main/java/com/anytypeio/anytype/domain/config/UserSettingsRepository.kt @@ -1,6 +1,10 @@ package com.anytypeio.anytype.domain.config +import com.anytypeio.anytype.core_models.Wallpaper + interface UserSettingsRepository { + suspend fun setWallpaper(wallpaper: Wallpaper) + suspend fun getWallpaper(): Wallpaper suspend fun setDefaultObjectType(type: String, name: String) suspend fun getDefaultObjectType(): Pair } \ No newline at end of file diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/wallpaper/ObserveWallpaper.kt b/domain/src/main/java/com/anytypeio/anytype/domain/wallpaper/ObserveWallpaper.kt new file mode 100644 index 0000000000..d4eda20335 --- /dev/null +++ b/domain/src/main/java/com/anytypeio/anytype/domain/wallpaper/ObserveWallpaper.kt @@ -0,0 +1,12 @@ +package com.anytypeio.anytype.domain.wallpaper + +import com.anytypeio.anytype.core_models.Wallpaper +import com.anytypeio.anytype.domain.base.BaseUseCase +import com.anytypeio.anytype.domain.base.FlowUseCase +import kotlinx.coroutines.flow.Flow + +class ObserveWallpaper : FlowUseCase() { + override fun build(params: BaseUseCase.None?): Flow { + return WallpaperStore.Default.observe() + } +} \ No newline at end of file diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/wallpaper/RestoreWallpaper.kt b/domain/src/main/java/com/anytypeio/anytype/domain/wallpaper/RestoreWallpaper.kt new file mode 100644 index 0000000000..a4c657a4df --- /dev/null +++ b/domain/src/main/java/com/anytypeio/anytype/domain/wallpaper/RestoreWallpaper.kt @@ -0,0 +1,13 @@ +package com.anytypeio.anytype.domain.wallpaper + +import com.anytypeio.anytype.domain.base.BaseUseCase +import com.anytypeio.anytype.domain.config.UserSettingsRepository + +class RestoreWallpaper( + private val repo: UserSettingsRepository +) : BaseUseCase() { + override suspend fun run(params: None) = safe { + val restored = repo.getWallpaper() + WallpaperStore.Default.set(restored) + } +} \ No newline at end of file diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/wallpaper/SetWallpaper.kt b/domain/src/main/java/com/anytypeio/anytype/domain/wallpaper/SetWallpaper.kt new file mode 100644 index 0000000000..b488b6d33b --- /dev/null +++ b/domain/src/main/java/com/anytypeio/anytype/domain/wallpaper/SetWallpaper.kt @@ -0,0 +1,32 @@ +package com.anytypeio.anytype.domain.wallpaper + +import com.anytypeio.anytype.core_models.Wallpaper +import com.anytypeio.anytype.domain.base.Interactor +import com.anytypeio.anytype.domain.config.UserSettingsRepository + +class SetWallpaper( + private val repo: UserSettingsRepository +) : Interactor() { + + override suspend fun run(params: Params) { + when (params) { + is Params.Gradient -> { + repo.setWallpaper( + Wallpaper.Gradient(params.code) + ) + WallpaperStore.Default.set(Wallpaper.Gradient(params.code)) + } + is Params.SolidColor -> { + repo.setWallpaper( + Wallpaper.Color(params.code) + ) + WallpaperStore.Default.set(Wallpaper.Color(params.code)) + } + } + } + + sealed class Params { + data class SolidColor(val code: String) : Params() + data class Gradient(val code: String) : Params() + } +} \ No newline at end of file diff --git a/domain/src/main/java/com/anytypeio/anytype/domain/wallpaper/WallpaperStore.kt b/domain/src/main/java/com/anytypeio/anytype/domain/wallpaper/WallpaperStore.kt new file mode 100644 index 0000000000..df653a431b --- /dev/null +++ b/domain/src/main/java/com/anytypeio/anytype/domain/wallpaper/WallpaperStore.kt @@ -0,0 +1,18 @@ +package com.anytypeio.anytype.domain.wallpaper + +import com.anytypeio.anytype.core_models.Wallpaper +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow + +interface WallpaperStore { + fun set(wallpaper: Wallpaper) + fun get() : Wallpaper + fun observe() : Flow + + object Default : WallpaperStore { + private val wallpaper = MutableStateFlow(Wallpaper.Default) + override fun set(wallpaper: Wallpaper) { this.wallpaper.value = wallpaper } + override fun get(): Wallpaper = wallpaper.value + override fun observe(): Flow = wallpaper + } +} \ No newline at end of file diff --git a/persistence/build.gradle b/persistence/build.gradle index 3699107fa8..cb12d051b7 100644 --- a/persistence/build.gradle +++ b/persistence/build.gradle @@ -23,7 +23,9 @@ android { } dependencies { + implementation project(':data') + implementation project(':core-models') def applicationDependencies = rootProject.ext.mainApplication def unitTestDependencies = rootProject.ext.unitTesting diff --git a/persistence/src/main/java/com/anytypeio/anytype/persistence/repo/DefaultUserSettingsCache.kt b/persistence/src/main/java/com/anytypeio/anytype/persistence/repo/DefaultUserSettingsCache.kt index 7fd872d3e2..cf992049e7 100644 --- a/persistence/src/main/java/com/anytypeio/anytype/persistence/repo/DefaultUserSettingsCache.kt +++ b/persistence/src/main/java/com/anytypeio/anytype/persistence/repo/DefaultUserSettingsCache.kt @@ -1,6 +1,7 @@ package com.anytypeio.anytype.persistence.repo import android.content.SharedPreferences +import com.anytypeio.anytype.core_models.Wallpaper import com.anytypeio.anytype.data.auth.repo.UserSettingsCache class DefaultUserSettingsCache(private val prefs: SharedPreferences) : UserSettingsCache { @@ -18,8 +19,74 @@ class DefaultUserSettingsCache(private val prefs: SharedPreferences) : UserSetti return Pair(type, name) } + override suspend fun setWallpaper(wallpaper: Wallpaper) { + when (wallpaper) { + is Wallpaper.Default -> { + prefs.edit() + .remove(WALLPAPER_VALUE_KEY) + .remove(WALLPAPER_TYPE_KEY) + .apply() + } + is Wallpaper.Color -> { + prefs + .edit() + .putInt(WALLPAPER_TYPE_KEY, WALLPAPER_TYPE_COLOR) + .putString(WALLPAPER_VALUE_KEY, wallpaper.code) + .apply() + } + is Wallpaper.Gradient -> { + prefs + .edit() + .putInt(WALLPAPER_TYPE_KEY, WALLPAPER_TYPE_GRADIENT) + .putString(WALLPAPER_VALUE_KEY, wallpaper.code) + .apply() + } + is Wallpaper.Image -> { + prefs + .edit() + .putInt(WALLPAPER_TYPE_KEY, WALLPAPER_TYPE_IMAGE) + .putString(WALLPAPER_VALUE_KEY, wallpaper.hash) + .apply() + } + } + } + + override suspend fun getWallpaper(): Wallpaper { + val type = prefs.getInt(WALLPAPER_TYPE_KEY, -1) + if (type != -1) { + val value = prefs.getString(WALLPAPER_VALUE_KEY, null) + if (value != null && value.isNotEmpty()) { + return when (type) { + WALLPAPER_TYPE_COLOR -> { + Wallpaper.Color(value) + } + WALLPAPER_TYPE_GRADIENT -> { + Wallpaper.Gradient(value) + } + WALLPAPER_TYPE_IMAGE -> { + Wallpaper.Image(value) + } + else -> { + Wallpaper.Default + } + } + } else { + return Wallpaper.Default + } + } else { + return Wallpaper.Default + } + } + companion object { const val DEFAULT_OBJECT_TYPE_ID_KEY = "prefs.user_settings.default_object_type.id" const val DEFAULT_OBJECT_TYPE_NAME_KEY = "prefs.user_settings.default_object_type.name" + + const val WALLPAPER_TYPE_COLOR = 1 + const val WALLPAPER_TYPE_GRADIENT = 2 + const val WALLPAPER_TYPE_IMAGE = 3 + + const val WALLPAPER_TYPE_KEY = "prefs.user_settings.wallpaper_type" + const val WALLPAPER_VALUE_KEY = "prefs.user_settings.wallpaper_value" } } \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/cover/CoverGradient.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/cover/CoverGradient.kt index 3e40662e8a..9660488706 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/cover/CoverGradient.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/editor/cover/CoverGradient.kt @@ -5,4 +5,11 @@ object CoverGradient { const val RED = "red" const val BLUE = "blue" const val TEAL = "teal" + const val PINK_ORANGE = "pinkOrange" + const val BLUE_PINK = "bluePink" + const val GREEN_ORANGE = "greenOrange" + const val SKY = "sky" + + + val default = listOf(YELLOW, RED, BLUE, TEAL, PINK_ORANGE, BLUE_PINK, GREEN_ORANGE, SKY) } \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/main/MainViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/main/MainViewModel.kt index d4a805a008..80851a2026 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/main/MainViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/main/MainViewModel.kt @@ -8,16 +8,34 @@ import com.anytypeio.anytype.analytics.base.sendEvent import com.anytypeio.anytype.analytics.base.updateUserProperties import com.anytypeio.anytype.analytics.props.Props import com.anytypeio.anytype.analytics.props.UserProperty +import com.anytypeio.anytype.core_models.Wallpaper import com.anytypeio.anytype.domain.auth.interactor.LaunchAccount import com.anytypeio.anytype.domain.base.BaseUseCase +import com.anytypeio.anytype.domain.wallpaper.ObserveWallpaper +import com.anytypeio.anytype.domain.wallpaper.RestoreWallpaper +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch import timber.log.Timber class MainViewModel( private val launchAccount: LaunchAccount, + private val observeWallpaper: ObserveWallpaper, + private val restoreWallpaper: RestoreWallpaper, private val analytics: Analytics ) : ViewModel() { + val wallpaper = MutableStateFlow(Wallpaper.Default) + + init { + viewModelScope.launch { restoreWallpaper(BaseUseCase.None) } + viewModelScope.launch { + observeWallpaper.build(BaseUseCase.None).collect { + wallpaper.value = it + } + } + } + fun onRestore() { val startTime = System.currentTimeMillis() viewModelScope.launch { diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/main/MainViewModelFactory.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/main/MainViewModelFactory.kt index 02249a625b..d1b13ac2fb 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/main/MainViewModelFactory.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/main/MainViewModelFactory.kt @@ -4,13 +4,22 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import com.anytypeio.anytype.analytics.base.Analytics import com.anytypeio.anytype.domain.auth.interactor.LaunchAccount +import com.anytypeio.anytype.domain.wallpaper.ObserveWallpaper +import com.anytypeio.anytype.domain.wallpaper.RestoreWallpaper class MainViewModelFactory( private val launchAccount: LaunchAccount, - private val analytics: Analytics + private val analytics: Analytics, + private val observeWallpaper: ObserveWallpaper, + private val restoreWallpaper: RestoreWallpaper ) : ViewModelProvider.Factory { @Suppress("UNCHECKED_CAST") override fun create( modelClass: Class - ): T = MainViewModel(launchAccount, analytics) as T + ): T = MainViewModel( + launchAccount = launchAccount, + analytics = analytics, + observeWallpaper = observeWallpaper, + restoreWallpaper = restoreWallpaper + ) as T } \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/wallpaper/WallpaperColor.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/wallpaper/WallpaperColor.kt new file mode 100644 index 0000000000..18101a0e8c --- /dev/null +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/wallpaper/WallpaperColor.kt @@ -0,0 +1,52 @@ +package com.anytypeio.anytype.presentation.wallpaper + +enum class WallpaperColor(val code: String, val hex: String) { + YELLOW( + hex = "#FBE885", + code = "yellow" + ), + ORANGE( + hex = "#F5B748", + code = "orange" + ), + RED( + hex = "#E46036", + code = "red" + ), + PINK( + hex = "#E6B1A4", + code = "pink" + ), + PURPLE( + hex = "#611A36", + code = "purple" + ), + BLUE( + hex = "#376BE1", + code = "blue" + ), + ICE( + hex = "#97CCEF", + code = "ice" + ), + TEAL( + hex = "#9FB0B6", + code = "teal" + ), + GREEN( + hex = "#336C45", + code = "green" + ), + LIGHT_GREY( + hex = "#DFDDD1", + code = "lightgrey" + ), + DARK_GREY( + hex = "#ACA998", + code = "darkgrey" + ), + BLACK( + hex = "#2C2B28", + code = "black" + ), +} \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/wallpaper/WallpaperSelectView.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/wallpaper/WallpaperSelectView.kt new file mode 100644 index 0000000000..ae66dba13f --- /dev/null +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/wallpaper/WallpaperSelectView.kt @@ -0,0 +1,9 @@ +package com.anytypeio.anytype.presentation.wallpaper + +sealed class WallpaperSelectView { + sealed class Section : WallpaperSelectView() { + object SolidColor: Section() + object Gradient: Section() + } + data class Wallpaper(val item: WallpaperView) : WallpaperSelectView() +} diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/wallpaper/WallpaperSelectViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/wallpaper/WallpaperSelectViewModel.kt new file mode 100644 index 0000000000..9e54b75e92 --- /dev/null +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/wallpaper/WallpaperSelectViewModel.kt @@ -0,0 +1,76 @@ +package com.anytypeio.anytype.presentation.wallpaper + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.viewModelScope +import com.anytypeio.anytype.domain.base.Interactor +import com.anytypeio.anytype.domain.wallpaper.SetWallpaper +import com.anytypeio.anytype.presentation.common.BaseViewModel +import com.anytypeio.anytype.presentation.editor.cover.CoverGradient +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.launch + +class WallpaperSelectViewModel( + private val setWallpaper: SetWallpaper +) : BaseViewModel() { + + val isDismissed = MutableStateFlow(false) + val state = MutableStateFlow>(emptyList()) + + init { + state.value = mutableListOf().apply { + add(WallpaperSelectView.Section.SolidColor) + addAll( + WallpaperColor.values().map { + WallpaperSelectView.Wallpaper( + item = WallpaperView.SolidColor(it.code) + ) + } + ) + add(WallpaperSelectView.Section.Gradient) + addAll( + CoverGradient.default.map { code -> + WallpaperSelectView.Wallpaper( + item = WallpaperView.Gradient(code) + ) + } + ) + } + } + + fun onWallpaperSelected(wallpaper: WallpaperView) { + viewModelScope.launch { + val params = when(wallpaper) { + is WallpaperView.Gradient -> SetWallpaper.Params.Gradient(wallpaper.code) + is WallpaperView.SolidColor -> SetWallpaper.Params.SolidColor(wallpaper.code) + } + setWallpaper(params).collect { status -> + when(status) { + is Interactor.Status.Error -> { + + } + is Interactor.Status.Started -> { + + } + is Interactor.Status.Success -> { + isDismissed.value = true + } + } + } + } + } + + class Factory( + private val setWallpaper: SetWallpaper + ) : ViewModelProvider.Factory { + + @Suppress("UNCHECKED_CAST") + override fun create(modelClass: Class): T { + return WallpaperSelectViewModel( + setWallpaper = setWallpaper + ) as T + } + } + +} \ No newline at end of file diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/wallpaper/WallpaperView.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/wallpaper/WallpaperView.kt new file mode 100644 index 0000000000..25296c96e3 --- /dev/null +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/wallpaper/WallpaperView.kt @@ -0,0 +1,6 @@ +package com.anytypeio.anytype.presentation.wallpaper + +sealed class WallpaperView { + data class SolidColor(val code: String) : WallpaperView() + data class Gradient(val code: String) : WallpaperView() +} \ No newline at end of file