更改换默认头像规则, 快传安装游戏后清空消息栏消息

This commit is contained in:
khy
2017-03-08 10:01:56 +08:00
parent 9a2f4c984c
commit fba0a6ec71
6 changed files with 77 additions and 84 deletions

View File

@ -65,6 +65,7 @@ import com.gh.gamecenter.manager.PackageManager;
import com.gh.gamecenter.manager.UpdateManager;
import com.gh.gamecenter.news.NewsFragment;
import com.gh.gamecenter.personal.PersonalFragment;
import com.gh.gamecenter.retrofit.JSONObjectResponse;
import com.gh.gamecenter.retrofit.ObservableUtil;
import com.gh.gamecenter.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
@ -387,6 +388,10 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
handler.postDelayed(skipRun, 500);
Log.e("TD_CHANNEL_ID", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"));
if (sp.getBoolean("changeDefaultIcon", false) && sp.getInt("default_user_icon", 0) != 0) {
postDefaultIcon(true, sp.getInt("default_user_icon", 0));
}
}
// 更新用户使用的助手信息
@ -1214,6 +1219,46 @@ public class MainActivity extends BaseFragmentActivity implements OnClickListene
protected void onDestroy() {
super.onDestroy();
DownloadManager.getInstance(this).removeObserver(dataWatcher);
if (sp.getBoolean("changeDefaultIcon", false) && sp.getInt("default_user_icon", 0) != 0) {
postDefaultIcon(true, sp.getInt("default_user_icon", 0));
}
}
// 提交默认头像
private 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);
sp.edit().putBoolean("changeDefaultIcon", false);
}
@Override
public void onFailure(HttpException e) {
super.onFailure(e);
if (e != null) {
if (e.code() == 401) {
postDefaultIcon(true, i);
return;
}
}
}
}
);
}
}