Commit 4750bea1 authored by Varun Patil's avatar Varun Patil

Remove (a lot of) dead code

parent c63f58a8
......@@ -46,77 +46,18 @@ import retrofit2.Response;
public class LoginActivity extends AppCompatActivity {
private static final String TAG = "LoginActivity";
private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
private static final String CLIENT_ID = "vR1pU7wXWyve1rUkg0fMS6StL1Kr6paoSmRIiLXJ";
private final Uri redirectUri = Uri.parse("https://redirecturi");
private final Uri mAuthEndpoint = Uri.parse("http://gymkhana.iitb.ac.in/sso/oauth/authorize/");
private final Uri mTokenEndpoint = Uri.parse("http://gymkhana.iitb.ac.in/sso/oauth/token/");
private final String redirectUri = "https://redirecturi";
private final String guestUri = "https://guesturi";
public String authCode = null;
SessionManager session;
Context mContext = this;
private AuthorizationService mAuthService;
private BroadcastReceiver mRegistrationBroadcastReceiver;
private boolean isReceiverRegistered;
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
session = new SessionManager(mContext);
setContentView(R.layout.activity_login);
mAuthService = new AuthorizationService(this);
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean sentToken = sharedPreferences.getBoolean(Constants.SENT_TOKEN_TO_SERVER, false);
if (sentToken) {
String token = intent.getStringExtra("Token");
Log.d(TAG, "Going to login with :" + authCode + "\n" + token);
//************
//TODO Remove following 6 lines after the server is hosted
String gcmRegId = token;
// session.createLoginSession(gcmRegId);
// Intent i = new Intent(mContext, MainActivity.class);
// i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// startActivity(i);
//**************
login(authCode, redirectUri.toString(), gcmRegId);
} else {
}
}
};
registerReceiver();
}
@Override
protected void onNewIntent(Intent intent) {
checkIntent(intent);
}
private void checkIntent(@Nullable Intent intent) {
if (intent != null) {
Log.d(TAG, "Intent Received");
String action = intent.getAction();
if (action != null) {
switch (action) {
case "HANDLE_AUTHORIZATION_RESPONSE": {
handleAuthorizationResponse(intent);
}
break;
default:
Log.d(TAG, intent.getAction());
}
}
}
}
@Override
......@@ -130,7 +71,7 @@ public class LoginActivity extends AppCompatActivity {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
/* Capture redirect */
if (url.startsWith(redirectUri.toString())) {
if (url.startsWith(redirectUri)) {
/* Show progress dialog */
progressDialog = new ProgressDialog(LoginActivity.this);
progressDialog.setMessage("Logging In");
......@@ -141,12 +82,12 @@ public class LoginActivity extends AppCompatActivity {
/* Get auth code from query */
String query = Uri.parse(url).getQuery();
authCode = query.substring(query.lastIndexOf("=") + 1);
login(authCode, redirectUri.toString(), authCode);
login(authCode, redirectUri, authCode);
return true;
}
/* Guest Login */
if (url.startsWith("https://guesturi")) {
if (url.startsWith(guestUri)) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
return true;
......@@ -157,90 +98,6 @@ public class LoginActivity extends AppCompatActivity {
return false;
}
});
checkIntent(getIntent());
}
@Override
protected void onResume() {
super.onResume();
registerReceiver();
Log.d(TAG, "On Resume");
}
@Override
protected void onPause() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver);
isReceiverRegistered = false;
super.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
mAuthService.dispose();
}
private void handleAuthorizationResponse(@NonNull Intent intent) {
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Logging In");
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
progressDialog.show();
AuthorizationResponse response = AuthorizationResponse.fromIntent(intent);
AuthorizationException error = AuthorizationException.fromIntent(intent);
if (response != null) {
authCode = response.authorizationCode;
Log.d(TAG, "Received AuthorizationResponse: " + "AuthCode: " + authCode);
if (checkPlayServices()) {
Intent registerIntent = new Intent(this, RegistrationIntentService.class);
startService(registerIntent);
}
//
} else {
Log.i(TAG, "Authorization failed: " + error.getMessage());
Toast.makeText(this,
"Authorization failed", Toast.LENGTH_LONG)
.show();
}
}
private void makeAuthRequest(@NonNull AuthorizationServiceConfiguration serviceConfig) {
AuthorizationRequest authRequest = new AuthorizationRequest.Builder(
serviceConfig,
CLIENT_ID,
"code",
redirectUri)
.setScope("basic profile picture sex ldap phone insti_address program secondary_emails")
.build();
Log.d(TAG, "Making auth request");
String action = "HANDLE_AUTHORIZATION_RESPONSE";
Intent postAuthorizationIntent = new Intent(action);
PendingIntent pendingIntent = PendingIntent.getActivity(this, authRequest.hashCode(), postAuthorizationIntent, 0);
mAuthService.performAuthorizationRequest(
authRequest,
pendingIntent,
mAuthService.createCustomTabsIntentBuilder()
.setToolbarColor(getCustomTabColor())
.build());
}
//TODO: Change the color of Chrome custom tabs based on app theme color
@TargetApi(Build.VERSION_CODES.M)
@SuppressWarnings("deprecation")
private int getCustomTabColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return getColor(R.color.colorPrimaryDark);
} else {
return getResources().getColor(R.color.colorPrimaryDark);
}
}
private void login(String authorizationCode, final String redirectURI, String gcmID) {
......@@ -269,15 +126,6 @@ public class LoginActivity extends AppCompatActivity {
});
}
private void registerReceiver() {
if (!isReceiverRegistered) {
LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
new IntentFilter(Constants.REGISTRATION_COMPLETE));
isReceiverRegistered = true;
}
}
private boolean checkPlayServices() {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment