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; }
public static boolean addMovieToFavorites( Context context, IMoviesRepository repository, MovieEntity entity, boolean favorite) { entity.setFavorite(favorite); ConstantValues.FAVORITE_MOVIES_SUBJECT.onNext(new MovieIdFavorite(entity, favorite)); if (favorite) { repository.add(entity); addToFavorites(context, entity); return true; } else { repository.remove(entity); removeFromFavorites(context, entity); return false; } }