Commit e57a93c8 authored by Tanner Grehawick's avatar Tanner Grehawick
Browse files

toast shown when facility is favorited from detail activity as well as in list

parent 383665c8
Pipeline #767 passed with stages
in 4 minutes and 33 seconds
package srct.whatsopen.presenters;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Path;
import android.preference.PreferenceManager;
import android.widget.Toast;
import java.text.ParseException;
import java.text.SimpleDateFormat;
......@@ -12,6 +15,7 @@ import java.util.Date;
import io.realm.Realm;
import io.realm.RealmList;
import srct.whatsopen.R;
import srct.whatsopen.model.Facility;
import srct.whatsopen.model.OpenTimes;
import srct.whatsopen.model.SpecialSchedule;
......@@ -33,6 +37,14 @@ public class FacilityPresenter {
// and updates the favorite status in SharedPreferences
public void toggleFavorite(Facility facility) {
final boolean status = !facility.isFavorited();
Context context = mFacilityView.getContext();
Resources res = context.getResources();
int formatName = status ? R.string.toast_set_favorite : R.string.toast_unset_favorite;
String msg = String.format(res.getString(formatName), facility.getName());
Toast toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
toast.show();
mFacilityView.changeFavoriteIcon(status);
// Get Realm instance and SharedPreferences
......
......@@ -138,12 +138,6 @@ public class FacilityListAdapter extends
@OnClick(R.id.favorite_button)
public void setFavorite() {
mPresenter.toggleFavorite(data);
Context context = getContext();
Resources res = context.getResources();
int formatName = data.isFavorited() ? R.string.toast_unset_favorite : R.string.toast_set_favorite;
String msg = String.format(res.getString(formatName), data.getName());
Toast toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
toast.show();
}
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment