Add alternate strings for load failed in PickDisplayNameActivity

This commit is contained in:
andrew 2023-10-16 11:35:14 +10:30
parent c2088efe43
commit eb691eded9
5 changed files with 63 additions and 22 deletions

View File

@ -24,10 +24,9 @@ import kotlinx.coroutines.launch
import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.BaseActionBarActivity
import org.thoughtcrime.securesms.dependencies.ConfigFactory
import org.thoughtcrime.securesms.onboarding.pickname.PickDisplayNameActivity
import org.thoughtcrime.securesms.onboarding.pickname.startPickDisplayNameActivity
import org.thoughtcrime.securesms.ui.AppTheme
import org.thoughtcrime.securesms.ui.ProgressArc
import org.thoughtcrime.securesms.util.push
import javax.inject.Inject
private const val EXTRA_MNEMONIC = "mnemonic"
@ -50,9 +49,13 @@ class LoadingActivity: BaseActionBarActivity() {
private fun register(skipped: Boolean) {
prefs.setLastConfigurationSyncTime(System.currentTimeMillis())
Intent(this, if (skipped) PickDisplayNameActivity::class.java else PNModeActivity::class.java)
.apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK }
.also(::push)
val flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
when {
skipped -> startPickDisplayNameActivity(true, flags)
else -> startPNModeActivity(flags)
}
}
override fun onCreate(savedInstanceState: Bundle?) {

View File

@ -180,6 +180,8 @@ class PNModeActivity : BaseActionBarActivity() {
// endregion
}
fun Context.startPNModeActivity() {
Intent(this, PNModeActivity::class.java).also(::startActivity)
fun Context.startPNModeActivity(flags: Int = 0) {
Intent(this, PNModeActivity::class.java)
.also { it.flags = flags }
.also(::startActivity)
}

View File

@ -32,6 +32,8 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import network.loki.messenger.R
import org.thoughtcrime.securesms.BaseActionBarActivity
import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2
import org.thoughtcrime.securesms.conversation.v2.ConversationViewModel
import org.thoughtcrime.securesms.onboarding.startPNModeActivity
import org.thoughtcrime.securesms.ui.AppTheme
import org.thoughtcrime.securesms.ui.OutlineButton
@ -40,10 +42,20 @@ import org.thoughtcrime.securesms.ui.base
import org.thoughtcrime.securesms.ui.baseBold
import org.thoughtcrime.securesms.ui.colorDestructive
import org.thoughtcrime.securesms.util.setUpActionBarSessionLogo
import javax.inject.Inject
private const val EXTRA_PICK_NEW_NAME = "extra_pick_new_name"
@AndroidEntryPoint
class PickDisplayNameActivity : BaseActionBarActivity() {
private val viewModel: PickDisplayNameViewModel by viewModels()
@Inject
lateinit var viewModelFactory: PickDisplayNameViewModel.AssistedFactory
private val viewModel: PickDisplayNameViewModel by viewModels {
val pickNewName = intent.getBooleanExtra(EXTRA_PICK_NEW_NAME, false)
viewModelFactory.create(pickNewName)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -132,6 +144,9 @@ class PickDisplayNameActivity : BaseActionBarActivity() {
}
}
fun Context.startPickDisplayNameActivity() {
Intent(this, PickDisplayNameActivity::class.java).also(::startActivity)
fun Context.startPickDisplayNameActivity(failedToLoad: Boolean = false, flags: Int = 0) {
Intent(this, PickDisplayNameActivity::class.java)
.apply { putExtra(EXTRA_PICK_NEW_NAME, failedToLoad) }
.also { it.flags = flags }
.also(::startActivity)
}

View File

@ -3,8 +3,10 @@ package org.thoughtcrime.securesms.onboarding.pickname
import android.content.Context
import androidx.annotation.StringRes
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
@ -20,22 +22,18 @@ import org.session.libsignal.utilities.KeyHelper
import org.session.libsignal.utilities.hexEncodedPublicKey
import org.thoughtcrime.securesms.crypto.KeyPairUtilities
import org.thoughtcrime.securesms.dependencies.ConfigFactory
import javax.inject.Inject
@HiltViewModel
class PickDisplayNameViewModel @Inject constructor(
private val prefs: TextSecurePreferences
class PickDisplayNameViewModel(
pickNewName: Boolean,
private val prefs: TextSecurePreferences,
private val configFactory: ConfigFactory
): ViewModel() {
private val state = MutableStateFlow(State())
private val state = MutableStateFlow(if (pickNewName) pickNewNameState() else State())
val stateFlow = state.asStateFlow()
private val event = Channel<Event>()
val eventFlow = event.receiveAsFlow()
@Inject
lateinit var configFactory: ConfigFactory
private val database: LokiAPIDatabaseProtocol
get() = SnodeModule.shared.storage
@ -75,13 +73,29 @@ class PickDisplayNameViewModel @Inject constructor(
}
fun onChange(value: String) {
state.update {
it.copy(
state.update { state -> state.copy(
displayName = value,
error = value.takeIf { it.length > NAME_PADDED_LENGTH }?.let { R.string.activity_display_name_display_name_too_long_error }
)
}
}
@dagger.assisted.AssistedFactory
interface AssistedFactory {
fun create(pickNewName: Boolean): Factory
}
@Suppress("UNCHECKED_CAST")
class Factory @AssistedInject constructor(
@Assisted private val pickNewName: Boolean,
private val prefs: TextSecurePreferences,
private val configFactory: ConfigFactory
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return PickDisplayNameViewModel(pickNewName, prefs, configFactory) as T
}
}
}
data class State(
@ -91,6 +105,11 @@ data class State(
val displayName: String = ""
)
fun pickNewNameState() = State(
title = R.string.activity_display_name_pick_a_new_display_name,
description = R.string.activity_display_name_unable_to_load_new_name_explanation
)
sealed interface Event {
object DONE: Event
}

View File

@ -728,7 +728,9 @@
<string name="activity_restore_explanation">Enter the recovery phrase that was given to you when you signed up to restore your account.</string>
<string name="activity_restore_seed_edit_text_hint">Enter your recovery phrase</string>
<string name="activity_display_name_title_2">Pick your display name</string>
<string name="activity_display_name_pick_a_new_display_name">Pick a new display name</string>
<string name="activity_display_name_explanation">It can be your real name, an alias, or anything else you like — and you can change it any time.</string>
<string name="activity_display_name_unable_to_load_new_name_explanation">We were unable to load your display name. Please enter a new display name to continue.</string>
<string name="activity_display_name_edit_text_hint">Enter a display name</string>
<string name="activity_display_name_display_name_missing_error">Please pick a display name</string>
<string name="activity_display_name_display_name_too_long_error">Please pick a shorter display name</string>