Skip to content

Commit 2ddf7b8

Browse files
author
ChenRui
committed
登录添加重试操作;解决闪存评论处理问题;
1 parent 47d5696 commit 2ddf7b8

13 files changed

+296
-22
lines changed

app/src/main/java/com/rae/cnblogs/CnblogsLayoutInflater.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.util.AttributeSet;
66
import android.view.View;
77

8+
import com.rae.cnblogs.widget.SkinCardView;
89
import com.rae.cnblogs.widget.SkinRoundedImageView;
910

1011
import skin.support.app.SkinLayoutInflater;
@@ -20,6 +21,8 @@ public View createView(@NonNull Context context, String name, @NonNull Attribute
2021
switch (name) {
2122
case "com.makeramen.roundedimageview.RoundedImageView":
2223
return new SkinRoundedImageView(context, attrs);
24+
case "android.support.v7.widget.CardView":
25+
return new SkinCardView(context, attrs);
2326
}
2427
return null;
2528
}

app/src/main/java/com/rae/cnblogs/fragment/MomentDetailFragment.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
import com.rae.cnblogs.adapter.BaseItemAdapter;
1616
import com.rae.cnblogs.adapter.MomentAdapter;
1717
import com.rae.cnblogs.adapter.MomentDetailAdapter;
18+
import com.rae.cnblogs.dialog.IAppDialog;
19+
import com.rae.cnblogs.dialog.IAppDialogClickListener;
1820
import com.rae.cnblogs.dialog.impl.EditCommentDialog;
21+
import com.rae.cnblogs.dialog.impl.HintCardDialog;
1922
import com.rae.cnblogs.dialog.impl.MenuDeleteDialog;
2023
import com.rae.cnblogs.model.MomentHolder;
2124
import com.rae.cnblogs.presenter.CnblogsPresenterFactory;
@@ -335,6 +338,23 @@ public void onDeleteMomentSuccess() {
335338
getActivity().finish();
336339
}
337340

