@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 100) { if (resultCode == Constants.Bookmark.ADD) { DbHelper db = new DbHelper(this); Bookmark b = new Bookmark(); b.setName("Create issue at " + mUserLogin + "/" + mRepoName); b.setObjectType(Constants.Bookmark.OBJECT_TYPE_ISSUE); b.setObjectClass(IssueCreateActivity.class.getName()); long id = db.saveBookmark(b); BookmarkParam[] params = new BookmarkParam[2]; BookmarkParam param = new BookmarkParam(); param.setBookmarkId(id); param.setKey(Constants.Repository.REPO_OWNER); param.setValue(mUserLogin); params[0] = param; param = new BookmarkParam(); param.setBookmarkId(id); param.setKey(Constants.Repository.REPO_NAME); param.setValue(mRepoName); params[1] = param; db.saveBookmarkParam(params); } } }
private void fillData() { final DbHelper db = new DbHelper(this); ListView listView = (ListView) findViewById(R.id.list_view); listView.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { Bookmark b = (Bookmark) adapterView.getAdapter().getItem(position); if (position == 0) { setResult(Constants.Bookmark.ADD, null); Toast.makeText( BookmarkListActivity.this, getResources().getString(R.string.bookmark_saved), Toast.LENGTH_LONG) .show(); finish(); } else { List<BookmarkParam> params = db.findBookmarkParams(b.getId()); Intent intent; try { intent = new Intent() .setClass(BookmarkListActivity.this, Class.forName(b.getObjectClass())); for (BookmarkParam param : params) { try { int v = Integer.parseInt(param.getValue()); intent.putExtra(param.getKey(), v); } catch (NumberFormatException e) { intent.putExtra(param.getKey(), param.getValue()); } } startActivity(intent); } catch (ClassNotFoundException e) { Log.e(Constants.LOG_TAG, e.getMessage(), e); } } } }); listView.setOnItemLongClickListener( new OnItemLongClickListener() { @Override public boolean onItemLongClick( AdapterView<?> adapterView, View view, int position, long id) { if (position != 0) { final Bookmark b = (Bookmark) adapterView.getAdapter().getItem(position); AlertDialog.Builder builder = new AlertDialog.Builder(BookmarkListActivity.this); builder.setTitle(R.string.remove_bookmark); builder.setIcon(android.R.drawable.ic_dialog_alert); builder .setMessage(R.string.remove_bookmark_confirm) .setCancelable(false) .setPositiveButton( "Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); db.deleteBookmark(b.getId()); fillData(); } }) .setNegativeButton( "No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); } return false; } }); BookmarkAdapter adapter = new BookmarkAdapter(this, new ArrayList<Bookmark>(), mHideAdd); listView.setAdapter(adapter); List<Bookmark> list = db.findAllBookmark(); Bookmark newBookmark = new Bookmark(); newBookmark.setName(mName); newBookmark.setObjectType(mObjectType); adapter.add(newBookmark); for (Bookmark b : list) { adapter.add(b); adapter.notifyDataSetChanged(); } }