This repository was archived by the owner on Jun 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathMomentDetailActivity.java
121 lines (105 loc) · 3.96 KB
/
MomentDetailActivity.java
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.rae.cnblogs.moment;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.rae.cnblogs.AppRoute;
import com.rae.cnblogs.activity.SwipeBackBasicActivity;
import com.rae.cnblogs.basic.rx.AndroidObservable;
import com.rae.cnblogs.dialog.ShareDialogFragment;
import com.rae.cnblogs.moment.fragment.MomentDetailFragment;
import com.rae.cnblogs.sdk.ApiDefaultObserver;
import com.rae.cnblogs.sdk.CnblogsApiFactory;
import com.rae.cnblogs.sdk.UserProvider;
import com.rae.cnblogs.sdk.api.IMomentApi;
import com.rae.cnblogs.sdk.bean.MomentBean;
import com.rae.cnblogs.widget.PlaceholderView;
import butterknife.BindView;
import butterknife.OnClick;
/**
* 详情
* Created by ChenRui on 2017/11/2 0002 15:01.
*/
@Route(path = AppRoute.PATH_MOMENT_DETAIL)
public class MomentDetailActivity extends SwipeBackBasicActivity {
private MomentBean mMomentBean;
@BindView(R2.id.placeholder)
PlaceholderView mPlaceholderView;
private String mIngId;
private String mUserId;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_moment_detail);
mMomentBean = getIntent().getParcelableExtra("data");
mIngId = getIntent().getStringExtra("ingId");
mUserId = getIntent().getStringExtra("userId");
if (mMomentBean != null && !TextUtils.isEmpty(mMomentBean.getId())) {
mPlaceholderView.dismiss();
attachFragment();
} else if (!TextUtils.isEmpty(mIngId) && !TextUtils.isEmpty(mUserId)) {
// 根据闪存ID获取详情
loadMomentDetail();
} else {
mPlaceholderView.empty("参数缺失");
}
mPlaceholderView.setOnRetryClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (UserProvider.getInstance().isLogin()) {
loadMomentDetail();
} else {
AppRoute.routeToLogin(v.getContext());
}
}
});
}
@SuppressLint("InvalidR2Usage")
private void attachFragment() {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_content, MomentDetailFragment.newInstance(mMomentBean))
.commitNow();
}
private void loadMomentDetail() {
if (!UserProvider.getInstance().isLogin()) {
mPlaceholderView.retry("登录后更精彩");
return;
}
IMomentApi momentApi = CnblogsApiFactory.getInstance(this).getMomentApi();
AndroidObservable
.create(momentApi.getMomentDetail(mUserId, mIngId, System.currentTimeMillis()))
.with(this)
.subscribe(new ApiDefaultObserver<MomentBean>() {
@Override
protected void onError(String message) {
mPlaceholderView.retry(message);
}
@Override
protected void accept(MomentBean momentBean) {
mMomentBean = momentBean;
attachFragment();
mPlaceholderView.dismiss();
}
});
}
@OnClick(R2.id.back)
public void onBackClick() {
}
/**
* 分享
*/
@OnClick(R2.id.btn_share)
public void onShareClick() {
String title = mMomentBean.getAuthorName() + ":" + mMomentBean.getContent();
String url = mMomentBean.getSourceUrl();
ShareDialogFragment.newInstance(
url,
title,
mMomentBean.getContent(),
mMomentBean.getAvatar(), 0, false, false)
.show(getSupportFragmentManager(), "share");
}
}