don't crash in "Add Repo" if an invalid URL is given

Oops, missed this in 89e04cc078bb96a6999ccc4a42f23800272e2be2
This commit is contained in:
Hans-Christoph Steiner 2018-03-30 13:15:41 +02:00
parent 3f3ff5ffd7
commit 06f42f864f

View File

@ -296,7 +296,7 @@ public class ManageReposActivity extends AppCompatActivity
try { try {
url = normalizeUrl(url); url = normalizeUrl(url);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
invalidUrl(null); invalidUrl();
return; return;
} }
@ -411,7 +411,7 @@ public class ManageReposActivity extends AppCompatActivity
} }
if (repo == null) { if (repo == null) {
repoDoesntExist(repo); repoDoesntExist();
} else { } else {
if (repo.isSwap) { if (repo.isSwap) {
repoIsSwap(repo); repoIsSwap(repo);
@ -432,8 +432,8 @@ public class ManageReposActivity extends AppCompatActivity
} }
} }
private void repoDoesntExist(Repo repo) { private void repoDoesntExist() {
updateUi(repo, AddRepoState.DOESNT_EXIST, 0, false, R.string.repo_add_add, true); updateUi(null, AddRepoState.DOESNT_EXIST, 0, false, R.string.repo_add_add, true);
} }
private void repoIsSwap(Repo repo) { private void repoIsSwap(Repo repo) {
@ -450,8 +450,8 @@ public class ManageReposActivity extends AppCompatActivity
true, R.string.overwrite, false); true, R.string.overwrite, false);
} }
private void invalidUrl(Repo repo) { private void invalidUrl() {
updateUi(repo, AddRepoState.INVALID_URL, R.string.invalid_url, true, updateUi(null, AddRepoState.INVALID_URL, R.string.invalid_url, true,
R.string.repo_add_add, false); R.string.repo_add_add, false);
} }
@ -480,8 +480,15 @@ public class ManageReposActivity extends AppCompatActivity
if (addRepoState != state) { if (addRepoState != state) {
addRepoState = state; addRepoState = state;
String name;
if (repo == null) {
name = '"' + getString(R.string.unknown) + '"';
} else {
name = repo.name;
}
if (messageRes > 0) { if (messageRes > 0) {
overwriteMessage.setText(String.format(getString(messageRes), repo.name)); overwriteMessage.setText(String.format(getString(messageRes), name));
overwriteMessage.setVisibility(View.VISIBLE); overwriteMessage.setVisibility(View.VISIBLE);
if (redMessage) { if (redMessage) {
overwriteMessage.setTextColor(getResources().getColor(R.color.red)); overwriteMessage.setTextColor(getResources().getColor(R.color.red));