Skip to content

Commit

Permalink
DROID-3217 Space-level chat | Enhancement | Screen with message react…
Browse files Browse the repository at this point in the history
…ion and corresponding members (#1970)
  • Loading branch information
uburoiubu authored Jan 6, 2025
1 parent 9be32df commit 1bfaf20
Show file tree
Hide file tree
Showing 16 changed files with 827 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ import com.anytypeio.anytype.di.feature.ViewerFilterModule
import com.anytypeio.anytype.di.feature.ViewerSortModule
import com.anytypeio.anytype.di.feature.auth.DaggerDeletedAccountComponent
import com.anytypeio.anytype.di.feature.cover.UnsplashModule
import com.anytypeio.anytype.di.feature.discussions.DaggerChatReactionPickerComponent
import com.anytypeio.anytype.di.feature.discussions.DaggerChatReactionComponent
import com.anytypeio.anytype.di.feature.discussions.DaggerDiscussionComponent
import com.anytypeio.anytype.di.feature.discussions.DaggerSelectChatReactionComponent
import com.anytypeio.anytype.di.feature.discussions.DaggerSpaceLevelChatComponent
import com.anytypeio.anytype.di.feature.gallery.DaggerGalleryInstallationComponent
import com.anytypeio.anytype.di.feature.home.DaggerHomeScreenComponent
Expand Down Expand Up @@ -105,6 +106,7 @@ import com.anytypeio.anytype.feature_allcontent.presentation.AllContentViewModel
import com.anytypeio.anytype.feature_date.viewmodel.DateObjectVmParams
import com.anytypeio.anytype.feature_discussions.presentation.ChatReactionViewModel
import com.anytypeio.anytype.feature_discussions.presentation.DiscussionViewModel
import com.anytypeio.anytype.feature_discussions.presentation.SelectChatReactionViewModel
import com.anytypeio.anytype.gallery_experience.viewmodel.GalleryInstallationViewModel
import com.anytypeio.anytype.presentation.editor.EditorViewModel
import com.anytypeio.anytype.presentation.history.VersionHistoryViewModel
Expand Down Expand Up @@ -1081,8 +1083,16 @@ class ComponentManager(
.build()
}

val chatReactionPickerComponent = ComponentMapWithParam { params: ChatReactionViewModel.Params ->
DaggerChatReactionPickerComponent
val selectChatReactionComponent = ComponentMapWithParam { params: SelectChatReactionViewModel.Params ->
DaggerSelectChatReactionComponent
.builder()
.withDependencies(findComponentDependencies())
.withParams(params)
.build()
}

val chatReactionComponent = ComponentMapWithParam { params: ChatReactionViewModel.Params ->
DaggerChatReactionComponent
.builder()
.withDependencies(findComponentDependencies())
.withParams(params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,40 @@ package com.anytypeio.anytype.di.feature.discussions

import androidx.lifecycle.ViewModelProvider
import com.anytypeio.anytype.core_utils.di.scope.PerScreen
import com.anytypeio.anytype.data.auth.repo.block.BlockRemote
import com.anytypeio.anytype.di.common.ComponentDependencies
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.block.repo.BlockRepository
import com.anytypeio.anytype.domain.config.UserSettingsRepository
import com.anytypeio.anytype.emojifier.data.Emoji
import com.anytypeio.anytype.emojifier.data.EmojiProvider
import com.anytypeio.anytype.emojifier.suggest.EmojiSuggester
import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.domain.multiplayer.ActiveSpaceMemberSubscriptionContainer
import com.anytypeio.anytype.feature_discussions.presentation.ChatReactionViewModel
import com.anytypeio.anytype.ui.chats.ChatReactionFragment
import dagger.Binds
import dagger.BindsInstance
import dagger.Component
import dagger.Module
import dagger.Provides

@Component(
dependencies = [ChatReactionPickerDependencies::class],
dependencies = [ChatReactionDependencies::class],
modules = [
ChatReactionPickerModule::class,
ChatReactionPickerModule.Declarations::class
ChatReactionModule::class,
ChatReactionModule.Declarations::class
]
)
@PerScreen
interface ChatReactionPickerComponent {
interface ChatReactionComponent {
@Component.Builder
interface Builder {
@BindsInstance
fun withParams(params: ChatReactionViewModel.Params): Builder
fun withDependencies(dependencies: ChatReactionPickerDependencies): Builder
fun build(): ChatReactionPickerComponent
fun withDependencies(dependencies: ChatReactionDependencies): Builder
fun build(): ChatReactionComponent
}

fun getViewModel(): ChatReactionViewModel
fun inject(fragment: ChatReactionFragment)
}

@Module
object ChatReactionPickerModule {
@Provides
@PerScreen
@JvmStatic
fun provideEmojiProvider(): EmojiProvider = Emoji
object ChatReactionModule {

@Module
interface Declarations {
Expand All @@ -57,10 +47,9 @@ object ChatReactionPickerModule {
}
}

interface ChatReactionPickerDependencies : ComponentDependencies {
interface ChatReactionDependencies : ComponentDependencies {
fun dispatchers(): AppCoroutineDispatchers
fun suggester(): EmojiSuggester
fun repo(): BlockRepository
fun auth(): AuthRepository
fun prefs(): UserSettingsRepository
fun urlBuilder(): UrlBuilder
fun members(): ActiveSpaceMemberSubscriptionContainer
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ class DiscussionFragment : BaseComposeFragment() {
onRequestOpenFullScreenImage = {
// TODO
},
onChatReaction = {
onSelectChatReaction = {
// TODO
}
},
onViewChatReaction = { a, b -> }
)

if (showBottomSheet) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.anytypeio.anytype.di.feature.discussions

import androidx.lifecycle.ViewModelProvider
import com.anytypeio.anytype.core_utils.di.scope.PerScreen
import com.anytypeio.anytype.di.common.ComponentDependencies
import com.anytypeio.anytype.domain.auth.repo.AuthRepository
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.block.repo.BlockRepository
import com.anytypeio.anytype.domain.config.UserSettingsRepository
import com.anytypeio.anytype.emojifier.data.Emoji
import com.anytypeio.anytype.emojifier.data.EmojiProvider
import com.anytypeio.anytype.emojifier.suggest.EmojiSuggester
import com.anytypeio.anytype.feature_discussions.presentation.SelectChatReactionViewModel
import com.anytypeio.anytype.ui.chats.SelectChatReactionFragment
import dagger.Binds
import dagger.BindsInstance
import dagger.Component
import dagger.Module
import dagger.Provides

@Component(
dependencies = [SelectChatReactionDependencies::class],
modules = [
SelectChatReactionModule::class,
SelectChatReactionModule.Declarations::class
]
)
@PerScreen
interface SelectChatReactionComponent {
@Component.Builder
interface Builder {
@BindsInstance
fun withParams(params: SelectChatReactionViewModel.Params): Builder
fun withDependencies(dependencies: SelectChatReactionDependencies): Builder
fun build(): SelectChatReactionComponent
}

fun getViewModel(): SelectChatReactionViewModel
fun inject(fragment: SelectChatReactionFragment)
}

@Module
object SelectChatReactionModule {
@Provides
@PerScreen
@JvmStatic
fun provideEmojiProvider(): EmojiProvider = Emoji

@Module
interface Declarations {
@PerScreen
@Binds
fun bindViewModelFactory(
factory: SelectChatReactionViewModel.Factory
): ViewModelProvider.Factory
}
}

interface SelectChatReactionDependencies : ComponentDependencies {
fun dispatchers(): AppCoroutineDispatchers
fun suggester(): EmojiSuggester
fun repo(): BlockRepository
fun auth(): AuthRepository
fun prefs(): UserSettingsRepository
}
13 changes: 10 additions & 3 deletions app/src/main/java/com/anytypeio/anytype/di/main/MainComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import com.anytypeio.anytype.di.feature.ObjectTypeChangeSubComponent
import com.anytypeio.anytype.di.feature.PersonalizationSettingsSubComponent
import com.anytypeio.anytype.di.feature.SplashDependencies
import com.anytypeio.anytype.di.feature.auth.DeletedAccountDependencies
import com.anytypeio.anytype.di.feature.discussions.ChatReactionPickerDependencies
import com.anytypeio.anytype.di.feature.discussions.ChatReactionDependencies
import com.anytypeio.anytype.di.feature.discussions.SelectChatReactionDependencies
import com.anytypeio.anytype.di.feature.discussions.DiscussionComponentDependencies
import com.anytypeio.anytype.di.feature.gallery.GalleryInstallationComponentDependencies
import com.anytypeio.anytype.di.feature.home.HomeScreenDependencies
Expand Down Expand Up @@ -137,7 +138,8 @@ interface MainComponent :
LinkToObjectDependencies,
MoveToDependencies,
DateObjectDependencies,
ChatReactionPickerDependencies
SelectChatReactionDependencies,
ChatReactionDependencies
{

fun inject(app: AndroidApplication)
Expand Down Expand Up @@ -391,6 +393,11 @@ abstract class ComponentDependenciesModule {

@Binds
@IntoMap
@ComponentDependenciesKey(ChatReactionPickerDependencies::class)
@ComponentDependenciesKey(SelectChatReactionDependencies::class)
abstract fun provideChatReactionPickerDependencies(component: MainComponent): ComponentDependencies

@Binds
@IntoMap
@ComponentDependenciesKey(ChatReactionDependencies::class)
abstract fun provideChatReactionDependencies(component: MainComponent): ComponentDependencies
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.core.os.bundleOf
Expand All @@ -17,7 +16,7 @@ import com.anytypeio.anytype.core_utils.ext.arg
import com.anytypeio.anytype.core_utils.ui.BaseBottomSheetComposeFragment
import com.anytypeio.anytype.di.common.componentManager
import com.anytypeio.anytype.feature_discussions.presentation.ChatReactionViewModel
import com.anytypeio.anytype.feature_discussions.ui.ChatReactionPicker
import com.anytypeio.anytype.feature_discussions.ui.ChatReactionScreen
import com.anytypeio.anytype.ui.settings.typography
import javax.inject.Inject
import kotlin.getValue
Expand All @@ -26,6 +25,7 @@ class ChatReactionFragment : BaseBottomSheetComposeFragment() {

private val chat: Id get() = arg<Id>(CHAT_ID_KEY)
private val msg: Id get() = arg<Id>(MSG_ID_KEY)
private val emoji: String get() = arg<String>(EMOJI_KEY)

@Inject
lateinit var factory: ChatReactionViewModel.Factory
Expand All @@ -42,49 +42,51 @@ class ChatReactionFragment : BaseBottomSheetComposeFragment() {
MaterialTheme(
typography = typography
) {
ChatReactionPicker(
views = vm.views.collectAsStateWithLifecycle(emptyList()).value,
onEmojiClicked = vm::onEmojiClicked
ChatReactionScreen(
viewState = vm.viewState.collectAsStateWithLifecycle().value
)
LaunchedEffect(Unit) {
vm.isDismissed.collect { isDismissed ->
if (isDismissed) dismiss()
}
}
}
}
}

override fun injectDependencies() {
componentManager().chatReactionPickerComponent
componentManager().chatReactionComponent
.get(
key = chat,
key = getComponentKey(),
param = ChatReactionViewModel.Params(
chat = chat,
msg = msg
msg = msg,
emoji = emoji
)
)
.inject(this)
}

override fun releaseDependencies() {
// TODO
componentManager().chatReactionComponent.release(id = getComponentKey())
}

private fun getComponentKey(): String = "$COMPONENT_PREFIX-$chat"

companion object {

private const val SPACE_ID_KEY = "chat.reaction-picker.space"
private const val CHAT_ID_KEY = "chat.reaction-picker.chat"
private const val MSG_ID_KEY = "chat.reaction-picker.msg"
private const val COMPONENT_PREFIX = "chat-reaction"

private const val SPACE_ID_KEY = "chat.reaction.space"
private const val CHAT_ID_KEY = "chat.reaction.chat"
private const val MSG_ID_KEY = "chat.reaction.msg"
private const val EMOJI_KEY = "chat.reaction.emoji"

fun args(
space: SpaceId,
chat: String,
msg: String
msg: String,
emoji: String
): Bundle = bundleOf(
SPACE_ID_KEY to space.id,
CHAT_ID_KEY to chat,
MSG_ID_KEY to msg
MSG_ID_KEY to msg,
EMOJI_KEY to emoji
)
}
}
Loading

0 comments on commit 1bfaf20

Please sign in to comment.