Repackage Loading and MessageNotifications

This commit is contained in:
Andrew 2024-06-16 14:08:58 +09:30
parent c6952cfcc1
commit b18561acb4
9 changed files with 137 additions and 131 deletions

View File

@ -113,7 +113,7 @@
android:windowSoftInputMode="adjustResize" android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.Session.DayNight.FlatActionBar" /> android:theme="@style/Theme.Session.DayNight.FlatActionBar" />
<activity <activity
android:name="org.thoughtcrime.securesms.onboarding.LoadingActivity" android:name="org.thoughtcrime.securesms.onboarding.loading.LoadingActivity"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.Session.DayNight.FlatActionBar" /> android:theme="@style/Theme.Session.DayNight.FlatActionBar" />

View File

@ -28,13 +28,12 @@ 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.Divider 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.ItemButton
import org.thoughtcrime.securesms.ui.color.LocalColors
import org.thoughtcrime.securesms.ui.LocalDimensions import org.thoughtcrime.securesms.ui.LocalDimensions
import org.thoughtcrime.securesms.ui.PreviewTheme import org.thoughtcrime.securesms.ui.PreviewTheme
import org.thoughtcrime.securesms.ui.SessionColorsParameterProvider 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.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

View File

@ -123,7 +123,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
const val FROM_ONBOARDING = "HomeActivity_FROM_ONBOARDING" const val FROM_ONBOARDING = "HomeActivity_FROM_ONBOARDING"
} }
private lateinit var binding: ActivityHomeBinding private lateinit var binding: ActivityHomeBinding
private lateinit var glide: GlideRequests private lateinit var glide: GlideRequests

View File

@ -30,6 +30,7 @@ import kotlinx.coroutines.launch
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.BaseActionBarActivity import org.thoughtcrime.securesms.BaseActionBarActivity
import org.thoughtcrime.securesms.onboarding.loading.startLoadingActivity
import org.thoughtcrime.securesms.onboarding.messagenotifications.startMessageNotificationsActivity import org.thoughtcrime.securesms.onboarding.messagenotifications.startMessageNotificationsActivity
import org.thoughtcrime.securesms.ui.LocalDimensions import org.thoughtcrime.securesms.ui.LocalDimensions
import org.thoughtcrime.securesms.ui.PreviewTheme import org.thoughtcrime.securesms.ui.PreviewTheme

View File

@ -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))
}
}

View File

@ -1,36 +1,20 @@
package org.thoughtcrime.securesms.onboarding package org.thoughtcrime.securesms.onboarding.loading
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels 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.collectAsState
import androidx.compose.runtime.getValue 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 androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import network.loki.messenger.R
import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.BaseActionBarActivity import org.thoughtcrime.securesms.BaseActionBarActivity
import org.thoughtcrime.securesms.dependencies.ConfigFactory import org.thoughtcrime.securesms.dependencies.ConfigFactory
import org.thoughtcrime.securesms.onboarding.messagenotifications.startMessageNotificationsActivity import org.thoughtcrime.securesms.onboarding.messagenotifications.startMessageNotificationsActivity
import org.thoughtcrime.securesms.onboarding.pickname.startPickDisplayNameActivity 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.ui.setComposeContent
import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo
import javax.inject.Inject import javax.inject.Inject
@ -69,7 +53,10 @@ class LoadingActivity: BaseActionBarActivity() {
ApplicationContext.getInstance(this).newAccount = false ApplicationContext.getInstance(this).newAccount = false
setComposeContent { LoadingScreen() } setComposeContent {
val state by viewModel.stateFlow.collectAsState()
LoadingScreen(state)
}
setUpActionBarSessionLogo(true) 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) { fun Context.startLoadingActivity(mnemonic: ByteArray) {

View File

@ -1,4 +1,4 @@
package org.thoughtcrime.securesms.onboarding package org.thoughtcrime.securesms.onboarding.loading
import android.content.Context import android.content.Context
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel

View File

@ -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))
}
}

View File

@ -4,36 +4,15 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels 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.Composable
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue 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 dagger.hilt.android.AndroidEntryPoint
import network.loki.messenger.R
import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.BaseActionBarActivity import org.thoughtcrime.securesms.BaseActionBarActivity
import org.thoughtcrime.securesms.home.HomeActivity import org.thoughtcrime.securesms.home.HomeActivity
import org.thoughtcrime.securesms.notifications.PushRegistry 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.ui.setComposeContent
import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo
import javax.inject.Inject 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) { fun Context.startMessageNotificationsActivity(flags: Int = 0) {
Intent(this, MessageNotificationsActivity::class.java) Intent(this, MessageNotificationsActivity::class.java)
.also { it.flags = flags } .also { it.flags = flags }