1
1
package com .rae .cnblogs .activity ;
2
2
3
+ import android .content .DialogInterface ;
3
4
import android .os .Bundle ;
4
5
import android .support .annotation .Nullable ;
5
6
import android .support .v4 .app .Fragment ;
6
- import android .support .v4 .app .FragmentTransaction ;
7
+ import android .support .v7 .widget .LinearLayoutManager ;
8
+ import android .support .v7 .widget .RecyclerView ;
7
9
import android .text .TextUtils ;
8
10
import android .view .View ;
9
11
import android .widget .TextView ;
10
12
11
13
import com .rae .cnblogs .AppRoute ;
12
14
import com .rae .cnblogs .AppUI ;
13
15
import com .rae .cnblogs .R ;
16
+ import com .rae .cnblogs .RaeViewCompat ;
14
17
import com .rae .cnblogs .RxObservable ;
18
+ import com .rae .cnblogs .adapter .BlogContentAdapter ;
15
19
import com .rae .cnblogs .dialog .DialogProvider ;
16
20
import com .rae .cnblogs .dialog .IAppDialog ;
17
21
import com .rae .cnblogs .dialog .impl .BlogShareDialog ;
18
- import com .rae .cnblogs .fragment .BlogContentFragment ;
22
+ import com .rae .cnblogs .dialog .impl .EditCommentDialog ;
23
+ import com .rae .cnblogs .dialog .impl .HintCardDialog ;
24
+ import com .rae .cnblogs .presenter .CnblogsPresenterFactory ;
25
+ import com .rae .cnblogs .presenter .IBlogCommentPresenter ;
19
26
import com .rae .cnblogs .sdk .ApiDefaultObserver ;
20
27
import com .rae .cnblogs .sdk .bean .BlogBean ;
28
+ import com .rae .cnblogs .sdk .bean .BlogCommentBean ;
21
29
import com .rae .cnblogs .sdk .bean .BlogType ;
22
30
import com .rae .cnblogs .sdk .db .DbBlog ;
23
31
import com .rae .cnblogs .sdk .db .DbFactory ;
24
32
import com .rae .cnblogs .widget .PlaceholderView ;
33
+ import com .rae .swift .Rx ;
25
34
26
35
import org .jsoup .Jsoup ;
27
36
41
50
* 博文查看
42
51
* Created by ChenRui on 2016/12/6 21:38.
43
52
*/
44
- public class BlogContentActivity extends SwipeBackBaseActivity {
53
+ public class BlogContentActivity extends SwipeBackBaseActivity implements EditCommentDialog . OnEditCommentListener , IBlogCommentPresenter . IBlogCommentView {
45
54
46
55
// @BindView(R.id.tool_bar)
47
56
// Toolbar mToolbar;
@@ -72,12 +81,17 @@ public class BlogContentActivity extends SwipeBackBaseActivity {
72
81
73
82
@ BindView (R .id .placeholder )
74
83
PlaceholderView mPlaceholderView ;
84
+ @ BindView (R .id .recycler_view )
85
+ RecyclerView mRecyclerView ;
86
+
75
87
76
88
private BlogShareDialog mShareDialog ;
77
89
private BlogBean mBlog ;
78
90
private BlogType mBlogType ;
79
- // private BlogCommentFragment mBlogCommentFragment;
80
- private BlogContentFragment mBlogContentFragment ;
91
+ // private BlogCommentFragment mBlogCommentFragment;
92
+ // private BlogContentFragment mBlogContentFragment;
93
+ private EditCommentDialog mEditCommentDialog ;
94
+ private IBlogCommentPresenter mCommentPresenter ;
81
95
82
96
@ Override
83
97
protected void onCreate (@ Nullable Bundle savedInstanceState ) {
@@ -103,6 +117,9 @@ protected void onViewSourceClick() {
103
117
}
104
118
};
105
119
120
+ mEditCommentDialog = new EditCommentDialog (getContext ());
121
+ mEditCommentDialog .setOnEditCommentListener (this );
122
+ mCommentPresenter = CnblogsPresenterFactory .getBlogCommentPresenter (this , mBlogType , this );
106
123
if (mBlog != null ) {
107
124
mPlaceholderView .dismiss ();
108
125
onLoadData (mBlog );
@@ -127,6 +144,10 @@ else if (!TextUtils.isEmpty(blogId)) {
127
144
mPlaceholderView .empty ("博客不存在" );
128
145
}
129
146
147
+
148
+ mRecyclerView .setLayoutManager (new LinearLayoutManager (this ));
149
+ mRecyclerView .setAdapter (new BlogContentAdapter ());
150
+
130
151
}
131
152
132
153
/**
@@ -218,15 +239,15 @@ private void onLoadData(BlogBean blog) {
218
239
// 评论
219
240
// mBlogCommentFragment = BlogCommentFragment.newInstance(mBlog, mBlogType);
220
241
// 内容
221
- mBlogContentFragment = BlogContentFragment .newInstance (mBlog , mBlogType );
242
+ // mBlogContentFragment = BlogContentFragment.newInstance(mBlog, mBlogType);
222
243
223
244
224
245
// 加载Fragment
225
- FragmentTransaction transaction = getSupportFragmentManager ().beginTransaction ();
246
+ // FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
226
247
// transaction.add(R.id.fl_comment, mBlogCommentFragment);
227
- transaction .add (R .id .fl_content , mBlogContentFragment );
248
+ // transaction.add(R.id.fl_content, mBlogContentFragment);
228
249
// fix bugly #472
229
- transaction .commitAllowingStateLoss ();
250
+ // transaction.commitAllowingStateLoss();
230
251
}
231
252
232
253
// 分享
@@ -245,6 +266,7 @@ public void onCommentClick() {
245
266
// 发表评论
246
267
@ OnClick (R .id .tv_edit_comment )
247
268
public void onEditCommentClick () {
269
+ mEditCommentDialog .show ();
248
270
// 通知里面的评论打开发表对话框
249
271
// EventBus.getDefault().post(new EditCommentEvent());
250
272
}
@@ -270,8 +292,92 @@ public void onActionBarClick() {
270
292
// if (mCommentLayout.getVisibility() == View.VISIBLE) {
271
293
// mBlogCommentFragment.scrollToTop();
272
294
// } else {
273
- mBlogContentFragment .scrollToTop ();
295
+ // mBlogContentFragment.scrollToTop();
274
296
// }
297
+
298
+ RaeViewCompat .scrollToTop (mRecyclerView );
299
+ }
300
+
301
+ @ Override
302
+ public void onPostComment (String content , BlogCommentBean parent , boolean isReference ) {
303
+ // 发表评论
304
+ AppUI .loading (getContext (), "正在发表.." );
305
+ mCommentPresenter .post (parent );
306
+ mEditCommentDialog .dismiss ();
307
+ }
308
+
309
+ @ Override
310
+ public void onLoadCommentSuccess (List <BlogCommentBean > data ) {
311
+ // 不用处理
312
+ }
313
+
314
+ @ Override
315
+ public BlogBean getBlog () {
316
+ return mBlog ;
317
+ }
318
+
319
+ @ Override
320
+ public void onLoadCommentEmpty () {
321
+ // 不用处理
322
+ }
323
+
324
+ @ Override
325
+ public void onLoadMoreCommentEmpty () {
326
+ // 不用处理
327
+ }
328
+
329
+ @ Override
330
+ public String getCommentContent () {
331
+ return mEditCommentDialog .getCommentContent ();
332
+ }
333
+
334
+ @ Override
335
+ public void onPostCommentFailed (String msg ) {
336
+ AppUI .dismiss ();
337
+ AppUI .failed (getContext (), msg );
338
+ }
339
+
340
+ @ Override
341
+ public void onPostCommentSuccess () {
342
+ AppUI .dismiss ();
343
+ mEditCommentDialog .dismiss ();
344
+ // 评论数量加1
345
+ int comment = Rx .parseInt (mBlog .getComment ()) + 1 ;
346
+ mCommentBadgeView .setText (String .valueOf (comment ));
347
+
348
+ if (config ().hasCommentGuide ()) {
349
+ AppUI .toastInCenter (getContext (), "您伟大的讲话发表成功" );
350
+ } else {
351
+ HintCardDialog dialog = new HintCardDialog (getContext ());
352
+ dialog .setMessage (getString (R .string .dialog_tips_post_comment ));
353
+ dialog .setOnDismissListener (new DialogInterface .OnDismissListener () {
354
+ @ Override
355
+ public void onDismiss (DialogInterface dialog ) {
356
+ config ().commentGuide ();
357
+ }
358
+ });
359
+ dialog .show ();
360
+ }
361
+ }
362
+
363
+ @ Override
364
+ public boolean enableReferenceComment () {
365
+ return mEditCommentDialog .enableReferenceComment ();
366
+ }
367
+
368
+ @ Override
369
+ public void onDeleteCommentSuccess (BlogCommentBean item ) {
370
+ // 不用处理
371
+ }
372
+
373
+ @ Override
374
+ public void onDeleteCommentFailed (String msg ) {
375
+ // 不用处理
376
+ }
377
+
378
+ @ Override
379
+ public void onLoadCommentFailed (String message ) {
380
+ // 不用处理
275
381
}
276
382
277
383
0 commit comments