Bug 925082 - Open PinSiteDialog with current pinned term. r=wesj
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 04 Nov 2013 14:39:00 -0800
changeset 153502 c90796281722b4e07c4161c0ed59616bd324b822
parent 153501 ceb1e4a434a0fac948edabdd66878a0004dc34dc
child 153503 c7bf717e72b1e1918018d55d4566af42077dae9d
push id35816
push userkwierso@gmail.com
push dateTue, 05 Nov 2013 05:22:53 +0000
treeherdermozilla-inbound@442b47e9fb80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs925082
milestone28.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
Bug 925082 - Open PinSiteDialog with current pinned term. r=wesj
mobile/android/base/home/PinSiteDialog.java
mobile/android/base/home/TopSitesGridView.java
mobile/android/base/home/TopSitesPage.java
--- a/mobile/android/base/home/PinSiteDialog.java
+++ b/mobile/android/base/home/PinSiteDialog.java
@@ -19,16 +19,17 @@ import android.support.v4.content.Loader
 import android.support.v4.widget.CursorAdapter;
 import android.text.Editable;
 import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.WindowManager;
 import android.widget.AdapterView;
 import android.widget.EditText;
 import android.widget.ListView;
 
 /**
  * Dialog fragment that displays frecency search results, for pinning a site, in a GridView.
  */
 class PinSiteDialog extends DialogFragment {
@@ -90,17 +91,18 @@ class PinSiteDialog extends DialogFragme
             }
 
             @Override
             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
             }
 
             @Override
             public void onTextChanged(CharSequence s, int start, int before, int count) {
-                filter(mSearch.getText().toString());
+                setSearchTerm(mSearch.getText().toString());
+                filter(mSearchTerm);
             }
         });
 
         mSearch.setOnKeyListener(new View.OnKeyListener() {
             @Override
             public boolean onKey(View v, int keyCode, KeyEvent event) {
                 if (keyCode != KeyEvent.KEYCODE_ENTER || mOnSiteSelectedListener == null) {
                     return false;
@@ -112,16 +114,25 @@ class PinSiteDialog extends DialogFragme
                 final String url = TopSitesPage.encodeUserEnteredUrl(text);
                 mOnSiteSelectedListener.onSiteSelected(url, text);
 
                 dismiss();
                 return true;
             }
         });
 
+        mSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() {
+            @Override
+            public void onFocusChange(View v, boolean hasFocus) {
+                if (hasFocus) {
+                    getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
+                }
+            }
+        });
+
         mList = (HomeListView) view.findViewById(R.id.list);
         mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                 if (mOnSiteSelectedListener != null) {
                     final Cursor c = mAdapter.getCursor();
                     if (c == null || !c.moveToPosition(position)) {
                         return;
@@ -149,30 +160,33 @@ class PinSiteDialog extends DialogFragme
         mList.setAdapter(mAdapter);
 
         // Create callbacks before the initial loader is started
         mLoaderCallbacks = new CursorLoaderCallbacks();
 
         // Reconnect to the loader only if present
         manager.initLoader(LOADER_ID_SEARCH, null, mLoaderCallbacks);
 
-        // Default filter.
+        // If there is a search term, put it in the text field
+        if (!TextUtils.isEmpty(mSearchTerm)) {
+            mSearch.setText(mSearchTerm);
+            mSearch.selectAll();
+        }
+
+        // Always start with an empty filter
         filter("");
     }
 
+    public void setSearchTerm(String searchTerm) {
+        mSearchTerm = searchTerm;
+    }
+
     private void filter(String searchTerm) {
-        if (!TextUtils.isEmpty(searchTerm) &&
-            TextUtils.equals(mSearchTerm, searchTerm)) {
-            return;
-        }
-
-        mSearchTerm = searchTerm;
-
         // Restart loaders with the new search term
-        SearchLoader.restart(getLoaderManager(), LOADER_ID_SEARCH, mLoaderCallbacks, mSearchTerm);
+        SearchLoader.restart(getLoaderManager(), LOADER_ID_SEARCH, mLoaderCallbacks, searchTerm);
     }
 
     public void setOnSiteSelectedListener(OnSiteSelectedListener listener) {
         mOnSiteSelectedListener = listener;
     }
 
     private static class SearchAdapter extends CursorAdapter {
         private LayoutInflater mInflater;
--- a/mobile/android/base/home/TopSitesGridView.java
+++ b/mobile/android/base/home/TopSitesGridView.java
@@ -31,17 +31,17 @@ import java.util.EnumSet;
  * A grid view of top and pinned sites.
  * Each cell in the grid is a TopSitesGridItemView.
  */
 public class TopSitesGridView extends GridView {
     private static final String LOGTAG = "GeckoTopSitesGridView";
 
     // Listener for editing pinned sites.
     public static interface OnEditPinnedSiteListener {
-        public void onEditPinnedSite(int position);
+        public void onEditPinnedSite(int position, String searchTerm);
     }
 
     // Max number of top sites that needs to be shown.
     private final int mMaxSites;
 
     // Number of columns to show.
     private final int mNumColumns;
 
@@ -111,17 +111,17 @@ public class TopSitesGridView extends Gr
                 // If the url is empty, the user can pin a site.
                 // If not, navigate to the page given by the url.
                 if (!TextUtils.isEmpty(url)) {
                     if (mUrlOpenListener != null) {
                         mUrlOpenListener.onUrlOpen(url, EnumSet.noneOf(OnUrlOpenListener.Flags.class));
                     }
                 } else {
                     if (mEditPinnedSiteListener != null) {
-                        mEditPinnedSiteListener.onEditPinnedSite(position);
+                        mEditPinnedSiteListener.onEditPinnedSite(position, "");
                     }
                 }
             }
         });
 
         setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
             @Override
             public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
--- a/mobile/android/base/home/TopSitesPage.java
+++ b/mobile/android/base/home/TopSitesPage.java
@@ -333,17 +333,18 @@ public class TopSitesPage extends HomeFr
                     BrowserDB.unpinSite(context.getContentResolver(), position);
                 }
             });
 
             return true;
         }
 
         if (itemId == R.id.top_sites_edit) {
-            mEditPinnedSiteListener.onEditPinnedSite(info.position);
+            // Decode "user-entered" URLs before showing them.
+            mEditPinnedSiteListener.onEditPinnedSite(info.position, decodeUserEnteredUrl(info.url));
             return true;
         }
 
         return false;
     }
 
     @Override
     protected void load() {
@@ -377,26 +378,27 @@ public class TopSitesPage extends HomeFr
                                                     OnSiteSelectedListener {
         // Tag for the PinSiteDialog fragment.
         private static final String TAG_PIN_SITE = "pin_site";
 
         // Position of the pin.
         private int mPosition;
 
         @Override
-        public void onEditPinnedSite(int position) {
+        public void onEditPinnedSite(int position, String searchTerm) {
             mPosition = position;
 
             final FragmentManager manager = getActivity().getSupportFragmentManager();
             PinSiteDialog dialog = (PinSiteDialog) manager.findFragmentByTag(TAG_PIN_SITE);
             if (dialog == null) {
                 dialog = PinSiteDialog.newInstance();
             }
 
             dialog.setOnSiteSelectedListener(this);
+            dialog.setSearchTerm(searchTerm);
             dialog.show(manager, TAG_PIN_SITE);
         }
 
         @Override
         public void onSiteSelected(final String url, final String title) {
             final int position = mPosition;
             final Context context = getActivity().getApplicationContext();
             ThreadUtils.postToBackgroundThread(new Runnable() {