Skip to content

Commit e1e963d

Browse files
author
ChenRui
committed
添加发布闪存功能
1 parent 9b99e3a commit e1e963d

36 files changed

+1365
-29
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@
2727
android:name=".activity.LauncherActivity"
2828
android:screenOrientation="portrait"
2929
android:theme="@style/AppTheme.NoActionBar.FullScreen">
30-
<!-- <intent-filter>
30+
<intent-filter>
3131
<action android:name="android.intent.action.MAIN"/>
3232

3333
<category android:name="android.intent.category.LAUNCHER"/>
34-
</intent-filter>-->
34+
</intent-filter>
3535
</activity>
3636

3737
<!--主界面-->
3838
<activity
3939
android:name=".activity.MainActivity"
4040
android:screenOrientation="portrait"
4141
android:theme="@style/AppTheme.Dark">
42-
<intent-filter>
42+
<!-- <intent-filter>
4343
<action android:name="android.intent.action.MAIN"/>
4444
4545
<category android:name="android.intent.category.LAUNCHER"/>
46-
</intent-filter>
46+
</intent-filter>-->
4747
</activity>
4848

4949
<activity
@@ -132,6 +132,24 @@
132132
android:label="@string/font_setting"
133133
android:screenOrientation="portrait"/>
134134

135+
<activity
136+
android:name=".activity.CommentActivity"
137+
android:label="@string/label_comment"
138+
android:screenOrientation="portrait"/>
139+
140+
<activity
141+
android:name=".activity.PostMomentActivity"
142+
android:screenOrientation="portrait">
143+
<!-- <intent-filter>
144+
<action android:name="android.intent.action.MAIN"/>
145+
<category android:name="android.intent.category.LAUNCHER"/>
146+
</intent-filter>-->
147+
</activity>
148+
<activity
149+
android:name=".activity.ImageSelectionActivity"
150+
android:label="@string/label_image_selection"
151+
android:screenOrientation="portrait"/>
152+
135153
<service
136154
android:name=".service.CnblogsService"
137155
android:label="@string/service_name"/>
@@ -193,10 +211,6 @@
193211
</intent-filter>
194212

195213
</activity>
196-
<activity
197-
android:name=".activity.CommentActivity"
198-
android:label="@string/label_comment"
199-
android:screenOrientation="portrait"/>
200214

