RxJava2-监听EditText变化并查询数据库并更新UI

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Disposable subscription = RxTextView.textChangeEvents(etSearch)
.debounce(200, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.toFlowable(BackpressureStrategy.BUFFER)
.switchMap(new Function<TextViewTextChangeEvent, Publisher<RealmResults<Note>>>() {
@Override
public Publisher<RealmResults<Note>> apply(TextViewTextChangeEvent event) throws Exception {
String etContent = event.getText().toString();
if (etContent.length() > 0) {
mLv.setVisibility(View.VISIBLE);
} else {
mLv.setVisibility(View.GONE);
}
if (etContent.length() > 0) {
mLv.setVisibility(View.VISIBLE);
} else {
mLv.setVisibility(View.GONE);
}
finalMAdapter.setSearchStr(etContent);
if (dirId == MyApplication.DEFAULT_DIR_ID) {
return Realm.getDefaultInstance().where(Note.class)
.contains("title", etContent)
.sort("timeMills", Sort.DESCENDING).findAllAsync().asFlowable();
} else {
return Realm.getDefaultInstance().where(Note.class)
.equalTo("dirId", dirId)
.contains("title", etContent)
.sort("timeMills", Sort.DESCENDING).findAllAsync().asFlowable();
}
}
})
.filter(new Predicate<RealmResults<Note>>() {
@Override
public boolean test(RealmResults<Note> notes) throws Exception {
return notes.isLoaded();
}
})
.subscribe(new Consumer<RealmResults<Note>>() {
@Override
public void accept(RealmResults<Note> notes) throws Exception {
mNotes = notes;
if (notes != null && notes.size() > 0) {
llNoResult.setVisibility(View.GONE);
} else {
llNoResult.setVisibility(View.VISIBLE);
}
finalMAdapter.updateAll(mNotes);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
throwable.printStackTrace();
}
});

Linux-编辑器vi的使用

进入vi编辑器

1
vi filename

插入

i

保存

按ESC键 跳到命令模式,然后:
:w 保存文件但不退出vi
:w file 将修改另外保存到file中,不退出vi
:w! 强制保存,不推出vi
:wq 保存文件并退出vi
:wq! 强制保存文件,并退出vi
q: 不保存文件,退出vi
:q! 不保存文件,强制退出vi
:e! 放弃所有修改,从上次保存文件开始再编辑

Android-8.0新特性-通知通道配置

Android 8.0开始发送通知需要配置渠道id;

Application#onCreate()中配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//8.0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// 通知渠道的id
String id = "你的渠道id";
// 用户可以看到的通知渠道的名字.
CharSequence name = getString(R.string.app_name);
// 用户可以看到的通知渠道的描述
String description = getString(R.string.app_push_message_hint);
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
mChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
// 配置通知渠道的属性
mChannel.setDescription(description);
// 设置通知出现时的闪灯(如果 android 设备支持的话)
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.setSound(Uri.parse("android.resource://" + BaseUtil.getPackageInfo(BaseUtil.getApp()).packageName + "/" + R.raw.hint_zz_four), null);
// 设置通知出现时的震动(如果 android 设备支持的话)
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
//最后在notificationmanager中创建该通知渠道
if (mNotificationManager != null) {
mNotificationManager.createNotificationChannel(mChannel);
}
}