diff --git a/fe2-android/app/src/main/java/com/github/dedis/popstellar/ui/home/QrFragment.kt b/fe2-android/app/src/main/java/com/github/dedis/popstellar/ui/home/QrFragment.kt
index 1d851f2074..aa99c07661 100644
--- a/fe2-android/app/src/main/java/com/github/dedis/popstellar/ui/home/QrFragment.kt
+++ b/fe2-android/app/src/main/java/com/github/dedis/popstellar/ui/home/QrFragment.kt
@@ -10,6 +10,7 @@ import com.github.dedis.popstellar.R
import com.github.dedis.popstellar.databinding.QrFragmentBinding
import com.github.dedis.popstellar.model.qrcode.MainPublicKeyData
import com.github.dedis.popstellar.utility.ActivityUtils.getQRCodeColor
+import com.github.dedis.popstellar.utility.GeneralUtils
import com.github.dedis.popstellar.utility.security.KeyManager
import com.google.gson.Gson
import dagger.hilt.android.AndroidEntryPoint
@@ -25,6 +26,7 @@ class QrFragment : Fragment() {
private lateinit var binding: QrFragmentBinding
private lateinit var viewModel: HomeViewModel
+ private lateinit var clipboardManager: GeneralUtils.ClipboardUtil
override fun onCreateView(
inflater: LayoutInflater,
@@ -34,6 +36,7 @@ class QrFragment : Fragment() {
// Inflate the layout for this fragment
binding = QrFragmentBinding.inflate(inflater, container, false)
binding.lifecycleOwner = activity
+ clipboardManager = GeneralUtils.ClipboardUtil(requireActivity())
viewModel = HomeActivity.obtainViewModel(requireActivity())
@@ -44,6 +47,15 @@ class QrFragment : Fragment() {
return binding.root
}
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ setupCopyButton()
+ }
+
+ private fun setupCopyButton() {
+ clipboardManager.setupCopyButton(binding.copyPublicKeyButton, binding.pkText, "Public Key")
+ }
+
override fun onResume() {
super.onResume()
viewModel.setPageTitle(R.string.witness_qr)
diff --git a/fe2-android/app/src/main/res/layout/qr_fragment.xml b/fe2-android/app/src/main/res/layout/qr_fragment.xml
index 9e0ac273e5..fe837eff11 100644
--- a/fe2-android/app/src/main/res/layout/qr_fragment.xml
+++ b/fe2-android/app/src/main/res/layout/qr_fragment.xml
@@ -12,30 +12,42 @@
android:layout_width="@dimen/qr_rollcall_img"
android:layout_height="@dimen/qr_rollcall_img"
android:contentDescription="@string/witness"
- app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintEnd_toEndOf="parent" />
+ app:layout_constraintTop_toTopOf="parent" />
+ app:layout_constraintTop_toBottomOf="@id/pk_qr_code" />
+
+
+ app:layout_constraintTop_toBottomOf="@id/pk_title" />
diff --git a/fe2-android/app/src/main/res/values/strings.xml b/fe2-android/app/src/main/res/values/strings.xml
index c319b20ea0..4800828c43 100644
--- a/fe2-android/app/src/main/res/values/strings.xml
+++ b/fe2-android/app/src/main/res/values/strings.xml
@@ -16,6 +16,7 @@
Copy to Clipboard Server Address
Copy to Clipboard Lao ID
+ Copy to Clipboard Public Key
Social Media
@@ -388,5 +389,5 @@
LAO coins
Invalid QRCode laoData
Invalid URL
-
+
diff --git a/fe2-android/app/src/test/framework/common/java/com/github/dedis/popstellar/testutils/pages/home/QrPageObject.java b/fe2-android/app/src/test/framework/common/java/com/github/dedis/popstellar/testutils/pages/home/QrPageObject.java
index 5cb6f4b288..28224a4023 100644
--- a/fe2-android/app/src/test/framework/common/java/com/github/dedis/popstellar/testutils/pages/home/QrPageObject.java
+++ b/fe2-android/app/src/test/framework/common/java/com/github/dedis/popstellar/testutils/pages/home/QrPageObject.java
@@ -19,4 +19,8 @@ public static ViewInteraction qrCode() {
public static ViewInteraction privateKey() {
return onView(withId(R.id.pk_text));
}
+
+ public static ViewInteraction copyPublicKeyButton() {
+ return onView(withId(R.id.copy_public_key_button));
+ }
}
diff --git a/fe2-android/app/src/test/ui/robolectric/com/github/dedis/popstellar/ui/home/QrFragmentTest.kt b/fe2-android/app/src/test/ui/robolectric/com/github/dedis/popstellar/ui/home/QrFragmentTest.kt
index d9d684dbb3..5ce73cdcd7 100644
--- a/fe2-android/app/src/test/ui/robolectric/com/github/dedis/popstellar/ui/home/QrFragmentTest.kt
+++ b/fe2-android/app/src/test/ui/robolectric/com/github/dedis/popstellar/ui/home/QrFragmentTest.kt
@@ -1,14 +1,20 @@
package com.github.dedis.popstellar.ui.home
+import android.content.ClipboardManager
+import android.content.Context
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.test.espresso.action.ViewActions
+import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.platform.app.InstrumentationRegistry
import com.github.dedis.popstellar.di.DataRegistryModuleHelper.buildRegistry
import com.github.dedis.popstellar.di.JsonModule.provideGson
import com.github.dedis.popstellar.testutils.Base64DataUtils
+import com.github.dedis.popstellar.testutils.BundleBuilder
+import com.github.dedis.popstellar.testutils.fragment.ActivityFragmentScenarioRule
import com.github.dedis.popstellar.testutils.pages.home.HomePageObject
import com.github.dedis.popstellar.testutils.pages.home.QrPageObject
import com.github.dedis.popstellar.utility.security.KeyManager
@@ -16,6 +22,7 @@ import com.google.gson.Gson
import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
+import junit.framework.TestCase
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -74,6 +81,18 @@ class QrFragmentTest {
.check(ViewAssertions.matches(ViewMatchers.withText(keyManager.mainPublicKey.encoded)))
}
+ @Test
+ fun copyPublicKeyButton_CopiesCorrectText() {
+ QrPageObject.copyPublicKeyButton().perform(ViewActions.click())
+ val clipboard = InstrumentationRegistry.getInstrumentation().targetContext.getSystemService(
+ Context.CLIPBOARD_SERVICE) as ClipboardManager
+ TestCase.assertTrue(clipboard.hasPrimaryClip())
+ val clipData = clipboard.primaryClip
+ TestCase.assertNotNull(clipData)
+ val copiedText = clipData!!.getItemAt(0).text.toString()
+ QrPageObject.privateKey().check(ViewAssertions.matches(ViewMatchers.withText(copiedText)))
+ }
+
companion object {
private val KEY_PAIR = Base64DataUtils.generateKeyPair()
private val PK = KEY_PAIR.publicKey