Skip to content

Commit fb887f1

Browse files
author
ChenRui
committed
完成闪存发布功能
1 parent 340151d commit fb887f1

24 files changed

+665
-98
lines changed

app/build.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ def buglyAppId = properties.getProperty("buglyAppId", "replace_your_bugly_appid"
1515
def leancloudAppId = properties.getProperty("leancloudAppId", "replace_your_leancloud_appid")
1616
def leancloudAppKey = properties.getProperty("leancloudAppKey", "replace_your_leancloud_appeky")
1717

18+
def wechatAppId = properties.getProperty("wechatAppId", "replace_your_wechatAppId")
19+
def wechatAppSecret = properties.getProperty("wechatAppSecret", "replace_wechatAppSecret")
20+
def weiboAppId = properties.getProperty("weiboAppId", "replace_your_weboAppId")
21+
def weiboAppSecret = properties.getProperty("weiboAppSecret", "replace_your_weiboAppSecret")
22+
def qqAppId = properties.getProperty("qqAppId", "replace_your_qqAppId")
23+
def qqAppSecret = properties.getProperty("qqAppSecret", "replace_your_qqAppSecret")
24+
1825

1926
android {
2027
compileSdkVersion rootProject.ext.compileSdkVersion
@@ -44,6 +51,16 @@ android {
4451
buildConfigField 'String', 'BUGLY_APP_ID', '"' + buglyAppId + '"'
4552
buildConfigField 'String', 'LEAN_CLOUD_APP_ID', '"' + leancloudAppId + '"'
4653
buildConfigField 'String', 'LEAN_CLOUD_APP_KEY', '"' + leancloudAppKey + '"'
54+
55+
// 微信APP ID
56+
buildConfigField 'String', 'WECHAT_APP_ID', '"' + wechatAppId + '"'
57+
buildConfigField 'String', 'WECHAT_APP_SECRET', '"' + wechatAppSecret + '"'
58+
buildConfigField 'String', 'WEIBO_APP_ID', '"' + weiboAppId + '"'
59+
buildConfigField 'String', 'WEIBO_APP_SECRET', '"' + weiboAppSecret + '"'
60+
buildConfigField 'String', 'QQ_APP_ID', '"' + qqAppId + '"'
61+
buildConfigField 'String', 'QQ_APP_SECRET', '"' + qqAppSecret + '"'
62+
63+
4764
manifestPlaceholders = [
4865
UMENG_APPKEY: umengAppKey
4966
]

app/src/main/AndroidManifest.xml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
android:name=".activity.LauncherActivity"
3030
android:screenOrientation="portrait"
3131
android:theme="@style/AppTheme.NoActionBar.FullScreen">
32-
<!-- <intent-filter>
33-
<action android:name="android.intent.action.MAIN"/>
32+
<intent-filter>
33+
<action android:name="android.intent.action.MAIN"/>
3434

35-
<category android:name="android.intent.category.LAUNCHER"/>
36-
</intent-filter>-->
35+
<category android:name="android.intent.category.LAUNCHER"/>
36+
</intent-filter>
3737
</activity>
3838

3939
<!--主界面-->
@@ -142,12 +142,7 @@
142142
<activity
143143
android:name=".activity.PostMomentActivity"
144144
android:label="@string/label_post_moment"
145-
android:screenOrientation="portrait">
146-
<intent-filter>
147-
<action android:name="android.intent.action.MAIN"/>
148-
<category android:name="android.intent.category.LAUNCHER"/>
149-
</intent-filter>
150-
</activity>
145+
android:screenOrientation="portrait"/>
151146
<activity
152147
android:name=".activity.ImageSelectionActivity"
153148
android:label="@string/label_image_selection"
@@ -159,6 +154,9 @@
159154
android:name=".service.CnblogsService"
160155
android:label="@string/service_name"/>
161156

157+
158+
<service android:name=".service.MomentIntentService"/>
159+
162160
<!--应用宝 -->
163161
<activity
164162
android:name="com.umeng.qq.tencent.AssistActivity"

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ public final class AppConstant {
88
/**
99
* 微信APP ID
1010
*/
11-
public final static String WECHAT_APP_ID = "wx53e2633a2b1fa785";
11+
public final static String WECHAT_APP_ID = BuildConfig.WECHAT_APP_ID;
1212
/**
1313
* 微信APPSecret
1414
*/
15-
public final static String WECHAT_APP_SECRET = "wx53e2633a2b1fa785";
15+
public final static String WECHAT_APP_SECRET = BuildConfig.WECHAT_APP_SECRET;
1616
/**
1717
* 微博APP ID
1818
*/
19-
public final static String WEIBO_APP_ID = "1018850937";
19+
public final static String WEIBO_APP_ID = BuildConfig.WEIBO_APP_ID;
2020
/**
2121
* 微博APPSecret
2222
*/
23-
public final static String WEIBO_APP_SECRET = "79152f5ac3d4b183b346f241e2966310";
23+
public final static String WEIBO_APP_SECRET = BuildConfig.WEIBO_APP_SECRET;
2424
/**
2525
* QQ APP ID
2626
*/
27-
public final static String QQ_APP_ID = "1105927778";
27+
public final static String QQ_APP_ID = BuildConfig.QQ_APP_ID;
2828
/**
2929
* QQ APPSecret
3030
*/
31-
public final static String QQ_APP_SECRET = "6klDHIKKtF3JYCz4";
31+
public final static String QQ_APP_SECRET = BuildConfig.QQ_APP_SECRET;
3232
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ private void loadImageData() {
198198
Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
199199

200200
ContentResolver contentResolver = this.getContentResolver();
201-
Cursor cursor = contentResolver.query(uri, null, null, null, null);
201+
// 按时间倒序排列,取2000条记录
202+
Cursor cursor = contentResolver.query(uri, null, null, null, MediaStore.Images.Media.DATE_MODIFIED + " DESC limit 0,2000");
202203
// 没有图片
203204
if (cursor == null || cursor.getCount() <= 0) return;
204205
while (cursor.moveToNext()) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,24 @@ protected void accept(VersionInfo versionInfo) {
146146
// 请求权限
147147
requestPermissions();
148148

149+
autoSelectedTab();
150+
151+
}
152+
153+
@Override
154+
protected void onNewIntent(Intent intent) {
155+
super.onNewIntent(intent);
156+
autoSelectedTab();
157+
}
158+
159+
/**
160+
* 自动跳转标签
161+
*/
162+
private void autoSelectedTab() {
163+
int tab = getIntent().getIntExtra("tab", -1);
164+
if (tab >= 0 && mTabLayout != null) {
165+
mViewPager.setCurrentItem(tab);
166+
}
149167
}
150168

151169

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

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.rae.cnblogs.activity;
22

3+
import android.content.DialogInterface;
34
import android.content.Intent;
45
import android.os.Bundle;
56
import android.support.annotation.Nullable;
67
import android.support.v7.widget.GridLayoutManager;
78
import android.support.v7.widget.RecyclerView;
9+
import android.text.Editable;
10+
import android.text.TextUtils;
11+
import android.text.TextWatcher;
812
import android.view.LayoutInflater;
913
import android.view.View;
1014
import android.view.ViewGroup;
@@ -16,14 +20,16 @@
1620
import com.rae.cnblogs.AppUI;
1721
import com.rae.cnblogs.GlideApp;
1822
import com.rae.cnblogs.R;
23+
import com.rae.cnblogs.dialog.impl.DefaultDialog;
1924
import com.rae.cnblogs.presenter.CnblogsPresenterFactory;
2025
import com.rae.cnblogs.presenter.IPostMomentContract;
26+
import com.rae.cnblogs.sdk.model.ImageMetaData;
27+
import com.rae.cnblogs.sdk.model.MomentMetaData;
2128

2229
import java.util.ArrayList;
2330
import java.util.List;
2431

2532
import butterknife.BindView;
26-
import butterknife.ButterKnife;
2733
import butterknife.OnClick;
2834

2935
/**
@@ -39,13 +45,34 @@ public class PostMomentActivity extends BaseActivity implements IPostMomentContr
3945
RecyclerView mRecyclerView;
4046
private IPostMomentContract.Presenter mPresenter;
4147
private PostImageAdapter mAdapter;
48+
private MomentMetaData mMomentMetaData;
4249

4350
@Override
4451
protected void onCreate(@Nullable Bundle savedInstanceState) {
4552
super.onCreate(savedInstanceState);
4653
setContentView(R.layout.activity_post_moment);
47-
ButterKnife.bind(this);
4854
showHomeAsUp();
55+
56+
// 发布失败后传递的对象
57+
mMomentMetaData = getIntent().getParcelableExtra(Intent.EXTRA_TEXT);
58+
59+
mContentView.addTextChangedListener(new TextWatcher() {
60+
@Override
61+
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
62+
63+
}
64+
65+
@Override
66+
public void onTextChanged(CharSequence s, int start, int before, int count) {
67+
mPostView.setEnabled(mContentView.length() > 0);
68+
}
69+
70+
@Override
71+
public void afterTextChanged(Editable s) {
72+
73+
}
74+
});
75+
4976
mPresenter = CnblogsPresenterFactory.getPostMomentPresenter(this, this);
5077
mRecyclerView.setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER);
5178
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
@@ -63,6 +90,26 @@ public void onClick(View v) {
6390
AppRoute.jumpToImagePreview(PostMomentActivity.this, mAdapter.getImageSelectedList(), (Integer) v.getTag(), mAdapter.getImageSelectedList(), mAdapter.getMaxCount());
6491
}
6592
});
93+
94+
95+
if (mMomentMetaData != null) {
96+
mContentView.setText(mMomentMetaData.content);
97+
ArrayList<String> urls = new ArrayList<>();
98+
for (ImageMetaData image : mMomentMetaData.images) {
99+
urls.add(image.localPath);
100+
}
101+
mAdapter.setUrls(urls);
102+
mAdapter.notifyDataSetChanged();
103+
}
104+
105+
String msg = getIntent().getStringExtra(Intent.EXTRA_HTML_TEXT); // 发布失败的消息
106+
if (!TextUtils.isEmpty(msg)) {
107+
DefaultDialog dialog = new DefaultDialog(this);
108+
dialog.setMessage(msg);
109+
dialog.setCancelButtonVisibility(View.GONE);
110+
dialog.show();
111+
}
112+
66113
}
67114

68115
@Override
@@ -90,7 +137,10 @@ public String getContent() {
90137
public void onPostMomentFailed(String msg) {
91138
mPostView.setEnabled(true);
92139
AppUI.dismiss();
93-
AppUI.failed(this, msg);
140+
DefaultDialog dialog = new DefaultDialog(this);
141+
dialog.setMessage(msg);
142+
dialog.setCancelButtonVisibility(View.GONE);
143+
dialog.show();
94144
}
95145

96146
@Override
@@ -101,30 +151,26 @@ public void onPostMomentSuccess() {
101151

102152
@Override
103153
public List<String> getImageUrls() {
104-
return null;
154+
return mAdapter.getImageSelectedList();
155+
}
156+
157+
@Override
158+
public void onPostMomentInProgress() {
159+
AppUI.dismiss();
160+
DefaultDialog dialog = new DefaultDialog(this);
161+
dialog.setMessage("为了节省您的时间,已为进入后台发送,结果请稍后留意通知栏消息。");
162+
dialog.setCancelButtonVisibility(View.GONE);
163+
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
164+
@Override
165+
public void onDismiss(DialogInterface dialog) {
166+
finish();
167+
}
168+
});
169+
dialog.show();
105170
}
106171

107172
@OnClick(R.id.tv_post)
108173
public void onPostViewClick() {
109-
110-
// Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/raetest.jpg");
111-
// mImageView.setImageBitmap(bitmap);
112-
//
113-
// RequestBody body = MultipartBody.create(null, new File("/sdcard/raetest.jpg"));
114-
// MultipartBody.Part file = MultipartBody.Part.create(body);
115-
//
116-
// RxObservable.create(postApi.uploadImage("rae.jpg", "rae.jpg", body), "test").subscribe(new ApiDefaultObserver<String>() {
117-
// @Override
118-
// protected void onError(String message) {
119-
// AppUI.failed(getContext(), message);
120-
// }
121-
//
122-
// @Override
123-
// protected void accept(String url) {
124-
// AppUI.toastInCenter(getContext(), "上传成功!" + url);
125-
// }
126-
// });
127-
128174
if (mPresenter.post()) {
129175
AppUI.loading(this, "正在发布");
130176
mPostView.setEnabled(false);

app/src/main/java/com/rae/cnblogs/dialog/impl/DefaultDialog.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public DefaultDialog(Context context) {
4242

4343
@Override
4444
protected void initDialog() {
45-
initWindowAttr(getWindow());
45+
if (getWindow() != null) {
46+
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
47+
}
4648
initView();
4749
super.initDialog();
4850
}
@@ -63,9 +65,9 @@ private void initView() {
6365
protected void initWindowAttr(Window window) {
6466
if (window == null) return;
6567

66-
window.requestFeature(Window.FEATURE_NO_TITLE);
6768
WindowManager.LayoutParams lp = window.getAttributes();
68-
window.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT | Gravity.RIGHT);
69+
window.setGravity(Gravity.CENTER | Gravity.START | Gravity.END);
70+
6971
lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
7072
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
7173
window.setAttributes(lp);
@@ -78,6 +80,7 @@ protected void initWindowAttr(Window window) {
7880
@Override
7981
public void show() {
8082
super.show();
83+
initWindowAttr(getWindow());
8184
Animation anim = AnimationUtils.loadAnimation(getContext(), R.anim.scale_in);
8285
mContentView.startAnimation(anim);
8386
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.rae.cnblogs.AppUI;
2424
import com.rae.cnblogs.GlideApp;
2525
import com.rae.cnblogs.R;
26-
import com.rae.cnblogs.RaeAnim;
2726
import com.rae.cnblogs.ThemeCompat;
2827
import com.rae.cnblogs.activity.BaseActivity;
2928
import com.rae.swift.Rx;
@@ -85,7 +84,7 @@ public class ImagePreviewActivity extends BaseActivity implements ViewPager.OnPa
8584
@Override
8685
protected void onCreate(@Nullable Bundle savedInstanceState) {
8786
super.onCreate(savedInstanceState);
88-
overridePendingTransition(R.anim.image_scale_in, 0);
87+
overridePendingTransition(R.anim.image_scale_in, R.anim.keep_status);
8988
setContentView(R.layout.activity_image_preview);
9089

9190
ArrayList<String> images = getIntent().getStringArrayListExtra("images");
@@ -151,9 +150,8 @@ public void onClick(View v) {
151150

152151
@Override
153152
public void finish() {
154-
RaeAnim.fadeOut(mCloseView);
155153
super.finish();
156-
overridePendingTransition(0, R.anim.image_scale_out);
154+
overridePendingTransition(R.anim.keep_status, R.anim.image_scale_out);
157155
}
158156

159157
@OnClick(R.id.img_back)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,11 @@ interface View {
2121
void onPostMomentSuccess();
2222

2323
List<String> getImageUrls();
24+
25+
/**
26+
* 后台发送
27+
*/
28+
void onPostMomentInProgress();
29+
2430
}
2531
}

0 commit comments

Comments
 (0)