mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Added linking in the ui.
This commit is contained in:
parent
7d1883cfd2
commit
10c1a9cced
@ -76,8 +76,28 @@
|
|||||||
app:labeledEditText_background="@color/loki_darkest_gray"
|
app:labeledEditText_background="@color/loki_darkest_gray"
|
||||||
app:labeledEditText_label="@string/activity_key_pair_mnemonic_edit_text_label"/>
|
app:labeledEditText_label="@string/activity_key_pair_mnemonic_edit_text_label"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/linkExplanationTextView"
|
||||||
|
style="@style/Signal.Text.Body"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:text="@string/activity_key_pair_seed_explanation_3"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
|
<org.thoughtcrime.securesms.components.LabeledEditText
|
||||||
|
android:id="@+id/publicKeyEditText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginBottom="20dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:labeledEditText_background="@color/loki_darkest_gray"
|
||||||
|
app:labeledEditText_label="@string/activity_key_pair_public_key_edit_text_label"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/toggleModeButton"
|
android:id="@+id/toggleRestoreModeButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:background="@color/transparent"
|
android:background="@color/transparent"
|
||||||
@ -86,6 +106,26 @@
|
|||||||
android:elevation="0dp"
|
android:elevation="0dp"
|
||||||
android:stateListAnimator="@null" />
|
android:stateListAnimator="@null" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/toggleRegisterModeButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:background="@color/transparent"
|
||||||
|
android:textColor="@color/signal_primary"
|
||||||
|
android:text="@string/activity_key_pair_toggle_mode_button_title_2"
|
||||||
|
android:elevation="0dp"
|
||||||
|
android:stateListAnimator="@null" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/toggleLinkModeButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:background="@color/transparent"
|
||||||
|
android:textColor="@color/signal_primary"
|
||||||
|
android:text="@string/activity_key_pair_toggle_mode_button_title_3"
|
||||||
|
android:elevation="0dp"
|
||||||
|
android:stateListAnimator="@null" />
|
||||||
|
|
||||||
<com.dd.CircularProgressButton
|
<com.dd.CircularProgressButton
|
||||||
android:id="@+id/registerOrRestoreButton"
|
android:id="@+id/registerOrRestoreButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -1558,13 +1558,17 @@
|
|||||||
<string name="activity_key_pair_title">Create Your Loki Messenger Account</string>
|
<string name="activity_key_pair_title">Create Your Loki Messenger Account</string>
|
||||||
<string name="activity_key_pair_seed_explanation_1">Please save the seed below in a safe location. It can be used to restore your account if you lose access, or to migrate to a new device.</string>
|
<string name="activity_key_pair_seed_explanation_1">Please save the seed below in a safe location. It can be used to restore your account if you lose access, or to migrate to a new device.</string>
|
||||||
<string name="activity_key_pair_seed_explanation_2">Restore your account by entering your seed below</string>
|
<string name="activity_key_pair_seed_explanation_2">Restore your account by entering your seed below</string>
|
||||||
|
<string name="activity_key_pair_seed_explanation_3">Link to an existing device by going into its in-app settings and clicking "Link Device".</string>
|
||||||
<string name="activity_key_pair_copy_button_title">Copy</string>
|
<string name="activity_key_pair_copy_button_title">Copy</string>
|
||||||
<string name="activity_key_pair_mnemonic_edit_text_label">Your Seed</string>
|
<string name="activity_key_pair_mnemonic_edit_text_label">Your Seed</string>
|
||||||
<string name="activity_key_pair_toggle_mode_button_title_1">Restore Using Seed</string>
|
<string name="activity_key_pair_toggle_mode_button_title_1">Restore Using Seed</string>
|
||||||
<string name="activity_key_pair_toggle_mode_button_title_2">Register a New Account</string>
|
<string name="activity_key_pair_toggle_mode_button_title_2">Register a New Account</string>
|
||||||
|
<string name="activity_key_pair_toggle_mode_button_title_3">Link Device</string>
|
||||||
<string name="activity_key_pair_mnemonic_copied_message">Copied to clipboard</string>
|
<string name="activity_key_pair_mnemonic_copied_message">Copied to clipboard</string>
|
||||||
<string name="activity_key_pair_register_or_restore_button_title_1">Register</string>
|
<string name="activity_key_pair_register_or_restore_button_title_1">Register</string>
|
||||||
<string name="activity_key_pair_register_or_restore_button_title_2">Restore</string>
|
<string name="activity_key_pair_register_or_restore_button_title_2">Restore</string>
|
||||||
|
<string name="activity_key_pair_register_or_restore_button_title_3">Link</string>
|
||||||
|
<string name="activity_key_pair_public_key_edit_text_label">Other Device Pub Key</string>
|
||||||
<!-- Conversation list activity -->
|
<!-- Conversation list activity -->
|
||||||
<string name="activity_conversation_list_empty_state_message">Looks like you don\'t have any conversations yet. Get started by messaging a friend.</string>
|
<string name="activity_conversation_list_empty_state_message">Looks like you don\'t have any conversations yet. Get started by messaging a friend.</string>
|
||||||
<!-- Settings activity -->
|
<!-- Settings activity -->
|
||||||
|
@ -1067,6 +1067,11 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (LokiDeviceLinkingSession.Companion.getShared().isListeningForLinkingRequest()) {
|
||||||
|
Log.w("Loki", "Received authorisation but device is not is listening.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Unimplemented for REQUEST
|
// Unimplemented for REQUEST
|
||||||
if (authorisation.getType() != LokiPairingAuthorisation.Type.GRANT) { return; }
|
if (authorisation.getType() != LokiPairingAuthorisation.Type.GRANT) { return; }
|
||||||
Log.d("Loki", "Receiving pairing authorisation from: " + authorisation.getPrimaryDevicePubKey());
|
Log.d("Loki", "Receiving pairing authorisation from: " + authorisation.getPrimaryDevicePubKey());
|
||||||
|
@ -10,6 +10,7 @@ import android.view.inputmethod.InputMethodManager
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import kotlinx.android.synthetic.main.activity_seed.*
|
import kotlinx.android.synthetic.main.activity_seed.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
|
import org.thoughtcrime.securesms.ApplicationContext
|
||||||
import org.thoughtcrime.securesms.BaseActionBarActivity
|
import org.thoughtcrime.securesms.BaseActionBarActivity
|
||||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||||
import org.thoughtcrime.securesms.database.Address
|
import org.thoughtcrime.securesms.database.Address
|
||||||
@ -21,6 +22,7 @@ import org.whispersystems.curve25519.Curve25519
|
|||||||
import org.whispersystems.libsignal.util.KeyHelper
|
import org.whispersystems.libsignal.util.KeyHelper
|
||||||
import org.whispersystems.signalservice.loki.crypto.MnemonicCodec
|
import org.whispersystems.signalservice.loki.crypto.MnemonicCodec
|
||||||
import org.whispersystems.signalservice.loki.utilities.Analytics
|
import org.whispersystems.signalservice.loki.utilities.Analytics
|
||||||
|
import org.whispersystems.signalservice.loki.utilities.PublicKeyValidation
|
||||||
import org.whispersystems.signalservice.loki.utilities.hexEncodedPublicKey
|
import org.whispersystems.signalservice.loki.utilities.hexEncodedPublicKey
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
@ -34,8 +36,10 @@ class SeedActivity : BaseActionBarActivity() {
|
|||||||
private var mnemonic: String? = null
|
private var mnemonic: String? = null
|
||||||
set(newValue) { field = newValue; updateMnemonicTextView() }
|
set(newValue) { field = newValue; updateMnemonicTextView() }
|
||||||
|
|
||||||
|
private var dialog: ProgressDialog? = null
|
||||||
|
|
||||||
// region Types
|
// region Types
|
||||||
enum class Mode { Register, Restore }
|
enum class Mode { Register, Restore, Link }
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Lifecycle
|
// region Lifecycle
|
||||||
@ -44,10 +48,17 @@ class SeedActivity : BaseActionBarActivity() {
|
|||||||
setContentView(R.layout.activity_seed)
|
setContentView(R.layout.activity_seed)
|
||||||
setUpLanguageFileDirectory()
|
setUpLanguageFileDirectory()
|
||||||
updateSeed()
|
updateSeed()
|
||||||
|
updateUI()
|
||||||
copyButton.setOnClickListener { copy() }
|
copyButton.setOnClickListener { copy() }
|
||||||
toggleModeButton.setOnClickListener { toggleMode() }
|
toggleRestoreModeButton.setOnClickListener { mode = Mode.Restore }
|
||||||
|
toggleRegisterModeButton.setOnClickListener { mode = Mode.Register }
|
||||||
|
toggleLinkModeButton.setOnClickListener { mode = Mode.Link }
|
||||||
registerOrRestoreButton.setOnClickListener { registerOrRestore() }
|
registerOrRestoreButton.setOnClickListener { registerOrRestore() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region General
|
// region General
|
||||||
@ -85,14 +96,28 @@ class SeedActivity : BaseActionBarActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateUI() {
|
private fun updateUI() {
|
||||||
seedExplanationTextView1.visibility = if (mode == Mode.Register) View.VISIBLE else View.GONE
|
val showOnRegister = if (mode == Mode.Register) View.VISIBLE else View.GONE
|
||||||
mnemonicTextView.visibility = if (mode == Mode.Register) View.VISIBLE else View.GONE
|
val showOnRestore = if (mode == Mode.Restore) View.VISIBLE else View.GONE
|
||||||
copyButton.visibility = if (mode == Mode.Register) View.VISIBLE else View.GONE
|
val showOnLink = if (mode == Mode.Link) View.VISIBLE else View.GONE
|
||||||
seedExplanationTextView2.visibility = if (mode == Mode.Restore) View.VISIBLE else View.GONE
|
|
||||||
mnemonicEditText.visibility = if (mode == Mode.Restore) View.VISIBLE else View.GONE
|
seedExplanationTextView1.visibility = showOnRegister
|
||||||
val toggleModeButtonTitleID = if (mode == Mode.Register) R.string.activity_key_pair_toggle_mode_button_title_1 else R.string.activity_key_pair_toggle_mode_button_title_2
|
mnemonicTextView.visibility = showOnRegister
|
||||||
toggleModeButton.setText(toggleModeButtonTitleID)
|
copyButton.visibility = showOnRegister
|
||||||
val registerOrRestoreButtonTitleID = if (mode == Mode.Register) R.string.activity_key_pair_register_or_restore_button_title_1 else R.string.activity_key_pair_register_or_restore_button_title_2
|
seedExplanationTextView2.visibility = showOnRestore
|
||||||
|
mnemonicEditText.visibility = showOnRestore
|
||||||
|
publicKeyEditText.visibility = showOnLink
|
||||||
|
linkExplanationTextView.visibility = showOnLink
|
||||||
|
|
||||||
|
toggleRegisterModeButton.visibility = if (mode != Mode.Register) View.VISIBLE else View.GONE
|
||||||
|
toggleRestoreModeButton.visibility = if (mode != Mode.Restore) View.VISIBLE else View.GONE
|
||||||
|
toggleLinkModeButton.visibility = if (mode != Mode.Link) View.VISIBLE else View.GONE
|
||||||
|
|
||||||
|
val registerOrRestoreButtonTitleID = when (mode) {
|
||||||
|
Mode.Register -> R.string.activity_key_pair_register_or_restore_button_title_1
|
||||||
|
Mode.Restore -> R.string.activity_key_pair_register_or_restore_button_title_2
|
||||||
|
Mode.Link -> R.string.activity_key_pair_register_or_restore_button_title_3
|
||||||
|
}
|
||||||
|
|
||||||
registerOrRestoreButton.setText(registerOrRestoreButtonTitleID)
|
registerOrRestoreButton.setText(registerOrRestoreButtonTitleID)
|
||||||
if (mode == Mode.Restore) {
|
if (mode == Mode.Restore) {
|
||||||
mnemonicEditText.requestFocus()
|
mnemonicEditText.requestFocus()
|
||||||
@ -101,6 +126,14 @@ class SeedActivity : BaseActionBarActivity() {
|
|||||||
val inputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
val inputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
inputMethodManager.hideSoftInputFromWindow(mnemonicEditText.windowToken, 0)
|
inputMethodManager.hideSoftInputFromWindow(mnemonicEditText.windowToken, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mode == Mode.Link) {
|
||||||
|
publicKeyEditText.requestFocus()
|
||||||
|
} else {
|
||||||
|
publicKeyEditText.clearFocus()
|
||||||
|
val inputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
|
inputMethodManager.hideSoftInputFromWindow(publicKeyEditText.windowToken, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateMnemonic() {
|
private fun updateMnemonic() {
|
||||||
@ -121,13 +154,6 @@ class SeedActivity : BaseActionBarActivity() {
|
|||||||
Toast.makeText(this, R.string.activity_key_pair_mnemonic_copied_message, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.activity_key_pair_mnemonic_copied_message, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleMode() {
|
|
||||||
mode = when (mode) {
|
|
||||||
Mode.Register -> Mode.Restore
|
|
||||||
Mode.Restore -> Mode.Register
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun registerOrRestore() {
|
private fun registerOrRestore() {
|
||||||
var seed: ByteArray
|
var seed: ByteArray
|
||||||
when (mode) {
|
when (mode) {
|
||||||
@ -142,6 +168,12 @@ class SeedActivity : BaseActionBarActivity() {
|
|||||||
return Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
return Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Mode.Link -> {
|
||||||
|
if (!PublicKeyValidation.isValid(publicKeyEditText.text.trim().toString())) {
|
||||||
|
return Toast.makeText(this, "Invalid public key", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
seed = this.seed!!
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val hexEncodedSeed = Hex.toStringCondensed(seed)
|
val hexEncodedSeed = Hex.toStringCondensed(seed)
|
||||||
IdentityKeyUtil.save(this, IdentityKeyUtil.lokiSeedKey, hexEncodedSeed)
|
IdentityKeyUtil.save(this, IdentityKeyUtil.lokiSeedKey, hexEncodedSeed)
|
||||||
@ -155,14 +187,28 @@ class SeedActivity : BaseActionBarActivity() {
|
|||||||
val registrationID = KeyHelper.generateRegistrationId(false)
|
val registrationID = KeyHelper.generateRegistrationId(false)
|
||||||
TextSecurePreferences.setLocalRegistrationId(this, registrationID)
|
TextSecurePreferences.setLocalRegistrationId(this, registrationID)
|
||||||
DatabaseFactory.getIdentityDatabase(this).saveIdentity(Address.fromSerialized(hexEncodedPublicKey), publicKey,
|
DatabaseFactory.getIdentityDatabase(this).saveIdentity(Address.fromSerialized(hexEncodedPublicKey), publicKey,
|
||||||
IdentityDatabase.VerifiedStatus.VERIFIED, true, System.currentTimeMillis(), true)
|
IdentityDatabase.VerifiedStatus.VERIFIED, true, System.currentTimeMillis(), true)
|
||||||
TextSecurePreferences.setLocalNumber(this, hexEncodedPublicKey)
|
TextSecurePreferences.setLocalNumber(this, hexEncodedPublicKey)
|
||||||
when (mode) {
|
when (mode) {
|
||||||
Mode.Register -> Analytics.shared.track("Seed Created")
|
Mode.Register -> Analytics.shared.track("Seed Created")
|
||||||
Mode.Restore -> Analytics.shared.track("Seed Restored")
|
Mode.Restore -> Analytics.shared.track("Seed Restored")
|
||||||
|
Mode.Link -> Analytics.shared.track("Device Linked")
|
||||||
|
}
|
||||||
|
if (mode == Mode.Link) {
|
||||||
|
TextSecurePreferences.setHasSeenWelcomeScreen(this, true)
|
||||||
|
TextSecurePreferences.setPromptedPushRegistration(this, true)
|
||||||
|
val application = ApplicationContext.getInstance(this)
|
||||||
|
application.startLongPollingIfNeeded()
|
||||||
|
application.setUpStorageAPIIfNeeded()
|
||||||
|
|
||||||
|
// TODO: Show activity view here?
|
||||||
|
|
||||||
|
// TODO: Also need to reset on registration
|
||||||
|
|
||||||
|
} else {
|
||||||
|
startActivity(Intent(this, AccountDetailsActivity::class.java))
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
startActivity(Intent(this, AccountDetailsActivity::class.java))
|
|
||||||
finish()
|
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user