private void setMasters() {
   if (mSelectedMaster != null) {
     mSelectedMasterView.setText(mSelectedMaster.getName());
     mSelectedSlave = Slave.getSlave(mSelectedMaster.getId(), getArguments().getInt(Slave.ID));
     if (mSelectedSlave != null) {
       mSelectedSlaveView.setText(mSelectedSlave.getName());
     }
   }
   mMasters = Master.getMasters();
   if (mMasters.size() > 0 && mSelectedMaster != null) {
     mSelectedMasterView.setText(mSelectedMaster.getName());
   }
 }
 private void getArgumentsData() {
   mKey = getArguments().getString(Permission.KEY);
   if (mKey != null) {
     mScreenTitle.setText(R.string.edit_virtual_key);
     mDeletePermissionButton.setVisibility(Button.VISIBLE);
   }
   User user = User.getLoggedUser();
   mSelectedMaster = Master.getMaster(getArguments().getString(Master.ID), user.getId());
   String oldSlave = String.valueOf(getArguments().getInt(PERMISSION_OLD_SLAVE, -1));
   mOldSlaveId = Integer.valueOf(oldSlave);
   mPermissionName = getArguments().getString(Permission.NAME);
   if (getArguments().getString(Permission.OBJECT_ID) != null) {
     mToEditPermission = Permission.getPermission(getArguments().getString(Permission.OBJECT_ID));
     String startDate = mToEditPermission.getStartDate();
     String endDate = mToEditPermission.getEndDate();
     if (endDate.equals("0")) endDate = "2016-01-01T00:01";
     mStartHourView.setText(startDate.substring(startDate.indexOf('T') + 1, startDate.length()));
     mEndHourView.setText(endDate.substring(endDate.indexOf('T') + 1, endDate.length()));
     mStartDateView.setText(Permission.getFormattedDate(startDate));
     mEndDateView.setText(Permission.getFormattedDate(endDate));
     mPermissionTypeView.setText(mToEditPermission.getType());
     mSelectedMasterView.setOnClickListener(null);
   } else {
     mStartDateView.setText(Permission.getFormattedDate("2016-01-01T00:01"));
     mEndDateView.setText(Permission.getFormattedDate("2016-01-01T00:01"));
   }
   if (!TextUtils.isEmpty(mPermissionName)) {
     mPermissionEmailView.setText(mPermissionName);
     mPermissionEmailView.setFocusable(false);
   }
 }
 private Slave getAllSlavesRepresentative() {
   return Slave.create(
       mSelectedMaster.getId(),
       getString(R.string.all_slaves),
       0,
       0,
       User.getLoggedUser().getId());
 }
 private void setSlaves() {
   if (mSelectedMaster == null) return;
   mSlaves = new ArrayList<>();
   mSlaves.add(getAllSlavesRepresentative());
   mSlaves.addAll(mSelectedMaster.getSlaves());
   mSelectedSlaveView.setClickable(true);
   mSelectedSlave = mSlaves.get(0);
   mSelectedSlaveView.setText(mSelectedSlave.getName());
 }
 @OnClick(R.id.ok_button)
 public void newPermissionClicked() {
   if (!NetworkingUtils.isOnline(getContext())) {
     Snackbar.make(getView(), R.string.no_internet_connection, Snackbar.LENGTH_LONG).show();
     return;
   }
   User user = User.getUser(mPermissionEmailView.getText().toString());
   if (user == null) {
     Snackbar.make(getView(), getString(R.string.invalid_email), Snackbar.LENGTH_LONG).show();
     return;
   }
   user.saveLocal();
   int slaveId = 0;
   if (mSelectedSlave != null) {
     slaveId = mSelectedSlave.getId();
   }
   if (Permission.getType(mPermissionTypeView.getText().toString()) != Permission.ADMIN_PERMISSION
       && (mSlaves == null || mSlaves.size() == 0)) {
     Snackbar.make(getView(), R.string.master_without_slaves, Snackbar.LENGTH_LONG).show();
     return;
   }
   Permission adminPermission = User.getLoggedUser().getAdminPermission(mSelectedMaster);
   if (adminPermission == null) {
     Snackbar.make(getView(), R.string.you_are_not_admin, Snackbar.LENGTH_LONG).show();
     return;
   }
   String userKey = adminPermission.getKey();
   int permissionType = Permission.getType(mPermissionTypeView.getText().toString());
   String startDate =
       Permission.getDefaultDateString(mStartDateView.getText().toString())
           + "T"
           + mStartHourView.getText().toString();
   String endDate = "0";
   if (permissionType == Permission.TEMPORAL_PERMISSION) {
     endDate =
         Permission.getDefaultDateString(mEndDateView.getText().toString())
             + "T"
             + mEndHourView.getText().toString();
   }
   if (TextUtils.isEmpty(mKey)) {
     Permission permission =
         Permission.create(user, mSelectedMaster, permissionType, "", startDate, endDate, slaveId);
     mPermissionModifiedListener.onCreatePermissionClicked(permission, userKey);
     // If editing permission
   } else {
     mToEditPermission.setType(Permission.getType(mPermissionTypeView.getText().toString()));
     mToEditPermission.setStartDate(startDate);
     mToEditPermission.setEndDate(endDate);
     mToEditPermission.setSlaveId(slaveId);
     mPermissionModifiedListener.onModifyPermissionClicked(
         mToEditPermission, mOldSlaveId, userKey, mSelectedMaster.getId());
   }
 }