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,25 +42,59 @@ 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
// before onCreateView is called.
delegate.collectAsState().value?.let {
NewConversationScreen(
accountId = TextSecurePreferences.getLocalNumber(requireContext())!!,
delegate = it
)
}
}
}
@Composable @Preview
fun NewConversationScreen() { @Composable
fun PreviewNewConversationScreen(
@PreviewParameter(SessionColorsParameterProvider::class) colors: Colors
) {
PreviewTheme(colors) {
NewConversationScreen(
accountId = "059287129387123",
object: NewConversationDelegate {
override fun onNewMessageSelected() {}
override fun onCreateGroupSelected() {}
override fun onJoinCommunitySelected() {}
override fun onContactSelected(address: String) {}
override fun onDialogBackPressed() {}
override fun onDialogClosePressed() {}
override fun onInviteFriend() {}
}
)
}
}
@Composable
fun NewConversationScreen(
accountId: String,
delegate: NewConversationDelegate
) {
Column(modifier = Modifier.background(LocalColors.current.backgroundSecondary)) { Column(modifier = Modifier.background(LocalColors.current.backgroundSecondary)) {
AppBar(stringResource(R.string.dialog_new_conversation_title), onClose = { delegate.onDialogClosePressed() }) AppBar(stringResource(R.string.dialog_new_conversation_title), onClose = delegate::onDialogClosePressed)
ItemButton(textId = R.string.messageNew, icon = R.drawable.ic_message) { delegate.onNewMessageSelected() } ItemButton(textId = R.string.messageNew, icon = R.drawable.ic_message, onClick = delegate::onNewMessageSelected)
Divider(startIndent = LocalDimensions.current.dividerIndent) Divider(startIndent = LocalDimensions.current.dividerIndent)
ItemButton(textId = R.string.activity_create_group_title, icon = R.drawable.ic_group) { delegate.onCreateGroupSelected() } ItemButton(textId = R.string.activity_create_group_title, icon = R.drawable.ic_group, onClick = delegate::onCreateGroupSelected)
Divider(startIndent = LocalDimensions.current.dividerIndent) Divider(startIndent = LocalDimensions.current.dividerIndent)
ItemButton(textId = R.string.dialog_join_community_title, icon = R.drawable.ic_globe) { delegate.onJoinCommunitySelected() } ItemButton(textId = R.string.dialog_join_community_title, icon = R.drawable.ic_globe, onClick = delegate::onJoinCommunitySelected)
Divider(startIndent = LocalDimensions.current.dividerIndent) 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() } 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( Column(
modifier = Modifier modifier = Modifier
.padding(horizontal = LocalDimensions.current.marginMedium) .padding(horizontal = LocalDimensions.current.marginMedium)
@ -70,8 +111,7 @@ class NewConversationHomeFragment : Fragment() {
style = small style = small
) )
Spacer(modifier = Modifier.height(LocalDimensions.current.itemSpacingSmall)) Spacer(modifier = Modifier.height(LocalDimensions.current.itemSpacingSmall))
QrImage(string = TextSecurePreferences.getLocalNumber(requireContext())!!, Modifier.contentDescription(R.string.AccessibilityId_qr_code)) QrImage(string = accountId, Modifier.contentDescription(R.string.AccessibilityId_qr_code))
}
} }
} }
} }