341+
@Override
342+
public void onLoadMoreNotLogin() {
343+
mRecyclerView.loadMoreComplete();
344+
HintCardDialog dialog = new HintCardDialog(getContext());
345+
dialog.showCloseButton();
346+
dialog.setMessage(getString(R.string.moment_unlogin_hint));
347+
dialog.setEnSureText(getString(R.string.go_login));
348+
dialog.setOnEnSureListener(new IAppDialogClickListener() {
349+
@Override
350+
public void onClick(IAppDialog dialog, int buttonType) {
351+
dialog.dismiss();
352+
AppRoute.jumpToLogin(getContext());
353+
}
354+
});
355+
dialog.show();
356+
}
357+
338358
@Override
339359
public void onDestroy() {
340360
super.onDestroy();

app/src/main/java/com/rae/cnblogs/fragment/WebLoginFragment.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
import android.webkit.WebView;
1313
import android.webkit.WebViewClient;
1414

15+
import com.rae.cnblogs.AppMobclickAgent;
1516
import com.rae.cnblogs.R;
1617
import com.rae.cnblogs.RxObservable;
18+
import com.rae.cnblogs.sdk.CnblogsApiException;
1719
import com.rae.cnblogs.sdk.CnblogsApiFactory;
1820
import com.rae.cnblogs.sdk.api.IUserApi;
19-
import com.rae.cnblogs.widget.PlaceholderView;
21+
import com.rae.cnblogs.widget.LoginPlaceholderView;
2022
import com.rae.cnblogs.widget.webclient.RaeWebViewClient;
23+
import com.tencent.bugly.crashreport.CrashReport;
2124

2225
/**
2326
* 网页登录
@@ -37,7 +40,7 @@ public static WebLoginFragment newInstance(String url) {
3740

3841
private IUserApi mUserApi;
3942

40-
private PlaceholderView mPlaceholderView;
43+
private LoginPlaceholderView mPlaceholderView;
4144

4245
@Override
4346
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -58,9 +61,33 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
5861
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
5962
super.onViewCreated(view, savedInstanceState);
6063
ViewGroup parent = (ViewGroup) mContentLayout.getParent();
61-
mPlaceholderView = new PlaceholderView(view.getContext());
64+
mPlaceholderView = new LoginPlaceholderView(view.getContext());
6265
mPlaceholderView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
6366
mPlaceholderView.dismiss();
67+
mPlaceholderView.setOnRetryClickListener(new View.OnClickListener() {
68+
@Override
69+
public void onClick(View v) {
70+
if (mPlaceholderView.isRouteLogin()) {
71+
mPlaceholderView.dismiss();
72+
// 重新登录
73+
mWebView.loadUrl(getRawUrl());
74+
75+
// 统计失败
76+
AppMobclickAgent.onClickEvent(v.getContext(), "WEB_RETRY_LOGIN");
77+
78+
CrashReport.postCatchedException(new CnblogsApiException("重试登录失败,当前路径:" + mWebView.getUrl()));
79+
80+
return;
81+
}
82+
83+
// 统计登录超时
84+
AppMobclickAgent.onClickEvent(v.getContext(), "WEB_LOGIN_TIMEOUT");
85+
86+
mPlaceholderView.loadingWithTimer(v.getContext().getString(R.string.login_retry));
87+
mPlaceholderView.dismissLoadingRetry();
88+
mWebView.reload();
89+
}
90+
});
6491
parent.addView(mPlaceholderView);
6592
}
6693

@@ -79,7 +106,7 @@ public WebViewClient getWebViewClient() {
79106
public void onPageStarted(WebView view, String url, Bitmap favicon) {
80107
super.onPageStarted(view, url, favicon);
81108
if (!TextUtils.isEmpty(url) && url.contains("home.cnblogs.com")) {
82-
mPlaceholderView.loading(getString(R.string.loading_web_user_info));
109+
mPlaceholderView.loadingWithTimer(getString(R.string.loading_web_user_info));
83110
}
84111
}
85112

app/src/main/java/com/rae/cnblogs/fragment/WebViewFragment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
175175
}
176176
}
177177

178+
public String getRawUrl() {
179+
return mRawUrl;
180+
}
181+
178182
@Override
179183
public void onDestroy() {
180184
if (mContentLayout != null) {

app/src/main/java/com/rae/cnblogs/presenter/IMomentDetailContract.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,10 @@ interface View {
9191
void onDeleteMomentFailed(String string);
9292

9393
void onDeleteMomentSuccess();
94+
95+
/**
96+
* 加载更多的时候没有登录
97+
*/
98+
void onLoadMoreNotLogin();
9499
}
95100
}

app/src/main/java/com/rae/cnblogs/presenter/impl/MomentDetailPresenterImpl.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class MomentDetailPresenterImpl extends BasePresenter<IMomentDetailContra
3333
private final IFriendsApi mFriendApi;
3434
private FriendsInfoBean mBloggerInfo;
3535
private boolean mRefresh;
36+
private boolean mFromLoadMore;
3637

