mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 06:35:42 +00:00
Bug 856558 - Prevent Bookmark keywords from including spaces, r=bnicholson, f=mfinkle
This commit is contained in:
parent
51646063e8
commit
9f0dd7af86
@ -519,6 +519,62 @@ public class AwesomeBar extends GeckoActivity
|
||||
mContextMenuSubject = tab.getSubject(menu, view, menuInfo);
|
||||
}
|
||||
|
||||
private abstract class EditBookmarkTextWatcher implements TextWatcher {
|
||||
protected AlertDialog mDialog;
|
||||
protected EditBookmarkTextWatcher mPairedTextWatcher;
|
||||
protected boolean mEnabled = true;
|
||||
|
||||
public EditBookmarkTextWatcher(AlertDialog aDialog) {
|
||||
mDialog = aDialog;
|
||||
}
|
||||
|
||||
public void setPairedTextWatcher(EditBookmarkTextWatcher aTextWatcher) {
|
||||
mPairedTextWatcher = aTextWatcher;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return mEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// Disable if the we're disabled or paired partner is disabled
|
||||
boolean enabled = mEnabled && (mPairedTextWatcher == null || mPairedTextWatcher.isEnabled());
|
||||
mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {}
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
}
|
||||
|
||||
private class LocationTextWatcher extends EditBookmarkTextWatcher implements TextWatcher {
|
||||
public LocationTextWatcher(AlertDialog aDialog) {
|
||||
super(aDialog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// Disable if the location is empty
|
||||
mEnabled = (s.toString().trim().length() > 0);
|
||||
super.onTextChanged(s, start, before, count);
|
||||
}
|
||||
}
|
||||
|
||||
private class KeywordTextWatcher extends EditBookmarkTextWatcher implements TextWatcher {
|
||||
public KeywordTextWatcher(AlertDialog aDialog) {
|
||||
super(aDialog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// Disable if the keyword contains spaces
|
||||
mEnabled = (s.toString().trim().indexOf(' ') == -1);
|
||||
super.onTextChanged(s, start, before, count);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
if (mContextMenuSubject == null)
|
||||
@ -560,8 +616,8 @@ public class AwesomeBar extends GeckoActivity
|
||||
@Override
|
||||
public Void doInBackground(Void... params) {
|
||||
String newUrl = locationText.getText().toString().trim();
|
||||
BrowserDB.updateBookmark(getContentResolver(), id, newUrl, nameText.getText().toString(),
|
||||
keywordText.getText().toString());
|
||||
String newKeyword = keywordText.getText().toString().trim();
|
||||
BrowserDB.updateBookmark(getContentResolver(), id, newUrl, nameText.getText().toString(), newKeyword);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -582,25 +638,17 @@ public class AwesomeBar extends GeckoActivity
|
||||
|
||||
final AlertDialog dialog = editPrompt.create();
|
||||
|
||||
// disable OK button if the URL is empty
|
||||
locationText.addTextChangedListener(new TextWatcher() {
|
||||
private boolean mEnabled = true;
|
||||
// Create our TextWatchers
|
||||
LocationTextWatcher locationTextWatcher = new LocationTextWatcher(dialog);
|
||||
KeywordTextWatcher keywordTextWatcher = new KeywordTextWatcher(dialog);
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {}
|
||||
// Cross reference the TextWatchers
|
||||
locationTextWatcher.setPairedTextWatcher(keywordTextWatcher);
|
||||
keywordTextWatcher.setPairedTextWatcher(locationTextWatcher);
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
boolean enabled = (s.toString().trim().length() > 0);
|
||||
if (mEnabled != enabled) {
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(enabled);
|
||||
mEnabled = enabled;
|
||||
}
|
||||
}
|
||||
});
|
||||
// Add the TextWatcher Listeners
|
||||
locationText.addTextChangedListener(locationTextWatcher);
|
||||
keywordText.addTextChangedListener(keywordTextWatcher);
|
||||
|
||||
dialog.show();
|
||||
break;
|
||||
|
@ -150,8 +150,8 @@ public class testBookmarksTab extends BaseTest {
|
||||
mAsserter.is(checkBookmarkEdit(1,"Bookmark Link",list), true, "Bookmark Link was changed");
|
||||
|
||||
// Test edit bookmark keyword
|
||||
editBookmark(1,2," Bookmark Keyword ",list);
|
||||
mAsserter.is(checkBookmarkEdit(1,"Bookmark Keyword",list), true, "Bookmark Keyword was changed");
|
||||
editBookmark(1,2," BookmarkKeyword ",list);
|
||||
mAsserter.is(checkBookmarkEdit(1,"BookmarkKeyword",list), true, "Bookmark Keyword was changed");
|
||||
|
||||
// Remove Bookmark from Context Menu
|
||||
waitForText("Bookmarks");
|
||||
|
Loading…
Reference in New Issue
Block a user