From 93cbca23a426712bf5badf76467bbef9c5e06633 Mon Sep 17 00:00:00 2001 From: AMiracle-creator Date: Tue, 14 May 2024 22:28:31 +0300 Subject: [PATCH 1/3] add copyboard to public key --- .../dedis/popstellar/ui/home/QrFragment.kt | 13 +++++++++ .../app/src/main/res/layout/qr_fragment.xml | 28 +++++++++++++------ .../app/src/main/res/values/strings.xml | 17 ++--------- 3 files changed, 36 insertions(+), 22 deletions(-) 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..cbd01c9cd5 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,16 @@ class QrFragment : Fragment() { return binding.root } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setupCopyButton() + } + + private fun setupCopyButton() { + clipboardManager.setupCopyButton( + binding.copyServerButton, 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..52783e33d9 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..ab13e13e81 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 Public Key Social Media @@ -25,7 +26,6 @@ Witnessing Invite Tokens - Linked organizations Disconnect @@ -294,15 +294,6 @@ Enter PoPCHA URL to log in PoPCHA URL - - There are no linked organizations for now. To create a new link, tap the + button on the bottom right corner. - There are no linked organizations for now. - Invite an organization - Join an invitation - Scan the QR code with the other organizers device - Next step - Finish - No stored data found Clear all storage @@ -329,10 +320,6 @@ Receive button The sight on top of camera Close button for manual add window - Create a new link - Invite another organization - Join another organization invitation - Qr code image to display federation connecting information You are not in a LAO @@ -389,4 +376,6 @@ Invalid QRCode laoData Invalid URL + No internet connection + From 13ef9c025fdac7ed7eaafd6f39aea0656952cc8f Mon Sep 17 00:00:00 2001 From: AMiracle-creator Date: Sun, 2 Jun 2024 17:10:32 +0300 Subject: [PATCH 2/3] fix + tests --- .../dedis/popstellar/ui/home/QrFragment.kt | 3 +-- .../app/src/main/res/layout/qr_fragment.xml | 2 +- .../app/src/main/res/values/strings.xml | 19 +++++++++++++++---- .../testutils/pages/home/QrPageObject.java | 4 ++++ .../popstellar/ui/home/QrFragmentTest.kt | 19 +++++++++++++++++++ 5 files changed, 40 insertions(+), 7 deletions(-) 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 cbd01c9cd5..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 @@ -53,8 +53,7 @@ class QrFragment : Fragment() { } private fun setupCopyButton() { - clipboardManager.setupCopyButton( - binding.copyServerButton, binding.pkText, "Public Key") + clipboardManager.setupCopyButton(binding.copyPublicKeyButton, binding.pkText, "Public Key") } override fun onResume() { 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 52783e33d9..fe837eff11 100644 --- a/fe2-android/app/src/main/res/layout/qr_fragment.xml +++ b/fe2-android/app/src/main/res/layout/qr_fragment.xml @@ -29,7 +29,7 @@ app:layout_constraintTop_toBottomOf="@id/pk_qr_code" /> Copy to Clipboard Server Address Copy to Clipboard Lao ID - Copy to Public Key + Copy to Clipboard Public Key Social Media @@ -26,6 +26,7 @@ Witnessing Invite Tokens + Linked organizations Disconnect @@ -294,6 +295,15 @@ Enter PoPCHA URL to log in PoPCHA URL + + There are no linked organizations for now. To create a new link, tap the + button on the bottom right corner. + There are no linked organizations for now. + Invite an organization + Join an invitation + Scan the QR code with the other organizers device + Next step + Finish + No stored data found Clear all storage @@ -320,6 +330,10 @@ Receive button The sight on top of camera Close button for manual add window + Create a new link + Invite another organization + Join another organization invitation + Qr code image to display federation connecting information You are not in a LAO @@ -375,7 +389,4 @@ LAO coins Invalid QRCode laoData Invalid URL - - No internet connection - 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 From bf921242c7950ef75df03d69a506764a389def99 Mon Sep 17 00:00:00 2001 From: AMiracle-creator Date: Sun, 2 Jun 2024 17:15:33 +0300 Subject: [PATCH 3/3] strings fix --- fe2-android/app/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/fe2-android/app/src/main/res/values/strings.xml b/fe2-android/app/src/main/res/values/strings.xml index 51e483bab1..4800828c43 100644 --- a/fe2-android/app/src/main/res/values/strings.xml +++ b/fe2-android/app/src/main/res/values/strings.xml @@ -389,4 +389,5 @@ LAO coins Invalid QRCode laoData Invalid URL +