Skip to content

Commit

Permalink
Merge pull request #1949 from dedis/work-fe2-maxime-roll-call-attende…
Browse files Browse the repository at this point in the history
…e-copy-button

added copy button in RollCall QR Token fragment
  • Loading branch information
Kaz-ookid authored Jun 27, 2024
2 parents d2a394e + e8bb9d1 commit be8abce
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
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 @@ -83,13 +83,33 @@
style="@style/text_medium_title"
app:layout_constraintTop_toBottomOf="@+id/roll_call_pk_qr_code" />

<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_pop_token_username" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/roll_call_pop_token_username">

<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_pop_token_username" />

<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

0 comments on commit be8abce

Please sign in to comment.