OSDN Git Service

Migrate to AndroidX
[android-x86/packages-apps-Eleven.git] / src / org / lineageos / eleven / ui / activities / SearchActivity.java
index 94dd78f..940be53 100644 (file)
@@ -26,9 +26,6 @@ import android.os.Handler;
 import android.os.IBinder;
 import android.provider.BaseColumns;
 import android.provider.MediaStore;
-import android.support.v4.app.FragmentActivity;
-import android.support.v4.app.LoaderManager.LoaderCallbacks;
-import android.support.v4.content.Loader;
 import android.text.TextUtils;
 import android.view.Menu;
 import android.view.MenuItem;
@@ -46,6 +43,10 @@ import android.widget.ListView;
 import android.widget.SearchView;
 import android.widget.SearchView.OnQueryTextListener;
 
+import androidx.fragment.app.FragmentActivity;
+import androidx.loader.app.LoaderManager;
+import androidx.loader.content.Loader;
+
 import org.lineageos.eleven.Config;
 import org.lineageos.eleven.IElevenService;
 import org.lineageos.eleven.R;
@@ -86,10 +87,15 @@ import static org.lineageos.eleven.utils.MusicUtils.mService;
  * @author Andrew Neal (andrewdneal@gmail.com)
  */
 public class SearchActivity extends FragmentActivity implements
-        LoaderCallbacks<SectionListContainer<SearchResult>>,
+        LoaderManager.LoaderCallbacks<SectionListContainer<SearchResult>>,
         OnScrollListener, OnQueryTextListener, OnItemClickListener, ServiceConnection,
         OnTouchListener {
     /**
+     * Intent extra for identifying the search type to filter for
+     */
+    public static String EXTRA_SEARCH_MODE = "search_mode";
+
+    /**
      * Loading delay of 500ms so we don't flash the screen too much when loading new searches
      */
     private static int LOADING_DELAY = 500;
@@ -267,7 +273,7 @@ public class SearchActivity extends FragmentActivity implements
 
         // Initialize the adapter
         SummarySearchAdapter adapter = new SummarySearchAdapter(this);
-        mAdapter = new SectionAdapter<SearchResult, SummarySearchAdapter>(this, adapter);
+        mAdapter = new SectionAdapter<>(this, adapter);
         // Set the prefix
         mAdapter.getUnderlyingAdapter().setPrefix(mFilterString);
         mAdapter.setupHeaderParameters(R.layout.list_search_header, false);
@@ -308,7 +314,7 @@ public class SearchActivity extends FragmentActivity implements
             mTopLevelSearch = false;
 
             // get the search type to filter by
-            int type = getIntent().getIntExtra(SearchManager.SEARCH_MODE, -1);
+            int type = getIntent().getIntExtra(SearchActivity.EXTRA_SEARCH_MODE, -1);
             if (type >= 0 && type < ResultType.values().length) {
                 mSearchType = ResultType.values()[type];
             }
@@ -395,7 +401,7 @@ public class SearchActivity extends FragmentActivity implements
             comparator = SectionCreatorUtils.createSearchResultComparison(this);
         }
 
-        return new SectionCreator<SearchResult>(this,
+        return new SectionCreator<>(this,
                 new SummarySearchLoader(this, mFilterString, mSearchType),
                 comparator);
     }
@@ -554,9 +560,8 @@ public class SearchActivity extends FragmentActivity implements
      */
     public void setLoading() {
         if (mCurrentState != VisibleState.Loading) {
-            if (!mHandler.hasCallbacks(mLoadingRunnable)) {
-                mHandler.postDelayed(mLoadingRunnable, LOADING_DELAY);
-            }
+            mHandler.removeCallbacks(mLoadingRunnable);
+            mHandler.postDelayed(mLoadingRunnable, LOADING_DELAY);
         }
     }
 
@@ -646,7 +651,7 @@ public class SearchActivity extends FragmentActivity implements
             SearchResult item = mAdapter.getTItem(position - 1);
             Intent intent = new Intent(this, SearchActivity.class);
             intent.putExtra(SearchManager.QUERY, mFilterString);
-            intent.putExtra(SearchManager.SEARCH_MODE, item.mType.ordinal());
+            intent.putExtra(SearchActivity.EXTRA_SEARCH_MODE, item.mType.ordinal());
             startActivity(intent);
         } else {
             SearchResult item = mAdapter.getTItem(position);
@@ -753,7 +758,7 @@ public class SearchActivity extends FragmentActivity implements
          * @return the results for that search
          */
         protected List<SearchResult> runSearchForType() {
-            ArrayList<SearchResult> results = new ArrayList<SearchResult>();
+            ArrayList<SearchResult> results = new ArrayList<>();
             Cursor cursor = null;
             try {
                 if (mSearchType == ResultType.Playlist) {
@@ -799,7 +804,7 @@ public class SearchActivity extends FragmentActivity implements
          * @return the results for that search
          */
         public List<SearchResult> runGenericSearch() {
-            ArrayList<SearchResult> results = new ArrayList<SearchResult>();
+            ArrayList<SearchResult> results = new ArrayList<>();
             // number of types to query for
             final int numTypes = ResultType.getNumTypes();
 
@@ -895,14 +900,12 @@ public class SearchActivity extends FragmentActivity implements
                 keywords[i] = "%" + keywords[i] + "%";
             }
 
-            String where = "";
-
-            // make the where clause
+            final StringBuilder where = new StringBuilder();
             for (int i = 0; i < keywords.length; i++) {
                 if (i == 0) {
-                    where = "name LIKE ?";
+                    where.append("name LIKE ?");
                 } else {
-                    where += " AND name LIKE ?";
+                    where.append(" AND name LIKE ?");
                 }
             }
 
@@ -913,7 +916,7 @@ public class SearchActivity extends FragmentActivity implements
                             BaseColumns._ID,
                         /* 1 */
                             MediaStore.Audio.PlaylistsColumns.NAME
-                    }, where, keywords, MediaStore.Audio.Playlists.DEFAULT_SORT_ORDER);
+                    }, where.toString(), keywords, MediaStore.Audio.Playlists.DEFAULT_SORT_ORDER);
         }
     }
 
@@ -928,7 +931,7 @@ public class SearchActivity extends FragmentActivity implements
         @Override
         public ArrayAdapter<String> loadInBackground() {
             ArrayList<String> strings = SearchHistory.getInstance(getContext()).getRecentSearches();
-            ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),
+            ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(),
                     R.layout.list_item_search_history, R.id.line_one);
             adapter.addAll(strings);
             return adapter;
@@ -938,7 +941,7 @@ public class SearchActivity extends FragmentActivity implements
     /**
      * This handles the Loader callbacks for the search history
      */
-    public class SearchHistoryCallback implements LoaderCallbacks<ArrayAdapter<String>> {
+    public class SearchHistoryCallback implements LoaderManager.LoaderCallbacks<ArrayAdapter<String>> {
         @Override
         public Loader<ArrayAdapter<String>> onCreateLoader(int i, Bundle bundle) {
             // prep the loader in case the query takes a long time