Skip to content

Commit

Permalink
Add access token revoke before logout (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
bxute authored and aviaryan committed Sep 10, 2018
1 parent e6aac0e commit 2312c23
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dependencies {
testImplementation "org.robolectric:shadows-multidex:$roboelectricVersion"
implementation 'android.arch.lifecycle:extensions:1.1.1'
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
implementation 'com.github.hapramp:steemconnect4j:v1.3.1'
implementation 'com.github.hapramp:steemconnect4j:v1.3.2'
implementation 'com.github.bxute:CryptoCoinView:v0.6'
implementation 'com.github.bxute:MarkDEditor:v0.9'
implementation fileTree(include: ['*.jar'], dir: 'libs')
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/hapramp/datastore/DataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void run() {
String res = response.body().string();
DataCache.cache(url, res);
if (!cachedDataReturned) {
dispatchUserCommunity(res, true, communitiesCallback);
dispatchAllCommunity(res, true, communitiesCallback);
}
} else {
dispatchUserCommunityError("Error Code:" + response.code(), communitiesCallback);
Expand Down
77 changes: 75 additions & 2 deletions app/src/main/java/com/hapramp/ui/fragments/SettingsFragment.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
package com.hapramp.ui.fragments;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.hapramp.R;
import com.hapramp.analytics.AnalyticsParams;
import com.hapramp.analytics.AnalyticsUtil;
import com.hapramp.preferences.HaprampPreferenceManager;
import com.hapramp.steemconnect.SteemConnectUtils;
import com.hapramp.steemconnect4j.SteemConnect;
import com.hapramp.steemconnect4j.SteemConnectCallback;
import com.hapramp.steemconnect4j.SteemConnectException;
import com.hapramp.ui.activity.LoginActivity;
import com.hapramp.utils.ConnectionUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
Expand All @@ -36,6 +44,7 @@ public class SettingsFragment extends Fragment {
@BindView(R.id.invite_btn)
TextView inviteBtn;
private Context mContext;
private ProgressDialog progressDialog;

public SettingsFragment() {
}
Expand All @@ -52,9 +61,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_settings, container, false);
initProgressDialog();
unbinder = ButterKnife.bind(this, view);
return view;
}

private void initProgressDialog() {
progressDialog = new ProgressDialog(mContext);
progressDialog.setCancelable(false);
}

@Override
Expand Down Expand Up @@ -115,9 +129,68 @@ public void onClick(DialogInterface dialog, int which) {
}

private void logout() {
//clear preferences
AnalyticsUtil.logEvent(AnalyticsParams.EVENT_LOGOUT);
HaprampPreferenceManager.getInstance().clearPreferences();
revokeAccessToken();
}

private void revokeAccessToken() {
if (!ConnectionUtils.isConnected(mContext)) {
Toast.makeText(mContext, "Cannot revoke Token. Please connect to internet!",
Toast.LENGTH_LONG).show();
return;
}
final Handler mHanlder = new Handler();
showLogoutProgress();
final SteemConnect steemConnect = SteemConnectUtils.getSteemConnectInstance(
HaprampPreferenceManager.getInstance().getSC2AccessToken()
);
new Thread() {
@Override
public void run() {
steemConnect.revokeToken(new SteemConnectCallback() {
@Override
public void onResponse(String s) {
mHanlder.post(
new Runnable() {
@Override
public void run() {
hideLogoutProgress();
HaprampPreferenceManager.getInstance().clearPreferences();
navigateToLoginPage();
}
}
);
}

@Override
public void onError(final SteemConnectException e) {
mHanlder.post(new Runnable() {
@Override
public void run() {
hideLogoutProgress();
Toast.makeText(mContext, "Failed to logout", Toast.LENGTH_LONG).show();
}
});
}
});
}
}.start();
}

private void showLogoutProgress() {
if (progressDialog != null) {
progressDialog.setMessage("Logging out...");
progressDialog.show();
}
}

private void hideLogoutProgress() {
if (progressDialog != null) {
progressDialog.dismiss();
}
}

private void navigateToLoginPage() {
Intent intent = new Intent(mContext, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Expand Down

0 comments on commit 2312c23

Please sign in to comment.