@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case NEW_USER_ACTIVITY_ID: if (resultCode == RESULT_OK) { ParcelableUser parcelableuser = (ParcelableUser) data.getParcelableExtra("user"); User user = parcelableuser.getUser(); DatabaseUser dbuser = new DatabaseUser(this); dbuser.AddUser(user); ((UserArrayAdapter) getListAdapter()).add(user); ((UserArrayAdapter) getListAdapter()).notifyDataSetChanged(); } break; case MOD_USER_ACTIVITY_ID: if (resultCode == RESULT_OK) { ParcelableUser parcelableuser = (ParcelableUser) data.getParcelableExtra("user"); User user = parcelableuser.getUser(); DatabaseUser dbuser = new DatabaseUser(this); dbuser.UpdateUser(user); ((UserArrayAdapter) getListAdapter()).modifyRow(info.position, user); ((UserArrayAdapter) getListAdapter()).notifyDataSetChanged(); } break; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DatabaseUser dbuser = new DatabaseUser(this); userList = dbuser.getAllUser(); setListAdapter(new UserArrayAdapter(this, userList)); // Feliratkozás a hosszú lenyomás hatására előjövő menü kezelésére registerForContextMenu(getListView()); if (userList.size() == 0) { Intent myIntent = new Intent(); myIntent.setClass(UsersActivity.this, AddUserActivity.class); startActivity(myIntent); } }
@Override public boolean onContextItemSelected(MenuItem item) { info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); int menuItemIndex = item.getItemId(); switch (menuItemIndex) { // törlés case 0: { DatabaseUser dbUser = new DatabaseUser(this); User user = (User) getListAdapter().getItem(info.position); dbUser.DeleteUser(user); ((UserArrayAdapter) getListAdapter()) .deleteRow((User) getListAdapter().getItem(info.position)); ((UserArrayAdapter) getListAdapter()).notifyDataSetChanged(); } break; // új case 1: { User newuser = new User(); Intent myIntent = new Intent(); myIntent.setClass(UsersActivity.this, AddUserActivity.class); ParcelableUser parcelableUser = new ParcelableUser(newuser); myIntent.putExtra("user", parcelableUser); startActivityForResult(myIntent, NEW_USER_ACTIVITY_ID); } break; // módosítás case 2: { User moduser = (User) getListAdapter().getItem(info.position); Intent myIntent = new Intent(); myIntent.setClass(UsersActivity.this, AddUserActivity.class); ParcelableUser parcelableUser = new ParcelableUser(moduser); myIntent.putExtra("user", parcelableUser); startActivityForResult(myIntent, MOD_USER_ACTIVITY_ID); } break; default: break; } return true; }
/** * Update of the databaseUser which is specified in parameter * * @param databaseUser The instance of the DatabaseUser which contains the data to store * @param plugin The current plugin using this method * @return The instance of the DatabaseUser which has been updated */ public static DatabaseUser update(DatabaseUser databaseUser, Plugin plugin) { _dao.store(databaseUser, plugin); LuteceUserService.userAttributesChanged(databaseUser.getLogin()); return databaseUser; }
/** * Remove the databaseUser whose identifier is specified in parameter * * @param databaseUser The DatabaseUser object to remove * @param plugin The current plugin using this method */ public static void remove(DatabaseUser databaseUser, Plugin plugin) { _dao.delete(databaseUser, plugin); LuteceUserService.userAttributesChanged(databaseUser.getLogin()); }