author | Mark Capella <markcapella@twcny.rr.com> |
Sat, 27 Apr 2013 11:30:05 -0400 | |
changeset 130144 | 8f5c7725deb9935fca434d1ce8edb8edd0d8ee73 |
parent 130143 | dbe8ad85f3596ceeb9b52fc44ed8085eb70e47d6 |
child 130145 | f926fbeab6af4eded7715a169c4e1abecf2d8d03 |
push id | 24599 |
push user | ryanvm@gmail.com |
push date | Sun, 28 Apr 2013 01:24:06 +0000 |
treeherder | mozilla-central@9d8977cbbfc6 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | bnicholson |
bugs | 856558 |
milestone | 23.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
mobile/android/base/AwesomeBar.java | file | annotate | diff | comparison | revisions | |
mobile/android/base/tests/testBookmarksTab.java.in | file | annotate | diff | comparison | revisions |
--- a/mobile/android/base/AwesomeBar.java +++ b/mobile/android/base/AwesomeBar.java @@ -514,16 +514,72 @@ public class AwesomeBar extends GeckoAct @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); AwesomeBarTab tab = mAwesomeTabs.getAwesomeBarTabForView(view); 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) return false; final int id = mContextMenuSubject.id; final String url = mContextMenuSubject.url; final byte[] b = mContextMenuSubject.favicon; @@ -555,18 +611,18 @@ public class AwesomeBar extends GeckoAct editPrompt.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { (new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) { @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; } @Override public void onPostExecute(Void result) { Toast.makeText(AwesomeBar.this, R.string.bookmark_updated, Toast.LENGTH_SHORT).show(); } }).execute(); @@ -577,35 +633,27 @@ public class AwesomeBar extends GeckoAct @Override public void onClick(DialogInterface dialog, int whichButton) { // do nothing } }); final AlertDialog dialog = editPrompt.create(); - // disable OK button if the URL is empty - locationText.addTextChangedListener(new TextWatcher() { - private boolean mEnabled = true; - - @Override - public void afterTextChanged(Editable s) {} - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + // Create our TextWatchers + LocationTextWatcher locationTextWatcher = new LocationTextWatcher(dialog); + KeywordTextWatcher keywordTextWatcher = new KeywordTextWatcher(dialog); - @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; - } - } - }); + // Cross reference the TextWatchers + locationTextWatcher.setPairedTextWatcher(keywordTextWatcher); + keywordTextWatcher.setPairedTextWatcher(locationTextWatcher); + + // Add the TextWatcher Listeners + locationText.addTextChangedListener(locationTextWatcher); + keywordText.addTextChangedListener(keywordTextWatcher); dialog.show(); break; } case R.id.remove_bookmark: { (new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) { private boolean mInReadingList;
--- a/mobile/android/base/tests/testBookmarksTab.java.in +++ b/mobile/android/base/tests/testBookmarksTab.java.in @@ -145,18 +145,18 @@ public class testBookmarksTab extends Ba editBookmark(1,0," Bookmark Name ",list); mAsserter.is(checkBookmarkEdit(1," Bookmark Name ",list), true, "Bookmark Name was changed"); // Test edit bookmark link editBookmark(1,1," Bookmark Link ",list); 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"); child = list.getChildAt(1); mAsserter.ok(child != null, "second list item can be retrieved", child != null ? child.toString() : "null!"); mSolo.clickLongOnView(child); waitForText("Share"); mSolo.clickOnText("Remove");