// Path: AndroidRepairApp/app/src/main/java/com/canviz/repairapp/utility/AuthenticationHelper.java
// public class AuthenticationHelper {
// 
//     private static Activity mActivity;
//     public static AuthenticationContext mAADAuthContext = null;
// 
//     final static String TAG = "AuthenticationHelper";
// 
//     public static void initialize(Activity activity) throws NoSuchPaddingException, NoSuchAlgorithmException {
//         mActivity = activity;
//         mAADAuthContext = new AuthenticationContext(
//                 mActivity.getApplicationContext(),
//                 Constants.AAD_AUTHORITY,
//                 false);
//     }
// 
//     public static AuthenticationContext getAuthenticationContext() {
//         return mAADAuthContext;
//     }
// 
//     public static void acquireToken(String serverUrl, AuthenticationCallback<AuthenticationResult> callback) {
//         getAuthenticationContext().acquireToken(
//                 mActivity,
//                 serverUrl,
//                 Constants.AAD_CLIENT_ID,
//                 Constants.AAD_REDIRECT_URL,
//                 PromptBehavior.Auto,
//                 callback);
//     }
// 
//     public static  void acquireTokenSilent(String resource, String userId,AuthenticationCallback<AuthenticationResult> callback){
//         getAuthenticationContext().acquireTokenSilent(
//                 resource,
//                 Constants.AAD_CLIENT_ID,
//                 userId,
//                 callback);
//     }
// 
//     public static SettableFuture<String> acquireToken(String resource){
//         final SettableFuture<String> future = SettableFuture.create();
//         try {
//             getAuthenticationContext().acquireToken(
//                     mActivity,
//                     resource,
//                     Constants.AAD_CLIENT_ID,
//                     Constants.AAD_REDIRECT_URL,
//                     PromptBehavior.Auto,
//                     new AuthenticationCallback<AuthenticationResult>() {
//                         @Override
//                         public void onSuccess(AuthenticationResult authenticationResult) {
//                             future.set(authenticationResult.getAccessToken());
//                         }
// 
//                         @Override
//                         public void onError(Exception e) {
//                             future.setException(e);
//                         }
//                     });
//         } catch (Throwable t) {
//             future.setException(t);
//         }
// 
//         return future;
//     }
// 
//     public static ListClient getSharePointListClient(String accessToken) {
//         OAuthCredentials credentials = new OAuthCredentials(accessToken);
//         return new ListClient(Constants.SHAREPOINT_URL, Constants.SHAREPOINT_SITE_PATH, credentials);
//     }
// 
//     private static DependencyResolver getDependencyResolver(final String token) {
//         DefaultDependencyResolver dependencyResolver = new DefaultDependencyResolver(token);
//         dependencyResolver.getLogger().setEnabled(true);
//         dependencyResolver.getLogger().setLogLevel(LogLevel.VERBOSE);
//         return dependencyResolver;
//     }
// 
//     public static IGraphServiceClient getGraphServiceClient(Application app, String token){
//         return new GraphServiceClient
//                 .Builder()
//                 .fromConfig(DefaultClientConfig.createWithAuthenticationProvider(new GraphAuthenticationProvider(app, token)))
//                 .buildClient();
//     }
// 
//     public static SettableFuture<String> getGraphAccessToken(){
//         final SettableFuture<String> future = SettableFuture.create();
//         try {
//             getAuthenticationContext().acquireToken(
//                     mActivity,
//                     Constants.GRAPH_RESOURCE_ID,
//                     Constants.AAD_CLIENT_ID,
//                     Constants.AAD_REDIRECT_URL,
//                     PromptBehavior.Auto,
//                     new AuthenticationCallback<AuthenticationResult>() {
//                         @Override
//                         public void onSuccess(AuthenticationResult authenticationResult) {
//                             future.set(authenticationResult.getAccessToken());
//                         }
// 
//                         @Override
//                         public void onError(Exception e) {
//                             future.setException(e);
//                         }
//                     });
//         } catch (Throwable t) {
//             future.setException(t);
//         }
//         return future;
//     }
// }


