Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@crypticminds
Created January 30, 2020 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crypticminds/43f2dc692eb2a54ca77cd75dec27253d to your computer and use it in GitHub Desktop.
Save crypticminds/43f2dc692eb2a54ca77cd75dec27253d to your computer and use it in GitHub Desktop.
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.arcane.coldstoragecache.callback.OnOperationSuccessfulCallback
import com.arcane.generated.MyBeautifulCacheLayer
class FreezeCacheActivity : AppCompatActivity(), OnOperationSuccessfulCallback<String?> {
private lateinit var button: Button
private lateinit var firstRemoteCall: TextView
private lateinit var secondRemoteCall: TextView
private val valueArray = arrayListOf("a", "b", "c")
//Initializing the generated cache layer here.
private val cacheLayer: MyBeautifulCacheLayer = MyBeautifulCacheLayer()
private var counter = 1
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button = findViewById(R.id.button)
firstRemoteCall = findViewById(R.id.remotecall1)
secondRemoteCall = findViewById(R.id.remotecall2)
/**
* On button click random values from the array will be used to make the
* remote calls.
* The counter variable is used to control the two calls are made alternatively
* on button clicks.
*/
button.setOnClickListener {
if (counter % 2 == 0) {
//calling the method using the generated cache layer
cacheLayer.makeRemoteCallToServiceA(valueArray.random(), this)
} else {
//calling the method using the generated cache layer
cacheLayer.makeRemoteCallToServiceB(
valueArray.random(),
valueArray.random(),
valueArray.random(),
this
)
}
counter += 1
}
}
//we recieve the output of the cache here
override fun onSuccess(output: String?, operation: String) {
runOnUiThread {
when (operation) {
"makeRemoteCallToServiceA" -> firstRemoteCall.text = output!!
"makeRemoteCallToServiceB" -> secondRemoteCall.text = output!!
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment