//TODO make sure this doesn't break anything
private void onHeartClicked(MenuItem item) {
        ArrayList favoritesList = null;
        String filename = "favorites.json";
        FileInputStream inputStream = null;
        try {
            inputStream = openFileInput(filename);
            String json = IOUtils.toString(inputStream, "UTF-8");
            Gson gson = new Gson();
            favoritesList = gson.fromJson(json, ArrayList.class);
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if(favoritesList == null) return;
        SharedPreferences sharedPreferences = getSharedPreferences("pref", Context.MODE_PRIVATE);
        Boolean isFavorited = sharedPreferences.getBoolean(stopName + "Favorited", false);
        if (!isFavorited) { //favoriting
            item.setIcon(R.drawable.ic_favorite_white_24dp);
            item.getIcon().setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent), PorterDuff.Mode.SRC_IN);
            favoritesList.add(stopName); //TODO make sure this doesn't break anything
            isFavorited = true;
        } else { //unfavoriting
            item.setIcon(R.drawable.ic_favorite_border_white_24dp);
            item.getIcon().setColorFilter(Color.parseColor("#ffffff"), PorterDuff.Mode.SRC_IN);
            favoritesList.remove(stopName);
            isFavorited = false;
        }
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(stopName + "Favorited", isFavorited);
        editor.putString(stopName, stopId); //Stores stop id value with stopName key
        editor.apply();
        gsonFileUtils.writeListToFile(favoritesList, this);
    }
item.setIcon(R.drawable.ic_favorite_white_24dp);
item.getIcon().setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent), PorterDuff.Mode.SRC_IN);
favoritesList.add(stopName); //TODO make sure this doesn't break anything
isFavorited = true;
} else { //unfavoriting
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
if(favoritesList == null) return;
SharedPreferences sharedPreferences = getSharedPreferences("pref", Context.MODE_PRIVATE);
Boolean isFavorited = sharedPreferences.getBoolean(stopName + "Favorited", false);
if (!isFavorited) { //favoriting
item.setIcon(R.drawable.ic_favorite_white_24dp);
item.getIcon().setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent), PorterDuff.Mode.SRC_IN);
favoritesList.add(stopName); //TODO make sure this doesn't break anything
isFavorited = true;
} else { //unfavoriting
item.setIcon(R.drawable.ic_favorite_border_white_24dp);
item.getIcon().setColorFilter(Color.parseColor("#ffffff"), PorterDuff.Mode.SRC_IN);
favoritesList.remove(stopName);
isFavorited = false;
}
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(stopName + "Favorited", isFavorited);
editor.putString(stopName, stopId); //Stores stop id value with stopName key
private void onHeartClicked(MenuItem item) {
ArrayList favoritesList = null;
String filename = "favorites.json";
FileInputStream inputStream = null;
try {
inputStream = openFileInput(filename);
String json = IOUtils.toString(inputStream, "UTF-8");
Gson gson = new Gson();
favoritesList = gson.fromJson(json, ArrayList.class);
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
if(favoritesList == null) return;
SharedPreferences sharedPreferences = getSharedPreferences("pref", Context.MODE_PRIVATE);
Boolean isFavorited = sharedPreferences.getBoolean(stopName + "Favorited", false);
if (!isFavorited) { //favoriting
item.setIcon(R.drawable.ic_favorite_white_24dp);
item.getIcon().setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent), PorterDuff.Mode.SRC_IN);
favoritesList.add(stopName); //TODO make sure this doesn't break anything
isFavorited = true;
} else { //unfavoriting
item.setIcon(R.drawable.ic_favorite_border_white_24dp);
item.getIcon().setColorFilter(Color.parseColor("#ffffff"), PorterDuff.Mode.SRC_IN);
favoritesList.remove(stopName);
isFavorited = false;
}
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(stopName + "Favorited", isFavorited);
editor.putString(stopName, stopId); //Stores stop id value with stopName key
editor.apply();
gsonFileUtils.writeListToFile(favoritesList, this);
}