修改获取token逻辑,以及处理token 401问题
This commit is contained in:
@ -24,7 +24,7 @@ import com.gc.materialdesign.views.ProgressBarCircularIndeterminate;
|
||||
import com.gh.base.BaseActivity;
|
||||
import com.gh.base.OnRequestCallBackListener;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.TokenUtils;
|
||||
import com.gh.common.util.LoginUtils;
|
||||
import com.gh.gamecenter.adapter.VoteAdapter;
|
||||
import com.gh.gamecenter.db.VersionVoteDao;
|
||||
import com.gh.gamecenter.db.info.VersionVoteInfo;
|
||||
@ -41,9 +41,7 @@ import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.HttpException;
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
@ -142,7 +140,7 @@ public class VoteActivity extends BaseActivity implements SwipeRefreshLayout.OnR
|
||||
|
||||
@Override
|
||||
public void loadDone(String obj) {
|
||||
postVersionVote(obj, true, false); // 投票
|
||||
postVersionVote(obj, false); // 投票
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -181,7 +179,7 @@ public class VoteActivity extends BaseActivity implements SwipeRefreshLayout.OnR
|
||||
Toast.makeText(VoteActivity.this, "请输入名字", Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
postVersionVote(nickname, true, true);
|
||||
postVersionVote(nickname, true);
|
||||
dialog.dismiss();
|
||||
return true;
|
||||
}
|
||||
@ -208,7 +206,7 @@ public class VoteActivity extends BaseActivity implements SwipeRefreshLayout.OnR
|
||||
Toast.makeText(VoteActivity.this, "请输入名字", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
postVersionVote(nickname, true, true);
|
||||
postVersionVote(nickname, true);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
@ -235,7 +233,7 @@ public class VoteActivity extends BaseActivity implements SwipeRefreshLayout.OnR
|
||||
}, 300);
|
||||
}
|
||||
|
||||
private void postVersionVote(final String name, final boolean isCheck, final boolean isNewVote) {
|
||||
private void postVersionVote(final String name, final boolean isNewVote) {
|
||||
final Dialog waitDialog = DialogUtils.showWaitDialog(VoteActivity.this, "提交中...");
|
||||
|
||||
JSONObject object = new JSONObject();
|
||||
@ -248,14 +246,8 @@ public class VoteActivity extends BaseActivity implements SwipeRefreshLayout.OnR
|
||||
|
||||
final RequestBody body = RequestBody.create(MediaType.parse("application/json"), object.toString());
|
||||
|
||||
TokenUtils
|
||||
.getToken(VoteActivity.this, isCheck)
|
||||
.flatMap(new Func1<String, Observable<ResponseBody>>() {
|
||||
@Override
|
||||
public Observable<ResponseBody> call(String token) {
|
||||
return RetrofitManager.getApi().postVersionVote(token, body, mGameId);
|
||||
}
|
||||
})
|
||||
RetrofitManager.getApi()
|
||||
.postVersionVote(LoginUtils.getToken(this), body, mGameId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Response<ResponseBody>() {
|
||||
@ -266,7 +258,6 @@ public class VoteActivity extends BaseActivity implements SwipeRefreshLayout.OnR
|
||||
|
||||
try {
|
||||
String string = response.string();
|
||||
Utils.log("========提交成功" + string);
|
||||
JSONObject responseObject = new JSONObject(string);
|
||||
boolean cast = responseObject.getBoolean("cast");
|
||||
String id = responseObject.getString("_id");
|
||||
@ -301,13 +292,6 @@ public class VoteActivity extends BaseActivity implements SwipeRefreshLayout.OnR
|
||||
super.onFailure(e);
|
||||
Utils.toast(VoteActivity.this, "提交失败");
|
||||
waitDialog.dismiss();
|
||||
|
||||
if (e != null) {
|
||||
if (e.code() == 401) {
|
||||
postVersionVote(name, false, isNewVote);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user