import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.security.NoSuchAlgorithmException;
import javax.crypto.NoSuchPaddingException;
import com.canviz.repairapp.utility.AuthenticationHelper;
import com.canviz.repairapp.utility.Helper;
import com.microsoft.aad.adal.AuthenticationCallback;
import com.microsoft.aad.adal.AuthenticationContext;
import com.microsoft.aad.adal.AuthenticationResult;
import com.microsoft.aad.adal.PromptBehavior;
import com.microsoft.services.sharepoint.ListClient;
                authenticationResult.getRefreshToken()
        );
        */

        mApp.setUserId(authenticationResult.getUserInfo().getUserId());
        mApp.setToken(authenticationResult.getAccessToken());

        signComplete();
    }

    private void handleError(String errorMessage) {
        new AlertDialog.Builder(this)
                .setTitle("Whoops!")
                .setMessage("Something went wrong: " + errorMessage)
                .setPositiveButton("Ok", null)
                .show();
    }

    private void signComplete(){
        mApp.setSelectedIncidentModel(null);

        Intent incident = new Intent();
        incident.setClass(SigninActivity.this,IncidentActivity.class);
        startActivity(incident);
        finish();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
// Path: AndroidRepairApp/app/src/main/java/com/canviz/repairapp/utility/AuthenticationHelper.java
// public class AuthenticationHelper {
// 
//     private static Activity mActivity;
//     public static AuthenticationContext mAADAuthContext = null;
// 
//     final static String TAG = "AuthenticationHelper";
// 
//     public static void initialize(Activity activity) throws NoSuchPaddingException, NoSuchAlgorithmException {
//         mActivity = activity;
//         mAADAuthContext = new AuthenticationContext(
//                 mActivity.getApplicationContext(),
//                 Constants.AAD_AUTHORITY,
//                 false);
//     }
// 
//     public static AuthenticationContext getAuthenticationContext() {
//         return mAADAuthContext;
//     }
// 
//     public static void acquireToken(String serverUrl, AuthenticationCallback<AuthenticationResult> callback) {
//         getAuthenticationContext().acquireToken(
//                 mActivity,
//                 serverUrl,
//                 Constants.AAD_CLIENT_ID,
//                 Constants.AAD_REDIRECT_URL,
//                 PromptBehavior.Auto,
//                 callback);
//     }
// 
//     public static  void acquireTokenSilent(String resource, String userId,AuthenticationCallback<AuthenticationResult> callback){
//         getAuthenticationContext().acquireTokenSilent(
//                 resource,
//                 Constants.AAD_CLIENT_ID,
//                 userId,
//                 callback);
//     }
// 
//     public static SettableFuture<String> acquireToken(String resource){
//         final SettableFuture<String> future = SettableFuture.create();
//         try {
//             getAuthenticationContext().acquireToken(
//                     mActivity,
//                     resource,
//                     Constants.AAD_CLIENT_ID,
//                     Constants.AAD_REDIRECT_URL,
//                     PromptBehavior.Auto,
//                     new AuthenticationCallback<AuthenticationResult>() {
//                         @Override
//                         public void onSuccess(AuthenticationResult authenticationResult) {
//                             future.set(authenticationResult.getAccessToken());
//                         }
// 
//                         @Override
//                         public void onError(Exception e) {
//                             future.setException(e);
//                         }
//                     });
//         } catch (Throwable t) {
//             future.setException(t);
//         }
// 
//         return future;
//     }
// 
//     public static ListClient getSharePointListClient(String accessToken) {
//         OAuthCredentials credentials = new OAuthCredentials(accessToken);
//         return new ListClient(Constants.SHAREPOINT_URL, Constants.SHAREPOINT_SITE_PATH, credentials);
//     }
// 
//     private static DependencyResolver getDependencyResolver(final String token) {
//         DefaultDependencyResolver dependencyResolver = new DefaultDependencyResolver(token);
//         dependencyResolver.getLogger().setEnabled(true);
//         dependencyResolver.getLogger().setLogLevel(LogLevel.VERBOSE);
//         return dependencyResolver;
//     }
// 
//     public static IGraphServiceClient getGraphServiceClient(Application app, String token){
//         return new GraphServiceClient
//                 .Builder()
//                 .fromConfig(DefaultClientConfig.createWithAuthenticationProvider(new GraphAuthenticationProvider(app, token)))
//                 .buildClient();
//     }
// 
//     public static SettableFuture<String> getGraphAccessToken(){
//         final SettableFuture<String> future = SettableFuture.create();
//         try {
//             getAuthenticationContext().acquireToken(
//                     mActivity,
//                     Constants.GRAPH_RESOURCE_ID,
//                     Constants.AAD_CLIENT_ID,
//                     Constants.AAD_REDIRECT_URL,
//                     PromptBehavior.Auto,
//                     new AuthenticationCallback<AuthenticationResult>() {
//                         @Override
//                         public void onSuccess(AuthenticationResult authenticationResult) {
//                             future.set(authenticationResult.getAccessToken());
//                         }
// 
//                         @Override
//                         public void onError(Exception e) {
//                             future.setException(e);
//                         }
//                     });
//         } catch (Throwable t) {
//             future.setException(t);
//         }
//         return future;
//     }
// }


// Path: AndroidRepairApp/app/src/main/java/com/canviz/repairapp/SigninActivity.java
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.security.NoSuchAlgorithmException;
import javax.crypto.NoSuchPaddingException;
import com.canviz.repairapp.utility.AuthenticationHelper;
import com.canviz.repairapp.utility.Helper;
import com.microsoft.aad.adal.AuthenticationCallback;
import com.microsoft.aad.adal.AuthenticationContext;
import com.microsoft.aad.adal.AuthenticationResult;
import com.microsoft.aad.adal.PromptBehavior;
import com.microsoft.services.sharepoint.ListClient;

                authenticationResult.getRefreshToken()
        );
        */

        mApp.setUserId(authenticationResult.getUserInfo().getUserId());
        mApp.setToken(authenticationResult.getAccessToken());

        signComplete();
    }

    private void handleError(String errorMessage) {
        new AlertDialog.Builder(this)
                .setTitle("Whoops!")
                .setMessage("Something went wrong: " + errorMessage)
                .setPositiveButton("Ok", null)
                .show();
    }

    private void signComplete(){
        mApp.setSelectedIncidentModel(null);

        Intent incident = new Intent();
        incident.setClass(SigninActivity.this,IncidentActivity.class);
        startActivity(incident);
        finish();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        AuthenticationHelper.getAuthenticationContext().onActivityResult(requestCode, resultCode, data);