@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (data == null) return; if (requestCode == 0) { Initd.write(mEditInitd, data.getCharSequenceExtra(EditorActivity.TEXT_INTENT).toString()); reload(); } else if (requestCode == 1) { Initd.write(mCreateName, data.getCharSequenceExtra(EditorActivity.TEXT_INTENT).toString()); mCreateName = null; reload(); } }
private void load(List<RecyclerViewItem> items) { for (final String initd : Initd.list()) { CardView cardView = new CardView(getActivity()); cardView.setOnMenuListener( new CardView.OnMenuListener() { @Override public void onMenuReady(CardView cardView, PopupMenu popupMenu) { Menu menu = popupMenu.getMenu(); menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.edit)); menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.delete)); popupMenu.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case 0: mEditInitd = initd; Intent intent = new Intent(getActivity(), EditorActivity.class); intent.putExtra(EditorActivity.TITLE_INTENT, initd); intent.putExtra(EditorActivity.TEXT_INTENT, Initd.read(initd)); startActivityForResult(intent, 0); break; case 1: mDeleteDialog = ViewUtils.dialogBuilder( getString(R.string.sure_question), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) {} }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Initd.delete(initd); reload(); } }, new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { mDeleteDialog = null; } }, getActivity()); mDeleteDialog.show(); break; } return false; } }); } }); DescriptionView descriptionView = new DescriptionView(); descriptionView.setSummary(initd); descriptionView.setOnItemClickListener( new RecyclerViewItem.OnItemClickListener() { @Override public void onClick(RecyclerViewItem item) { mExecuteDialog = ViewUtils.dialogBuilder( getString(R.string.exceute_question, initd), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) {} }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { execute(initd); } }, new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { mExecuteDialog = null; } }, getActivity()); mExecuteDialog.show(); } }); cardView.addItem(descriptionView); items.add(cardView); } }