Created
September 14, 2018 15:32
-
-
Save CoderJava/f4710076eb89b9f2642f78f1d1432954 to your computer and use it in GitHub Desktop.
MainActivity Database Debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ... | |
| 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