Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added copy button in RollCall QR Token fragment #1949

Merged
merged 6 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions docs/messageData.md
Original file line number Diff line number Diff line change
Expand Up @@ -3364,6 +3364,7 @@ This message is sent by both organizers to their servers to be broadcast. The me

```json5
// ../protocol/examples/messageData/federation_tokens_exchange/federation_tokens_exchange.json

{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some unwanted spaces added here I guess

"object": "federation",
"action": "tokens_exchange",
Expand All @@ -3372,11 +3373,13 @@ This message is sent by both organizers to their servers to be broadcast. The me
"tokens": ["M5ZychEi5rwm22FjwjNuljL1qMJWD2sE7oX9fcHNMDU="],
"timestamp": 1712854874
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

```
</details>

```json5
// ../protocol/query/method/message/data/dataFederationTokensExchange.json

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/dedis/popstellar/master/protocol/query/method/message/data/dataFederationTokensExchange.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.github.dedis.popstellar.utility.ActivityUtils.getQRCodeColor
import com.github.dedis.popstellar.utility.ActivityUtils.handleExpandArrow
import com.github.dedis.popstellar.utility.Constants.ID_NULL
import com.github.dedis.popstellar.utility.Constants.ROLL_CALL_ID
import com.github.dedis.popstellar.utility.UIUtils
import com.github.dedis.popstellar.utility.error.ErrorUtils.logAndShow
import com.github.dedis.popstellar.utility.error.UnknownLaoException
import com.github.dedis.popstellar.utility.error.UnknownRollCallException
Expand All @@ -55,6 +56,8 @@ class RollCallFragment : AbstractEventFragment {

private val deAnonymizationWarned = MutableLiveData(false)

private lateinit var clipboardManager: UIUtils.ClipboardUtil

constructor()

override fun onCreateView(
Expand All @@ -67,7 +70,7 @@ class RollCallFragment : AbstractEventFragment {

laoViewModel = obtainViewModel(requireActivity())
rollCallViewModel = obtainRollCallViewModel(requireActivity(), laoViewModel.laoId)

clipboardManager = UIUtils.ClipboardUtil(requireActivity())
rollCall =
try {
rollCallRepo.getRollCallWithPersistentId(
Expand Down Expand Up @@ -147,6 +150,9 @@ class RollCallFragment : AbstractEventFragment {

handleBackNav(TAG)

clipboardManager.setupCopyButton(
binding.rollCallPopTokenTextCopyButton, binding.rollCallPopTokenText, "PoP Token Hash")

return binding.root
}

Expand Down
30 changes: 25 additions & 5 deletions fe2-android/app/src/main/res/layout/roll_call_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,33 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/roll_call_end_time" />

<TextView
android:id="@+id/roll_call_pop_token_text"
<LinearLayout
android:id="@+id/lao_properties_identifier_container"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/roll_call_pk_qr_code" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/roll_call_pk_qr_code">

<TextView
android:id="@+id/roll_call_pop_token_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
app:layout_constraintTop_toBottomOf="@+id/roll_call_pk_qr_code" />

<ImageButton
android:id="@+id/roll_call_pop_token_text_copy_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_content_copy"
android:layout_gravity="bottom"
android:contentDescription="@string/copy_to_clipboard_lao_id"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:layout_marginStart="8dp"/>
</LinearLayout>


<TextView
android:id="@+id/roll_call_fragment_title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public static ViewInteraction rollCallPopTokenText() {
return onView(withId(R.id.roll_call_pop_token_text));
}

public static ViewInteraction rollCallPopTokenTextCopyButton() {
return onView(withId(R.id.roll_call_pop_token_text_copy_button));
}

public static ViewInteraction rollCallLocationCard() {
return onView(withId(R.id.roll_call_location_card));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.dedis.popstellar.ui.lao.event.rollcall

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.assertion.ViewAssertions
Expand Down Expand Up @@ -36,6 +38,7 @@ import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import io.reactivex.subjects.BehaviorSubject
import junit.framework.TestCase
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -558,6 +561,23 @@ class RollCallFragmentTest {
UITestUtils.assertToastIsDisplayedWithText(R.string.roll_call_attendees_list_not_sorted)
}

@Test
fun copyTokenButtonCopiesCorrectText() {

fakeClientLao()
rollCallRepo.updateRollCall(LAO_ID, openRollCall(ROLL_CALL))
RollCallFragmentPageObject.rollCallPopTokenTextCopyButton().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()
RollCallFragmentPageObject.rollCallPopTokenText().check(ViewAssertions.matches(ViewMatchers.withText(copiedText)))

}

/** Utility function to create a LAO when the user is not the organizer */
@Throws(UnknownLaoException::class)
private fun fakeClientLao() {
Expand Down
Loading