mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-3239 Participant screen | Open from relations values (#2037)
This commit is contained in:
parent
113e572e32
commit
158d163709
4 changed files with 85 additions and 46 deletions
|
@ -23,16 +23,22 @@ import com.anytypeio.anytype.core_ui.relations.RelationObjectValueScreen
|
|||
import com.anytypeio.anytype.core_utils.ext.argBoolean
|
||||
import com.anytypeio.anytype.core_utils.ext.argString
|
||||
import com.anytypeio.anytype.core_utils.ext.subscribe
|
||||
import com.anytypeio.anytype.core_utils.ext.toast
|
||||
import com.anytypeio.anytype.core_utils.ui.BaseBottomSheetComposeFragment
|
||||
import com.anytypeio.anytype.di.common.componentManager
|
||||
import com.anytypeio.anytype.presentation.home.OpenObjectNavigation
|
||||
import com.anytypeio.anytype.presentation.relations.value.`object`.ObjectValueViewModel
|
||||
import com.anytypeio.anytype.presentation.relations.value.`object`.ObjectValueViewModelFactory
|
||||
import com.anytypeio.anytype.presentation.relations.value.tagstatus.RelationContext
|
||||
import com.anytypeio.anytype.ui.chats.ChatFragment
|
||||
import com.anytypeio.anytype.ui.date.DateObjectFragment
|
||||
import com.anytypeio.anytype.ui.editor.EditorFragment
|
||||
import com.anytypeio.anytype.ui.profile.ParticipantFragment
|
||||
import com.anytypeio.anytype.ui.sets.ObjectSetFragment
|
||||
import com.anytypeio.anytype.ui.settings.typography
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import javax.inject.Inject
|
||||
import timber.log.Timber
|
||||
|
||||
class ObjectValueFragment : BaseBottomSheetComposeFragment() {
|
||||
|
||||
|
@ -74,30 +80,76 @@ class ObjectValueFragment : BaseBottomSheetComposeFragment() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
setupCollapsedHeight()
|
||||
jobs += lifecycleScope.subscribe(vm.commands) { observeCommands(it) }
|
||||
jobs += lifecycleScope.subscribe(vm.navigation) { nav ->
|
||||
when (nav) {
|
||||
is OpenObjectNavigation.OpenEditor -> {
|
||||
findNavController().navigate(
|
||||
R.id.objectNavigation,
|
||||
EditorFragment.args(
|
||||
ctx = nav.target,
|
||||
space = nav.space
|
||||
)
|
||||
)
|
||||
}
|
||||
is OpenObjectNavigation.OpenDataView -> {
|
||||
findNavController().navigate(
|
||||
R.id.dataViewNavigation,
|
||||
ObjectSetFragment.args(
|
||||
ctx = nav.target,
|
||||
space = nav.space
|
||||
)
|
||||
)
|
||||
}
|
||||
is OpenObjectNavigation.OpenParticipant -> {
|
||||
runCatching {
|
||||
findNavController().navigate(
|
||||
R.id.participantScreen,
|
||||
ParticipantFragment.args(
|
||||
objectId = nav.target,
|
||||
space = nav.space
|
||||
)
|
||||
)
|
||||
}.onFailure {
|
||||
Timber.w("Error while opening participant screen")
|
||||
}
|
||||
}
|
||||
is OpenObjectNavigation.OpenChat -> {
|
||||
findNavController().navigate(
|
||||
R.id.chatScreen,
|
||||
ChatFragment.args(
|
||||
ctx = nav.target,
|
||||
space = nav.space
|
||||
)
|
||||
)
|
||||
}
|
||||
OpenObjectNavigation.NonValidObject -> {
|
||||
toast(getString(R.string.error_non_valid_object))
|
||||
}
|
||||
is OpenObjectNavigation.OpenDateObject -> {
|
||||
runCatching {
|
||||
findNavController().navigate(
|
||||
R.id.dateObjectScreen,
|
||||
DateObjectFragment.args(
|
||||
objectId = nav.target,
|
||||
space = nav.space
|
||||
)
|
||||
)
|
||||
}.onFailure {
|
||||
Timber.e(it, "Failed to navigate to date object screen")
|
||||
}
|
||||
}
|
||||
is OpenObjectNavigation.UnexpectedLayoutError -> {
|
||||
toast(getString(R.string.error_unexpected_layout))
|
||||
}
|
||||
else -> {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeCommands(command: ObjectValueViewModel.Command) = when (command) {
|
||||
ObjectValueViewModel.Command.Dismiss -> dismiss()
|
||||
is ObjectValueViewModel.Command.OpenObject -> {
|
||||
findNavController().navigate(
|
||||
R.id.objectNavigation,
|
||||
EditorFragment.args(
|
||||
ctx = command.id,
|
||||
space = command.space
|
||||
)
|
||||
)
|
||||
dismiss()
|
||||
}
|
||||
is ObjectValueViewModel.Command.OpenSet -> {
|
||||
findNavController().navigate(
|
||||
R.id.dataViewNavigation,
|
||||
ObjectSetFragment.args(
|
||||
ctx = command.id,
|
||||
space = command.space
|
||||
)
|
||||
)
|
||||
dismiss()
|
||||
}
|
||||
ObjectValueViewModel.Command.Expand -> expand()
|
||||
is ObjectValueViewModel.Command.DeleteObject -> {
|
||||
val dialog = DeleteOptionWarningFragment.new(
|
||||
|
|
|
@ -493,7 +493,7 @@ fun ProfileImageBlock(
|
|||
Text(
|
||||
text = stringResource(R.string.profile_settings_remove_image),
|
||||
style = BodyRegular,
|
||||
color = colorResource(id = R.color.palette_dark_red)
|
||||
color = colorResource(id = R.color.text_primary)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.anytypeio.anytype.core_models.ObjectTypeIds
|
|||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
import com.anytypeio.anytype.core_models.Payload
|
||||
import com.anytypeio.anytype.core_models.Relation.Format.FILE
|
||||
import com.anytypeio.anytype.core_models.isDataView
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction
|
||||
import com.anytypeio.anytype.core_utils.ext.typeOf
|
||||
|
@ -27,7 +26,8 @@ import com.anytypeio.anytype.presentation.analytics.AnalyticSpaceHelperDelegate
|
|||
import com.anytypeio.anytype.presentation.common.BaseViewModel
|
||||
import com.anytypeio.anytype.presentation.extension.sendAnalyticsRelationEvent
|
||||
import com.anytypeio.anytype.presentation.navigation.DefaultObjectView
|
||||
import com.anytypeio.anytype.core_models.SupportedLayouts.isEditorOrFileLayout
|
||||
import com.anytypeio.anytype.presentation.home.OpenObjectNavigation
|
||||
import com.anytypeio.anytype.presentation.home.navigation
|
||||
import com.anytypeio.anytype.presentation.objects.toView
|
||||
import com.anytypeio.anytype.presentation.relations.providers.ObjectRelationProvider
|
||||
import com.anytypeio.anytype.presentation.relations.providers.ObjectValueProvider
|
||||
|
@ -71,6 +71,8 @@ class ObjectValueViewModel(
|
|||
private val initialIds = mutableListOf<Id>()
|
||||
private var isInitialSortDone = false
|
||||
|
||||
val navigation = MutableSharedFlow<OpenObjectNavigation>()
|
||||
|
||||
init {
|
||||
Timber.d("ObjectValueViewModel init, params: $viewModelParams")
|
||||
viewModelScope.launch {
|
||||
|
@ -352,24 +354,13 @@ class ObjectValueViewModel(
|
|||
}
|
||||
|
||||
private fun onOpenObjectAction(item: ObjectValueItem.Object) {
|
||||
viewModelScope.launch {
|
||||
val layout = item.view.layout
|
||||
if (layout.isDataView()) {
|
||||
commands.emit(
|
||||
Command.OpenSet(
|
||||
id = item.view.id,
|
||||
space = item.view.space
|
||||
)
|
||||
)
|
||||
} else if (isEditorOrFileLayout(layout)) {
|
||||
commands.emit(
|
||||
Command.OpenObject(
|
||||
id = item.view.id,
|
||||
space = item.view.space
|
||||
)
|
||||
)
|
||||
} else {
|
||||
Timber.w("This layout is not supported: $layout")
|
||||
val nav = item.view.layout?.navigation(
|
||||
target = item.view.id,
|
||||
space = item.view.space
|
||||
)
|
||||
viewModelScope.launch{
|
||||
if (nav != null) {
|
||||
navigation.emit(nav)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -453,8 +444,6 @@ class ObjectValueViewModel(
|
|||
sealed class Command {
|
||||
object Dismiss : Command()
|
||||
object Expand : Command()
|
||||
data class OpenObject(val id: Id, val space: Id) : Command()
|
||||
data class OpenSet(val id: Id, val space: Id) : Command()
|
||||
data class DeleteObject(val id: Id) : Command()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,8 @@ import com.anytypeio.anytype.core_models.Id
|
|||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
import com.anytypeio.anytype.core_models.Payload
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.domain.base.Either
|
||||
import com.anytypeio.anytype.domain.base.ResultInteractor
|
||||
import com.anytypeio.anytype.domain.base.Resultat
|
||||
import com.anytypeio.anytype.domain.`object`.SetObjectDetails
|
||||
import com.anytypeio.anytype.domain.`object`.UpdateDetail
|
||||
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
|
||||
import com.anytypeio.anytype.test_utils.MockDataFactory
|
||||
import kotlin.test.assertEquals
|
||||
|
@ -33,6 +30,7 @@ class ObjectSetRecordViewModelTest {
|
|||
@Mock
|
||||
lateinit var setObjectDetails: SetObjectDetails
|
||||
|
||||
private val ctx: Id = MockDataFactory.randomUuid()
|
||||
private val defaultSpace = MockDataFactory.randomUuid()
|
||||
private val obj = ObjectWrapper.Basic(
|
||||
mapOf(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue