Bug 925082 - Open PinSiteDialog with current pinned term. r=wesj, a=bajaj
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 04 Nov 2013 14:39:00 -0800
changeset 166416 2a13504c19cd3aa3f2cb223ec8c5cb01d6564f72
parent 166415 6047fcf502a785b5380330acd4da4bf53b6c6c1d
child 166417 eff86a8b533212258ea55338628c650d9c58125c
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj, bajaj
bugs925082
milestone27.0a2
Bug 925082 - Open PinSiteDialog with current pinned term. r=wesj, a=bajaj
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
@@ -30,17 +30,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;
 
@@ -110,17 +110,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
@@ -348,17 +348,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() {
@@ -392,26 +393,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() {