|
@@ -1,22 +1,37 @@
|
|
|
package com.sheishuo.app.circle.activity;
|
|
|
|
|
|
+import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.widget.EditText;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
-import com.sheishuo.app.cache.AccountCache;
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
+import com.netease.nim.uikit.common.media.picker.PickImageHelper;
|
|
|
+import com.netease.nim.uikit.common.media.picker.model.PhotoInfo;
|
|
|
import com.sheishuo.app.R;
|
|
|
+import com.sheishuo.app.cache.AccountCache;
|
|
|
import com.sheishuo.app.circle.presenter.NewTweetPresenter;
|
|
|
+import com.sheishuo.app.common.util.img.ImgUtil;
|
|
|
import com.sheishuo.app.common.util.location.LocationHelper;
|
|
|
+import com.sheishuo.app.common.util.net.NetStatus;
|
|
|
import com.sheishuo.app.common.views.BaseToolbar;
|
|
|
import com.sheishuo.app.main.activity.MainActivity;
|
|
|
+import com.sheishuo.app.main.fragment.CircleOfFriendsFragment;
|
|
|
import com.sheishuo.app.uikit_implements.SheishuoUI;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import jp.wasabeef.glide.transformations.ColorFilterTransformation;
|
|
|
+
|
|
|
/**
|
|
|
* Created by KN on 2017/7/21.
|
|
|
*/
|
|
@@ -27,7 +42,12 @@ public class NewTweetingActivity extends SheishuoUI {
|
|
|
private BaseToolbar toolbar;
|
|
|
private EditText tweetContent;
|
|
|
private TextView locationTV;
|
|
|
+ private LinearLayout imgsLayout;
|
|
|
+ private ImageView addImg;
|
|
|
private NewTweetPresenter presenter;
|
|
|
+ private List<String> selectedPhotoPathList;
|
|
|
+ private List<Integer> photoIds;
|
|
|
+// private static MainActivity activity;
|
|
|
|
|
|
public static void start(Context context) {
|
|
|
start(context, null);
|
|
@@ -35,7 +55,7 @@ public class NewTweetingActivity extends SheishuoUI {
|
|
|
|
|
|
public static void start(Context context, Intent extras) {
|
|
|
Intent intent = new Intent();
|
|
|
- intent.setClass(context, MainActivity.class);
|
|
|
+ intent.setClass(context, NewTweetingActivity.class);
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
|
if (extras != null) {
|
|
|
intent.putExtras(extras);
|
|
@@ -43,7 +63,18 @@ public class NewTweetingActivity extends SheishuoUI {
|
|
|
context.startActivity(intent);
|
|
|
}
|
|
|
|
|
|
+ public static void startActivityForResult(Context context, Intent extras){
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setClass(context, NewTweetingActivity.class);
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
|
+ if (extras != null) {
|
|
|
+ intent.putExtras(extras);
|
|
|
+ }
|
|
|
+ if (context instanceof MainActivity){
|
|
|
+ ((MainActivity)context).startActivityForResult(intent,0);
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@@ -51,18 +82,19 @@ public class NewTweetingActivity extends SheishuoUI {
|
|
|
setContentView(R.layout.circle_new_tweeting);
|
|
|
findViews();
|
|
|
init();
|
|
|
+ setResult(CircleOfFriendsFragment.REFRESH_CIRCLE);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- private void findViews(){
|
|
|
+ private void findViews() {
|
|
|
toolbar = (BaseToolbar) findViewById(R.id.new_tweet_toolbar);
|
|
|
tweetContent = (EditText) findViewById(R.id.new_tweet_content);
|
|
|
locationTV = (TextView) findViewById(R.id.new_tweet_location_tv);
|
|
|
+ imgsLayout = (LinearLayout) findViewById(R.id.new_tweet_img_layout);
|
|
|
+ addImg = (ImageView) findViewById(R.id.new_tweet_add_imgs);
|
|
|
}
|
|
|
|
|
|
- private void init(){
|
|
|
+ private void init() {
|
|
|
|
|
|
presenter = new NewTweetPresenter(this);
|
|
|
|
|
@@ -78,7 +110,17 @@ public class NewTweetingActivity extends SheishuoUI {
|
|
|
toolbar.getRightTV().setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
- presenter.publishNewTweeting(tweetContent.getText().toString());
|
|
|
+ if (NetStatus.IS_BUSY){
|
|
|
+ showToast("内容发布中,请稍后...");
|
|
|
+ }else {
|
|
|
+ getHandler().postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ showToast("内容发布中...");
|
|
|
+ presenter.publishNewTweeting(tweetContent.getText().toString(),photoIds);
|
|
|
+ }
|
|
|
+ },1000);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -87,18 +129,81 @@ public class NewTweetingActivity extends SheishuoUI {
|
|
|
AccountCache.getAccount().setLatitude(LocationHelper.getLatitude());
|
|
|
AccountCache.getAccount().setLongitude(LocationHelper.getLongitude());
|
|
|
|
|
|
- Log.e(TAG,"location ===> " + LocationHelper.getLatitude() + " " + LocationHelper.getLongitude());
|
|
|
+ Log.e(TAG, "location ===> " + LocationHelper.getLatitude() + " " + LocationHelper.getLongitude());
|
|
|
locationTV.setText(AccountCache.getAccount().getCity() + AccountCache.getAccount().getDistrict());
|
|
|
|
|
|
|
|
|
+ //初始化照片添加监听事件
|
|
|
+ selectedPhotoPathList = new ArrayList<>();
|
|
|
+ photoIds = new ArrayList<>();
|
|
|
+ addImg.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+
|
|
|
+ PickImageHelper.PickImageOption option = new PickImageHelper.PickImageOption();
|
|
|
+ PickImageHelper.pickImage(context, 0, option);
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ for (String key : data.getExtras().keySet()) {
|
|
|
+ Log.e("key", key);
|
|
|
+ }
|
|
|
+
|
|
|
+ Bundle result = data.getExtras();
|
|
|
+ if (!result.getBoolean("from_local")) {
|
|
|
+ //照相机
|
|
|
+ String filePath = result.getString("file_path");
|
|
|
+ imgsLayout.removeAllViews();
|
|
|
+ ImageView imageView = new ImageView(this);
|
|
|
+ imageView.setAdjustViewBounds(true);
|
|
|
+ int toDp = (int) ImgUtil.convertDpToPixel(128, context);
|
|
|
+ imageView.setLayoutParams(new LinearLayout.LayoutParams(toDp, toDp));
|
|
|
+ Glide.with(context).load(filePath)
|
|
|
+ .centerCrop()
|
|
|
+ .bitmapTransform(new ColorFilterTransformation(context, 0x7900CCCC))
|
|
|
+ .into(imageView);
|
|
|
+ presenter.uploadPhoto(filePath);
|
|
|
+ } else {
|
|
|
+ //相册
|
|
|
+ imgsLayout.removeAllViews();
|
|
|
+ List<PhotoInfo> photoInfoList = (List<PhotoInfo>) result.getSerializable("photo_list");
|
|
|
+ for (PhotoInfo info : photoInfoList) {
|
|
|
+ ImageView imageView = new ImageView(this);
|
|
|
+ imageView.setAdjustViewBounds(true);
|
|
|
+ int toDp = (int) ImgUtil.convertDpToPixel(128, context);
|
|
|
+ imageView.setLayoutParams(new LinearLayout.LayoutParams(toDp, toDp));
|
|
|
+ Glide.with(context).load(info.getFilePath())
|
|
|
+ .centerCrop()
|
|
|
+ .bitmapTransform(new ColorFilterTransformation(context, 0x7900CCCC))
|
|
|
+ .into(imageView);
|
|
|
+ imgsLayout.addView(imageView);
|
|
|
+ selectedPhotoPathList.add(info.getAbsolutePath());
|
|
|
+ }
|
|
|
+
|
|
|
+ presenter.uploadPhoto(selectedPhotoPathList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+// activity.onActivityResult(0,CircleOfFriendsFragment.REFRESH_CIRCLE,null);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 以下为开放给Presenter的通用方法
|
|
|
*/
|
|
|
|
|
|
- public void showToast(final String toast){
|
|
|
+ public void showToast(final String toast) {
|
|
|
getHandler().post(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
@@ -108,9 +213,44 @@ public class NewTweetingActivity extends SheishuoUI {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void onTweetSuccess(){
|
|
|
+
|
|
|
+ public void onTweetSuccess() {
|
|
|
showToast("发布成功");
|
|
|
finish();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ //当一张照片上传完成后回调
|
|
|
+ public void onOnePhotoUploaded(final int index, final int photoId){
|
|
|
+ getHandler().post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ ImageView imageView = (ImageView) imgsLayout.getChildAt(index);
|
|
|
+ String filePath = selectedPhotoPathList.get(index);
|
|
|
+ Glide.with(context).load(filePath).into(imageView);
|
|
|
+ Collections.synchronizedList(photoIds);
|
|
|
+ photoIds.add(photoId);
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //全部照片上传完成
|
|
|
+ public void onAllPhotosUploaded(){
|
|
|
+ getHandler().post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ toolbar.getRightTV().setEnabled(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|