Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void addToFavorites(MenuItem item) {
- SharedPreferences sharedPreferences = new SharedPreferences(getApplicationContext());
- sharedPreferences.saveBoolean(title.toLowerCase().replaceAll(" ", "_").trim(), !sharedPreferences.getBoolean(title.toLowerCase().replaceAll(" ", "_").trim(), false));
- if (sharedPreferences.getBoolean(title.toLowerCase().replaceAll(" ", "_").trim(), false)) {
- item.setIcon(getResources().getDrawable(R.drawable.ic_action_favorite));
- Toast.makeText(getApplicationContext(), R.string.added_to_favorites, Toast.LENGTH_SHORT).show();
- }
- else {
- item.setIcon(getResources().getDrawable(R.drawable.ic_action_favorite_outline));
- Toast.makeText(getApplicationContext(), R.string.removed_from_favorites, Toast.LENGTH_SHORT).show();
- }
- MainActivity.updateDrawer(getApplicationContext());
- }
- //Then to loop through the array and check if that item exists in Shared Preferences
- for (int ii = 0; ii < jsonArrayWallpaper.length(); ii++) {
- if (sharedPreferences.getBoolean(jsonArrayWallpaper.getJSONObject(ii).getString("title").toLowerCase().replaceAll(" ", "_").trim(), false)) {
- icon.add(jsonArrayWallpaper.getJSONObject(ii).getString("url"));
- title.add(jsonArrayWallpaper.getJSONObject(ii).getString("title"));
- author.add(jsonArrayWallpaper.getJSONObject(ii).getString("author"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement