Skip to content

Instantly share code, notes, and snippets.

@CoderJava
Created September 14, 2018 15:32
Show Gist options
  • Select an option

  • Save CoderJava/f4710076eb89b9f2642f78f1d1432954 to your computer and use it in GitHub Desktop.

Select an option

Save CoderJava/f4710076eb89b9f2642f78f1d1432954 to your computer and use it in GitHub Desktop.
MainActivity Database Debugging
// ...
button_database.setOnClickListener { it ->
val waktuDb: WaktuDb = WaktuDb.getInstance(this@MainActivity)!!
Observable
.create<Boolean> { emitter ->
val strWaktu = SimpleDateFormat("dd-MM-yyyy HH:mm:ss", Locale.US)
.format(Date())
val waktuData = WaktuData(null, strWaktu)
waktuDb.waktuDao()
.insert(waktuData)
emitter.onNext(true)
emitter.onComplete()
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
Toast.makeText(this@MainActivity, "Data has been saved", Toast.LENGTH_SHORT)
.show()
},
{
it.printStackTrace()
Toast.makeText(this@MainActivity, "Error occured", Toast.LENGTH_SHORT)
.show()
},
{
/* nothing to do in here */
}
)
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment