1、用户信息相关页面整理
This commit is contained in:
@ -1,212 +1,23 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.arch.lifecycle.Observer;
|
||||
import android.arch.lifecycle.ViewModelProviders;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.EntranceUtils;
|
||||
import com.gh.common.util.RandomUtils;
|
||||
import com.gh.common.util.UserIconUtils;
|
||||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||||
import com.gh.gamecenter.login.ApiResponse;
|
||||
import com.gh.gamecenter.login.UserViewModel;
|
||||
import com.lightgame.utils.Utils;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import com.halo.assistant.fragment.user.SelectPortraitFragment;
|
||||
import com.halo.assistant.ui.IntentFactory;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/2/10.
|
||||
*/
|
||||
public class SelectUserIconActivity extends BaseActivity {
|
||||
|
||||
@BindView(R.id.skip_media_store)
|
||||
TextView mSkipMediaStore;
|
||||
|
||||
public final static int CROP_ICON_REQUEST = 12;
|
||||
public final static int MEDIA_ICON_REQUEST = 13;
|
||||
|
||||
private UserViewModel mUserViewModel;
|
||||
|
||||
private Dialog mLoadingDialog;
|
||||
|
||||
private SharedPreferences sp;
|
||||
@Deprecated
|
||||
public class SelectUserIconActivity extends CommonActivity {
|
||||
|
||||
@NonNull
|
||||
public static Intent getIntent(Context context) {
|
||||
Intent intent = new Intent(context, SelectUserIconActivity.class);
|
||||
return intent;
|
||||
return new IntentFactory.Builder(context)
|
||||
.setActivity(SelectUserIconActivity.class)
|
||||
.setFragment(SelectPortraitFragment.class).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_select_user_icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (data != null && requestCode == MEDIA_ICON_REQUEST) {
|
||||
Uri selectedImage = data.getData();
|
||||
if (selectedImage == null) {
|
||||
return;
|
||||
}
|
||||
String[] filePathColumn = {MediaStore.Images.Media.DATA};
|
||||
|
||||
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
|
||||
if (cursor == null) {
|
||||
return;
|
||||
}
|
||||
cursor.moveToFirst();
|
||||
|
||||
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
|
||||
String picturePath = cursor.getString(columnIndex);
|
||||
cursor.close();
|
||||
|
||||
Utils.log("picturePath = " + picturePath);
|
||||
// 上传头像
|
||||
Intent intent = CropImageActivity.getIntent(this, picturePath, "我的光环(选择头像)");
|
||||
startActivityForResult(intent, CROP_ICON_REQUEST);
|
||||
} else if (data != null && requestCode == CROP_ICON_REQUEST) {
|
||||
String url = data.getExtras().getString(EntranceUtils.KEY_URL);
|
||||
// Intent intent = new Intent();
|
||||
// intent.putExtra("url", url);
|
||||
// setResult(0x125, intent);
|
||||
// finish();
|
||||
change(url);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setNavigationTitle(getString(R.string.title_select_user_icon));
|
||||
|
||||
sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
UserViewModel.Factory factory = new UserViewModel.Factory(getApplication());
|
||||
mUserViewModel = ViewModelProviders.of(this, factory).get(UserViewModel.class);
|
||||
mUserViewModel.getEditObsUserinfo().observe(this, new Observer<ApiResponse<UserInfoEntity>>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable ApiResponse<UserInfoEntity> userInfoEntity) {
|
||||
if (mLoadingDialog != null) {
|
||||
mLoadingDialog.dismiss();
|
||||
}
|
||||
if (mLoadingDialog != null && userInfoEntity != null && userInfoEntity.getData() != null) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@OnClick({R.id.user_default_icon_1, R.id.user_default_icon_2, R.id.user_default_icon_3, R.id.user_default_icon_4,
|
||||
R.id.user_default_icon_5, R.id.user_default_icon_6, R.id.user_default_icon_7, R.id.user_default_icon_8, R.id.skip_media_store})
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.user_default_icon_1:
|
||||
postUserIocn(1);
|
||||
break;
|
||||
case R.id.user_default_icon_2:
|
||||
postUserIocn(2);
|
||||
break;
|
||||
case R.id.user_default_icon_3:
|
||||
postUserIocn(3);
|
||||
break;
|
||||
case R.id.user_default_icon_4:
|
||||
postUserIocn(4);
|
||||
break;
|
||||
case R.id.user_default_icon_5:
|
||||
postUserIocn(5);
|
||||
break;
|
||||
case R.id.user_default_icon_6:
|
||||
postUserIocn(6);
|
||||
break;
|
||||
case R.id.user_default_icon_7:
|
||||
postUserIocn(7);
|
||||
break;
|
||||
case R.id.user_default_icon_8:
|
||||
postUserIocn(8);
|
||||
break;
|
||||
case R.id.skip_media_store:
|
||||
|
||||
String iconCount = sp.getString("updateIconCount", null);
|
||||
if (!TextUtils.isEmpty(iconCount)) {
|
||||
long l = System.currentTimeMillis();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.CHINA);
|
||||
String time = format.format(new Date(l));
|
||||
|
||||
JSONObject json;
|
||||
try {
|
||||
json = new JSONObject(iconCount);
|
||||
String lastTime = json.getString("time");
|
||||
if (lastTime.equals(time) && json.getInt("count") == 2) {
|
||||
Utils.toast(SelectUserIconActivity.this, "每天最多只能上传2次头像");
|
||||
return;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
startActivityForResult(intent, MEDIA_ICON_REQUEST);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void postUserIocn(int i) {
|
||||
postDefaultIcon(i);
|
||||
}
|
||||
|
||||
public void postDefaultIcon(final int i) {
|
||||
String iconUrl = UserIconUtils.getUserIconUrl(i);
|
||||
|
||||
//初始化热点名称
|
||||
String chars = "abcdefghijklmnopqrstuvwxyz";
|
||||
int[] randomArray = RandomUtils.getRandomArray(2, 25);
|
||||
|
||||
String mySsid = "ghZS-";
|
||||
for (int j : randomArray) {
|
||||
mySsid = mySsid + chars.charAt(j);
|
||||
}
|
||||
mySsid = mySsid + i;
|
||||
sp.edit().putString("hotspotName", mySsid).apply();
|
||||
|
||||
sp.edit().putInt("default_user_icon", i).apply();
|
||||
|
||||
sp.edit().putBoolean("changeDefaultIcon", true).apply();
|
||||
|
||||
// Intent intent = new Intent();
|
||||
// intent.putExtra("url", iconUrl);
|
||||
// setResult(0x125, intent);
|
||||
// finish();
|
||||
change(iconUrl);
|
||||
}
|
||||
|
||||
|
||||
private void change(String url) {
|
||||
mLoadingDialog = DialogUtils.showWaitDialog(this, "正在修改信息...");
|
||||
mUserViewModel.changeUserInfo(url, "icon");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user