Пример #1
0
  @Override
  public void onBackPressed() {
    if (!editedReference.isEqual(reference) || rulesChanged()) {
      AlertDialog dialog =
          new AlertDialog.Builder(this)
              .setMessage("Save changes?")
              .setPositiveButton(
                  "Save",
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      if (validateName()) {
                        saveChanges();
                        Navigate.back(AutoPlaylistEditActivity.this);
                      }
                    }
                  })
              .setNegativeButton(
                  "Discard",
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      Navigate.back(AutoPlaylistEditActivity.this);
                    }
                  })
              .setNeutralButton("Cancel", null)
              .show();

      Themes.themeAlertDialog(dialog);
    } else {
      super.onBackPressed();
    }
  }
Пример #2
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.add:
        editedRules.add(new AutoPlaylist.Rule(AutoPlaylist.Rule.EMPTY));
        adapter.notifyItemInserted(editedRules.size());
        return true;
      case R.id.discard:
        if (rulesChanged()) {
          AlertDialog dialog =
              new AlertDialog.Builder(this)
                  .setMessage("Discard changes?")
                  .setPositiveButton(
                      "Discard",
                      new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                          finish();
                        }
                      })
                  .setNegativeButton(R.string.action_cancel, null)
                  .show();

          Themes.themeAlertDialog(dialog);
        } else {
          finish();
        }
        return true;
      case android.R.id.home:
        if (validateName()) {
          if (!editedReference.isEqual(reference) || rulesChanged()) {
            saveChanges();
          }
        } else {
          return true;
        }
        break;
    }
    return super.onOptionsItemSelected(item);
  }