OSDN Git Service

cmfm: properly fill all searchable data on restoration
authorJorge Ruesga <jorge@ruesga.com>
Sun, 7 Sep 2014 19:33:54 +0000 (21:33 +0200)
committerJorge Ruesga <jorge@ruesga.com>
Sun, 7 Sep 2014 19:33:54 +0000 (21:33 +0200)
Also cache search title and improve restoration doing Query a parcelable class
JIRA: BUGDUMP-21247
https://jira.cyanogenmod.org/browse/BUGDUMP-21247

Change-Id: I2a13d569affcf53ed8f2c38aeb251aa14e3cd431
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
src/com/cyanogenmod/filemanager/activities/SearchActivity.java
src/com/cyanogenmod/filemanager/model/Query.java
src/com/cyanogenmod/filemanager/parcelables/SearchInfoParcelable.java

index d09dcbf..4fbbec5 100644 (file)
@@ -748,6 +748,9 @@ public class SearchActivity extends Activity
                     SearchActivity.this.mSearchListView.setAdapter(adapter);
                     SearchActivity.this.mSearchListView.setSelection(0);
 
+                    SearchActivity.this.mQuery = query;
+                    SearchActivity.this.mSearchDirectory = mRestoreState.getSearchDirectory();
+
                 } catch (Throwable ex) {
                     //Capture the exception
                     ExceptionUtil.translateException(SearchActivity.this, ex);
index abda132..612bd68 100644 (file)
@@ -16,6 +16,8 @@
 
 package com.cyanogenmod.filemanager.model;
 
+import android.os.Parcel;
+import android.os.Parcelable;
 import android.text.TextUtils;
 
 import java.io.Serializable;
@@ -26,9 +28,9 @@ import java.util.List;
  * A class that restrict the number of queries that can
  * be made to the application search system.
  */
-public class Query implements Serializable {
+public class Query implements Serializable, Parcelable {
 
-    private static final long serialVersionUID = 3485374541081012723L;
+    private static final long serialVersionUID = 638590514968634860L;
 
     //IMP! This need to be sync which the command_list.xml resource
     //to have the same slots as the filled for the find command
@@ -44,6 +46,15 @@ public class Query implements Serializable {
     }
 
     /**
+     * Constructor of <code>Query</code>.
+     *
+     * @param in The parcel information
+     */
+    public Query(Parcel in) {
+        readFromParcel(in);
+    }
+
+    /**
      * Method that returns the value of an slot.
      *
      * @param slot The slot number
@@ -120,4 +131,60 @@ public class Query implements Serializable {
         }
         return terms;
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeStringArray(this.mQUERIES);
+    }
+
+    /**
+     * Fill the object from the parcel information.
+     *
+     * @param in The parcel information to recreate the object
+     */
+    private void readFromParcel(Parcel in) {
+        String[] queries = in.readStringArray();
+        if (queries != null) {
+            int  count = Math.min(SLOTS_COUNT, queries.length);
+            for (int i = 0; i < count; i++) {
+                mQUERIES[i] = queries[i];
+            }
+        }
+    }
+
+    /**
+     * The {@link android.os.Parcelable.Creator}.
+     *
+     * This field is needed for Android to be able to
+     * create new objects, individually or as arrays.
+     */
+    public static final Parcelable.Creator<Query> CREATOR =
+            new Parcelable.Creator<Query>() {
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public Query createFromParcel(Parcel in) {
+            return new Query(in);
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public Query[] newArray(int size) {
+            return new Query[size];
+        }
+    };
 }
index f9e264b..a6da308 100644 (file)
@@ -37,6 +37,7 @@ public class SearchInfoParcelable extends HistoryNavigable {
     private String mSearchDirectory;
     private List<SearchResult> mSearchResultList;
     private Query mSearchQuery;
+    private String mTitle;
     private boolean mSuccessNavigation = false;
 
     /**
@@ -44,6 +45,7 @@ public class SearchInfoParcelable extends HistoryNavigable {
      */
     public SearchInfoParcelable() {
         super();
+        setTitle();
     }
 
     /**
@@ -60,11 +62,16 @@ public class SearchInfoParcelable extends HistoryNavigable {
      */
     @Override
     public String getTitle() {
-        return FileManagerApplication.getInstance().
-                    getResources().
-                        getString(
-                            R.string.search_result_name,
-                            this.mSearchQuery.getTerms());
+        return mTitle;
+    }
+
+    private void setTitle() {
+        String terms = "";
+        if (this.mSearchQuery != null) {
+            terms = this.mSearchQuery.getTerms();
+        }
+        mTitle = FileManagerApplication.getInstance().getResources().getString(
+                R.string.search_result_name, terms);
     }
 
     /**
@@ -127,6 +134,7 @@ public class SearchInfoParcelable extends HistoryNavigable {
      */
     public void setSearchQuery(Query searchQuery) {
         this.mSearchQuery = searchQuery;
+        setTitle();
     }
 
     /**
@@ -173,7 +181,7 @@ public class SearchInfoParcelable extends HistoryNavigable {
         //- 2
         dest.writeInt(this.mSearchQuery == null ? 0 : 1);
         if (this.mSearchQuery != null) {
-            dest.writeSerializable(this.mSearchQuery);
+            dest.writeParcelable(this.mSearchQuery, 0);
         }
         //- 3
         dest.writeInt(this.mSuccessNavigation ? 1 : 0);
@@ -200,8 +208,9 @@ public class SearchInfoParcelable extends HistoryNavigable {
         //- 2
         int hasSearchQuery = in.readInt();
         if (hasSearchQuery == 1) {
-            this.mSearchQuery = (Query)in.readSerializable();
+            this.mSearchQuery = (Query)in.readParcelable(getClass().getClassLoader());
         }
+        setTitle();
         //- 3
         this.mSuccessNavigation = in.readInt() != 1;
     }