Skip to content

Commit

Permalink
feat: mediator DID can be updated from sample app UI (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianIOHK authored Nov 8, 2023
1 parent 416c3ee commit f20e1bb
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ class PrismAgent {
store = BasicMediatorHandler.PlutoMediatorRepositoryImpl(pluto)
)
setupMediatorHandler(tmpMediatorHandler)
start()
}

/**
Expand Down
4 changes: 4 additions & 0 deletions sampleapp/src/main/java/io/iohk/atala/prism/sampleapp/Sdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class Sdk() {
}
}

suspend fun updateMediatorDID(mediatorDID: String) {
agent?.setupMediatorDID(DID(mediatorDID))
}

fun stopAgent() {
agent?.let {
it.stopFetchingMessages()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class AgentFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.startAgent.setOnClickListener {
viewModel.startAgent()
val mediatorDID = binding.mediatorDid.text.toString()
viewModel.startAgent(mediatorDID)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import kotlinx.coroutines.launch

class AgentViewModel(application: Application) : AndroidViewModel(application) {

fun startAgent() {
fun startAgent(mediatorDID: String) {
val sdk = Sdk.getInstance(getApplication<Application>())
viewModelScope.launch {
sdk.startAgent()
sdk.updateMediatorDID(mediatorDID)
}
}
}
84 changes: 53 additions & 31 deletions sampleapp/src/main/res/layout/fragment_agent.xml
Original file line number Diff line number Diff line change
@@ -1,44 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.agent.AgentFragment">
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.agent.AgentFragment">

<TextView
android:id="@+id/agent_status_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Agent status:"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:id="@+id/agent_status_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Agent status:"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

<TextView
android:id="@+id/agent_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/agent_status_title"
tools:text="RUNNING" />
android:id="@+id/agent_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/agent_status_title"
tools:text="RUNNING"/>

<TextView
android:id="@+id/mediator_did_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/mediator_did"
android:layout_marginStart="16dp"
android:text="Mediator DID:"
/>

<EditText
android:id="@+id/mediator_did"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9zaXQtcHJpc20tbWVkaWF0b3IuYXRhbGFwcmlzbS5pbyIsInIiOltdLCJhIjpbImRpZGNvbW0vdjIiXX0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/start_agent"/>

<Button
android:id="@+id/start_agent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="Start agent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
android:id="@+id/start_agent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="Start agent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

0 comments on commit f20e1bb

Please sign in to comment.