-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1788 from dedis/work-fe2-johan
Highlighting Owned Token in Attendees List
- Loading branch information
Showing
4 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...p/src/main/java/com/github/dedis/popstellar/ui/lao/event/rollcall/RollCallArrayAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.github.dedis.popstellar.ui.lao.event.rollcall | ||
|
||
import android.content.Context | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ArrayAdapter | ||
import android.widget.TextView | ||
import androidx.core.content.ContextCompat | ||
import com.github.dedis.popstellar.R | ||
import com.github.dedis.popstellar.model.objects.security.PoPToken | ||
|
||
class RollCallArrayAdapter( | ||
private val context: Context, | ||
private val layout: Int, | ||
private val attendeesList: List<String>, | ||
private val myToken: PoPToken?, | ||
) : ArrayAdapter<String>(context, layout, attendeesList) { | ||
|
||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { | ||
val view = super.getView(position, convertView, parent) | ||
|
||
// highlights our token in the list | ||
val currentToken = getItem(position) | ||
if (myToken != null && currentToken == myToken.publicKey.encoded) { | ||
val colorAccent = ContextCompat.getColor(context, R.color.colorAccent) | ||
(view as TextView).setTextColor(colorAccent) | ||
} | ||
|
||
return view | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...robolectric/com/github/dedis/popstellar/ui/lao/event/rollcall/RollCallArrayAdapterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.github.dedis.popstellar.ui.lao.event.rollcall | ||
|
||
import android.content.Context | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
import androidx.core.content.ContextCompat | ||
import androidx.test.core.app.ApplicationProvider | ||
import com.github.dedis.popstellar.R | ||
import com.github.dedis.popstellar.model.objects.security.PoPToken | ||
import net.i2p.crypto.eddsa.Utils | ||
import org.junit.Assert | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mock | ||
import org.mockito.Mockito.mock | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class RollCallArrayAdapterTest { | ||
|
||
@Mock | ||
private lateinit var mockView: View | ||
|
||
private lateinit var adapter: RollCallArrayAdapter | ||
|
||
val context = ApplicationProvider.getApplicationContext<Context>() | ||
|
||
private val MY_PRIVATE_KEY = | ||
Utils.hexToBytes("3b28b4ab2fe355a13d7b24f90816ff0676f7978bf462fc84f1d5d948b119ec66") | ||
private val MY_PUBLIC_KEY = | ||
Utils.hexToBytes("e5cdb393fe6e0abacd99d521400968083a982400b6ac3e0a1e8f6018d1554bd7") | ||
private val OTHER_PRIVATE_KEY = | ||
Utils.hexToBytes("cf74d353042400806ee94c3e77eef983d9a1434d21c0a7568f203f5b091dde1d") | ||
private val OTHER_PUBLIC_KEY = | ||
Utils.hexToBytes("6015ae4d770294f94e651a9fd6ba9c6a11e5c80803c63ee472ad525f4c3523a6") | ||
|
||
private lateinit var attendeesList: List<String> | ||
|
||
@Before | ||
fun setup() { | ||
// Setting up a list of two tokens and the view | ||
val myToken = PoPToken(MY_PRIVATE_KEY, MY_PUBLIC_KEY) | ||
val otherToken = PoPToken(OTHER_PRIVATE_KEY, OTHER_PUBLIC_KEY) | ||
attendeesList = listOf(myToken.publicKey.encoded, otherToken.publicKey.encoded) | ||
adapter = RollCallArrayAdapter(context, R.id.valid_token_layout_text, attendeesList, myToken) | ||
mockView = TextView(context) | ||
val colorAccent = ContextCompat.getColor(context, R.color.textOnBackground) | ||
(mockView as TextView).setTextColor(colorAccent) | ||
} | ||
|
||
@Test | ||
fun verify_our_token_is_highlighted() { | ||
val view = adapter.getView(0, mockView, mock(ViewGroup::class.java)) as TextView | ||
val color = ContextCompat.getColor(context, R.color.colorAccent) | ||
Assert.assertEquals(color, view.currentTextColor) | ||
} | ||
|
||
@Test | ||
fun verify_other_token_is_not_highlighted() { | ||
val view = adapter.getView(1, mockView, mock(ViewGroup::class.java)) as TextView | ||
val color = ContextCompat.getColor(context, R.color.textOnBackground) | ||
Assert.assertEquals(color, view.currentTextColor) | ||
} | ||
|
||
} |