From ddf0b027d78b2578620f19333ac7e99feabab737 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 3 May 2024 23:37:42 +0930 Subject: [PATCH] Update NewConversationHomeFragment --- .../start/NewConversationDelegate.kt | 1 + .../start/NewConversationFragment.kt | 4 + .../start/NewConversationHomeFragment.kt | 92 +++++----- .../start/NewConversationHomeViewModel.kt | 35 ---- .../thoughtcrime/securesms/ui/Components.kt | 8 +- .../org/thoughtcrime/securesms/ui/Themes.kt | 1 + .../securesms/ui/components/AppBar.kt | 7 + .../layout/fragment_new_conversation_home.xml | 170 ------------------ 8 files changed, 65 insertions(+), 253 deletions(-) delete mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeViewModel.kt delete mode 100644 app/src/main/res/layout/fragment_new_conversation_home.xml diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationDelegate.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationDelegate.kt index 7e51e1de07..bed15d7a93 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationDelegate.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationDelegate.kt @@ -7,4 +7,5 @@ interface NewConversationDelegate { fun onContactSelected(address: String) fun onDialogBackPressed() fun onDialogClosePressed() + fun onInviteFriend() } \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationFragment.kt index 38eddddeaf..33d58ee89f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationFragment.kt @@ -80,6 +80,10 @@ class NewConversationFragment : BottomSheetDialogFragment(), NewConversationDele childFragmentManager.popBackStack() } + override fun onInviteFriend() { + + } + override fun onDialogClosePressed() { dismiss() } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeFragment.kt index 92f050f76a..c0d0b49047 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeFragment.kt @@ -4,67 +4,69 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.core.content.ContextCompat +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.material.Divider +import androidx.compose.material.MaterialTheme +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp import androidx.fragment.app.Fragment -import androidx.fragment.app.viewModels -import androidx.recyclerview.widget.DividerItemDecoration -import androidx.recyclerview.widget.RecyclerView import dagger.hilt.android.AndroidEntryPoint import network.loki.messenger.R -import network.loki.messenger.databinding.FragmentNewConversationHomeBinding -import org.session.libsession.messaging.contacts.Contact import org.session.libsession.utilities.TextSecurePreferences -import org.session.libsignal.utilities.PublicKeyValidation -import org.thoughtcrime.securesms.dependencies.DatabaseComponent -import org.thoughtcrime.securesms.mms.GlideApp +import org.thoughtcrime.securesms.ui.AppTheme +import org.thoughtcrime.securesms.ui.ItemButton +import org.thoughtcrime.securesms.ui.classicDarkColors +import org.thoughtcrime.securesms.ui.components.AppBar +import org.thoughtcrime.securesms.ui.components.QrImage +import org.thoughtcrime.securesms.ui.medium +import org.thoughtcrime.securesms.ui.small import javax.inject.Inject @AndroidEntryPoint class NewConversationHomeFragment : Fragment() { - private lateinit var binding: FragmentNewConversationHomeBinding - private val viewModel: NewConversationHomeViewModel by viewModels() - @Inject lateinit var textSecurePreferences: TextSecurePreferences lateinit var delegate: NewConversationDelegate override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, + inflater: LayoutInflater, + container: ViewGroup?, savedInstanceState: Bundle? - ): View { - binding = FragmentNewConversationHomeBinding.inflate(inflater) - return binding.root - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - binding.closeButton.setOnClickListener { delegate.onDialogClosePressed() } - binding.createPrivateChatButton.setOnClickListener { delegate.onNewMessageSelected() } - binding.createClosedGroupButton.setOnClickListener { delegate.onCreateGroupSelected() } - binding.joinCommunityButton.setOnClickListener { delegate.onJoinCommunitySelected() } - val adapter = ContactListAdapter(requireContext(), GlideApp.with(requireContext())) { - delegate.onContactSelected(it.address.serialize()) - } - val unknownSectionTitle = getString(R.string.new_conversation_unknown_contacts_section_title) - val recipients = viewModel.recipients.value?.filter { !it.isGroupRecipient && it.address.serialize() != textSecurePreferences.getLocalNumber()!! } ?: emptyList() - val contactGroups = recipients.map { - val sessionId = it.address.serialize() - val contact = DatabaseComponent.get(requireContext()).sessionContactDatabase().getContactWithSessionID(sessionId) - val displayName = contact?.displayName(Contact.ContactContext.REGULAR) ?: sessionId - ContactListItem.Contact(it, displayName) - }.sortedBy { it.displayName } - .groupBy { if (PublicKeyValidation.isValid(it.displayName)) unknownSectionTitle else it.displayName.firstOrNull()?.uppercase() ?: unknownSectionTitle } - .toMutableMap() - contactGroups.remove(unknownSectionTitle)?.let { contactGroups.put(unknownSectionTitle, it) } - adapter.items = contactGroups.flatMap { entry -> listOf(ContactListItem.Header(entry.key)) + entry.value } - binding.contactsRecyclerView.adapter = adapter - val divider = ContextCompat.getDrawable(requireActivity(), R.drawable.conversation_menu_divider)!!.let { - DividerItemDecoration(requireActivity(), RecyclerView.VERTICAL).apply { - setDrawable(it) + ): View = ComposeView(requireContext()).apply { + setContent { + AppTheme { + NewConversationScreen() } } - binding.contactsRecyclerView.addItemDecoration(divider) } -} \ No newline at end of file + + @Composable + fun NewConversationScreen() { + Column { + AppBar(stringResource(R.string.dialog_new_conversation_title), onClose = { delegate.onDialogClosePressed() }) + ItemButton(textId = R.string.messageNew, icon = R.drawable.ic_message) { delegate.onNewMessageSelected() } + Divider(modifier = Modifier.padding(start = 80.dp)) + ItemButton(textId = R.string.activity_create_group_title, icon = R.drawable.ic_group) { delegate.onCreateGroupSelected() } + Divider(modifier = Modifier.padding(start = 80.dp)) + ItemButton(textId = R.string.dialog_join_community_title, icon = R.drawable.ic_globe) { delegate.onJoinCommunitySelected() } + Divider(modifier = Modifier.padding(start = 80.dp)) + ItemButton(textId = R.string.activity_settings_invite_button_title, icon = R.drawable.ic_invite_friend) { delegate.onInviteFriend() } + Column(modifier = Modifier.padding(horizontal = 32.dp).padding(top = 20.dp)) { + Text(text = "Your Account ID", style = MaterialTheme.typography.medium) + Spacer(modifier = Modifier.height(4.dp)) + Text(text = "Friends can message you by scanning your QR code.", color = classicDarkColors[5], style = MaterialTheme.typography.small) + Spacer(modifier = Modifier.height(20.dp)) + QrImage(string = TextSecurePreferences.getLocalNumber(requireContext())!!, contentDescription = "Your session id") + } + } + } +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeViewModel.kt deleted file mode 100644 index 47fc50598c..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/start/NewConversationHomeViewModel.kt +++ /dev/null @@ -1,35 +0,0 @@ -package org.thoughtcrime.securesms.conversation.start - -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import org.session.libsession.utilities.recipients.Recipient -import org.thoughtcrime.securesms.database.ThreadDatabase -import javax.inject.Inject - -@HiltViewModel -class NewConversationHomeViewModel @Inject constructor(private val threadDb: ThreadDatabase): ViewModel() { - - private val _recipients = MutableLiveData>() - val recipients: LiveData> = _recipients - - init { - viewModelScope.launch { - threadDb.approvedConversationList.use { openCursor -> - val reader = threadDb.readerFor(openCursor) - val threads = mutableListOf() - while (true) { - threads += reader.next?.recipient ?: break - } - withContext(Dispatchers.Main) { - _recipients.value = threads - } - } - } - } -} diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt index 44c996b6de..2906b882d3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/Components.kt @@ -193,9 +193,11 @@ fun ItemButton( onClick = onClick, shape = RectangleShape, ) { - Box(modifier = Modifier - .width(80.dp) - .fillMaxHeight()) { + Box( + modifier = Modifier + .width(80.dp) + .fillMaxHeight() + ) { icon() } Text(text, modifier = Modifier.fillMaxWidth(), style = MaterialTheme.typography.h8) diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/Themes.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/Themes.kt index 51cdf01f71..719d91248f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/Themes.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/Themes.kt @@ -112,6 +112,7 @@ val sessionTypography = Typography( h6 = boldStyle(20.sp), ) +val Typography.medium get() = defaultStyle(18.sp) val Typography.base get() = defaultStyle(14.sp) val Typography.baseBold get() = boldStyle(14.sp) val Typography.small get() = defaultStyle(12.sp) diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/AppBar.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/AppBar.kt index 9e29d2379d..6c1cf2f85a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/AppBar.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/AppBar.kt @@ -13,9 +13,16 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import network.loki.messenger.R +@Preview +@Composable +fun AppBarPreview() { + AppBar(title = "Title", {}, {}) +} + @Composable fun AppBar(title: String, onClose: () -> Unit = {}, onBack: (() -> Unit)? = null) { Row(modifier = Modifier.height(64.dp), verticalAlignment = Alignment.CenterVertically) { diff --git a/app/src/main/res/layout/fragment_new_conversation_home.xml b/app/src/main/res/layout/fragment_new_conversation_home.xml deleted file mode 100644 index 1e649dd968..0000000000 --- a/app/src/main/res/layout/fragment_new_conversation_home.xml +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file