Search in sources :

Example 11 with Pojo

use of fr.neamar.kiss.pojo.Pojo in project KISS by Neamar.

the class MainActivity method registerLongClickOnFavorites.

private void registerLongClickOnFavorites() {
    View.OnLongClickListener listener = new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            int favNumber = Integer.parseInt((String) view.getTag());
            ArrayList<Pojo> favorites = KissApplication.getDataHandler(MainActivity.this).getFavorites(tryToRetrieve);
            if (favNumber >= favorites.size()) {
                // Clicking on a favorite before everything is loaded.
                Log.i(TAG, "Long clicking on an unitialized favorite.");
                return false;
            }
            // Favorites handling
            Pojo pojo = favorites.get(favNumber);
            final Result result = Result.fromPojo(MainActivity.this, pojo);
            result.getPopupMenu(MainActivity.this, adapter, view).show();
            return true;
        }
    };
    for (int id : favBarIds) {
        findViewById(id).setOnLongClickListener(listener);
    }
    for (int id : favsIds) {
        findViewById(id).setOnLongClickListener(listener);
    }
}
Also used : Pojo(fr.neamar.kiss.pojo.Pojo) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) BottomPullEffectView(fr.neamar.kiss.ui.BottomPullEffectView) ListView(android.widget.ListView) BlockableListView(fr.neamar.kiss.ui.BlockableListView) SuppressLint(android.annotation.SuppressLint) Result(fr.neamar.kiss.result.Result)

Example 12 with Pojo

use of fr.neamar.kiss.pojo.Pojo in project KISS by Neamar.

the class DataHandler method getHistory.

/**
     * Return previously selected items.<br />
     * May return null if no items were ever selected (app first use)<br />
     * May return an empty set if the providers are not done building records,
     * in this case it is probably a good idea to call this function 500ms after
     *
     * @param context        android context
     * @param itemCount      max number of items to retrieve, total number may be less (search or calls are not returned for instance)
     * @param smartHistory   Recency vs Frecency
     * @param itemsToExclude Items to exclude from history
     * @return pojos in recent history
     */
public ArrayList<Pojo> getHistory(Context context, int itemCount, boolean smartHistory, ArrayList<Pojo> itemsToExclude) {
    // Pre-allocate array slots that are likely to be used based on the current maximum item
    // count
    ArrayList<Pojo> history = new ArrayList<>(Math.min(itemCount, 256));
    // Read history
    List<ValuedHistoryRecord> ids = DBHelper.getHistory(context, itemCount, smartHistory);
    // Find associated items
    for (int i = 0; i < ids.size(); i++) {
        // Ask all providers if they know this id
        Pojo pojo = getPojo(ids.get(i).record);
        if (pojo != null) {
            //Look if the pojo should get excluded
            boolean exclude = false;
            for (int j = 0; j < itemsToExclude.size(); j++) {
                if (itemsToExclude.get(j).id.equals(pojo.id)) {
                    exclude = true;
                    break;
                }
            }
            if (!exclude) {
                history.add(pojo);
            }
        }
    }
    return history;
}
Also used : ShortcutsPojo(fr.neamar.kiss.pojo.ShortcutsPojo) Pojo(fr.neamar.kiss.pojo.Pojo) ValuedHistoryRecord(fr.neamar.kiss.db.ValuedHistoryRecord) ArrayList(java.util.ArrayList)

Example 13 with Pojo

use of fr.neamar.kiss.pojo.Pojo in project KISS by Neamar.

the class DataHandler method getResults.

/**
     * Get records for this query.
     *
     * @param context android context
     * @param query   query to run
     * @return ordered list of records
     */
public ArrayList<Pojo> getResults(Context context, String query) {
    query = query.toLowerCase().trim().replaceAll("<", "&lt;");
    currentQuery = query;
    // Have we ever made the same query and selected something ?
    List<ValuedHistoryRecord> lastIdsForQuery = DBHelper.getPreviousResultsForQuery(context, query);
    HashMap<String, Integer> knownIds = new HashMap<>();
    for (ValuedHistoryRecord id : lastIdsForQuery) {
        knownIds.put(id.record, id.value);
    }
    // Ask all providers for data
    ArrayList<Pojo> allPojos = new ArrayList<>();
    for (ProviderEntry entry : this.providers.values()) {
        if (entry.provider != null) {
            // Retrieve results for query:
            List<Pojo> pojos = entry.provider.getResults(query);
            // Add results to list
            for (Pojo pojo : pojos) {
                // Give a boost if item was previously selected for this query
                if (knownIds.containsKey(pojo.id)) {
                    pojo.relevance += 25 * Math.min(5, knownIds.get(pojo.id));
                }
                allPojos.add(pojo);
            }
        }
    }
    // Sort records according to relevance
    Collections.sort(allPojos, new PojoComparator());
    return allPojos;
}
Also used : ShortcutsPojo(fr.neamar.kiss.pojo.ShortcutsPojo) Pojo(fr.neamar.kiss.pojo.Pojo) HashMap(java.util.HashMap) PojoComparator(fr.neamar.kiss.pojo.PojoComparator) ValuedHistoryRecord(fr.neamar.kiss.db.ValuedHistoryRecord) ArrayList(java.util.ArrayList)

Example 14 with Pojo

use of fr.neamar.kiss.pojo.Pojo in project KISS by Neamar.

the class MainActivity method onFavoriteButtonClicked.

public void onFavoriteButtonClicked(View favorite) {
    // The bar is shown due to dispatchTouchEvent, hide it again to stop the bad ux.
    displayKissBar(false);
    int favNumber = Integer.parseInt((String) favorite.getTag());
    ArrayList<Pojo> favorites = KissApplication.getDataHandler(MainActivity.this).getFavorites(tryToRetrieve);
    if (favNumber >= favorites.size()) {
        // Clicking on a favorite before everything is loaded.
        Log.i(TAG, "Clicking on an unitialized favorite.");
        return;
    }
    // Favorites handling
    Pojo pojo = favorites.get(favNumber);
    final Result result = Result.fromPojo(MainActivity.this, pojo);
    result.fastLaunch(MainActivity.this, favorite);
}
Also used : Pojo(fr.neamar.kiss.pojo.Pojo) SuppressLint(android.annotation.SuppressLint) Result(fr.neamar.kiss.result.Result)

Aggregations

Pojo (fr.neamar.kiss.pojo.Pojo)14 ArrayList (java.util.ArrayList)10 ShortcutsPojo (fr.neamar.kiss.pojo.ShortcutsPojo)4 SuppressLint (android.annotation.SuppressLint)3 AppPojo (fr.neamar.kiss.pojo.AppPojo)3 Result (fr.neamar.kiss.result.Result)3 ImageView (android.widget.ImageView)2 ValuedHistoryRecord (fr.neamar.kiss.db.ValuedHistoryRecord)2 Drawable (android.graphics.drawable.Drawable)1 Pair (android.util.Pair)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 ContactsPojo (fr.neamar.kiss.pojo.ContactsPojo)1 PojoComparator (fr.neamar.kiss.pojo.PojoComparator)1 SearchPojo (fr.neamar.kiss.pojo.SearchPojo)1 SettingsPojo (fr.neamar.kiss.pojo.SettingsPojo)1 TogglesPojo (fr.neamar.kiss.pojo.TogglesPojo)1