3738
public MomentDetailPresenterImpl(Context context, IMomentDetailContract.View view) {
3839
super(context, view);
@@ -49,7 +50,7 @@ public void start() {
4950
if (Rx.isEmpty(momentInfo.getCommentList()) || mRefresh) {
5051
loaMomentDetail(momentInfo);
5152
} else {
52-
mView.onLoadComments(momentInfo.getCommentList(), false);
53+
notifyCommentSuccess(momentInfo.getCommentList());
5354
}
5455

5556
if (isLogin()) {
@@ -103,22 +104,29 @@ protected void onError(String message) {
103104

104105
@Override
105106
protected void accept(List<MomentCommentBean> momentCommentBeans) {
106-
if (Rx.isEmpty(momentCommentBeans)) {
107-
mView.onEmptyComment(getString(R.string.empty_comment));
108-
return;
109-
}
110-
111-
// 判断是否还有更多评论
112-
MomentCommentBean commentBean = momentCommentBeans.get(momentCommentBeans.size() - 1);
113-
boolean hasMore = "more".equals(commentBean.getId());
114-
if (hasMore)
115-
momentCommentBeans.remove(commentBean);
116-
117-
mView.onLoadComments(momentCommentBeans, hasMore);
107+
notifyCommentSuccess(momentCommentBeans);
118108
}
119109
});
120110
}
121111

112+
/**
113+
* 回调成功
114+
*/
115+
private void notifyCommentSuccess(List<MomentCommentBean> momentCommentBeans) {
116+
if (Rx.isEmpty(momentCommentBeans)) {
117+
mView.onEmptyComment(getString(R.string.empty_comment));
118+
return;
119+
}
120+
121+
// 判断是否还有更多评论
122+
MomentCommentBean commentBean = momentCommentBeans.get(momentCommentBeans.size() - 1);
123+
boolean hasMore = "more".equals(commentBean.getId());
124+
if (hasMore)
125+
momentCommentBeans.remove(commentBean);
126+
127+
mView.onLoadComments(momentCommentBeans, hasMore);
128+
}
129+
122130
@Override
123131
public void refresh() {
124132
mRefresh = true;
@@ -127,6 +135,10 @@ public void refresh() {
127135

128136
@Override
129137
public void loadMore() {
138+
if (isNotLogin()) {
139+
mView.onLoadMoreNotLogin();
140+
return;
141+
}
130142
// 目前没有发现有多页的情况,就重新刷新当前页面
131143
refresh();
132144
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.rae.cnblogs.widget;
2+
3+
import android.content.Context;
4+
import android.util.AttributeSet;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.view.animation.AnimationUtils;
9+
import android.widget.Button;
10+
import android.widget.TextView;
11+
12+
import com.rae.cnblogs.R;
13+
14+
/**
15+
* 登录的
16+
* Created by ChenRui on 2017/11/10 0010 10:12.
17+
*/
18+
public class LoginPlaceholderView extends PlaceholderView implements Runnable {
19+
20+
private Button mLoginRetryView;
21+
private TextView mLoginTipsView;
22+
private View mRetryLayout;
23+
// 重试次数
24+
int mRetryCount = 0;
25+
26+
public LoginPlaceholderView(Context context) {
27+
super(context);
28+
}
29+
30+
public LoginPlaceholderView(Context context, AttributeSet attrs) {
31+
super(context, attrs);
32+
}
33+
34+
public LoginPlaceholderView(Context context, AttributeSet attrs, int defStyleAttr) {
35+
super(context, attrs, defStyleAttr);
36+
}
37+
38+
public LoginPlaceholderView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
39+
super(context, attrs, defStyleAttr, defStyleRes);
40+
}
41+
42+
@Override
43+
protected void initView(AttributeSet attrs, int defStyleAttr) {
44+
super.initView(attrs, defStyleAttr);
45+
View view = LayoutInflater.from(getContext()).inflate(R.layout.view_placeholder_login_retry, (ViewGroup) mLoadingView);
46+
mLoginRetryView = view.findViewById(R.id.btn_placeholder_retry);
47+
mRetryLayout = view.findViewById(R.id.placeholder_retry_layout);
48+
mLoginTipsView = view.findViewById(R.id.tv_placeholder_retry_tips);
49+
mRetryLayout.setVisibility(View.INVISIBLE);
50+
}
51+
52+
@Override
53+
public void setOnRetryClickListener(final OnClickListener listener) {
54+
mLoginRetryView.setOnClickListener(new OnClickListener() {
55+
@Override
56+
public void onClick(View v) {
57+
mRetryCount += 1;
58+
listener.onClick(v);
59+
}
60+
});
61+
}
62+
63+
public int getRetryCount() {
64+
return mRetryCount;
65+
}
66+
67+
public void loadingWithTimer(String msg) {
68+
loading(msg);
69+
// 定时器
70+
removeCallbacks(this);
71+
// 连接超时
72+
postDelayed(this, 15000);
73+
}
74+
75+
@Override
76+
protected void onDetachedFromWindow() {
77+
super.onDetachedFromWindow();
78+
removeCallbacks(this);
79+
mLoginRetryView.setOnClickListener(null);
80+
}
81+
82+
public void dismissLoadingRetry() {
83+
mRetryLayout.startAnimation(AnimationUtils.loadAnimation(getContext(), android.R.anim.fade_out));
84+
mRetryLayout.setVisibility(View.INVISIBLE);
85+
}
86+
87+
@Override
88+
public void dismiss() {
89+
super.dismiss();
90+
removeCallbacks(this);
91+
}
92+
93+
@Override
94+
public void run() {
95+
96+
// 已经试过一次,还是不行提示重新登录
97+
if (mRetryCount > 0) {
98+
mLoginRetryView.setText(R.string.go_login);
99+
mLoginTipsView.setText(R.string.login_retry_route_tips);
100+
mLoadingProgressBar.setVisibility(View.GONE);
101+
mLoadingTextView.setVisibility(View.GONE);
102+
}
103+
104+
mRetryLayout.setVisibility(View.VISIBLE);
105+
mRetryLayout.startAnimation(AnimationUtils.loadAnimation(getContext(), android.R.anim.fade_in));
106+
}
107+
108+
/**
109+
* 是否达到去登录的重试次数了
110+
*/
111+
public boolean isRouteLogin() {
112+
return mRetryCount > 1;
113+
}
114+
}

app/src/main/java/com/rae/cnblogs/widget/PlaceholderView.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.view.View;
1515
import android.widget.FrameLayout;
1616
import android.widget.ImageView;
17+
import android.widget.ProgressBar;
1718
import android.widget.TextView;
1819

1920
import com.rae.cnblogs.AppRoute;
@@ -35,14 +36,15 @@ public class PlaceholderView extends FrameLayout implements SkinCompatSupportabl
3536
private SkinCompatBackgroundHelper mBackgroundTintHelper;
3637
private View mEmptyView;
3738
private View mLoginView;
38-
private View mLoadingView;
39+
View mLoadingView;
3940
private ImageView mEmptyImageView;
4041
private TextView mEmptyMessageView;
4142
private Drawable mDefaultEmptyIcon;
4243
private View mRetryView;
4344
private View mContentView;
44-
private TextView mLoadingTextView;
45-
private String mLoadingText;
45+
TextView mLoadingTextView;
46+
String mLoadingText;
47+
ProgressBar mLoadingProgressBar;
4648
private View mLoginBtn;
4749

4850
public PlaceholderView(Context context) {
@@ -70,7 +72,7 @@ public PlaceholderView(Context context, AttributeSet attrs, int defStyleAttr, in
7072
}
7173

7274

73-
private void initView(AttributeSet attrs, int defStyleAttr) {
75+
protected void initView(AttributeSet attrs, int defStyleAttr) {
7476

7577
mBackgroundTintHelper = new SkinCompatBackgroundHelper(this);
7678
mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);
@@ -79,6 +81,7 @@ private void initView(AttributeSet attrs, int defStyleAttr) {
7981
mEmptyView = mContentView.findViewById(R.id.ll_placeholder_empty);
8082
mLoginView = mContentView.findViewById(R.id.ll_placeholder_login);
8183
mLoadingView = mContentView.findViewById(R.id.ll_placeholder_loading);
84+
mLoadingProgressBar = mContentView.findViewById(R.id.pb_loading);
8285
mLoadingTextView = (TextView) mContentView.findViewById(R.id.tv_loading);
8386
mEmptyImageView = (ImageView) mContentView.findViewById(R.id.img_placeholder_empty);
8487
mEmptyMessageView = (TextView) mContentView.findViewById(R.id.tv_placeholder_empty_message);

0 commit comments

Comments
 (0)