更改换默认头像规则, 快传安装游戏后清空消息栏消息
This commit is contained in:
@ -10,34 +10,21 @@ import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.RandomUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.UserIconUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.OnClick;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by khy on 2017/2/10.
|
||||
@ -148,79 +135,31 @@ public class SelectUserIconActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
public void postUserIocn(int i) {
|
||||
postDefaultIcon(true, i);
|
||||
postDefaultIcon(i);
|
||||
}
|
||||
|
||||
public void postDefaultIcon(boolean isCheck, final int i) {
|
||||
TokenUtils.getToken(this, isCheck)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("icon_key" , "icon" + i);
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
||||
new JSONObject(params).toString());
|
||||
return RetrofitManager.getUser().postDefaultIcon(token, body);
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new JSONObjectResponse(){
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
super.onResponse(response);
|
||||
try {
|
||||
String icon = response.getString("icon");
|
||||
public void postDefaultIcon(final int i) {
|
||||
String iconUrl = UserIconUtils.getUserIconUrl(i);
|
||||
|
||||
sp.edit().putInt("default_user_icon", i).apply();
|
||||
//初始化热点名称
|
||||
String chars = "abcdefghijklmnopqrstuvwxyz";
|
||||
int[] randomArray = RandomUtils.getRandomArray(2, 25);
|
||||
|
||||
//初始化热点名称
|
||||
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();
|
||||
|
||||
String mySsid = "ghZS-";
|
||||
for (int i : randomArray) {
|
||||
mySsid = mySsid + chars.charAt(i);
|
||||
}
|
||||
mySsid = mySsid + i;
|
||||
sp.edit().putString("hotspotName", mySsid).apply();
|
||||
sp.edit().putInt("default_user_icon", i).apply();
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("url", icon);
|
||||
setResult(0x125, intent);
|
||||
finish();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
if (e != null) {
|
||||
if (e.code() == 401) {
|
||||
postDefaultIcon(true, i);
|
||||
return;
|
||||
}
|
||||
sp.edit().putBoolean("changeDefaultIcon", true).apply();
|
||||
|
||||
if (e.code() == 403) {
|
||||
try {
|
||||
JSONObject response = new JSONObject(new String(e.response().errorBody().bytes()));
|
||||
if ("too frequent".equals(response.getString("detail"))) {
|
||||
Toast.makeText(SelectUserIconActivity.this, "修改太频繁", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(SelectUserIconActivity.this, "修改失败", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
Toast.makeText(SelectUserIconActivity.this, "修改失败", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(SelectUserIconActivity.this, "网络异常,修改头像失败", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("url", iconUrl);
|
||||
setResult(0x125, intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user