@@ -15,8 +15,9 @@ import androidx.core.content.ContextCompat
1515import com.google.android.material.tabs.TabLayout
1616import io.outblock.fcl.Fcl
1717import io.outblock.fcl.provider.WalletProvider
18- import io.outblock.fcl.utils.ioScope
19- import io.outblock.fcl.utils.uiScope
18+ import kotlinx.coroutines.CoroutineScope
19+ import kotlinx.coroutines.Dispatchers
20+ import kotlinx.coroutines.launch
2021
2122class MainActivity : AppCompatActivity () {
2223 override fun onCreate (savedInstanceState : Bundle ? ) {
@@ -46,25 +47,25 @@ class MainActivity : AppCompatActivity() {
4647 """ .trimIndent()
4748 )
4849 findViewById<View >(R .id.button_query).setOnClickListener {
49- ioScope {
50+ CoroutineScope ( Dispatchers . IO ).launch {
5051 val cadence = edittext.text.toString()
5152 val result = Fcl .query {
5253 cadence(cadence)
5354 arg { int(7 ) }
5455 arg { int(3 ) }
5556 arg { address(" 0xba1132bc08f82fe2" ) }
5657 }
57- uiScope { findViewById<TextView >(R .id.query_result_view).text = result }
58+ CoroutineScope ( Dispatchers . Main ).launch { findViewById<TextView >(R .id.query_result_view).text = result }
5859 }
5960 }
6061 }
6162
6263 private fun setupSignMessage () {
6364 findViewById<View >(R .id.button_sign_message).setOnClickListener {
64- ioScope {
65+ CoroutineScope ( Dispatchers . IO ).launch {
6566 val message = findViewById<EditText >(R .id.sign_message_edittext).text.toString()
6667 val signature = Fcl .signMessage(message)
67- uiScope { findViewById<TextView >(R .id.signed_message_view).text = signature }
68+ CoroutineScope ( Dispatchers . Main ).launch { findViewById<TextView >(R .id.signed_message_view).text = signature }
6869 }
6970 }
7071 }
@@ -91,11 +92,11 @@ class MainActivity : AppCompatActivity() {
9192
9293 findViewById<View >(R .id.auth_button).setOnClickListener {
9394 val provider = if (tabLayout.selectedTabPosition == 0 ) WalletProvider .DAPPER else WalletProvider .BLOCTO
94- ioScope {
95+ CoroutineScope ( Dispatchers . IO ).launch {
9596 val auth = Fcl .authenticate(provider)
9697 Log .d(TAG , " authenticate complete:$auth " )
97- uiScope {
98- Toast .makeText(this , " authenticate complete" , Toast .LENGTH_SHORT ).show()
98+ CoroutineScope ( Dispatchers . Main ).launch {
99+ Toast .makeText(this @MainActivity , " authenticate complete" , Toast .LENGTH_SHORT ).show()
99100 findViewById<TextView >(R .id.address).text = auth.address
100101 }
101102 }
@@ -123,15 +124,15 @@ class MainActivity : AppCompatActivity() {
123124 )
124125
125126 button.setOnClickListener {
126- ioScope {
127+ CoroutineScope ( Dispatchers . IO ).launch {
127128 val tid = Fcl .mutate {
128129 cadence(editText.text.toString())
129130 arg { string(" Test2" ) }
130131 arg { int(1 ) }
131132 gaslimit(1000 )
132133 }
133134 Log .d(TAG , " tid:$tid " )
134- uiScope {
135+ CoroutineScope ( Dispatchers . Main ).launch {
135136 txidView.text = tid
136137 txidLayout.visibility = View .VISIBLE
137138 viewOnFlowScanView.setOnClickListener {
@@ -144,7 +145,7 @@ class MainActivity : AppCompatActivity() {
144145 }
145146 }
146147
147- fun String.openInSystemBrowser (context : Context ) {
148+ private fun String.openInSystemBrowser (context : Context ) {
148149 ContextCompat .startActivity(context, Intent (Intent .ACTION_VIEW , Uri .parse(this )), null )
149150 }
150151
0 commit comments