mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Rename LoadAccount
This commit is contained in:
parent
d6a659025d
commit
a1882b83f9
@ -108,7 +108,7 @@
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.Session.DayNight.FlatActionBar" />
|
||||
<activity
|
||||
android:name="org.thoughtcrime.securesms.onboarding.LinkDeviceActivity"
|
||||
android:name="org.thoughtcrime.securesms.onboarding.LoadAccountActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:theme="@style/Theme.Session.DayNight.FlatActionBar" />
|
||||
|
@ -1,6 +0,0 @@
|
||||
package org.thoughtcrime.securesms.onboarding
|
||||
|
||||
data class LinkDeviceState(
|
||||
val recoveryPhrase: String = "",
|
||||
val error: String? = null
|
||||
)
|
@ -7,7 +7,7 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.thoughtcrime.securesms.BaseActionBarActivity
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||
import org.thoughtcrime.securesms.onboarding.LinkDeviceActivity
|
||||
import org.thoughtcrime.securesms.onboarding.loadaccount.LoadAccountActivity
|
||||
import org.thoughtcrime.securesms.onboarding.pickname.startPickDisplayNameActivity
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService
|
||||
import org.thoughtcrime.securesms.ui.setComposeContent
|
||||
@ -35,7 +35,7 @@ class LandingActivity: BaseActionBarActivity() {
|
||||
prefs.setHasViewedSeed(false)
|
||||
startPickDisplayNameActivity()
|
||||
},
|
||||
loadAccount = { start<LinkDeviceActivity>() },
|
||||
loadAccount = { start<LoadAccountActivity>() },
|
||||
openTerms = { open("https://getsession.org/terms-of-service") },
|
||||
openPrivacyPolicy = { open("https://getsession.org/privacy-policy") }
|
||||
)
|
||||
|
@ -1,8 +1,5 @@
|
||||
package org.thoughtcrime.securesms.onboarding
|
||||
package org.thoughtcrime.securesms.onboarding.loadaccount
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.viewModels
|
||||
import androidx.camera.core.ExperimentalGetImage
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
@ -16,74 +13,31 @@ import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.material.Icon
|
||||
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.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import network.loki.messenger.R
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.thoughtcrime.securesms.BaseActionBarActivity
|
||||
import org.thoughtcrime.securesms.onboarding.loading.LoadingManager
|
||||
import org.thoughtcrime.securesms.onboarding.messagenotifications.startMessageNotificationsActivity
|
||||
import org.thoughtcrime.securesms.onboarding.ui.ContinueButton
|
||||
import org.thoughtcrime.securesms.ui.LocalDimensions
|
||||
import org.thoughtcrime.securesms.ui.PreviewTheme
|
||||
import org.thoughtcrime.securesms.ui.base
|
||||
import org.thoughtcrime.securesms.ui.components.MaybeScanQrCode
|
||||
import org.thoughtcrime.securesms.ui.components.OutlineButton
|
||||
import org.thoughtcrime.securesms.ui.components.SessionOutlinedTextField
|
||||
import org.thoughtcrime.securesms.ui.components.SessionTabRow
|
||||
import org.thoughtcrime.securesms.ui.contentDescription
|
||||
import org.thoughtcrime.securesms.ui.h4
|
||||
import org.thoughtcrime.securesms.ui.setComposeContent
|
||||
import javax.inject.Inject
|
||||
|
||||
private const val TAG = "LinkDeviceActivity"
|
||||
|
||||
private val TITLES = listOf(R.string.sessionRecoveryPassword, R.string.qrScan)
|
||||
|
||||
@AndroidEntryPoint
|
||||
@androidx.annotation.OptIn(ExperimentalGetImage::class)
|
||||
class LinkDeviceActivity : BaseActionBarActivity() {
|
||||
|
||||
@Inject lateinit var prefs: TextSecurePreferences
|
||||
@Inject lateinit var loadingManager: LoadingManager
|
||||
|
||||
val viewModel: LinkDeviceViewModel by viewModels()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
supportActionBar?.setTitle(R.string.activity_link_load_account)
|
||||
prefs.setHasViewedSeed(true)
|
||||
prefs.setConfigurationMessageSynced(false)
|
||||
prefs.setRestorationTime(System.currentTimeMillis())
|
||||
prefs.setLastProfileUpdateTime(0)
|
||||
|
||||
lifecycleScope.launch {
|
||||
viewModel.eventFlow.collect {
|
||||
loadingManager.load(it.mnemonic)
|
||||
startMessageNotificationsActivity()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
setComposeContent {
|
||||
val state by viewModel.stateFlow.collectAsState()
|
||||
LoadAccountScreen(state, viewModel::onChange, viewModel::onContinue, viewModel::onScanQrCode)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun LoadAccountScreen(
|
||||
state: LinkDeviceState,
|
||||
internal fun LoadAccountScreen(
|
||||
state: State,
|
||||
qrErrors: Flow<String>,
|
||||
onChange: (String) -> Unit = {},
|
||||
onContinue: () -> Unit = {},
|
||||
onScan: (String) -> Unit = {}
|
||||
@ -96,12 +50,9 @@ class LinkDeviceActivity : BaseActionBarActivity() {
|
||||
state = pagerState,
|
||||
modifier = Modifier.weight(1f)
|
||||
) { page ->
|
||||
val title = TITLES[page]
|
||||
|
||||
when (title) {
|
||||
when (TITLES[page]) {
|
||||
R.string.sessionRecoveryPassword -> RecoveryPassword(state, onChange, onContinue)
|
||||
R.string.qrScan -> MaybeScanQrCode(viewModel.qrErrorsFlow, onScan = onScan)
|
||||
}
|
||||
R.string.qrScan -> MaybeScanQrCode(qrErrors, onScan = onScan)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -109,14 +60,14 @@ class LinkDeviceActivity : BaseActionBarActivity() {
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreviewRecoveryPassword() {
|
||||
private fun PreviewRecoveryPassword() {
|
||||
PreviewTheme {
|
||||
RecoveryPassword(state = LinkDeviceState())
|
||||
RecoveryPassword(state = State())
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun RecoveryPassword(state: LinkDeviceState, onChange: (String) -> Unit = {}, onContinue: () -> Unit = {}) {
|
||||
private fun RecoveryPassword(state: State, onChange: (String) -> Unit = {}, onContinue: () -> Unit = {}) {
|
||||
Column {
|
||||
Column(
|
||||
modifier = Modifier.padding(horizontal = LocalDimensions.current.marginLarge)
|
@ -0,0 +1,49 @@
|
||||
package org.thoughtcrime.securesms.onboarding.loadaccount
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.viewModels
|
||||
import androidx.camera.core.ExperimentalGetImage
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
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.BaseActionBarActivity
|
||||
import org.thoughtcrime.securesms.onboarding.loading.LoadingManager
|
||||
import org.thoughtcrime.securesms.onboarding.messagenotifications.startMessageNotificationsActivity
|
||||
import org.thoughtcrime.securesms.ui.setComposeContent
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
@androidx.annotation.OptIn(ExperimentalGetImage::class)
|
||||
class LoadAccountActivity : BaseActionBarActivity() {
|
||||
|
||||
@Inject lateinit var prefs: TextSecurePreferences
|
||||
@Inject lateinit var loadingManager: LoadingManager
|
||||
|
||||
private val viewModel: LinkDeviceViewModel by viewModels()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
supportActionBar?.setTitle(R.string.activity_link_load_account)
|
||||
prefs.setHasViewedSeed(true)
|
||||
prefs.setConfigurationMessageSynced(false)
|
||||
prefs.setRestorationTime(System.currentTimeMillis())
|
||||
prefs.setLastProfileUpdateTime(0)
|
||||
|
||||
lifecycleScope.launch {
|
||||
viewModel.eventFlow.collect {
|
||||
loadingManager.load(it.mnemonic)
|
||||
startMessageNotificationsActivity()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
setComposeContent {
|
||||
val state by viewModel.stateFlow.collectAsState()
|
||||
LoadAccountScreen(state, viewModel.qrErrorsFlow, viewModel::onChange, viewModel::onContinue, viewModel::onScanQrCode)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.thoughtcrime.securesms.onboarding
|
||||
package org.thoughtcrime.securesms.onboarding.loadaccount
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
@ -22,11 +22,16 @@ import javax.inject.Inject
|
||||
|
||||
class LinkDeviceEvent(val mnemonic: ByteArray)
|
||||
|
||||
internal data class State(
|
||||
val recoveryPhrase: String = "",
|
||||
val error: String? = null
|
||||
)
|
||||
|
||||
@HiltViewModel
|
||||
class LinkDeviceViewModel @Inject constructor(
|
||||
internal class LinkDeviceViewModel @Inject constructor(
|
||||
private val application: Application
|
||||
): AndroidViewModel(application) {
|
||||
private val state = MutableStateFlow(LinkDeviceState())
|
||||
private val state = MutableStateFlow(State())
|
||||
val stateFlow = state.asStateFlow()
|
||||
|
||||
private val event = Channel<LinkDeviceEvent>()
|
||||
@ -56,7 +61,7 @@ class LinkDeviceViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
fun onChange(recoveryPhrase: String) {
|
||||
state.value = LinkDeviceState(recoveryPhrase)
|
||||
state.value = State(recoveryPhrase)
|
||||
}
|
||||
private fun onSuccess(seed: ByteArray) {
|
||||
viewModelScope.launch { event.send(LinkDeviceEvent(seed)) }
|
Loading…
Reference in New Issue
Block a user