public static boolean existInFavorites(Context context, MovieEntity entity) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); Set<String> movieFavoritesList = sp.getStringSet(ConstantValues.PREF_MOVIE_FAVORITES, null); if (movieFavoritesList != null && movieFavoritesList.contains(String.valueOf(entity.getId()))) return true; return false; }
public static void removeFromFavorites(Context context, MovieEntity entity) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); Set<String> movieFavoritesList = sp.getStringSet(ConstantValues.PREF_MOVIE_FAVORITES, null); if (movieFavoritesList == null) movieFavoritesList = new TreeSet<String>(); movieFavoritesList.remove(String.valueOf(entity.getId())); sp.edit().putStringSet(ConstantValues.PREF_MOVIE_FAVORITES, movieFavoritesList).apply(); }
public static Intent createShareIntent(Context context, MovieEntity entity) { Activity activity; String message = "Check out " + entity.getTitle() + " at https://www.themoviedb.org/movie/" + String.valueOf(entity.getId()); if (context instanceof Activity) { activity = (android.app.Activity) context; ShareCompat.IntentBuilder intentBuilder = ShareCompat.IntentBuilder.from(activity).setType("text/plain").setText(message); return intentBuilder.getIntent(); } return null; }