Created
April 15, 2020 04:37
-
-
Save gideonseven/58a1ed694a9ebabb3f4a3379c32b576e to your computer and use it in GitHub Desktop.
Throtle first
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
package com.don.myapplication; | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.widget.Button; | |
import com.jakewharton.rxbinding3.view.RxView; | |
import java.util.concurrent.TimeUnit; | |
import io.reactivex.android.schedulers.AndroidSchedulers; | |
import io.reactivex.disposables.CompositeDisposable; | |
import io.reactivex.schedulers.Schedulers; | |
public class TestingActivity extends AppCompatActivity { | |
Button btnSubmit, btnTest; | |
int count = 0; | |
public CompositeDisposable compositeDisposable; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_testing); | |
btnSubmit = findViewById(R.id.btn1); | |
btnTest = findViewById(R.id.btn2); | |
compositeDisposable = new CompositeDisposable(); | |
} | |
@Override | |
protected void onStart() { | |
super.onStart(); | |
compositeDisposable.add(RxView.clicks(btnSubmit) | |
.observeOn(Schedulers.io()) | |
.throttleFirst(1000, TimeUnit.MILLISECONDS) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(v -> Log.e("TAG", "Berapa kali di click " + count++))); | |
} | |
@Override | |
protected void onStop() { | |
compositeDisposable.clear(); | |
super.onStop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment