use of fr.neamar.kiss.result.Result 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);
}
}
use of fr.neamar.kiss.result.Result in project KISS by Neamar.
the class RecordAdapter method onClick.
public void onClick(final int position, View v) {
final Result result;
try {
result = results.get(position);
result.launch(getContext(), v);
} catch (ArrayIndexOutOfBoundsException ignored) {
return;
}
// Record the launch after some period,
// * to ensure the animation runs smoothly
// * to avoid a flickering -- launchOccurred will refresh the list
// Thus TOUCH_DELAY * 3
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
parent.launchOccurred(results.size() - position, result);
}
}, KissApplication.TOUCH_DELAY * 3);
}
use of fr.neamar.kiss.result.Result 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.result.Result 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