Skip to content

Commit 9896ce7

Browse files
committed
接口已经全部重构完成,但是有些页面有问题。
1 parent c28bae2 commit 9896ce7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+748
-464
lines changed

.idea/gradle.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/androidTest/java/com/rae/cnblogs/ExampleInstrumentedTest.java

+53-61
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@
33
import android.content.Context;
44
import android.support.test.InstrumentationRegistry;
55
import android.support.test.runner.AndroidJUnit4;
6-
import android.util.Log;
7-
8-
import com.rae.core.utils.RaeDateUtil;
96

107
import org.junit.Test;
118
import org.junit.runner.RunWith;
129

13-
import java.util.Calendar;
14-
import java.util.Date;
15-
import java.util.regex.Matcher;
16-
import java.util.regex.Pattern;
17-
1810
import static org.junit.Assert.assertEquals;
1911

2012
/**
@@ -32,58 +24,58 @@ public void useAppContext() throws Exception {
3224
assertEquals("com.rae.cnblogs", appContext.getPackageName());
3325
}
3426

35-
@Test
36-
public void testDate() {
37-
Log.d("rae", "测试今天:" + getDate("2016-12-06 00:00:00"));
38-
Log.d("rae", "测试昨天:" + getDate("2016-12-05 23:30"));
39-
Log.d("rae", "测试前天:" + getDate("2016-12-04 12:30"));
40-
Log.d("rae", "测试其他时间:" + getDate("2016-11-02 12:30"));
41-
}
42-
43-
44-
private String getDate(String text) {
45-
46-
String regx = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}";
47-
Matcher matcher = Pattern.compile(regx).matcher(text);
48-
if (!matcher.find()) {
49-
return text;
50-
}
51-
52-
text = matcher.group();
53-
String time = text.split(" ")[1];
54-
55-
// 时间间隔
56-
long span = (System.currentTimeMillis() - parseDate(text).getTime()) / 1000;
57-
58-
// 今天过去的时间
59-
Calendar calendar = Calendar.getInstance();
60-
calendar.set(Calendar.HOUR, 0);
61-
calendar.set(Calendar.MINUTE, 0);
62-
calendar.set(Calendar.SECOND, 0);
63-
calendar.set(Calendar.MILLISECOND, 0);
64-
65-
long today = (System.currentTimeMillis() - calendar.getTimeInMillis()) / 1000;
66-
if (span < today) {
67-
text = "今天 " + time;
68-
} else if (span < today + 86400) {
69-
text = "昨天 " + time;
70-
} else if (span < today + 2 * 86400) {
71-
text = "前天 " + time;
72-
}
73-
74-
75-
return text;
76-
}
77-
78-
private Date parseDate(String text) {
79-
Date target;
80-
try {
81-
target = RaeDateUtil.parse(text, "yyyy-MM-dd HH:mm");
82-
} catch (Exception e) {
83-
Log.e("rae", "解析出错!", e);
84-
target = new Date();
85-
}
86-
return target;
87-
}
27+
// @Test
28+
// public void testDate() {
29+
// Log.d("rae", "测试今天:" + getDate("2016-12-06 00:00:00"));
30+
// Log.d("rae", "测试昨天:" + getDate("2016-12-05 23:30"));
31+
// Log.d("rae", "测试前天:" + getDate("2016-12-04 12:30"));
32+
// Log.d("rae", "测试其他时间:" + getDate("2016-11-02 12:30"));
33+
// }
34+
35+
36+
// private String getDate(String text) {
37+
//
38+
// String regx = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}";
39+
// Matcher matcher = Pattern.compile(regx).matcher(text);
40+
// if (!matcher.find()) {
41+
// return text;
42+
// }
43+
//
44+
// text = matcher.group();
45+
// String time = text.split(" ")[1];
46+
//
47+
// // 时间间隔
48+
// long span = (System.currentTimeMillis() - parseDate(text).getTime()) / 1000;
49+
//
50+
// // 今天过去的时间
51+
// Calendar calendar = Calendar.getInstance();
52+
// calendar.set(Calendar.HOUR, 0);
53+
// calendar.set(Calendar.MINUTE, 0);
54+
// calendar.set(Calendar.SECOND, 0);
55+
// calendar.set(Calendar.MILLISECOND, 0);
56+
//
57+
// long today = (System.currentTimeMillis() - calendar.getTimeInMillis()) / 1000;
58+
// if (span < today) {
59+
// text = "今天 " + time;
60+
// } else if (span < today + 86400) {
61+
// text = "昨天 " + time;
62+
// } else if (span < today + 2 * 86400) {
63+
// text = "前天 " + time;
64+
// }
65+
//
66+
//
67+
// return text;
68+
// }
69+
70+
// private Date parseDate(String text) {
71+
// Date target;
72+
// try {
73+
// target = RaeDateUtil.parse(text, "yyyy-MM-dd HH:mm");
74+
// } catch (Exception e) {
75+
// Log.e("rae", "解析出错!", e);
76+
// target = new Date();
77+
// }
78+
// return target;
79+
// }
8880

8981
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.rae.cnblogs;
2+
3+
import android.support.annotation.Nullable;
4+
import android.text.TextUtils;
5+
6+
import java.util.ArrayList;
7+
import java.util.HashMap;
8+
import java.util.List;
9+
import java.util.Map;
10+
11+
import io.reactivex.Observable;
12+
import io.reactivex.android.schedulers.AndroidSchedulers;
13+
import io.reactivex.annotations.NonNull;
14+
import io.reactivex.disposables.Disposable;
15+
import io.reactivex.functions.Consumer;
16+
import io.reactivex.schedulers.Schedulers;
17+
18+
/**
19+
* RX API Observable
20+
* Created by ChenRui on 2017/5/5 0005 16:52.
21+
*/
22+
public final class RxObservable {
23+
24+
private final static Map<String, List<Disposable>> sObservableDisposableList = new HashMap<>();
25+
26+
27+
public static <T> Observable<T> create(Observable<T> observable) {
28+
final String className = getInvokeMethodName();
29+
// Log.i("rae", "当前调用:" + className);
30+
31+
List<Disposable> disposables = sObservableDisposableList.get(className);
32+
if (disposables == null) {
33+
disposables = new ArrayList<>();
34+
sObservableDisposableList.put(className, disposables);
35+
}
36+
return observable.doOnSubscribe(new Consumer<Disposable>() {
37+
@Override
38+
public void accept(@NonNull Disposable disposable) throws Exception {
39+
sObservableDisposableList.get(className).add(disposable);
40+
}
41+
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
42+
}
43+
44+
@Nullable
45+
private static String getInvokeMethodName() {
46+
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
47+
boolean hasFind = false;
48+
for (StackTraceElement element : stackTrace) {
49+
String className = element.getClassName();
50+
// Log.d("rae", element.toString());
51+
if (className.contains("RxObservable")) {
52+
hasFind = true;
53+
continue;
54+
}
55+
if (hasFind) {
56+
return className;
57+
}
58+
}
59+
return "default";
60+
}
61+
62+
/**
63+
* 释放当前所有HTTP请求
64+
*/
65+
public static void dispose() {
66+
for (List<Disposable> disposables : sObservableDisposableList.values()) {
67+
for (Disposable disposable : disposables) {
68+
if (disposable != null && !disposable.isDisposed())
69+
disposable.dispose();
70+
}
71+
}
72+
sObservableDisposableList.clear();
73+
}
74+
75+
/**
76+
* 释放指定TAG的请求
77+
*
78+
* @param tag 标签
79+
*/
80+
public static void dispose(String tag) {
81+
// Log.w("rae", "取消请求:" + tag);
82+
if (TextUtils.isEmpty(tag) || !sObservableDisposableList.containsKey(tag)) {
83+
return;
84+
}
85+
List<Disposable> disposables = sObservableDisposableList.get(tag);
86+
for (Disposable disposable : disposables) {
87+
if (disposable != null && !disposable.isDisposed())
88+
disposable.dispose();
89+
}
90+
disposables.clear();
91+
sObservableDisposableList.remove(tag);
92+
}
93+
94+
95+
}

app/src/main/java/com/rae/cnblogs/activity/BloggerActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.rae.cnblogs.sdk.bean.CategoryBean;
2424
import com.rae.cnblogs.sdk.bean.FriendsInfoBean;
2525
import com.rae.cnblogs.widget.BloggerLayout;
26-
import com.rae.core.fm.RaeFragmentAdapter;
26+
import com.rae.swift.app.RaeFragmentAdapter;
2727

2828
import butterknife.BindView;
2929
import butterknife.ButterKnife;

app/src/main/java/com/rae/cnblogs/activity/FriendsActivity.java

+26-21
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,28 @@
1010
import com.rae.cnblogs.AppRoute;
1111
import com.rae.cnblogs.AppUI;
1212
import com.rae.cnblogs.R;
13+
import com.rae.cnblogs.RxObservable;
1314
import com.rae.cnblogs.adapter.BaseItemAdapter;
1415
import com.rae.cnblogs.adapter.FriendsAdapter;
16+
import com.rae.cnblogs.sdk.ApiDefaultObserver;
1517
import com.rae.cnblogs.sdk.CnblogsApiFactory;
1618
import com.rae.cnblogs.sdk.api.IFriendsApi;
1719
import com.rae.cnblogs.sdk.bean.UserInfoBean;
1820
import com.rae.cnblogs.widget.PlaceholderView;
1921
import com.rae.cnblogs.widget.RaeRecyclerView;
20-
import com.rae.core.Rae;
21-
import com.rae.core.sdk.ApiUiArrayListener;
22-
import com.rae.core.sdk.exception.ApiException;
22+
import com.rae.swift.Rx;
2323

2424
import java.util.ArrayList;
2525
import java.util.List;
2626

2727
import butterknife.BindView;
28+
import io.reactivex.Observable;
2829

2930
/**
3031
* 粉丝和关注
3132
* Created by ChenRui on 2017/2/23 00:41.
3233
*/
33-
public class FriendsActivity extends SwipeBackBaseActivity implements ApiUiArrayListener<UserInfoBean> {
34+
public class FriendsActivity extends SwipeBackBaseActivity {
3435

3536
@BindView(R.id.title_tool_bar)
3637
Toolbar mToolbar;
@@ -108,25 +109,31 @@ public void setTitle(CharSequence title) {
108109

109110
// 获取数据
110111
private void start() {
111-
// 粉丝
112-
if (isFansType()) {
113-
mFriendApi.getFansList(mUserId, mPage, this);
114-
} else {
115-
mFriendApi.getFollowList(mUserId, mPage, this);
116-
}
112+
Observable<List<UserInfoBean>> observable = mFriendApi.getFollowAndFansList(mUserId, mPage, !isFansType());
113+
RxObservable.create(observable).subscribe(new ApiDefaultObserver<List<UserInfoBean>>() {
114+
@Override
115+
protected void onError(String message) {
116+
if (mPage > 1) {
117+
mRecyclerView.setNoMore(true);
118+
} else {
119+
mPlaceholderView.empty(message);
120+
}
121+
}
122+
123+
@Override
124+
protected void accept(List<UserInfoBean> data) {
125+
onLoadFriends(data);
126+
}
127+
});
117128
}
118129

119130
@Override
120-
public void onApiFailed(ApiException ex, String msg) {
121-
if (mPage > 1) {
122-
mRecyclerView.setNoMore(true);
123-
} else {
124-
mPlaceholderView.empty(msg);
125-
}
131+
protected void onDestroy() {
132+
super.onDestroy();
133+
RxObservable.dispose();
126134
}
127135

128-
@Override
129-
public void onApiSuccess(List<UserInfoBean> data) {
136+
public void onLoadFriends(List<UserInfoBean> data) {
130137
mPlaceholderView.dismiss();
131138

132139
if (mPage <= 1) {
@@ -140,7 +147,7 @@ public void onApiSuccess(List<UserInfoBean> data) {
140147
if (mDataList.size() <= 0 && mPage <= 1) {
141148
mPlaceholderView.empty(getString(R.string.empty_message));
142149
return;
143-
} else if (Rae.isEmpty(mDataList) && mPage > 1) {
150+
} else if (Rx.isEmpty(mDataList) && mPage > 1) {
144151
mRecyclerView.setNoMore(true);
145152
return;
146153
}
@@ -153,8 +160,6 @@ public void onApiSuccess(List<UserInfoBean> data) {
153160

154161
/**
155162
* 是否为粉丝类型
156-
*
157-
* @return
158163
*/
159164
public boolean isFansType() {
160165
return mFromType == AppRoute.ACTIVITY_FRIENDS_TYPE_FANS;

app/src/main/java/com/rae/cnblogs/activity/ImagePreviewActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import com.rae.cnblogs.R;
99
import com.rae.cnblogs.fragment.ImagePreviewFragment;
10-
import com.rae.core.fm.RaeFragmentAdapter;
10+
import com.rae.swift.app.RaeFragmentAdapter;
1111

1212
import java.util.ArrayList;
1313
import java.util.List;

app/src/main/java/com/rae/cnblogs/activity/LoginActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
204204
if (requestCode == AppRoute.REQ_CODE_WEB_LOGIN && resultCode == RESULT_OK) {
205205
// 登录成功,获取用户信息
206206
mErrorTime = 0;
207-
showLoading(getString(R.string.loading_user_info));
208-
mLoginPresenter.loadUserInfo();
207+
// showLoading(getString(R.string.loading_user_info));
208+
// mLoginPresenter.loadUserInfo();
209209
}
210210
}
211211

app/src/main/java/com/rae/cnblogs/activity/MainActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import com.rae.cnblogs.fragment.MineFragment;
1717
import com.rae.cnblogs.sdk.bean.BlogType;
1818
import com.rae.cnblogs.sdk.bean.CategoryBean;
19-
import com.rae.core.fm.RaeFragmentAdapter;
19+
import com.rae.swift.app.RaeFragmentAdapter;
2020

2121
import butterknife.BindView;
2222

app/src/main/java/com/rae/cnblogs/adapter/BaseItemAdapter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import android.view.View;
77
import android.view.ViewGroup;
88

9-
import com.rae.core.Rae;
9+
import com.rae.swift.Rx;
1010

1111
import java.util.List;
1212

@@ -68,7 +68,7 @@ T getDataItem(int position) {
6868

6969
@Override
7070
public int getItemCount() {
71-
return Rae.getCount(mDataList);
71+
return Rx.getCount(mDataList);
7272
}
7373

7474

0 commit comments

Comments
 (0)