From b18561acb4f2f7df93bbac7352f85b9ca4b2df5c Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 16 Jun 2024 14:08:58 +0930 Subject: [PATCH] Repackage Loading and MessageNotifications --- app/src/main/AndroidManifest.xml | 2 +- .../start/NewConversationHomeFragment.kt | 5 +- .../securesms/home/HomeActivity.kt | 1 - .../onboarding/LinkDeviceActivity.kt | 1 + .../securesms/onboarding/loading/Loading.kt | 48 +++++++++++ .../{ => loading}/LoadingActivity.kt | 55 ++----------- .../{ => loading}/LoadingViewModel.kt | 2 +- .../MessageNotifications.kt | 79 +++++++++++++++++++ .../MessageNotificationsActivity.kt | 75 ------------------ 9 files changed, 137 insertions(+), 131 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/Loading.kt rename app/src/main/java/org/thoughtcrime/securesms/onboarding/{ => loading}/LoadingActivity.kt (56%) rename app/src/main/java/org/thoughtcrime/securesms/onboarding/{ => loading}/LoadingViewModel.kt (98%) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9cbede54f6..a089d8a30b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -113,7 +113,7 @@ android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.Session.DayNight.FlatActionBar" /> 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 346f3650ef..5c5d79b71d 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 @@ -28,13 +28,12 @@ import kotlinx.coroutines.flow.MutableStateFlow import network.loki.messenger.R import org.session.libsession.utilities.TextSecurePreferences import org.thoughtcrime.securesms.ui.Divider -import org.thoughtcrime.securesms.ui.color.Colors -import org.thoughtcrime.securesms.ui.Divider import org.thoughtcrime.securesms.ui.ItemButton -import org.thoughtcrime.securesms.ui.color.LocalColors import org.thoughtcrime.securesms.ui.LocalDimensions import org.thoughtcrime.securesms.ui.PreviewTheme import org.thoughtcrime.securesms.ui.SessionColorsParameterProvider +import org.thoughtcrime.securesms.ui.color.Colors +import org.thoughtcrime.securesms.ui.color.LocalColors import org.thoughtcrime.securesms.ui.components.AppBar import org.thoughtcrime.securesms.ui.components.QrImage import org.thoughtcrime.securesms.ui.contentDescription diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index 5a0f8e7c13..ffa47c1860 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -123,7 +123,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), const val FROM_ONBOARDING = "HomeActivity_FROM_ONBOARDING" } - private lateinit var binding: ActivityHomeBinding private lateinit var glide: GlideRequests diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt index 0c018d2cac..bb02438c27 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/LinkDeviceActivity.kt @@ -30,6 +30,7 @@ import kotlinx.coroutines.launch import network.loki.messenger.R import org.session.libsession.utilities.TextSecurePreferences import org.thoughtcrime.securesms.BaseActionBarActivity +import org.thoughtcrime.securesms.onboarding.loading.startLoadingActivity import org.thoughtcrime.securesms.onboarding.messagenotifications.startMessageNotificationsActivity import org.thoughtcrime.securesms.ui.LocalDimensions import org.thoughtcrime.securesms.ui.PreviewTheme diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/Loading.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/Loading.kt new file mode 100644 index 0000000000..b32011e892 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/Loading.kt @@ -0,0 +1,48 @@ +package org.thoughtcrime.securesms.onboarding.loading + +import androidx.compose.animation.core.Animatable +import androidx.compose.animation.core.TweenSpec +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import network.loki.messenger.R +import org.thoughtcrime.securesms.ui.ProgressArc +import org.thoughtcrime.securesms.ui.base +import org.thoughtcrime.securesms.ui.contentDescription +import org.thoughtcrime.securesms.ui.h7 + +@Composable +fun LoadingScreen(state: State) { + val animatable = remember { Animatable(initialValue = 0f, visibilityThreshold = 0.005f) } + + LaunchedEffect(state) { + animatable.stop() + animatable.animateTo( + targetValue = 1f, + animationSpec = TweenSpec(durationMillis = state.duration.inWholeMilliseconds.toInt()) + ) + } + + Column(horizontalAlignment = Alignment.CenterHorizontally) { + Spacer(modifier = Modifier.weight(1f)) + ProgressArc( + animatable.value, + modifier = Modifier.contentDescription(R.string.AccessibilityId_loading_animation) + ) + Text( + stringResource(R.string.waitOneMoment), + style = h7 + ) + Text( + stringResource(R.string.loadAccountProgressMessage), + style = base + ) + Spacer(modifier = Modifier.weight(2f)) + } +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LoadingActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/LoadingActivity.kt similarity index 56% rename from app/src/main/java/org/thoughtcrime/securesms/onboarding/LoadingActivity.kt rename to app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/LoadingActivity.kt index 40b6656bf6..ebff016bce 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LoadingActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/LoadingActivity.kt @@ -1,36 +1,20 @@ -package org.thoughtcrime.securesms.onboarding +package org.thoughtcrime.securesms.onboarding.loading import android.content.Context import android.content.Intent import android.os.Bundle import androidx.activity.viewModels -import androidx.compose.animation.core.Animatable -import androidx.compose.animation.core.TweenSpec -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Spacer -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource import androidx.lifecycle.lifecycleScope import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch -import network.loki.messenger.R import org.session.libsession.utilities.TextSecurePreferences import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.BaseActionBarActivity import org.thoughtcrime.securesms.dependencies.ConfigFactory import org.thoughtcrime.securesms.onboarding.messagenotifications.startMessageNotificationsActivity import org.thoughtcrime.securesms.onboarding.pickname.startPickDisplayNameActivity -import org.thoughtcrime.securesms.ui.ProgressArc -import org.thoughtcrime.securesms.ui.base -import org.thoughtcrime.securesms.ui.contentDescription -import org.thoughtcrime.securesms.ui.h7 import org.thoughtcrime.securesms.ui.setComposeContent import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo import javax.inject.Inject @@ -69,7 +53,10 @@ class LoadingActivity: BaseActionBarActivity() { ApplicationContext.getInstance(this).newAccount = false - setComposeContent { LoadingScreen() } + setComposeContent { + val state by viewModel.stateFlow.collectAsState() + LoadingScreen(state) + } setUpActionBarSessionLogo(true) @@ -84,38 +71,6 @@ class LoadingActivity: BaseActionBarActivity() { } } } - - @Composable - fun LoadingScreen() { - val state by viewModel.stateFlow.collectAsState() - - val animatable = remember { Animatable(initialValue = 0f, visibilityThreshold = 0.005f) } - - LaunchedEffect(state) { - animatable.stop() - animatable.animateTo( - targetValue = 1f, - animationSpec = TweenSpec(durationMillis = state.duration.inWholeMilliseconds.toInt()) - ) - } - - Column(horizontalAlignment = Alignment.CenterHorizontally) { - Spacer(modifier = Modifier.weight(1f)) - ProgressArc( - animatable.value, - modifier = Modifier.contentDescription(R.string.AccessibilityId_loading_animation) - ) - Text( - stringResource(R.string.waitOneMoment), - style = h7 - ) - Text( - stringResource(R.string.loadAccountProgressMessage), - style = base - ) - Spacer(modifier = Modifier.weight(2f)) - } - } } fun Context.startLoadingActivity(mnemonic: ByteArray) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LoadingViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/LoadingViewModel.kt similarity index 98% rename from app/src/main/java/org/thoughtcrime/securesms/onboarding/LoadingViewModel.kt rename to app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/LoadingViewModel.kt index bf4aad1a4b..5bf54de634 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/LoadingViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loading/LoadingViewModel.kt @@ -1,4 +1,4 @@ -package org.thoughtcrime.securesms.onboarding +package org.thoughtcrime.securesms.onboarding.loading import android.content.Context import androidx.lifecycle.ViewModel diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt new file mode 100644 index 0000000000..25a8c33138 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotifications.kt @@ -0,0 +1,79 @@ +package org.thoughtcrime.securesms.onboarding.messagenotifications + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import network.loki.messenger.R +import org.thoughtcrime.securesms.ui.LocalDimensions +import org.thoughtcrime.securesms.ui.PreviewTheme +import org.thoughtcrime.securesms.ui.SessionColorsParameterProvider +import org.thoughtcrime.securesms.ui.base +import org.thoughtcrime.securesms.ui.color.Colors +import org.thoughtcrime.securesms.ui.components.NotificationRadioButton +import org.thoughtcrime.securesms.ui.components.OutlineButton +import org.thoughtcrime.securesms.ui.contentDescription +import org.thoughtcrime.securesms.ui.h4 + + +@Preview +@Composable +fun MessageNotificationsScreenPreview( + @PreviewParameter(SessionColorsParameterProvider::class) colors: Colors +) { + PreviewTheme(colors) { + MessageNotificationsScreen() + } +} + +@Composable +fun MessageNotificationsScreen( + state: MessageNotificationsState = MessageNotificationsState(), + setEnabled: (Boolean) -> Unit = {}, + onContinue: () -> Unit = {} +) { + Column { + Spacer(Modifier.weight(1f)) + Column(modifier = Modifier.padding(horizontal = LocalDimensions.current.marginMedium)) { + Text(stringResource(R.string.notificationsMessage), style = h4) + Spacer(Modifier.height(LocalDimensions.current.marginExtraSmall)) + Text(stringResource(R.string.onboardingMessageNotificationExplaination), style = base) + Spacer(Modifier.height(LocalDimensions.current.marginExtraSmall)) + NotificationRadioButton( + R.string.activity_pn_mode_fast_mode, + R.string.activity_pn_mode_fast_mode_explanation, + R.string.activity_pn_mode_recommended_option_tag, + contentDescription = R.string.AccessibilityId_fast_mode_notifications_button, + selected = state.pushEnabled, + onClick = { setEnabled(true) } + ) + Spacer(Modifier.height(LocalDimensions.current.marginExtraSmall)) + NotificationRadioButton( + R.string.activity_pn_mode_slow_mode, + R.string.activity_pn_mode_slow_mode_explanation, + contentDescription = R.string.AccessibilityId_slow_mode_notifications_button, + selected = state.pushDisabled, + onClick = { setEnabled(false) } + ) + } + Spacer(Modifier.weight(1f)) + OutlineButton( + stringResource(R.string.continue_2), + modifier = Modifier + .padding(horizontal = LocalDimensions.current.marginLarge) + .contentDescription(R.string.AccessibilityId_continue) + .align(Alignment.CenterHorizontally) + .fillMaxWidth(), + onClick = onContinue + ) + Spacer(modifier = Modifier.height(LocalDimensions.current.marginExtraExtraSmall)) + } +} diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotificationsActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotificationsActivity.kt index a0c9691d27..998e38f4d5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotificationsActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/messagenotifications/MessageNotificationsActivity.kt @@ -4,36 +4,15 @@ import android.content.Context import android.content.Intent import android.os.Bundle import androidx.activity.viewModels -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.tooling.preview.PreviewParameter import dagger.hilt.android.AndroidEntryPoint -import network.loki.messenger.R import org.session.libsession.utilities.TextSecurePreferences import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.BaseActionBarActivity import org.thoughtcrime.securesms.home.HomeActivity import org.thoughtcrime.securesms.notifications.PushRegistry -import org.thoughtcrime.securesms.ui.LocalDimensions -import org.thoughtcrime.securesms.ui.color.Colors -import org.thoughtcrime.securesms.ui.PreviewTheme -import org.thoughtcrime.securesms.ui.SessionColorsParameterProvider -import org.thoughtcrime.securesms.ui.base -import org.thoughtcrime.securesms.ui.components.NotificationRadioButton -import org.thoughtcrime.securesms.ui.components.OutlineButton -import org.thoughtcrime.securesms.ui.contentDescription -import org.thoughtcrime.securesms.ui.h4 import org.thoughtcrime.securesms.ui.setComposeContent import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo import javax.inject.Inject @@ -70,60 +49,6 @@ class MessageNotificationsActivity : BaseActionBarActivity() { } } -@Preview -@Composable -fun MessageNotificationsScreenPreview( - @PreviewParameter(SessionColorsParameterProvider::class) colors: Colors -) { - PreviewTheme(colors) { - MessageNotificationsScreen() - } -} - -@Composable -fun MessageNotificationsScreen( - state: MessageNotificationsState = MessageNotificationsState(), - setEnabled: (Boolean) -> Unit = {}, - onContinue: () -> Unit = {} -) { - Column { - Spacer(Modifier.weight(1f)) - Column(modifier = Modifier.padding(horizontal = LocalDimensions.current.marginMedium)) { - Text(stringResource(R.string.notificationsMessage), style = h4) - Spacer(Modifier.height(LocalDimensions.current.marginExtraSmall)) - Text(stringResource(R.string.onboardingMessageNotificationExplaination), style = base) - Spacer(Modifier.height(LocalDimensions.current.marginExtraSmall)) - NotificationRadioButton( - R.string.activity_pn_mode_fast_mode, - R.string.activity_pn_mode_fast_mode_explanation, - R.string.activity_pn_mode_recommended_option_tag, - contentDescription = R.string.AccessibilityId_fast_mode_notifications_button, - selected = state.pushEnabled, - onClick = { setEnabled(true) } - ) - Spacer(Modifier.height(LocalDimensions.current.marginExtraSmall)) - NotificationRadioButton( - R.string.activity_pn_mode_slow_mode, - R.string.activity_pn_mode_slow_mode_explanation, - contentDescription = R.string.AccessibilityId_slow_mode_notifications_button, - selected = state.pushDisabled, - onClick = { setEnabled(false) } - ) - } - Spacer(Modifier.weight(1f)) - OutlineButton( - stringResource(R.string.continue_2), - modifier = Modifier - .padding(horizontal = LocalDimensions.current.marginLarge) - .contentDescription(R.string.AccessibilityId_continue) - .align(Alignment.CenterHorizontally) - .fillMaxWidth(), - onClick = onContinue - ) - Spacer(modifier = Modifier.height(LocalDimensions.current.marginExtraExtraSmall)) - } -} - fun Context.startMessageNotificationsActivity(flags: Int = 0) { Intent(this, MessageNotificationsActivity::class.java) .also { it.flags = flags }