public void requestNext(BaseContainer view) { BaseContainer container = (BaseContainer) view.getParent().getParent(); if (container instanceof Todo) { int index = this.indexOfChild(container); this.addTodoOn(index + 1); } if (container instanceof Item) { int index = this.indexOfChild(container); this.addItemOn(index + 1); } }
public void requestDelete(BaseContainer view) { try { // For list items, getParent twice will get its BaseContainer. if (view.getParent().getParent() instanceof BaseContainer) { BaseContainer container = (BaseContainer) view.getParent().getParent(); int index = this.indexOfChild(container); // if (index < 1){ // return; // } // final BaseContainer toDel = (BaseContainer) this.getChildAt(index - 1); // if (container.getType() == Constants.TYPE_TODO && toDel.getType() == // Constants.TYPE_TODO){ // this.removeView(toDel); // } else { this.removeView((View) view.getParent().getParent()); this.addView(new Text(getContext()), index); // } return; } } catch (NullPointerException e) { // Eat it. } int index = this.indexOfChild(view); if (index < 1) { return; } final BaseContainer toDel = (BaseContainer) this.getChildAt(index - 1); if (toDel.getType() == Constants.TYPE_TEXT && toDel.isEmpty()) { removeView(toDel); return; } if (view.getType() == Constants.TYPE_TEXT && view.isEmpty() && index != getChildCount() - 1) { removeView(view); return; } if (toDel.getType() == Constants.TYPE_TODO) { removeView(toDel); return; } String which = null; switch (toDel.getType()) { case Constants.TYPE_IMAGE: which = "Image"; break; case Constants.TYPE_ATT: which = "File"; break; case Constants.TYPE_REC: which = "Voice"; break; } if (which == null) { return; } new AlertDialog.Builder(getContext()) .setTitle("Confirm") .setMessage("Delete " + which + " ?") .setPositiveButton( "Sure", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { EditView.this.removeView(toDel); dialog.dismiss(); } }) .setNegativeButton( "No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .create() .show(); }