mobile/android/base/home/SearchLoader.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 package org.mozilla.gecko.home;
     8 import org.mozilla.gecko.db.BrowserDB;
    10 import android.content.Context;
    11 import android.database.Cursor;
    12 import android.os.Bundle;
    13 import android.support.v4.app.LoaderManager;
    14 import android.support.v4.app.LoaderManager.LoaderCallbacks;
    15 import android.support.v4.content.Loader;
    17 /**
    18  * Encapsulates the implementation of the search cursor loader.
    19  */
    20 class SearchLoader {
    21     // Key for search terms
    22     private static final String KEY_SEARCH_TERM = "search_term";
    24     private SearchLoader() {
    25     }
    27     public static Loader<Cursor> createInstance(Context context, Bundle args) {
    28         if (args != null) {
    29             final String searchTerm = args.getString(KEY_SEARCH_TERM);
    30             return new SearchCursorLoader(context, searchTerm);
    31         } else {
    32             return new SearchCursorLoader(context, "");
    33         }
    34     }
    36     private static Bundle createArgs(String searchTerm) {
    37         Bundle args = new Bundle();
    38         args.putString(SearchLoader.KEY_SEARCH_TERM, searchTerm);
    40         return args;
    41     }
    43     public static void init(LoaderManager manager, int loaderId,
    44                                LoaderCallbacks<Cursor> callbacks, String searchTerm) {
    45         final Bundle args = createArgs(searchTerm);
    46         manager.initLoader(loaderId, args, callbacks);
    47     }
    49     public static void restart(LoaderManager manager, int loaderId,
    50                                LoaderCallbacks<Cursor> callbacks, String searchTerm) {
    51         final Bundle args = createArgs(searchTerm);
    52         manager.restartLoader(loaderId, args, callbacks);
    53     }
    55     public static class SearchCursorLoader extends SimpleCursorLoader {
    56         // Max number of search results
    57         private static final int SEARCH_LIMIT = 100;
    59         // The target search term associated with the loader
    60         private final String mSearchTerm;
    62         public SearchCursorLoader(Context context, String searchTerm) {
    63             super(context);
    64             mSearchTerm = searchTerm;
    65         }
    67         @Override
    68         public Cursor loadCursor() {
    69             return BrowserDB.filter(getContext().getContentResolver(), mSearchTerm, SEARCH_LIMIT);
    70         }
    72         public String getSearchTerm() {
    73             return mSearchTerm;
    74         }
    75     }
    77 }

mercurial