This file contains 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
fun View.visible() { | |
visibility = View.VISIBLE | |
} | |
fun View.invisible() { | |
visibility = View.INVISIBLE | |
} | |
fun View.gone() { | |
visibility = View.GONE |
This file contains 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
implementation 'com.tinder.scarlet:scarlet:0.1.10' | |
implementation 'com.tinder.scarlet:stream-adapter-rxjava2:0.1.10' | |
implementation 'com.tinder.scarlet:websocket-okhttp:0.1.10' | |
implementation 'com.tinder.scarlet:message-adapter-gson:0.1.10' | |
implementation 'com.tinder.scarlet:lifecycle-android:0.1.10' | |
implementation "io.reactivex.rxjava2:rxandroid:2.1.1" | |
implementation "io.reactivex.rxjava2:rxkotlin:2.4.0" | |
implementation "com.squareup.okhttp3:okhttp:4.5.0" |
This file contains 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
interface BitcoinService { | |
@Receive | |
fun observeWebSocketEvent(): Flowable<WebSocket.Event> | |
@Send | |
fun sendSubscribe(subscribe: Subscribe) | |
@Receive | |
fun observeResponse(): Flowable<Response> |
This file contains 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
private val client = OkHttpClient.Builder() | |
.addInterceptor(HttpLoggingInterceptor() | |
.setLevel(HttpLoggingInterceptor.Level.BASIC)) | |
.build() | |
private fun scarletLifecycle() = AndroidLifecycle.ofApplicationForeground(getApplication()) | |
private val service = Scarlet.Builder() | |
.webSocketFactory(client.newWebSocketFactory(BASE_URL)) | |
.addStreamAdapterFactory(RxJava2StreamAdapterFactory()) |
This file contains 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
service.observeWebSocketEvent() | |
.filter{ it is WebSocket.Event.OnConnectionOpened<*>} | |
.subscribe ({ service.sendSubscribe(Subscribe()) }, | |
{error -> error.printStackTrace()}) | |
service.observeResponse() | |
.subscribeOn(Schedulers.io()) | |
.subscribe({ | |
response.postValue(it) |
This file contains 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
fun jagaKonter() = viewModelScope.launch { | |
val listrik = async { beliListrik() } | |
val pulsa = async { beliPulsa() } | |
Log.d("example", "Semua Transaksi Selesai, Total Pendapatan : Rp. ${listrik.await()+pulsa.await()}") | |
} | |
suspend fun beliListrik(): Int{ | |
Log.d("example", "Melayani Pelanggan Pertama") | |
delay(7000L) |
This file contains 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
dependencies { | |
implementation fileTree(dir: 'libs', include: ['*.jar']) | |
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |
implementation 'androidx.appcompat:appcompat:1.1.0' | |
implementation 'androidx.core:core-ktx:1.2.0' | |
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | |
//-------------dependencies yang di butuhkan------------------ | |
//untuk viewmodel |
This file contains 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
........ | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
viewModel = ViewModelProvider(this)[MainViewModel::class.java] | |
tapMeButton = findViewById(R.id.tapMeButton) | |
gameScoreTextView = findViewById(R.id.gameScoreTextView) | |
timeLeftTextView = findViewById(R.id.timeLeftTextView) |
This file contains 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
................. | |
val timeLeft: LiveData<Int> get() = _timeLeft | |
private val _timeLeft = MutableLiveData(60) | |
private val countDownTimer = flow { | |
for (timeLeftOnTimer in 60 downTo 0){ | |
emit(timeLeftOnTimer) | |
delay(1000) | |
} | |
} |
This file contains 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
class NetworkInfo { | |
@Suppress("DEPRECATION") | |
@ExperimentalCoroutinesApi | |
fun checkConnection(context: Context) = callbackFlow{ | |
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
val networkRequest = NetworkRequest.Builder() | |
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR) |
OlderNewer