Пример #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 void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_instance_no_miniplayer);

    reference = getIntent().getParcelableExtra(PLAYLIST_EXTRA);
    if (reference == null) {
      reference = AutoPlaylist.EMPTY;
    }

    if (savedInstanceState != null) {
      editedReference = savedInstanceState.getParcelable(EDITED_HEADER);
      editedRules = savedInstanceState.getParcelableArrayList(EDITED_RULES);
    }

    if (editedReference == null || editedRules == null) {
      editedReference = new AutoPlaylist(reference);
      editedRules = new ArrayList<>(reference.getRules().length);
      Collections.addAll(editedRules, editedReference.getRules());
    }

    if (getSupportActionBar() != null) {
      if (reference == null) {
        getSupportActionBar().setTitle(R.string.playlist_auto_new);
      } else {
        getSupportActionBar().setTitle(reference.getPlaylistName());
      }
      getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_done_24dp);
    }

    adapter =
        new HeterogeneousAdapter()
            .addSection(new RuleHeaderSingleton(editedReference))
            .addSection(new RuleSection(editedRules, this));

    RecyclerView list = (RecyclerView) findViewById(R.id.list);
    list.setAdapter(adapter);
    list.setLayoutManager(new LinearLayoutManager(this));
    list.addItemDecoration(new BackgroundDecoration(Themes.getBackgroundElevated()));
    list.addItemDecoration(new DividerDecoration(this));
  }
Пример #3
0
 @Override
 public void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   outState.putParcelable(EDITED_HEADER, editedReference);
   outState.putParcelableArrayList(EDITED_RULES, editedRules);
 }