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);
}
}
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;
}
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("<", "<");
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;
}
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);
}
Aggregations