Skip to content

Commit

Permalink
hide some classes
Browse files Browse the repository at this point in the history
  • Loading branch information
john990 committed Jul 20, 2022
1 parent e3e1731 commit 4fbb7b1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
4 changes: 2 additions & 2 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {
}

dependencies {
// implementation project(path: ':fcl-android')
implementation project(path: ':fcl-android')

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
Expand All @@ -42,7 +42,7 @@ dependencies {

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'

implementation 'com.github.Outblock:fcl-android:0.03'
// implementation 'com.github.Outblock:fcl-android:0.03'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand Down
25 changes: 13 additions & 12 deletions example/src/main/java/io/outblock/fcl/example/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import androidx.core.content.ContextCompat
import com.google.android.material.tabs.TabLayout
import io.outblock.fcl.Fcl
import io.outblock.fcl.provider.WalletProvider
import io.outblock.fcl.utils.ioScope
import io.outblock.fcl.utils.uiScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -46,25 +47,25 @@ class MainActivity : AppCompatActivity() {
""".trimIndent()
)
findViewById<View>(R.id.button_query).setOnClickListener {
ioScope {
CoroutineScope(Dispatchers.IO).launch {
val cadence = edittext.text.toString()
val result = Fcl.query {
cadence(cadence)
arg { int(7) }
arg { int(3) }
arg { address("0xba1132bc08f82fe2") }
}
uiScope { findViewById<TextView>(R.id.query_result_view).text = result }
CoroutineScope(Dispatchers.Main).launch { findViewById<TextView>(R.id.query_result_view).text = result }
}
}
}

private fun setupSignMessage() {
findViewById<View>(R.id.button_sign_message).setOnClickListener {
ioScope {
CoroutineScope(Dispatchers.IO).launch {
val message = findViewById<EditText>(R.id.sign_message_edittext).text.toString()
val signature = Fcl.signMessage(message)
uiScope { findViewById<TextView>(R.id.signed_message_view).text = signature }
CoroutineScope(Dispatchers.Main).launch { findViewById<TextView>(R.id.signed_message_view).text = signature }
}
}
}
Expand All @@ -91,11 +92,11 @@ class MainActivity : AppCompatActivity() {

findViewById<View>(R.id.auth_button).setOnClickListener {
val provider = if (tabLayout.selectedTabPosition == 0) WalletProvider.DAPPER else WalletProvider.BLOCTO
ioScope {
CoroutineScope(Dispatchers.IO).launch {
val auth = Fcl.authenticate(provider)
Log.d(TAG, "authenticate complete:$auth")
uiScope {
Toast.makeText(this, "authenticate complete", Toast.LENGTH_SHORT).show()
CoroutineScope(Dispatchers.Main).launch {
Toast.makeText(this@MainActivity, "authenticate complete", Toast.LENGTH_SHORT).show()
findViewById<TextView>(R.id.address).text = auth.address
}
}
Expand Down Expand Up @@ -123,15 +124,15 @@ class MainActivity : AppCompatActivity() {
)

button.setOnClickListener {
ioScope {
CoroutineScope(Dispatchers.IO).launch {
val tid = Fcl.mutate {
cadence(editText.text.toString())
arg { string("Test2") }
arg { int(1) }
gaslimit(1000)
}
Log.d(TAG, "tid:$tid")
uiScope {
CoroutineScope(Dispatchers.Main).launch {
txidView.text = tid
txidLayout.visibility = View.VISIBLE
viewOnFlowScanView.setOnClickListener {
Expand All @@ -144,7 +145,7 @@ class MainActivity : AppCompatActivity() {
}
}

fun String.openInSystemBrowser(context: Context) {
private fun String.openInSystemBrowser(context: Context) {
ContextCompat.startActivity(context, Intent(Intent.ACTION_VIEW, Uri.parse(this)), null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ package io.outblock.fcl.utils
import io.outblock.fcl.BuildConfig
import kotlinx.coroutines.*

fun ioScope(unit: suspend () -> Unit) = CoroutineScope(Dispatchers.IO).launch { execute(unit) }
internal fun ioScope(unit: suspend () -> Unit) = CoroutineScope(Dispatchers.IO).launch { execute(unit) }

suspend fun contextScope(unit: suspend () -> Unit) = withContext(Dispatchers.Main) { execute(unit) }
internal suspend fun contextScope(unit: suspend () -> Unit) = withContext(Dispatchers.Main) { execute(unit) }

fun uiScope(unit: suspend () -> Unit) = CoroutineScope(Dispatchers.Main).launch { execute(unit) }
internal fun uiScope(unit: suspend () -> Unit) = CoroutineScope(Dispatchers.Main).launch { execute(unit) }

fun uiDelay(delayMs: Long, unit: suspend () -> Unit) = CoroutineScope(Dispatchers.Main).launch {
internal fun uiDelay(delayMs: Long, unit: suspend () -> Unit) = CoroutineScope(Dispatchers.Main).launch {
delay(delayMs)
execute(unit)
}

fun cpuScope(unit: suspend () -> Unit) = CoroutineScope(Dispatchers.Default).launch { execute(unit) }
internal fun cpuScope(unit: suspend () -> Unit) = CoroutineScope(Dispatchers.Default).launch { execute(unit) }

suspend fun repeatWhen(
internal suspend fun repeatWhen(
predicate: suspend () -> Boolean,
block: suspend () -> Unit,
) {
Expand All @@ -25,7 +25,7 @@ suspend fun repeatWhen(
}
}

suspend fun runBlockDelay(timeMillis: Long, block: suspend () -> Unit) {
internal suspend fun runBlockDelay(timeMillis: Long, block: suspend () -> Unit) {
val startTime = System.currentTimeMillis()
block.invoke()
val elapsedTime = System.currentTimeMillis() - startTime
Expand Down
12 changes: 6 additions & 6 deletions fcl-android/src/main/java/io/outblock/fcl/utils/Log.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ import io.outblock.fcl.BuildConfig

private val PRINT_LOG = BuildConfig.DEBUG

fun logv(tag: String?, msg: Any?) {
internal fun logv(tag: String?, msg: Any?) {
log(tag, msg, Log.VERBOSE)
}

fun logd(tag: String?, msg: Any?) {
internal fun logd(tag: String?, msg: Any?) {
log(tag, msg, Log.DEBUG)
}

fun logi(tag: String?, msg: Any?) {
internal fun logi(tag: String?, msg: Any?) {
log(tag, msg, Log.INFO)
}

fun logw(tag: String?, msg: Any?) {
internal fun logw(tag: String?, msg: Any?) {
log(tag, msg, Log.WARN)
}

fun loge(tag: String?, msg: Any?) {
internal fun loge(tag: String?, msg: Any?) {
log(tag, msg, Log.ERROR)
}

fun loge(msg: Throwable?, printStackTrace: Boolean = true) {
internal fun loge(msg: Throwable?, printStackTrace: Boolean = true) {
log("Exception", msg?.message ?: "", Log.ERROR)
if (PRINT_LOG && printStackTrace) {
msg?.printStackTrace()
Expand Down

0 comments on commit 4fbb7b1

Please sign in to comment.