Example 1 - Logging In


// You define your own login method
public void loginWithEmail(String email, String password) {

    // Call the BringgDriverSDK method "loginWithCredentials"
	// The last parameter is a LoginCallback callback interface
    bringgSDKClient.loginWithEmail(email, password, null, "us", 

		// Implement a new instance of the LoginCallback callback interface
		new LoginCallback() {

                // If the login fails, then onLoginFailed is invoked
                @Override
                public void onLoginFailed() {
                    // Add your own code to handle login failure events
                }

                // If the login is canceled, then onLoginCanceled is invoked
                @Override
                public void onLoginCanceled() {
                    // Add your own code to handle login cancellation events
                }

                // If the login succeeds, then onLoginSuccess is invoked
                @Override
                public void onLoginSuccess() {
                    // Add your own code to handle login succeeds events.
					
                    // For example, start an activity
                    startActivity(new Intent(LoginActivity.this, MainActivity.class));
					
                    // Then do a finish.
                    finish();
                }
            });
}

Example 2 - Fetching Tasks from the Server

// You define your own fetch the driver's tasks list from the server method
// If the fetch succeeds, get tasks
// If the fetch fails, handle the error
public void fetchTasksFromServer() {
	
	// Call the BringgDriverSDK method "refreshTasks"
	// The parameter is a RefreshTasksResultCallback callback interface
    bringgSDKClient.refreshTasks(
	
		// Implement a new instance of StartShiftResultCallback
		new RefreshTasksResultCallback() {
		
			// If the refresh fails, then onRefreshTasksFailure is invoked
			@Override
			public void onRefreshTasksFailure(int error) {
				
				// Handle the error
				switch (error) {
					case RefreshTasksResultCallback.ERROR_CODE_PENDING_REQUEST:
						// Already waiting for the tasks to return from server
						break;
					case RefreshTasksResultCallback.ERROR_CODE_TOO_MANY_ATTEMPTS:
						// Requested too many times in a short period of time. Wait before next attempt.
						break;
					case RefreshTasksResultCallback.ERROR_CODE_NO_RESULT:
						// Failed to get tasks. Attempt to get task later.
						break;
				}
			}

			// If the refresh succeeds, then onRefreshTasksSuccess is invoked
			@Override
			public void onRefreshTasksSuccess(OpenTasksResult openTasksResult) {
				// If the tasks list can be referenced
				if (openTasksResult.isSuccess()) {
					List<Task> taskList = openTasksResult.getTasks();
					// You own code to use the tasks list
				}
			}
    });
}

Example 3 - Shifts, Init App, and Fetch Tasks Combined

// You define your own start a shift method.
// If the shift starts successfully, 
//    initializes the state of your app and fetch the driver's tasks list
// If the shift fails to start, handle the error
public void startShiftAndInitState() {

	// Call the BringgDriverSDK method "startShiftAndWaitForApproval"
	// The last parameter is a StartShiftResultCallback callback interface
    bringgSDKClient.startShiftAndWaitForApproval(false, 
	
		// Implement a new instance of StartShiftResultCallback
		new StartShiftResultCallback() {
			
			// If the shift start fails, then onShiftStartFailed is invoked
			@Override
			public void onShiftStartFailed(int error) {
				
				// Handle each type of error.
				switch (error) {
					// Your code for each type of error.
				}
			}

			// If the shift start succeeds, then onShiftStarted is invoked
			@Override
			public void onShiftStarted() {
				// Fetch the tasks from the server                    
				fetchTasksFromServer();
			}
		}
    );
}

Example App

For additional examples and capabilities, see out our example app at https://github.com/bringg/ExampleApp-Android