import org.jetbrains.annotations.NotNull;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Objects;
String.format("[fragment] removing profile %s", mProfile.getUuid()));
mProfile.removeFromDB();
ArrayList<MobileLedgerProfile> oldList = Data.profiles.getValue();
- assert oldList != null;
+ if (oldList == null) throw new AssertionError();
ArrayList<MobileLedgerProfile> newList =
(ArrayList<MobileLedgerProfile>) oldList.clone();
newList.remove(mProfile);
int index = Data.getProfileIndex(mProfile);
MobileLedgerProfile newProfile = new MobileLedgerProfile(mProfile);
final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
- assert profiles != null;
+ if (profiles == null) throw new AssertionError();
profiles.set(index, newProfile);
+
+ ProfilesRecyclerViewAdapter prva = ProfilesRecyclerViewAdapter.getInstance();
+ if (prva != null) prva.notifyItemChanged(index);
+
if (mProfile.equals(Data.profile.getValue())) Data.profile.setValue(newProfile);
}
@Override
updateProfileFromUI();
mProfile.storeInDB();
final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
- assert profiles != null;
+ if (profiles == null) throw new AssertionError();
ArrayList<MobileLedgerProfile> newList =
(ArrayList<MobileLedgerProfile>) profiles.clone();
newList.add(mProfile);
profileNameLayout.setError(getResources().getText(R.string.err_profile_name_empty));
}
- val = String.valueOf(url.getText());
- if (val.trim().isEmpty()) {
+ val = String.valueOf(url.getText()).trim();
+ if (val.isEmpty()) {
valid = false;
urlLayout.setError(getResources().getText(R.string.err_profile_url_empty));
}
+ try {
+ URL url = new URL(val);
+ String host = url.getHost();
+ if (host == null || host.isEmpty()) throw new MalformedURLException("Missing host");
+ }
+ catch (MalformedURLException e) {
+ valid = false;
+ urlLayout.setError(getResources().getText(R.string.err_invalid_url));
+ }
if (useAuthentication.isChecked()) {
val = String.valueOf(userName.getText());
if (val.trim().isEmpty()) {