Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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())

Expand All @@ -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)
Expand Down
28 changes: 20 additions & 8 deletions fe2-android/app/src/main/res/layout/qr_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<TextView
android:id="@+id/pk_title"
style="@style/explication_text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/my_public_key"
style="@style/explication_text_style"
app:layout_constraintTop_toBottomOf="@id/pk_qr_code"
android:layout_marginTop="@dimen/home_button_vertical_margin"
android:text="@string/my_public_key"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
app:layout_constraintTop_toBottomOf="@id/pk_qr_code" />

<ImageButton
android:id="@+id/copy_public_key_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="@dimen/margin_button"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/copy_to_clipboard_public_key"
app:layout_constraintStart_toEndOf="@id/pk_title"
app:layout_constraintTop_toTopOf="@+id/pk_title"
app:srcCompat="@drawable/ic_content_copy" />

<TextView
android:id="@+id/pk_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/pk_title"
android:layout_marginTop="@dimen/home_button_vertical_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
app:layout_constraintTop_toBottomOf="@id/pk_title" />

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down
3 changes: 2 additions & 1 deletion fe2-android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<!-- copy to clipboard -->
<string name="copy_to_clipboard_server">Copy to Clipboard Server Address</string>
<string name="copy_to_clipboard_lao_id">Copy to Clipboard Lao ID</string>
<string name="copy_to_clipboard_public_key">Copy to Clipboard Public Key</string>

<!-- bottom nav -->
<string name="tab_social_media">Social Media</string>
Expand Down Expand Up @@ -388,5 +389,5 @@
<string name="lao_coins">LAO coins</string>
<string name="invalid_qrcode_lao_data">Invalid QRCode laoData</string>
<string name="invalid_qrcode_popcha_data">Invalid URL</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
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
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
Expand Down Expand Up @@ -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
Expand Down