- builder.setPositiveButton(R.string.Remove, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Log.d("profiles",
- String.format("[fragment] removing profile %s", mProfile.getUuid()));
- mProfile.removeFromDB();
- Data.profiles.remove(mProfile);
- if (Data.profile.get().equals(mProfile)) {
- Log.d("profiles", "[fragment] setting current profile to 0");
- Data.setCurrentProfile(Data.profiles.get(0));
- }
- getActivity().finish();
+ builder.setPositiveButton(R.string.Remove, (dialog, which) -> {
+ debug("profiles",
+ String.format("[fragment] removing profile %s", mProfile.getUuid()));
+ mProfile.removeFromDB();
+ ArrayList<MobileLedgerProfile> oldList = Data.profiles.getValue();
+ if (oldList == null) throw new AssertionError();
+ ArrayList<MobileLedgerProfile> newList =
+ (ArrayList<MobileLedgerProfile>) oldList.clone();
+ newList.remove(mProfile);
+ Data.profiles.setValue(newList);
+ if (mProfile.equals(Data.profile.getValue())) {
+ debug("profiles", "[fragment] setting current profile to 0");
+ Data.setCurrentProfile(newList.get(0));