Add PreviewNewConversationScreen

This commit is contained in:
Andrew 2024-06-15 02:03:27 +09:30
parent 6f128f3003
commit 2f9dbe27c8
2 changed files with 73 additions and 33 deletions

View File

@ -37,7 +37,7 @@ class NewConversationFragment : BottomSheetDialogFragment(), NewConversationDele
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
replaceFragment( replaceFragment(
fragment = NewConversationHomeFragment().also { it.delegate = this }, fragment = NewConversationHomeFragment().also { it.delegate.value = this },
fragmentKey = NewConversationHomeFragment::class.java.simpleName fragmentKey = NewConversationHomeFragment::class.java.simpleName
) )
} }

View File

@ -11,16 +11,23 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.MutableStateFlow
import network.loki.messenger.R import network.loki.messenger.R
import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.ui.Colors
import org.thoughtcrime.securesms.ui.Divider import org.thoughtcrime.securesms.ui.Divider
import org.thoughtcrime.securesms.ui.ItemButton import org.thoughtcrime.securesms.ui.ItemButton
import org.thoughtcrime.securesms.ui.LocalColors import org.thoughtcrime.securesms.ui.LocalColors
import org.thoughtcrime.securesms.ui.LocalDimensions import org.thoughtcrime.securesms.ui.LocalDimensions
import org.thoughtcrime.securesms.ui.PreviewTheme
import org.thoughtcrime.securesms.ui.SessionColorsParameterProvider
import org.thoughtcrime.securesms.ui.components.AppBar import org.thoughtcrime.securesms.ui.components.AppBar
import org.thoughtcrime.securesms.ui.components.QrImage import org.thoughtcrime.securesms.ui.components.QrImage
import org.thoughtcrime.securesms.ui.contentDescription import org.thoughtcrime.securesms.ui.contentDescription
@ -35,43 +42,76 @@ class NewConversationHomeFragment : Fragment() {
@Inject @Inject
lateinit var textSecurePreferences: TextSecurePreferences lateinit var textSecurePreferences: TextSecurePreferences
lateinit var delegate: NewConversationDelegate var delegate = MutableStateFlow<NewConversationDelegate?>(null)
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View = createThemedComposeView { NewConversationScreen() } ): View = createThemedComposeView {
// Warning, brittle code, NewConversationScreen will not be visible if no delegate is set
@Composable // before onCreateView is called.
fun NewConversationScreen() { delegate.collectAsState().value?.let {
Column(modifier = Modifier.background(LocalColors.current.backgroundSecondary)) { NewConversationScreen(
AppBar(stringResource(R.string.dialog_new_conversation_title), onClose = { delegate.onDialogClosePressed() }) accountId = TextSecurePreferences.getLocalNumber(requireContext())!!,
ItemButton(textId = R.string.messageNew, icon = R.drawable.ic_message) { delegate.onNewMessageSelected() } delegate = it
Divider(startIndent = LocalDimensions.current.dividerIndent) )
ItemButton(textId = R.string.activity_create_group_title, icon = R.drawable.ic_group) { delegate.onCreateGroupSelected() } }
Divider(startIndent = LocalDimensions.current.dividerIndent) }
ItemButton(textId = R.string.dialog_join_community_title, icon = R.drawable.ic_globe) { delegate.onJoinCommunitySelected() } }
Divider(startIndent = LocalDimensions.current.dividerIndent)
ItemButton(textId = R.string.activity_settings_invite_button_title, icon = R.drawable.ic_invite_friend, contentDescription = R.string.AccessibilityId_invite_friend_button) { delegate.onInviteFriend() } @Preview
Column( @Composable
modifier = Modifier fun PreviewNewConversationScreen(
.padding(horizontal = LocalDimensions.current.marginMedium) @PreviewParameter(SessionColorsParameterProvider::class) colors: Colors
.padding(top = LocalDimensions.current.itemSpacingMedium) ) {
) { PreviewTheme(colors) {
Text( NewConversationScreen(
text = stringResource(R.string.accountIdYours), accountId = "059287129387123",
style = xl object: NewConversationDelegate {
) override fun onNewMessageSelected() {}
Spacer(modifier = Modifier.height(LocalDimensions.current.itemSpacingTiny)) override fun onCreateGroupSelected() {}
Text( override fun onJoinCommunitySelected() {}
text = stringResource(R.string.qrYoursDescription), override fun onContactSelected(address: String) {}
color = LocalColors.current.textSecondary, override fun onDialogBackPressed() {}
style = small override fun onDialogClosePressed() {}
) override fun onInviteFriend() {}
Spacer(modifier = Modifier.height(LocalDimensions.current.itemSpacingSmall)) }
QrImage(string = TextSecurePreferences.getLocalNumber(requireContext())!!, Modifier.contentDescription(R.string.AccessibilityId_qr_code)) )
} }
}
@Composable
fun NewConversationScreen(
accountId: String,
delegate: NewConversationDelegate
) {
Column(modifier = Modifier.background(LocalColors.current.backgroundSecondary)) {
AppBar(stringResource(R.string.dialog_new_conversation_title), onClose = delegate::onDialogClosePressed)
ItemButton(textId = R.string.messageNew, icon = R.drawable.ic_message, onClick = delegate::onNewMessageSelected)
Divider(startIndent = LocalDimensions.current.dividerIndent)
ItemButton(textId = R.string.activity_create_group_title, icon = R.drawable.ic_group, onClick = delegate::onCreateGroupSelected)
Divider(startIndent = LocalDimensions.current.dividerIndent)
ItemButton(textId = R.string.dialog_join_community_title, icon = R.drawable.ic_globe, onClick = delegate::onJoinCommunitySelected)
Divider(startIndent = LocalDimensions.current.dividerIndent)
ItemButton(textId = R.string.activity_settings_invite_button_title, icon = R.drawable.ic_invite_friend, contentDescription = R.string.AccessibilityId_invite_friend_button, onClick = delegate::onInviteFriend)
Column(
modifier = Modifier
.padding(horizontal = LocalDimensions.current.marginMedium)
.padding(top = LocalDimensions.current.itemSpacingMedium)
) {
Text(
text = stringResource(R.string.accountIdYours),
style = xl
)
Spacer(modifier = Modifier.height(LocalDimensions.current.itemSpacingTiny))
Text(
text = stringResource(R.string.qrYoursDescription),
color = LocalColors.current.textSecondary,
style = small
)
Spacer(modifier = Modifier.height(LocalDimensions.current.itemSpacingSmall))
QrImage(string = accountId, Modifier.contentDescription(R.string.AccessibilityId_qr_code))
} }
} }
} }