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);
    }
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) {
            item.setIcon(R.drawable.ic_favorite_white_24dp);
            item.getIcon().setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent), PorterDuff.Mode.SRC_IN);
            favoritesList.add(stopName);
            isFavorited = true;
        } else {
            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);
        editor.apply();
        gsonFileUtils.writeListToFile(favoritesList, this);
    }
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) { item.seticon(r.drawable.ic_favorite_white_24dp); item.geticon().setcolorfilter(contextcompat.getcolor(getapplicationcontext(), r.color.coloraccent), porterduff.mode.src_in); favoriteslist.add(stopname); isfavorited = true; } else { 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); editor.apply(); gsonfileutils.writelisttofile(favoriteslist, this); }