Replaced EditText onTextChangedListener with RxJava implementation
This commit is contained in:
parent
fcba8979f6
commit
68b994feb4
3 changed files with 25 additions and 14 deletions
|
@ -1,4 +1,5 @@
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
apply plugin: 'me.tatarka.retrolambda'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
packagingOptions {
|
packagingOptions {
|
||||||
|
@ -10,6 +11,10 @@ android {
|
||||||
}
|
}
|
||||||
compileSdkVersion 26
|
compileSdkVersion 26
|
||||||
buildToolsVersion "26.0.0"
|
buildToolsVersion "26.0.0"
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.wbrawner.simplemarkdown"
|
applicationId "com.wbrawner.simplemarkdown"
|
||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
|
@ -40,6 +45,10 @@ dependencies {
|
||||||
compile 'com.jakewharton:butterknife:8.7.0'
|
compile 'com.jakewharton:butterknife:8.7.0'
|
||||||
compile 'com.android.support:support-v4:26.+'
|
compile 'com.android.support:support-v4:26.+'
|
||||||
compile 'com.commonsware.cwac:anddown:0.3.0'
|
compile 'com.commonsware.cwac:anddown:0.3.0'
|
||||||
|
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
|
||||||
|
compile 'io.reactivex.rxjava2:rxjava:2.1.0'
|
||||||
|
compile 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
|
||||||
|
compile 'com.jakewharton.rxbinding2:rxbinding-design:2.0.0'
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'
|
annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,13 +23,20 @@ import android.view.WindowManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.jakewharton.rxbinding2.widget.RxTextView;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.Scheduler;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
import static android.content.ContentValues.TAG;
|
import static android.content.ContentValues.TAG;
|
||||||
|
|
||||||
|
@ -77,20 +84,15 @@ public class EditFragment extends Fragment {
|
||||||
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
mMarkdownEditor.addTextChangedListener(new TextWatcher() {
|
Observable<String> obs = RxTextView.textChanges(mMarkdownEditor)
|
||||||
@Override
|
.debounce(50, TimeUnit.MILLISECONDS).map(editable -> editable.toString());
|
||||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
obs.subscribeOn(Schedulers.io());
|
||||||
}
|
obs.observeOn(AndroidSchedulers.mainThread());
|
||||||
|
obs.subscribe(string -> {
|
||||||
@Override
|
Log.d(TAG, "debounced " + string);
|
||||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
updatePreview(mContext);
|
||||||
updatePreview(mContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable editable) {
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ buildscript {
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:2.3.3'
|
classpath 'com.android.tools.build:gradle:2.3.3'
|
||||||
|
classpath 'me.tatarka:gradle-retrolambda:3.2.3'
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue