public void setRole() { Employee e = getTestEmployee(); if (e == null) { return; } final String role = roleSpinner.getSelectedItem().toString(); e.setRole(getRoleFromString(role)); employeeConnector.updateEmployee( e, new EmployeeConnector.EmployeeCallback<Employee>() { @Override public void onServiceSuccess(Employee result, ResultStatus status) { if (status.getStatusCode() / 100 == 2) { toast("Successfully set the test employee role to '" + role + "'."); } else { toast("Unable to set the test employee role: " + status.getStatusMessage()); } } @Override public void onServiceFailure(ResultStatus status) { toast("Unable to set the test employee role: " + status.getStatusMessage()); } }); }
public void setPin() { Employee e = getTestEmployee(); if (e == null) { return; } final String pin = pinEditText.getText().toString().trim(); e.setPin(pin); employeeConnector.updateEmployee( e, new EmployeeConnector.EmployeeCallback<Employee>() { @Override public void onServiceSuccess(Employee result, ResultStatus status) { if (status.getStatusCode() / 100 == 2) { toast("Successfully set the test employee pin to '" + pin + "'."); } else { toast("Unable to set the test employee pin: " + status.getStatusMessage()); } } @Override public void onServiceFailure(ResultStatus status) { toast("Unable to set the test employee pin: " + status.getStatusMessage()); } }); }
private Employee getTestEmployee() { if (employees == null) { toast("Employees have not been loaded."); return null; } for (Employee e : employees) { if (TEST_EMPLOYEE_NAME.equals(e.getName())) { return e; } } toast("Test employee has not been created."); return null; }
private void updateActiveEmployee(String status, ResultStatus resultStatus, Employee result) { statusActiveEmployeeText.setText( "<" + status + " " + (resultStatus != null ? resultStatus : "") + ": " + DateFormat.getDateTimeInstance().format(new Date()) + ">"); if (result == null) { resultActiveEmployeeText.setText("<no active employee>"); } else { resultActiveEmployeeText.setText(result.getName() + ", " + result.getEmail() + "\n"); } }
private void createTestEmployee() { Employee employee = null; employee = new Employee(); employee.setName(TEST_EMPLOYEE_NAME); employee.setNickname("Tester"); employee.setCustomId("test123"); employee.setEmail("*****@*****.**"); employee.setPin("123456"); employee.setRole(AccountRole.EMPLOYEE); employeeConnector.createEmployee( employee, new EmployeeConnector.EmployeeCallback<Employee>() { @Override public void onServiceSuccess(Employee result, ResultStatus status) { if (status.getStatusCode() / 100 != 2) { toast("Unable to create employee: " + status.getStatusMessage()); return; } toast("Successfully created test employee."); } @Override public void onServiceFailure(ResultStatus status) { toast("Unable to create test employee: " + status.getStatusMessage()); } }); }
private void notifyActiveEmployeeChanged(Employee employee) { String msg; if (employee != null) { msg = String.format("Active employee changed: %s (%s)", employee.getName(), employee.getId()); } else { msg = "Employee logged out"; } Notification n = new Notification.Builder(this) .setContentTitle(msg) .setContentText(msg) .setSmallIcon(android.R.drawable.stat_sys_warning) .getNotification(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); n.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, n); }
private void updateEmployees(String status, ResultStatus resultStatus, List<Employee> result) { statusEmployeesText.setText( "<" + status + " " + (resultStatus != null ? resultStatus : "") + ": " + DateFormat.getDateTimeInstance().format(new Date()) + ">"); if (result == null) { resultEmployeesText.setText(""); } else { String employees = ""; for (Employee employee : result) { employees += employee.getName() + ", " + employee.getEmail() + "\n"; } resultEmployeesText.setText(employees); } }
private void deleteTestEmployee() { Employee e = getTestEmployee(); if (e == null) { return; } employeeConnector.deleteEmployee( e.getId(), new EmployeeConnector.EmployeeCallback<Void>() { @Override public void onServiceSuccess(Void result, ResultStatus status) { if (status.getStatusCode() / 100 != 2) { toast("Unable to delete test employee: " + status.getStatusMessage()); } else { toast("Successfully deleted test employee."); } } @Override public void onServiceFailure(ResultStatus status) { toast("Unable to delete test employee: " + status.getStatusMessage()); } }); }