201215
<provider
202216
android:name="android.support.v4.content.FileProvider"

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
import com.rae.cnblogs.activity.FeedbackActivity;
1616
import com.rae.cnblogs.activity.FontSettingActivity;
1717
import com.rae.cnblogs.activity.FriendsActivity;
18+
import com.rae.cnblogs.activity.ImageSelectionActivity;
1819
import com.rae.cnblogs.activity.LoginActivity;
1920
import com.rae.cnblogs.activity.MainActivity;
21+
import com.rae.cnblogs.activity.PostMomentActivity;
2022
import com.rae.cnblogs.activity.SearchActivity;
2123
import com.rae.cnblogs.activity.SettingActivity;
2224
import com.rae.cnblogs.activity.SystemMessageActivity;
@@ -46,6 +48,10 @@ public final class AppRoute {
4648
public static final int REQ_CODE_FAVORITES = 103;
4749
// 博主
4850
public static final int REQ_CODE_BLOGGER = 104;
51+
// 发布闪存
52+
private static final int REQ_POST_MOMENT = 105;
53+
// 图片选择
54+
private static final int REQ_IMAGE_SELECTION = 106;
4955

5056
private static void startActivity(Context context, Intent intent) {
5157
context.startActivity(intent);
@@ -308,4 +314,21 @@ public static void jumpToComment(Context context, BlogBean blog, BlogType type)
308314
intent.putExtra("blog", blog);
309315
startActivity(context, intent);
310316
}
317+
318+
/**
319+
* 发布闪存
320+
*/
321+
public static void jumpToPostMoment(Activity context) {
322+
Intent intent = new Intent(context, PostMomentActivity.class);
323+
startActivityForResult(context, intent, REQ_POST_MOMENT);
324+
}
325+
326+
/**
327+
* 跳转到图片选择
328+
*/
329+
public static void jumpToImageSelection(Activity context, ArrayList<String> images) {
330+
Intent intent = new Intent(context, ImageSelectionActivity.class);
331+
intent.putStringArrayListExtra("images", images);
332+
startActivityForResult(context, intent, REQ_IMAGE_SELECTION);
333+
}
311334
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.rae.cnblogs;
2+
3+
4+
import java.util.List;
5+
6+
public interface IPageView<T> {
7+
void onNoMoreData();
8+
9+
void onEmptyData(String msg);
10+
11+
void onLoadData(List<T> data);
12+
13+
void onLoginExpired();
14+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//
2+
// Source code recreated from a .class file by IntelliJ IDEA
3+
// (powered by Fernflower decompiler)
4+
//
5+
6+
package com.rae.cnblogs;
7+
8+
import com.rae.cnblogs.sdk.ApiDefaultObserver;
9+
import com.rae.swift.Rx;
10+
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
14+
import io.reactivex.Observable;
15+
16+
public abstract class PageObservable<T> {
17+
public static int startPageIndex = 1;
18+
protected int mPage;
19+
private IPageView<T> mView;
20+
private final List<T> mDataList = new ArrayList<>();
21+
22+
public PageObservable(IPageView<T> view) {
23+
this(view, startPageIndex);
24+
}
25+
26+
public PageObservable(IPageView<T> view, int startIndex) {
27+
this.mPage = startIndex;
28+
this.mView = view;
29+
}
30+
31+
public void start() {
32+
this.mPage = startPageIndex;
33+
this.onLoadData(this.mPage);
34+
}
35+
36+
public void loadMore() {
37+
this.onLoadData(this.mPage);
38+
}
39+
40+
public void complete(List<T> dataList) {
41+
if (this.mPage <= startPageIndex) {
42+
this.mDataList.clear();
43+
}
44+
45+
if (this.mPage > startPageIndex && Rx.isEmpty(dataList)) {
46+
this.onNoMoreData();
47+
} else {
48+
this.mDataList.addAll(dataList);
49+
this.onLoadDataComplete(this.mDataList);
50+
++this.mPage;
51+
}
52+
}
53+
54+
public void destroy() {
55+
this.mDataList.clear();
56+
this.mView = null;
57+
}
58+
59+
protected void onNoMoreData() {
60+
this.mView.onNoMoreData();
61+
}
62+
63+
protected void onLoadData(int page) {
64+
RxObservable.create(this.onCreateObserver(page), "PageDataObservable").subscribe(new ApiDefaultObserver<List<T>>() {
65+
protected void onError(String message) {
66+
if (mView == null) return;
67+
if (mPage > PageObservable.startPageIndex) {
68+
mView.onNoMoreData();
69+
} else {
70+
mView.onEmptyData(message);
71+
}
72+
73+
}
74+
75+
protected void onEmpty(List<T> data) {
76+
this.onError("暂无记录");
77+
}
78+
79+
protected void accept(List<T> data) {
80+
if (mView == null) return;
81+
if (Rx.isEmpty(data)) {
82+
this.onEmpty(data);
83+
} else {
84+
complete(data);
85+
}
86+
}
87+
88+
protected void onLoginExpired() {
89+
if (mView == null) return;
90+
mView.onLoginExpired();
91+
}
92+
});
93+
}
94+
95+
protected abstract Observable<List<T>> onCreateObserver(int page);
96+
97+
protected void onLoadDataComplete(List<T> dataList) {
98+
this.mView.onLoadData(dataList);
99+
}
100+
}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
package com.rae.cnblogs.activity;
2+
3+
import android.content.ContentResolver;
4+
import android.database.Cursor;
5+
import android.net.Uri;
6+
import android.os.Bundle;
7+
import android.provider.MediaStore;
8+
import android.support.annotation.Nullable;
9+
import android.support.v7.widget.GridLayoutManager;
10+
import android.support.v7.widget.RecyclerView;
11+
import android.view.LayoutInflater;
12+
import android.view.View;
13+
import android.view.ViewGroup;
14+
import android.widget.CheckBox;
15+
import android.widget.CompoundButton;
16+
import android.widget.ImageView;
17+
import android.widget.TextView;
18+
19+
import com.rae.cnblogs.AppUI;
20+
import com.rae.cnblogs.GlideApp;
21+
import com.rae.cnblogs.R;
22+
23+
import java.io.File;
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
27+
import butterknife.BindView;
28+
29+
/**
30+
* 图片选择
31+
* Created by ChenRui on 2017/10/27 0027 14:04.
32+
*/
33+
public class ImageSelectionActivity extends BaseActivity {
34+
@BindView(R.id.recycler_view)
35+
RecyclerView mRecyclerView;
36+
private ImageSelectionAdapter mAdapter;
37+
38+
@Override
39+
protected void onCreate(@Nullable Bundle savedInstanceState) {
40+
super.onCreate(savedInstanceState);
41+
setContentView(R.layout.activity_image_selection);
42+
showHomeAsUp();
43+
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
44+
mAdapter = new ImageSelectionAdapter();
45+
mRecyclerView.setAdapter(mAdapter);
46+
}
47+
48+
@Override
49+
protected void onResume() {
50+
super.onResume();
51+
loadImageData();
52+
}
53+
54+
/**
55+
* 加载系统相册的图片
56+
*/
57+
private void loadImageData() {
58+
List<String> result = new ArrayList<>();
59+
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
60+
61+
ContentResolver contentResolver = this.getContentResolver();
62+
Cursor cursor = contentResolver.query(uri, null, null, null, null);
63+
// 没有图片
64+
if (cursor == null || cursor.getCount() <= 0) return;
65+
while (cursor.moveToNext()) {
66+
int index = cursor
67+
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
68+
String path = cursor.getString(index); // 文件地址
69+
File file = new File(path);
70+
if (file.exists()) {
71+
result.add(path);
72+
}
73+
}
74+
cursor.close();
75+
76+
mAdapter.setImageList(result);
77+
mAdapter.notifyDataSetChanged();
78+
}
79+
80+
81+
private static class ImageSelectionHolder extends RecyclerView.ViewHolder {
82+
TextView mPositionTextView;
83+
ImageView mImageView;
84+
CheckBox mCheckBox;
85+
View mCheckBoxLayout;
86+
87+
public ImageSelectionHolder(View itemView) {
88+
super(itemView);
89+
mImageView = itemView.findViewById(R.id.img_background);
90+
mCheckBox = itemView.findViewById(R.id.cb_checkbox);
91+
mCheckBoxLayout = itemView.findViewById(R.id.rl_checkbox);
92+
mPositionTextView = itemView.findViewById(R.id.tv_position);
93+
}
94+
}
95+
96+
private static class ImageSelectionAdapter extends RecyclerView.Adapter<ImageSelectionHolder> implements View.OnClickListener {
97+
98+
private final List<String> mUrls = new ArrayList<>();
99+
private final List<String> mSelectedList = new ArrayList<>();
100+
private LayoutInflater mLayoutInflater;
101+
102+
public ImageSelectionAdapter() {
103+
super();
104+
}
105+
106+
@Override
107+
public ImageSelectionHolder onCreateViewHolder(ViewGroup parent, int i) {
108+
if (mLayoutInflater == null) {
109+
mLayoutInflater = LayoutInflater.from(parent.getContext());
110+
}
111+
return new ImageSelectionHolder(mLayoutInflater.inflate(R.layout.item_image_selection, parent, false));
112+
}
113+
114+
@Override
115+
public void onBindViewHolder(ImageSelectionHolder holder, int position) {
116+
String fileName = mUrls.get(position);
117+
holder.mCheckBox.setTag(position);
118+
holder.mCheckBoxLayout.setOnClickListener(this);
119+
holder.mCheckBox.setChecked(mSelectedList.contains(fileName));
120+
if (holder.mCheckBox.isChecked()) {
121+
holder.mPositionTextView.setVisibility(View.VISIBLE);
122+
holder.mPositionTextView.setText(String.valueOf(mSelectedList.indexOf(fileName) + 1));
123+
} else {
124+
holder.mPositionTextView.setVisibility(View.GONE);
125+
}
126+
GlideApp.with(holder.itemView).load("file://" + fileName).into(holder.mImageView);
127+
}
128+
129+
@Override
130+
public int getItemCount() {
131+
return mUrls.size();
132+
}
133+
134+
public void remove(String fileName) {
135+
mUrls.remove(fileName);
136+
}
137+
138+
public void setImageList(List<String> imageList) {
139+
mUrls.clear();
140+
mUrls.addAll(imageList);
141+
}
142+
143+
@Override
144+
public void onClick(View v) {
145+
if (v.getId() == R.id.rl_checkbox) {
146+
onCheckBoxClick((CompoundButton) v.findViewById(R.id.cb_checkbox));
147+
}
148+
}
149+
150+
private void onCheckBoxClick(CompoundButton buttonView) {
151+
int position = (int) buttonView.getTag();
152+
String item = mUrls.get(position);
153+
if (buttonView.isChecked()) {
154+
// 不超过6张图片
155+
if (mSelectedList.size() >= 6) {
156+
buttonView.setChecked(false);
157+
AppUI.failed(buttonView.getContext(), "最多选择6张图片");
158+
return;
159+
}
160+
mSelectedList.remove(item);
161+
mSelectedList.add(item);
162+
} else {
163+
mSelectedList.remove(item);
164+
}
165+
166+
notifyDataSetChanged();
167+
}
168+
}
169+
}

0 commit comments

Comments
 (0)