Skip to content

Commit 5166814

Browse files
committed
add some operators
1 parent 9513349 commit 5166814

File tree

4 files changed

+138
-72
lines changed

4 files changed

+138
-72
lines changed

app/src/main/java/com/jiang/android/rxjavaapp/InitDataService.java

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.widget.Toast;
3434

3535
import com.jiang.android.rxjavaapp.actiity.MainActivity;
36+
import com.jiang.android.rxjavaapp.base.BaseAppManager;
3637
import com.jiang.android.rxjavaapp.common.CommonString;
3738
import com.jiang.android.rxjavaapp.common.OperatorsUrl;
3839
import com.jiang.android.rxjavaapp.common.SPKey;
@@ -81,6 +82,7 @@ public void call(Subscriber<? super Boolean> subscriber) {
8182
@Override
8283
public void onCompleted() {
8384
Toast.makeText(InitDataService.this, "数据库初始化成功", Toast.LENGTH_SHORT).show();
85+
BaseAppManager.getInstance().clear();
8486
SharePrefUtil.saveBoolean(InitDataService.this, SPKey.FIRST_ENTER, false);
8587
Intent dialogIntent = new Intent(getBaseContext(), MainActivity.class);
8688
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -120,26 +122,12 @@ public List<operators> getOperatorsData() {
120122
return lists;
121123
}
122124

123-
/**
124-
* Creating 创建操作 - Create/Defer/From/Just/Start/Repeat/Range
125-
* Transforming 变换操作 - Buffer/Window/Map/FlatMap/GroupBy/Scan
126-
* Filtering 过滤操作 - Debounce/Distinct/Filter/Sample/Skip/Take
127-
* Combining 结合操作 - And/StartWith/Join/Merge/Switch/Zip
128-
* Error Handling 错误处理 - Catch/Retry
129-
* Utility 辅助操作 - Delay/Do/ObserveOn/SubscribeOn/Subscribe
130-
* Conditional 条件和布尔操作 - All/Amb/Contains/SkipUntil/TakeUntil
131-
* Mathematical 算术和聚合操作 - Average/Concat/Count/Max/Min/Sum/Reduce
132-
* Async 异步操作 - Start/ToAsync/StartFuture/FromAction/FromCallable/RunAsync
133-
* Connect 连接操作 - Connect/Publish/RefCount/Replay
134-
* Convert 转换操作 - ToFuture/ToList/ToIterable/ToMap/toMultiMap
135-
* Blocking 阻塞操作 - ForEach/First/Last/MostRecent/Next/Single/Latest
136-
* String 字符串操作 - ByLine/Decode/Encode/From/Join/Split/StringConcat
137-
*/
138-
139125
public List<alloperators> getAllOperators() {
140126

141127
List<alloperators> alloperatorses = new ArrayList<>();
142128
getIntroduceList(alloperatorses);
129+
getCreatingList(alloperatorses);
130+
getTransformList(alloperatorses);
143131
return alloperatorses;
144132
}
145133

@@ -152,14 +140,33 @@ private void getIntroduceList(List<alloperators> alloperatorses) {
152140

153141
}
154142

143+
private void getCreatingList(List<alloperators> alloperatorses) {
144+
alloperatorses.add(new alloperators(6l, "just()", "将一个或多个对象转换成发射这个或这些对象的一个Observable", CommonString.JUST, OperatorsUrl.JUST, 2l));
145+
alloperatorses.add(new alloperators(7l, "from()", "将一个Iterable, 一个Future, 或者一个数组转换成一个Observable", CommonString.FROM, OperatorsUrl.FROM, 2l));
146+
alloperatorses.add(new alloperators(8l, "repeat()", "创建一个重复发射指定数据或数据序列的Observable", CommonString.REPEAT, OperatorsUrl.REPEAT, 2l));
147+
alloperatorses.add(new alloperators(9l, "repeatWhen()", "创建一个重复发射指定数据或数据序列的Observable,它依赖于另一个Observable发射的数据", CommonString.REPEAT_WHEN, OperatorsUrl.REPEAT, 2l));
148+
alloperatorses.add(new alloperators(10l, "create()", "使用一个函数从头创建一个Observable", CommonString.CREATE, OperatorsUrl.CREATE, 2l));
149+
alloperatorses.add(new alloperators(11l, "defer()", "只有当订阅者订阅才创建Observable;为每个订阅创建一个新的Observable", CommonString.DEFER, OperatorsUrl.DEFER, 2l));
150+
alloperatorses.add(new alloperators(12l, "range()", "创建一个发射指定范围的整数序列的Observable", CommonString.RANGE, OperatorsUrl.DEFER, 2l));
151+
alloperatorses.add(new alloperators(13l, "interval()", "创建一个按照给定的时间间隔发射整数序列的Observable", CommonString.INTERVAL, OperatorsUrl.INTERVAL, 2l));
152+
alloperatorses.add(new alloperators(14l, "timer()", "创建一个按照给定的时间间隔发射整数序列的Observable", CommonString.TIMER, OperatorsUrl.TIMER, 2l));
153+
alloperatorses.add(new alloperators(15l, "empty()", "创建一个什么都不做直接通知完成的Observable", CommonString.EMPTY, OperatorsUrl.EMPTY, 2l));
154+
alloperatorses.add(new alloperators(16l, "error()", "创建一个什么都不做直接通知错误的Observable", CommonString.EMPTY, OperatorsUrl.EMPTY, 2l));
155+
alloperatorses.add(new alloperators(17l, "never()", "创建一个不发射任何数据的Observable", CommonString.EMPTY, OperatorsUrl.EMPTY, 2l));
156+
157+
}
155158

156-
/**
157-
*
158-
*
159-
* ReactiveX - 什么是Rx,Rx的理念和优势
160-
Observables - 简要介绍Observable的观察者模型
161-
Single - 一种特殊的只发射单个值的Observable
162-
Subject - Observable和Observer的复合体,也是二者的桥梁
163-
*/
159+
private void getTransformList(List<alloperators> alloperatorses) {
160+
alloperatorses.add(new alloperators(18l, "map()", "对序列的每一项都应用一个函数来变换Observable发射的数据序列", CommonString.MAP, OperatorsUrl.MAP, 3l));
161+
alloperatorses.add(new alloperators(19l, "flatMap()", "将Observable发射的数据集合变换为Observables集合,然后将这些Observable发射的数据平坦化的放进一个单独的Observable", CommonString.FLATMAP, OperatorsUrl.FLATMAP, 3l));
162+
alloperatorses.add(new alloperators(20l, "concatMap()", "将Observable发射的数据集合变换为Observables集合,然后将这些Observable发射的数据平坦化的放进一个单独的Observable", CommonString.CONTACTMAP, OperatorsUrl.CONTACTMAP, 3l));
163+
alloperatorses.add(new alloperators(21l, "switchMap()", "将Observable发射的数据集合变换为Observables集合,然后只发射这些Observables最近发射的数据", CommonString.SWITCHMAP, OperatorsUrl.SWITCHMAP, 3l));
164+
alloperatorses.add(new alloperators(22l, "scan()", "对Observable发射的每一项数据应用一个函数,然后按顺序依次发射每一个值", CommonString.SCAN, OperatorsUrl.SCAN, 3l));
165+
alloperatorses.add(new alloperators(23l, "groupBy()", "将Observable分拆为Observable集合,将原始Observable发射的数据按Key分组,每一个Observable发射一组不同的数据", CommonString.GROUPBY, OperatorsUrl.GROUPBY, 3l));
166+
alloperatorses.add(new alloperators(24l, "buffer()", "它定期从Observable收集数据到一个集合,然后把这些数据集合打包发射,而不是一次发射一个", CommonString.BUFFER, OperatorsUrl.BUFFER, 3l));
167+
alloperatorses.add(new alloperators(25l, "window()", "定期将来自Observable的数据分拆成一些Observable窗口,然后发射这些窗口,而不是每次发射一项", CommonString.WINDOW, OperatorsUrl.WINDOW, 3l));
168+
alloperatorses.add(new alloperators(26l, "cast()", "在发射之前强制将Observable发射的所有数据转换为指定类型", CommonString.CAST, OperatorsUrl.CAST, 3l));
169+
170+
}
164171

165172
}

app/src/main/java/com/jiang/android/rxjavaapp/actiity/MainActivity.java

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
4848
private List<alloperators> mContentLists = new ArrayList<>();
4949
private RecyclerView mContentRecyclerView;
5050
private ArrayList<String> photos;
51+
private DrawerLayout drawer;
52+
private NavigationView navigationView;
53+
private ActionBarDrawerToggle toggle;
5154

5255
@Override
5356
protected void initViewsAndEvents() {
@@ -58,16 +61,13 @@ protected void initViewsAndEvents() {
5861

5962
}
6063

61-
private void initContentRecyclerView() {
62-
LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
63-
mContentRecyclerView.setLayoutManager(manager);
64-
mContentRecyclerView.setHasFixedSize(true);
64+
private void getAllOperatorById(final long parent_id) {
6565
Observable.create(new Observable.OnSubscribe<List<alloperators>>() {
6666
@Override
6767
public void call(Subscriber<? super List<alloperators>> subscriber) {
6868
try {
6969
subscriber.onNext(DbUtil.getAllOperatorsService()
70-
.query("where operators_id=?", new String[]{String.valueOf(mList.get(0).getOuter_id())}));
70+
.query("where operators_id=?", new String[]{String.valueOf(parent_id)}));
7171
subscriber.onCompleted();
7272
} catch (Exception e) {
7373
subscriber.onError(e);
@@ -87,48 +87,60 @@ public void call(List<alloperators> operatorses) {
8787

8888
}
8989

90+
private void initContentRecyclerView() {
91+
LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
92+
mContentRecyclerView.setLayoutManager(manager);
93+
mContentRecyclerView.setHasFixedSize(true);
94+
getAllOperatorById(mList.get(0).getOuter_id());
95+
96+
}
97+
9098
private void initContentAdapter() {
91-
mContentAdapter = new BaseAdapter() {
92-
@Override
93-
protected void onBindView(BaseViewHolder holder, final int position) {
94-
95-
ImageView iv = holder.getView(R.id.item_content_iv);
96-
TextView title = holder.getView(R.id.item_content_title);
97-
TextView desc = holder.getView(R.id.item_content_desc);
98-
title.setText(mContentLists.get(position).getName());
99-
desc.setText(mContentLists.get(position).getDesc());
100-
ImageLoader.getInstance().displayImage(mContentLists.get(position).getImg(), iv);
101-
iv.setClickable(true);
102-
iv.setOnClickListener(new View.OnClickListener() {
103-
@Override
104-
public void onClick(View v) {
105-
showImgFullScreen(position);
106-
}
107-
});
108-
}
99+
if (mContentAdapter == null) {
100+
mContentAdapter = new BaseAdapter() {
101+
@Override
102+
protected void onBindView(BaseViewHolder holder, final int position) {
103+
104+
ImageView iv = holder.getView(R.id.item_content_iv);
105+
TextView title = holder.getView(R.id.item_content_title);
106+
TextView desc = holder.getView(R.id.item_content_desc);
107+
title.setText(mContentLists.get(position).getName());
108+
desc.setText(mContentLists.get(position).getDesc());
109+
ImageLoader.getInstance().displayImage(mContentLists.get(position).getImg(), iv);
110+
iv.setClickable(true);
111+
iv.setOnClickListener(new View.OnClickListener() {
112+
@Override
113+
public void onClick(View v) {
114+
showImgFullScreen(position);
115+
}
116+
});
117+
}
109118

110-
@Override
111-
protected int getLayoutID(int position) {
112-
return R.layout.item_index_content;
113-
}
119+
@Override
120+
protected int getLayoutID(int position) {
121+
return R.layout.item_index_content;
122+
}
114123

115-
@Override
116-
public int getItemCount() {
117-
return mContentLists.size();
118-
}
119-
};
120-
mContentAdapter.setOnItemClickListener(new OnItemClickListener() {
121-
@Override
122-
public void onItemClick(int position) {
123-
Bundle bundle = new Bundle();
124-
bundle.putString(BaseWebActivity.BUNDLE_KEY_TITLE, mContentLists.get(position).getName());
125-
bundle.putString(BaseWebActivity.BUNDLE_KEY_URL, mContentLists.get(position).getUrl());
126-
bundle.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, true);
127-
readyGo(BaseWebActivity.class, bundle);
124+
@Override
125+
public int getItemCount() {
126+
return mContentLists.size();
127+
}
128+
};
129+
mContentAdapter.setOnItemClickListener(new OnItemClickListener() {
130+
@Override
131+
public void onItemClick(int position) {
132+
Bundle bundle = new Bundle();
133+
bundle.putString(BaseWebActivity.BUNDLE_KEY_TITLE, mContentLists.get(position).getName());
134+
bundle.putString(BaseWebActivity.BUNDLE_KEY_URL, mContentLists.get(position).getUrl());
135+
bundle.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, true);
136+
readyGo(BaseWebActivity.class, bundle);
128137

129-
}
130-
});
131-
mContentRecyclerView.setAdapter(mContentAdapter);
138+
}
139+
});
140+
mContentRecyclerView.setAdapter(mContentAdapter);
141+
} else {
142+
mContentAdapter.notifyDataSetChanged();
143+
}
132144
}
133145

134146
private void initNavRecycerView() {
@@ -185,7 +197,11 @@ protected int getLayoutID(int position) {
185197
mAdapter.setOnItemClickListener(new OnItemClickListener() {
186198
@Override
187199
public void onItemClick(int position) {
188-
showToast(mNavRecyclerView, mList.get(position).getName());
200+
201+
getAllOperatorById(mList.get(position).getOuter_id());
202+
if (drawer.isDrawerOpen(GravityCompat.START)) {
203+
drawer.closeDrawer(GravityCompat.START);
204+
}
189205
}
190206
});
191207
mNavRecyclerView.setAdapter(mAdapter);
@@ -198,13 +214,13 @@ protected int getContentViewLayoutID() {
198214
}
199215

200216
private void initNavigationView() {
201-
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
202-
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
217+
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
218+
toggle = new ActionBarDrawerToggle(
203219
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
204220
drawer.setDrawerListener(toggle);
205221
toggle.syncState();
206222

207-
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
223+
navigationView = (NavigationView) findViewById(R.id.nav_view);
208224

209225
mHeadView = (LinearLayout) navigationView.getHeaderView(0);
210226
mNavRecyclerView = (RecyclerView) navigationView.getHeaderView(0).findViewById(R.id.index_nav_recycler);
@@ -220,7 +236,6 @@ private void initToolBar() {
220236

221237
@Override
222238
public void onBackPressed() {
223-
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
224239
if (drawer.isDrawerOpen(GravityCompat.START)) {
225240
drawer.closeDrawer(GravityCompat.START);
226241
} else {

app/src/main/java/com/jiang/android/rxjavaapp/common/CommonString.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,28 @@ public class CommonString {
4040

4141
public static final String OBSERVABLES = "https://github.com/mcxiaoke/RxDocs/raw/master/images/legend.png";
4242
public static final String SUBJECT = "https://github.com/mcxiaoke/RxDocs/raw/master/images/S.AsyncSubject.png";
43+
public static final String JUST = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/just.png";
44+
public static final String FROM = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/from.png";
45+
public static final String REPEAT = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/repeat.c.png";
46+
public static final String REPEAT_WHEN = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/repeatWhen.f.png";
47+
public static final String CREATE = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/create.c.png";
48+
public static final String DEFER = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/defer.c.png";
49+
50+
public static final String RANGE = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/range.png";
51+
public static final String INTERVAL = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/interval.c.png";
52+
public static final String TIMER = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/timer.p.png";
53+
public static final String EMPTY = SPLASH_INDEX_URL;
54+
55+
// transd form
56+
public static final String MAP = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/map.png";
57+
public static final String FLATMAP = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/flatMap.png";
58+
public static final String CONTACTMAP = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/concatMap.png";
59+
public static final String SWITCHMAP = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/switchMap.png";
60+
public static final String SCAN = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/scan.c.png";
61+
public static final String GROUPBY = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/groupBy.c.png";
62+
public static final String BUFFER = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/buffer.png";
63+
public static final String WINDOW = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/window.C.png";
64+
public static final String CAST = "https://github.com/mcxiaoke/RxDocs/raw/master/images/operators/cast.png";
65+
66+
4367
}

app/src/main/java/com/jiang/android/rxjavaapp/common/OperatorsUrl.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,24 @@ public class OperatorsUrl {
4040
public static final String SINGLE = "https://github.com/mcxiaoke/RxDocs/blob/master/Single.md";
4141
public static final String SUBJECT = "https://github.com/mcxiaoke/RxDocs/blob/master/Subject.md";
4242
public static final String SCHEDULE = "https://github.com/mcxiaoke/RxDocs/blob/master/Scheduler.md";
43+
public static final String JUST = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/Just.md";
44+
public static final String FROM = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/From.md";
45+
public static final String REPEAT = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/Repeat.md";
46+
public static final String CREATE = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/Create.md";
47+
public static final String DEFER = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/Defer.md";
48+
public static final String INTERVAL = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/Interval.md";
49+
public static final String TIMER = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/Timer.md";
50+
public static final String EMPTY = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/Empty.md";
51+
52+
// transform
53+
public static final String MAP = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/Map.md";
54+
public static final String FLATMAP = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/FlatMap.md";
55+
public static final String CONTACTMAP = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/FlatMap.md";
56+
public static final String SWITCHMAP = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/FlatMap.md";
57+
public static final String SCAN = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/Scan.md";
58+
public static final String GROUPBY = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/GroupBy.md";
59+
public static final String BUFFER = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/Buffer.md";
60+
public static final String WINDOW = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/Window.md";
61+
public static final String CAST = "https://github.com/mcxiaoke/RxDocs/blob/master/operators/Map.md";
62+
4363
}

0 commit comments

Comments
 (0)