Add copy mnemonic button

This commit is contained in:
Niels Andriesse 2019-06-05 16:05:08 +10:00
parent 2c35ed2177
commit e36d9e110c
3 changed files with 33 additions and 5 deletions

View File

@ -43,10 +43,23 @@
android:layout_marginTop="16dp"
android:alpha="0.8"
android:textStyle="italic"
android:textAlignment="center" />
android:textAlignment="center"
tools:text="quick brown fox jump lazy dog" />
<Button
android:id="@+id/copyButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:background="@color/white"
android:textColor="@color/signal_primary"
android:text="@string/activity_key_pair_copy_button_title"
android:elevation="0dp"
android:stateListAnimator="@null" />
<com.dd.CircularProgressButton
android:id="@+id/nextButton"
android:id="@+id/registerButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="20dp"
@ -57,7 +70,7 @@
app:cpb_colorProgress="@color/textsecure_primary"
app:cpb_cornerRadius="4dp"
app:cpb_selectorIdle="@drawable/progress_button_state"
app:cpb_textIdle="@string/activity_key_pair_button_title" />
app:cpb_textIdle="@string/activity_key_pair_register_button_title" />
</LinearLayout>

View File

@ -1526,6 +1526,8 @@
<!-- Key pair activity -->
<string name="activity_key_pair_title">Create Your Loki Messenger Account</string>
<string name="activity_key_pair_subtitle">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_button_title">Register</string>
<string name="activity_key_pair_copy_button_title">Copy</string>
<string name="activity_key_pair_mnemonic_copied_message">Copied to Clipboard</string>
<string name="activity_key_pair_register_button_title">Register</string>
</resources>

View File

@ -1,7 +1,11 @@
package org.thoughtcrime.securesms.loki
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_key_pair.*
import org.thoughtcrime.securesms.BaseActionBarActivity
import org.thoughtcrime.securesms.ConversationListActivity
@ -18,6 +22,7 @@ import org.whispersystems.signalservice.loki.utilities.hexEncodedPublicKey
import java.io.File
import java.io.FileOutputStream
class KeyPairActivity : BaseActionBarActivity() {
private lateinit var languageFileDirectory: File
private var keyPair: IdentityKeyPair? = null
@ -31,7 +36,8 @@ class KeyPairActivity : BaseActionBarActivity() {
setContentView(R.layout.activity_key_pair)
setUpLanguageFileDirectory()
updateKeyPair()
nextButton.setOnClickListener { register() }
copyButton.setOnClickListener { copy() }
registerButton.setOnClickListener { register() }
}
// endregion
@ -74,6 +80,13 @@ class KeyPairActivity : BaseActionBarActivity() {
// endregion
// region Interaction
private fun copy() {
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("mnemonic", mnemonic)
clipboard.primaryClip = clip
Toast.makeText(this, R.string.activity_key_pair_mnemonic_copied_message, Toast.LENGTH_SHORT).show()
}
private fun register() {
val publicKey = keyPair!!.publicKey
val hexEncodedPublicKey = keyPair!!.hexEncodedPublicKey