feat: update destinations to account for list of contacts
This commit is contained in:
parent
6c3ac9bc5d
commit
c19bd3da3d
|
@ -1,6 +1,7 @@
|
||||||
package org.thoughtcrime.securesms.groups
|
package org.thoughtcrime.securesms.groups
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Parcelable
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -18,6 +19,7 @@ import com.ramcosta.composedestinations.result.NavResult
|
||||||
import com.ramcosta.composedestinations.result.ResultBackNavigator
|
import com.ramcosta.composedestinations.result.ResultBackNavigator
|
||||||
import com.ramcosta.composedestinations.result.ResultRecipient
|
import com.ramcosta.composedestinations.result.ResultRecipient
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import kotlinx.parcelize.Parcelize
|
||||||
import network.loki.messenger.databinding.FragmentCreateGroupBinding
|
import network.loki.messenger.databinding.FragmentCreateGroupBinding
|
||||||
import org.session.libsession.messaging.contacts.Contact
|
import org.session.libsession.messaging.contacts.Contact
|
||||||
import org.thoughtcrime.securesms.conversation.start.NewConversationDelegate
|
import org.thoughtcrime.securesms.conversation.start.NewConversationDelegate
|
||||||
|
@ -26,7 +28,7 @@ import org.thoughtcrime.securesms.groups.compose.CreateGroupNavGraph
|
||||||
import org.thoughtcrime.securesms.groups.compose.SelectContacts
|
import org.thoughtcrime.securesms.groups.compose.SelectContacts
|
||||||
import org.thoughtcrime.securesms.groups.compose.StateUpdate
|
import org.thoughtcrime.securesms.groups.compose.StateUpdate
|
||||||
import org.thoughtcrime.securesms.groups.compose.ViewState
|
import org.thoughtcrime.securesms.groups.compose.ViewState
|
||||||
import org.thoughtcrime.securesms.groups.destinations.SelectContactScreenDestination
|
import org.thoughtcrime.securesms.groups.destinations.SelectContactsScreenDestination
|
||||||
import org.thoughtcrime.securesms.ui.AppTheme
|
import org.thoughtcrime.securesms.ui.AppTheme
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
|
@ -44,7 +46,9 @@ class CreateGroupFragment : Fragment() {
|
||||||
val getDelegate = { delegate }
|
val getDelegate = { delegate }
|
||||||
setContent {
|
setContent {
|
||||||
AppTheme {
|
AppTheme {
|
||||||
DestinationsNavHost(navGraph = NavGraphs.createGroup, dependenciesContainerBuilder = {
|
DestinationsNavHost(
|
||||||
|
navGraph = NavGraphs.createGroup,
|
||||||
|
dependenciesContainerBuilder = {
|
||||||
dependency(getDelegate)
|
dependency(getDelegate)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -54,12 +58,15 @@ class CreateGroupFragment : Fragment() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
data class ContactList(val contacts: List<Contact>) : Parcelable
|
||||||
|
|
||||||
@CreateGroupNavGraph(start = true)
|
@CreateGroupNavGraph(start = true)
|
||||||
@Composable
|
@Composable
|
||||||
@Destination
|
@Destination
|
||||||
fun CreateGroupScreen(
|
fun CreateGroupScreen(
|
||||||
navigator: DestinationsNavigator,
|
navigator: DestinationsNavigator,
|
||||||
resultSelectContact: ResultRecipient<SelectContactScreenDestination, Contact>,
|
resultSelectContact: ResultRecipient<SelectContactsScreenDestination, ContactList>,
|
||||||
viewModel: CreateGroupViewModel = hiltViewModel(),
|
viewModel: CreateGroupViewModel = hiltViewModel(),
|
||||||
getDelegate: () -> NewConversationDelegate
|
getDelegate: () -> NewConversationDelegate
|
||||||
) {
|
) {
|
||||||
|
@ -68,9 +75,11 @@ fun CreateGroupScreen(
|
||||||
resultSelectContact.onNavResult { navResult ->
|
resultSelectContact.onNavResult { navResult ->
|
||||||
when (navResult) {
|
when (navResult) {
|
||||||
is NavResult.Value -> {
|
is NavResult.Value -> {
|
||||||
viewModel.updateState(StateUpdate.AddContact(navResult.value))
|
viewModel.updateState(StateUpdate.AddContacts(navResult.value.contacts))
|
||||||
|
}
|
||||||
|
|
||||||
|
is NavResult.Canceled -> { /* do nothing */
|
||||||
}
|
}
|
||||||
is NavResult.Canceled -> { /* do nothing */ }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +89,7 @@ fun CreateGroupScreen(
|
||||||
onClose = {
|
onClose = {
|
||||||
getDelegate().onDialogClosePressed()
|
getDelegate().onDialogClosePressed()
|
||||||
},
|
},
|
||||||
onSelectContact = { navigator.navigate(SelectContactScreenDestination) },
|
onSelectContact = { navigator.navigate(SelectContactsScreenDestination) },
|
||||||
onBack = {
|
onBack = {
|
||||||
getDelegate().onDialogBackPressed()
|
getDelegate().onDialogBackPressed()
|
||||||
}
|
}
|
||||||
|
@ -90,8 +99,8 @@ fun CreateGroupScreen(
|
||||||
@CreateGroupNavGraph
|
@CreateGroupNavGraph
|
||||||
@Composable
|
@Composable
|
||||||
@Destination
|
@Destination
|
||||||
fun SelectContactScreen(
|
fun SelectContactsScreen(
|
||||||
resultNavigator: ResultBackNavigator<Contact>,
|
resultNavigator: ResultBackNavigator<ContactList>,
|
||||||
viewModel: CreateGroupViewModel = hiltViewModel(),
|
viewModel: CreateGroupViewModel = hiltViewModel(),
|
||||||
getDelegate: () -> NewConversationDelegate
|
getDelegate: () -> NewConversationDelegate
|
||||||
) {
|
) {
|
||||||
|
@ -104,6 +113,8 @@ fun SelectContactScreen(
|
||||||
contacts - currentMembers,
|
contacts - currentMembers,
|
||||||
onBack = { resultNavigator.navigateBack() },
|
onBack = { resultNavigator.navigateBack() },
|
||||||
onClose = { getDelegate().onDialogClosePressed() },
|
onClose = { getDelegate().onDialogClosePressed() },
|
||||||
onContactsSelected = {}
|
onContactsSelected = {
|
||||||
|
resultNavigator.navigateBack(ContactList(it))
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
|
@ -31,7 +31,7 @@ class CreateGroupViewModel @Inject constructor(
|
||||||
|
|
||||||
fun updateState(stateUpdate: StateUpdate) {
|
fun updateState(stateUpdate: StateUpdate) {
|
||||||
when (stateUpdate) {
|
when (stateUpdate) {
|
||||||
is StateUpdate.AddContact -> _viewState.update { copy(members = members + stateUpdate.value) }
|
is StateUpdate.AddContacts -> _viewState.update { copy(members = members + stateUpdate.value) }
|
||||||
is StateUpdate.Description -> _viewState.update { copy(description = stateUpdate.value) }
|
is StateUpdate.Description -> _viewState.update { copy(description = stateUpdate.value) }
|
||||||
is StateUpdate.Name -> _viewState.update { copy(name = stateUpdate.value) }
|
is StateUpdate.Name -> _viewState.update { copy(name = stateUpdate.value) }
|
||||||
is StateUpdate.RemoveContact -> _viewState.update { copy(members = members - stateUpdate.value) }
|
is StateUpdate.RemoveContact -> _viewState.update { copy(members = members - stateUpdate.value) }
|
||||||
|
|
|
@ -202,6 +202,7 @@ fun ClosedGroupPreview(
|
||||||
CreateGroup(
|
CreateGroup(
|
||||||
viewState = ViewState.DEFAULT.copy(
|
viewState = ViewState.DEFAULT.copy(
|
||||||
// override any preview parameters
|
// override any preview parameters
|
||||||
|
members = previewMembers.toList()
|
||||||
),
|
),
|
||||||
updateState = {},
|
updateState = {},
|
||||||
onSelectContact = {},
|
onSelectContact = {},
|
||||||
|
@ -233,5 +234,5 @@ sealed class StateUpdate {
|
||||||
data class Name(val value: String): StateUpdate()
|
data class Name(val value: String): StateUpdate()
|
||||||
data class Description(val value: String): StateUpdate()
|
data class Description(val value: String): StateUpdate()
|
||||||
data class RemoveContact(val value: Contact): StateUpdate()
|
data class RemoveContact(val value: Contact): StateUpdate()
|
||||||
data class AddContact(val value: Contact): StateUpdate()
|
data class AddContacts(val value: List<Contact>): StateUpdate()
|
||||||
}
|
}
|
Loading…
Reference in New Issue