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
| @Database(entities = [(WaktuData::class)], version = 1) | |
| abstract class WaktuDb : RoomDatabase() { | |
| abstract fun waktuDao(): WaktuDao | |
| companion object { | |
| private var INSTANCE: WaktuDb? = null | |
| fun getInstance(context: Context) : WaktuDb? { | |
| if (INSTANCE == null) { |
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) |
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
| apply plugin: 'com.android.application' | |
| apply plugin: 'kotlin-android' | |
| apply plugin: 'kotlin-android-extensions' | |
| apply plugin: 'kotlin-kapt' | |
| android { | |
| compileSdkVersion 28 | |
| defaultConfig { | |
| applicationId "com.ysn.stethodev" | |
| minSdkVersion 19 |
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
| import android.content.Context; | |
| import android.content.SharedPreferences; | |
| import com.google.gson.Gson; | |
| import com.google.gson.GsonBuilder; | |
| import org.json.JSONException; | |
| import org.json.JSONObject; | |
| import java.io.IOException; |
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
| import io.reactivex.Observable; | |
| import io.reactivex.ObservableOnSubscribe; | |
| public class RxOperatorCreate { | |
| public static void main(String[] args) { | |
| Observable | |
| .create((ObservableOnSubscribe<String>) emitter -> { | |
| emitter.onNext("Yudi Setiawan"); | |
| emitter.onComplete(); | |
| }) |
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
| public class RxOperatorDefer { | |
| public static void main(String[] args) { | |
| User user = new User(); | |
| Observable<String> name = user.getName(); | |
| user.setName("Yudi Setiawan"); | |
| name.subscribe(System.out::println); | |
| } | |
| } | |
| class User { |
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
| public class RxOperatorFrom { | |
| public static void main(String[] args) { | |
| String[] names = new String[]{"Yudi Setiawan", "Harli Lopies", "Rosalia"}; | |
| Observable.fromArray(names) | |
| .subscribe(System.out::println); | |
| } | |
| } |
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
| public class RxOperatorInterval { | |
| public static void main(String[] args) throws InterruptedException { | |
| CountDownLatch countDownLatch = new CountDownLatch(1); | |
| Observable.interval(1000 * 2, TimeUnit.MILLISECONDS) | |
| .subscribe(new Observer<Long>() { | |
| @Override | |
| public void onSubscribe(Disposable d) { | |
| System.out.println("onSubscribe"); | |
| } |
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
| public class RxOperatorJust { | |
| public static void main(String[] args) { | |
| String[] names = new String[]{"Yudi Setiawan", "Harli Lopies", "Rosalia"}; | |
| Observable.just(names) | |
| .subscribe(strings -> System.out.println(Arrays.toString(strings))); | |
| } | |
| } |
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
| public class Main { | |
| public static void main(String[] args) { | |
| Observable.range(0, 5) | |
| .subscribe(System.out::println); | |
| } | |
| } |