include repo name in messages in "App Repo" dialog

This should hopefully make things a little clearer to the user.
This commit is contained in:
Hans-Christoph Steiner 2018-03-29 14:48:21 +02:00
parent 759c3b90fc
commit 89e04cc078
2 changed files with 35 additions and 29 deletions

View File

@ -275,7 +275,7 @@ public class ManageReposActivity extends AppCompatActivity implements LoaderMana
try { try {
url = normalizeUrl(url); url = normalizeUrl(url);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
invalidUrl(); invalidUrl(null);
return; return;
} }
@ -364,69 +364,77 @@ public class ManageReposActivity extends AppCompatActivity implements LoaderMana
final Repo repo = !TextUtils.isEmpty(uri) ? RepoProvider.Helper.findByAddress(context, uri) : null; final Repo repo = !TextUtils.isEmpty(uri) ? RepoProvider.Helper.findByAddress(context, uri) : null;
if (repo == null) { if (repo == null) {
repoDoesntExist(); repoDoesntExist(repo);
} else { } else {
if (repo.isSwap) { if (repo.isSwap) {
repoIsSwap(); repoIsSwap(repo);
} else if (repo.fingerprint == null && fingerprint.length() > 0) { } else if (repo.fingerprint == null && fingerprint.length() > 0) {
upgradingToSigned(); upgradingToSigned(repo);
} else if (repo.fingerprint != null && !repo.fingerprint.equalsIgnoreCase(fingerprint)) { } else if (repo.fingerprint != null && !repo.fingerprint.equalsIgnoreCase(fingerprint)) {
repoFingerprintDoesntMatch(); repoFingerprintDoesntMatch(repo);
} else { } else {
// Could be either an unsigned repo, and no fingerprint was supplied, // Could be either an unsigned repo, and no fingerprint was supplied,
// or it could be a signed repo with a matching fingerprint. // or it could be a signed repo with a matching fingerprint.
if (repo.inuse) { if (repo.inuse) {
repoExistsAndEnabled(); repoExistsAndEnabled(repo);
} else { } else {
repoExistsAndDisabled(); repoExistsAndDisabled(repo);
} }
} }
} }
} }
private void repoDoesntExist() { private void repoDoesntExist(Repo repo) {
updateUi(AddRepoState.DOESNT_EXIST, 0, false, R.string.repo_add_add, true); updateUi(repo, AddRepoState.DOESNT_EXIST, 0, false, R.string.repo_add_add, true);
} }
private void repoIsSwap() { private void repoIsSwap(Repo repo) {
updateUi(AddRepoState.IS_SWAP, 0, false, R.string.repo_add_add, true); updateUi(repo, AddRepoState.IS_SWAP, 0, false, R.string.repo_add_add, true);
} }
/** /**
* Same address with different fingerprint, this could be malicious, so display a message * Same address with different fingerprint, this could be malicious, so display a message
* force the user to manually delete the repo before adding this one. * force the user to manually delete the repo before adding this one.
*/ */
private void repoFingerprintDoesntMatch() { private void repoFingerprintDoesntMatch(Repo repo) {
updateUi(AddRepoState.EXISTS_FINGERPRINT_MISMATCH, R.string.repo_delete_to_overwrite, updateUi(repo, AddRepoState.EXISTS_FINGERPRINT_MISMATCH,
R.string.repo_delete_to_overwrite,
true, R.string.overwrite, false); true, R.string.overwrite, false);
} }
private void invalidUrl() { private void invalidUrl(Repo repo) {
updateUi(AddRepoState.INVALID_URL, R.string.invalid_url, true, updateUi(repo, AddRepoState.INVALID_URL, R.string.invalid_url, true,
R.string.repo_add_add, false); R.string.repo_add_add, false);
} }
private void repoExistsAndDisabled() { private void repoExistsAndDisabled(Repo repo) {
updateUi(AddRepoState.EXISTS_DISABLED, updateUi(repo, AddRepoState.EXISTS_DISABLED,
R.string.repo_exists_enable, false, R.string.enable, true); R.string.repo_exists_enable, false, R.string.enable, true);
} }
private void repoExistsAndEnabled() { private void repoExistsAndEnabled(Repo repo) {
updateUi(AddRepoState.EXISTS_ENABLED, R.string.repo_exists_and_enabled, false, updateUi(repo, AddRepoState.EXISTS_ENABLED, R.string.repo_exists_and_enabled, false,
R.string.ok, true); R.string.ok, true);
} }
private void upgradingToSigned() { private void repoExistsAddMirror(Repo repo) {
updateUi(AddRepoState.EXISTS_UPGRADABLE_TO_SIGNED, R.string.repo_exists_add_fingerprint, updateUi(repo, AddRepoState.EXISTS_ADD_MIRROR, R.string.repo_exists_add_mirror, false,
R.string.repo_add_mirror, true);
}
private void upgradingToSigned(Repo repo) {
updateUi(repo, AddRepoState.EXISTS_UPGRADABLE_TO_SIGNED, R.string.repo_exists_add_fingerprint,
false, R.string.add_key, true); false, R.string.add_key, true);
} }
private void updateUi(AddRepoState state, int messageRes, boolean redMessage, int addTextRes, boolean addEnabled) { @DebugLog
private void updateUi(Repo repo, AddRepoState state, int messageRes, boolean redMessage, int addTextRes,
boolean addEnabled) {
if (addRepoState != state) { if (addRepoState != state) {
addRepoState = state; addRepoState = state;
if (messageRes > 0) { if (messageRes > 0) {
overwriteMessage.setText(messageRes); overwriteMessage.setText(String.format(getString(messageRes), repo.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));

View File

@ -134,12 +134,10 @@ This often occurs with apps installed via Google Play or other sources, if they
<string name="repo_add_url">Repository address</string> <string name="repo_add_url">Repository address</string>
<string name="repo_add_fingerprint">Fingerprint (optional)</string> <string name="repo_add_fingerprint">Fingerprint (optional)</string>
<string name="repo_exists_add_fingerprint">This repo is already setup, this will add new key information.</string> <string name="repo_exists_add_fingerprint">%1$s is already setup, this will add new key information.</string>
<string name="repo_exists_enable">This repo is already setup, confirm that you want to re-enable it.</string> <string name="repo_exists_enable">%1$s is already setup, confirm that you want to re-enable it.</string>
<string name="repo_exists_and_enabled">The incoming repo is already setup and enabled.</string> <string name="repo_exists_and_enabled">%1$s is already setup and enabled.</string>
<string name="repo_delete_to_overwrite">You must first delete this repo before you can add one with a different <string name="repo_delete_to_overwrite">First delete %1$s in order to add this with a conflicting key.</string>
key.
</string>
<string name="bad_fingerprint">Bad fingerprint</string> <string name="bad_fingerprint">Bad fingerprint</string>
<string name="invalid_url">This is not a valid URL.</string> <string name="invalid_url">This is not a valid URL.</string>
<string name="malformed_repo_uri">Ignoring malformed repo URI: %s</string> <string name="malformed_repo_uri">Ignoring malformed repo URI: %s</string>