Clear access token of not valid anymore

This commit is contained in:
jannis 2020-01-08 12:37:45 +01:00
parent 59c1781dd4
commit 832f6441cb
2 changed files with 9 additions and 5 deletions

View File

@ -118,12 +118,12 @@ public class OAuthAuthentication {
.putBoolean("authenticated", true).apply(); .putBoolean("authenticated", true).apply();
} }
public void clearAccessToken(){ void clearAccessToken() {
preferences.edit().putBoolean("authenticated", false).apply(); preferences.edit().putBoolean("authenticated", false).apply();
} }
private void retrieveAccessToken(String verificationCode){ private void retrieveAccessToken(String verificationCode){
handler.post(() -> dialogController.show()); handler.post(dialogController::show);
try{ try{
oAuthProvider.retrieveAccessToken(oAuthConsumer, verificationCode); oAuthProvider.retrieveAccessToken(oAuthConsumer, verificationCode);
handler.post(() -> { handler.post(() -> {

View File

@ -93,8 +93,12 @@ public class OsmTraceUploader {
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
handler.post(() -> { handler.post(() -> {
@StringRes int textRes= e instanceof OsmAuthorizationException ? @StringRes int textRes = R.string.uploadFailed;
R.string.uploadFailedOsmNotAuthorized : R.string.uploadFailed;
if (e instanceof OsmAuthorizationException) {
textRes = R.string.uploadFailedOsmNotAuthorized;
new OAuthAuthentication(handler, activity, null).clearAccessToken();
}
Toast.makeText(activity, textRes, Toast.LENGTH_LONG).show(); Toast.makeText(activity, textRes, Toast.LENGTH_LONG).show();
dialogController.cancel(); dialogController.cancel();
@ -104,7 +108,7 @@ public class OsmTraceUploader {
} }
private void executeTask(){ private void executeTask(){
handler.post(() -> dialogController.show()); handler.post(dialogController::show);
setProgress(0); setProgress(0);
if(cut){ cut(); } if(cut){ cut(); }
setProgress(20); setProgress(20);