|
@@ -5,20 +5,30 @@ import android.content.Context;
|
|
|
import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.widget.CompoundButton;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.Switch;
|
|
|
import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
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.netease.nim.uikit.common.ui.dialog.DialogMaker;
|
|
|
import com.netease.nim.uikit.common.ui.imageview.HeadImageView;
|
|
|
+import com.netease.nim.uikit.common.util.log.LogUtil;
|
|
|
+import com.netease.nim.uikit.session.actions.PickImageAction;
|
|
|
+import com.netease.nimlib.sdk.AbortableFuture;
|
|
|
import com.netease.nimlib.sdk.NIMClient;
|
|
|
import com.netease.nimlib.sdk.RequestCallback;
|
|
|
+import com.netease.nimlib.sdk.RequestCallbackWrapper;
|
|
|
+import com.netease.nimlib.sdk.ResponseCode;
|
|
|
+import com.netease.nimlib.sdk.nos.NosService;
|
|
|
import com.netease.nimlib.sdk.uinfo.UserInfoProvider;
|
|
|
import com.netease.nimlib.sdk.uinfo.UserService;
|
|
|
import com.netease.nimlib.sdk.uinfo.constant.UserInfoFieldEnum;
|
|
@@ -31,11 +41,13 @@ import com.sheishuo.app.common.util.net.INet;
|
|
|
import com.sheishuo.app.common.util.net.NetImpl;
|
|
|
import com.sheishuo.app.common.util.net.ResponseCallback;
|
|
|
import com.sheishuo.app.common.views.BaseToolbar;
|
|
|
+import com.sheishuo.app.contact.helper.UserUpdateHelper;
|
|
|
import com.sheishuo.app.core_module.location.LocationSelectActivity;
|
|
|
import com.sheishuo.app.core_module.sheishuo.view.ui.SettingTextEditActivity;
|
|
|
import com.sheishuo.app.impl.SheishuoUI;
|
|
|
import com.sheishuo.app.main.fragment.MineFragment;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -58,6 +70,7 @@ public class PersonalSettingsActivity extends SheishuoUI {
|
|
|
public static final int REQUEST_REALNAME = 5402;
|
|
|
public static final int REQUEST_IDNUM = 5403;
|
|
|
|
|
|
+ public static final int AVATAR_TIME_OUT = 30000;
|
|
|
|
|
|
private String TAG = this.getClass().getSimpleName();
|
|
|
private Context context = this;
|
|
@@ -79,6 +92,7 @@ public class PersonalSettingsActivity extends SheishuoUI {
|
|
|
private INet net = new NetImpl();
|
|
|
private ResponseCallback callback;
|
|
|
|
|
|
+ AbortableFuture<String> uploadAvatarFuture;
|
|
|
|
|
|
public static void start(Context context) {
|
|
|
start(context, null);
|
|
@@ -421,27 +435,33 @@ public class PersonalSettingsActivity extends SheishuoUI {
|
|
|
//照相机
|
|
|
String filePath = result.getString("file_path");
|
|
|
if (requestCode == MineFragment.AVATAR_SELECTED){
|
|
|
- Glide.with(this).load(filePath)
|
|
|
- .centerCrop()
|
|
|
- .into(avatarImg);
|
|
|
- Map<UserInfoFieldEnum,Object> filedMap = new HashMap<>();
|
|
|
- filedMap.put(UserInfoFieldEnum.AVATAR,filePath);
|
|
|
- NIMClient.getService(UserService.class).updateUserInfo(filedMap).setCallback(new RequestCallback<Void>() {
|
|
|
- @Override
|
|
|
- public void onSuccess(Void aVoid) {
|
|
|
- showToast(getBaseContext(), "更新头像成功");
|
|
|
- }
|
|
|
|
|
|
+ new Handler().postDelayed(outimeTask, AVATAR_TIME_OUT);
|
|
|
+ uploadAvatarFuture = NIMClient.getService(NosService.class).upload(new File(filePath), PickImageAction.MIME_JPEG);
|
|
|
+ uploadAvatarFuture.setCallback(new RequestCallbackWrapper<String>() {
|
|
|
@Override
|
|
|
- public void onFailed(int i) {
|
|
|
- showToast(getBaseContext(), "更新头像失败");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onException(Throwable throwable) {
|
|
|
- showToast(getBaseContext(), "更新头像失败");
|
|
|
-
|
|
|
+ public void onResult(int code, String url, Throwable exception) {
|
|
|
+ if (code == ResponseCode.RES_SUCCESS && !TextUtils.isEmpty(url)) {
|
|
|
+ LogUtil.i(TAG, "upload avatar success, url =" + url);
|
|
|
+ Glide.with(PersonalSettingsActivity.this).load(url)
|
|
|
+ .centerCrop()
|
|
|
+ .into(avatarImg);
|
|
|
+ UserUpdateHelper.update(UserInfoFieldEnum.AVATAR, url, new RequestCallbackWrapper<Void>() {
|
|
|
+ @Override
|
|
|
+ public void onResult(int code, Void result, Throwable exception) {
|
|
|
+ if (code == ResponseCode.RES_SUCCESS) {
|
|
|
+ Toast.makeText(PersonalSettingsActivity.this, R.string.head_update_success, Toast.LENGTH_SHORT).show();
|
|
|
+ onUpdateDone();
|
|
|
+ } else {
|
|
|
+ Toast.makeText(PersonalSettingsActivity.this, R.string.head_update_failed, Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }); // 更新资料
|
|
|
+ } else {
|
|
|
+ Toast.makeText(PersonalSettingsActivity.this, R.string.user_info_update_failed, Toast
|
|
|
+ .LENGTH_SHORT).show();
|
|
|
+ onUpdateDone();
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -452,28 +472,33 @@ public class PersonalSettingsActivity extends SheishuoUI {
|
|
|
//相册
|
|
|
List<PhotoInfo> photoInfoList = (List<PhotoInfo>) result.getSerializable("photo_list");
|
|
|
if (requestCode == MineFragment.AVATAR_SELECTED){
|
|
|
- Glide.with(this)
|
|
|
- .load(photoInfoList.get(0).getFilePath())
|
|
|
- .centerCrop()
|
|
|
- .into(avatarImg);
|
|
|
- Map<UserInfoFieldEnum,Object> filedMap = new HashMap<>();
|
|
|
- filedMap.put(UserInfoFieldEnum.AVATAR,photoInfoList.get(0).getAbsolutePath());
|
|
|
- NIMClient.getService(UserService.class).updateUserInfo(filedMap).setCallback(new RequestCallback<Void>() {
|
|
|
- @Override
|
|
|
- public void onSuccess(Void aVoid) {
|
|
|
- showToast(getBaseContext(), "更新头像成功");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onFailed(int i) {
|
|
|
- showToast(getBaseContext(), "更新头像失败");
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
+ new Handler().postDelayed(outimeTask, AVATAR_TIME_OUT);
|
|
|
+ uploadAvatarFuture = NIMClient.getService(NosService.class).upload(new File(photoInfoList.get(0).getAbsolutePath()), PickImageAction.MIME_JPEG);
|
|
|
+ uploadAvatarFuture.setCallback(new RequestCallbackWrapper<String>() {
|
|
|
@Override
|
|
|
- public void onException(Throwable throwable) {
|
|
|
- showToast(getBaseContext(), "更新头像失败");
|
|
|
-
|
|
|
+ public void onResult(int code, String url, Throwable exception) {
|
|
|
+ if (code == ResponseCode.RES_SUCCESS && !TextUtils.isEmpty(url)) {
|
|
|
+ LogUtil.i(TAG, "upload avatar success, url =" + url);
|
|
|
+ Glide.with(PersonalSettingsActivity.this).load(url)
|
|
|
+ .centerCrop()
|
|
|
+ .into(avatarImg);
|
|
|
+ UserUpdateHelper.update(UserInfoFieldEnum.AVATAR, url, new RequestCallbackWrapper<Void>() {
|
|
|
+ @Override
|
|
|
+ public void onResult(int code, Void result, Throwable exception) {
|
|
|
+ if (code == ResponseCode.RES_SUCCESS) {
|
|
|
+ Toast.makeText(PersonalSettingsActivity.this, R.string.head_update_success, Toast.LENGTH_SHORT).show();
|
|
|
+ onUpdateDone();
|
|
|
+ } else {
|
|
|
+ Toast.makeText(PersonalSettingsActivity.this, R.string.head_update_failed, Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }); // 更新资料
|
|
|
+ } else {
|
|
|
+ Toast.makeText(PersonalSettingsActivity.this, R.string.user_info_update_failed, Toast
|
|
|
+ .LENGTH_SHORT).show();
|
|
|
+ onUpdateDone();
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -483,6 +508,27 @@ public class PersonalSettingsActivity extends SheishuoUI {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private void cancelUpload(int resId) {
|
|
|
+ if (uploadAvatarFuture != null) {
|
|
|
+ uploadAvatarFuture.abort();
|
|
|
+ Toast.makeText(PersonalSettingsActivity.this, resId, Toast.LENGTH_SHORT).show();
|
|
|
+ onUpdateDone();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Runnable outimeTask = new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ cancelUpload(R.string.user_info_update_failed);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ private void onUpdateDone() {
|
|
|
+ uploadAvatarFuture = null;
|
|
|
+ DialogMaker.dismissProgressDialog();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void selectGender(final UserService userService) {
|
|
|
final int[] yourChoice = new int[1];
|
|
|
final String[] items = {"保密", "男", "女"};
|