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;
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;
* @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;
// 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);
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];
}
comparator = SectionCreatorUtils.createSearchResultComparison(this);
}
- return new SectionCreator<SearchResult>(this,
+ return new SectionCreator<>(this,
new SummarySearchLoader(this, mFilterString, mSearchType),
comparator);
}
*/
public void setLoading() {
if (mCurrentState != VisibleState.Loading) {
- if (!mHandler.hasCallbacks(mLoadingRunnable)) {
- mHandler.postDelayed(mLoadingRunnable, LOADING_DELAY);
- }
+ mHandler.removeCallbacks(mLoadingRunnable);
+ mHandler.postDelayed(mLoadingRunnable, LOADING_DELAY);
}
}
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);
* @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) {
* @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();
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 ?");
}
}
BaseColumns._ID,
/* 1 */
MediaStore.Audio.PlaylistsColumns.NAME
- }, where, keywords, MediaStore.Audio.Playlists.DEFAULT_SORT_ORDER);
+ }, where.toString(), keywords, MediaStore.Audio.Playlists.DEFAULT_SORT_ORDER);
}
}
@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;
/**
* 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