Search in sources :

Example 1 with Pojo

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

the class AppProvider method getAllApps.

public ArrayList<Pojo> getAllApps() {
    ArrayList<Pojo> records = new ArrayList<>(pojos.size());
    records.trimToSize();
    for (AppPojo pojo : pojos) {
        pojo.displayName = pojo.name;
        pojo.displayTags = pojo.tags;
        records.add(pojo);
    }
    return records;
}
Also used : AppPojo(fr.neamar.kiss.pojo.AppPojo) AppPojo(fr.neamar.kiss.pojo.AppPojo) Pojo(fr.neamar.kiss.pojo.Pojo) ArrayList(java.util.ArrayList)

Example 2 with Pojo

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

the class SettingsProvider method getResults.

public ArrayList<Pojo> getResults(String query) {
    ArrayList<Pojo> results = new ArrayList<>();
    int relevance;
    String settingNameLowerCased;
    for (SettingsPojo setting : pojos) {
        relevance = 0;
        settingNameLowerCased = setting.nameNormalized;
        if (settingNameLowerCased.startsWith(query))
            relevance = 10;
        else if (settingNameLowerCased.contains(" " + query))
            relevance = 5;
        else if (settingName.startsWith(query)) {
            // Also display for a search on "settings" for instance
            relevance = 4;
        }
        if (relevance > 0) {
            setting.displayName = setting.name.replaceFirst("(?i)(" + Pattern.quote(query) + ")", "{$1}");
            setting.relevance = relevance;
            results.add(setting);
        }
    }
    return results;
}
Also used : Pojo(fr.neamar.kiss.pojo.Pojo) SettingsPojo(fr.neamar.kiss.pojo.SettingsPojo) SettingsPojo(fr.neamar.kiss.pojo.SettingsPojo) ArrayList(java.util.ArrayList)

Example 3 with Pojo

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

the class TogglesProvider method getResults.

public ArrayList<Pojo> getResults(String query) {
    ArrayList<Pojo> results = new ArrayList<>();
    int relevance;
    String toggleNameLowerCased;
    for (TogglesPojo toggle : pojos) {
        relevance = 0;
        toggleNameLowerCased = toggle.nameNormalized;
        if (toggleNameLowerCased.startsWith(query))
            relevance = 75;
        else if (toggleNameLowerCased.contains(" " + query))
            relevance = 30;
        else if (toggleNameLowerCased.contains(query))
            relevance = 1;
        else if (toggleName.startsWith(query)) {
            // Also display for a search on "settings" for instance
            relevance = 4;
        }
        if (relevance > 0) {
            toggle.displayName = toggle.name.replaceFirst("(?i)(" + Pattern.quote(query) + ")", "{$1}");
            toggle.relevance = relevance;
            results.add(toggle);
        }
    }
    return results;
}
Also used : Pojo(fr.neamar.kiss.pojo.Pojo) TogglesPojo(fr.neamar.kiss.pojo.TogglesPojo) ArrayList(java.util.ArrayList) TogglesPojo(fr.neamar.kiss.pojo.TogglesPojo)

Example 4 with Pojo

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

the class DataHandler method getFavorites.

/**
     * Return most used items.<br />
     * May return null if no items were ever selected (app first use)
     *
     * @param limit max number of items to retrieve. You may end with less items if favorites contains non existing items.
     * @return favorites' pojo
     */
public ArrayList<Pojo> getFavorites(int limit) {
    ArrayList<Pojo> favorites = new ArrayList<>(limit);
    String favApps = PreferenceManager.getDefaultSharedPreferences(this.context).getString("favorite-apps-list", "");
    List<String> favAppsList = Arrays.asList(favApps.split(";"));
    // Find associated items
    for (int i = 0; i < favAppsList.size(); i++) {
        Pojo pojo = getPojo(favAppsList.get(i));
        if (pojo != null) {
            favorites.add(pojo);
        }
        if (favorites.size() >= limit) {
            break;
        }
    }
    return favorites;
}
Also used : ShortcutsPojo(fr.neamar.kiss.pojo.ShortcutsPojo) Pojo(fr.neamar.kiss.pojo.Pojo) ArrayList(java.util.ArrayList)

Example 5 with Pojo

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

the class MainActivity method displayFavorites.

public void displayFavorites() {
    int[] favoritesIds = favoritesKissBar.getVisibility() == View.VISIBLE ? favsIds : favBarIds;
    ArrayList<Pojo> favoritesPojo = KissApplication.getDataHandler(MainActivity.this).getFavorites(tryToRetrieve);
    if (favoritesPojo.size() == 0) {
        int noFavCnt = prefs.getInt("no-favorites-tip", 0);
        if (noFavCnt < 3 && !prefs.getBoolean("enable-favorites-bar", false)) {
            Toast toast = Toast.makeText(MainActivity.this, getString(R.string.no_favorites), Toast.LENGTH_SHORT);
            toast.show();
            prefs.edit().putInt("no-favorites-tip", ++noFavCnt).apply();
        }
    }
    // Don't look for items after favIds length, we won't be able to display them
    for (int i = 0; i < Math.min(favoritesIds.length, favoritesPojo.size()); i++) {
        Pojo pojo = favoritesPojo.get(i);
        ImageView image = (ImageView) findViewById(favoritesIds[i]);
        Result result = Result.fromPojo(MainActivity.this, pojo);
        Drawable drawable = result.getDrawable(MainActivity.this);
        if (drawable != null) {
            image.setImageDrawable(drawable);
        } else {
            Log.e(TAG, "Falling back to default image for favorite.");
            // Use the default contact image otherwise
            image.setImageResource(R.drawable.ic_contact);
        }
        image.setVisibility(View.VISIBLE);
        image.setContentDescription(pojo.displayName);
    }
    // Hide empty favorites (not enough favorites yet)
    for (int i = favoritesPojo.size(); i < favoritesIds.length; i++) {
        findViewById(favoritesIds[i]).setVisibility(View.GONE);
    }
}
Also used : Pojo(fr.neamar.kiss.pojo.Pojo) Toast(android.widget.Toast) Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView) 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