From 3344449bf41fbf9953e692853286d9ac46920f29 Mon Sep 17 00:00:00 2001 From: Marcin Jedynski Date: Sat, 8 Dec 2018 10:55:53 +0100 Subject: [PATCH] fixed choosing/viewing values from sharing tab --- .../uam/wmi/findmytutor/activity/SharingFragment.java | 10 +++++++--- .../java/com/uam/wmi/findmytutor/utils/PrefUtils.java | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java index 1b526a9..692c187 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/activity/SharingFragment.java @@ -143,6 +143,9 @@ public class SharingFragment extends PreferenceFragment { statusMapping.put(1, "consultation"); statusMapping.put(2, "busy"); + statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext())); + manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext())); +// manualLocationList.setSummary(PrefUtils.getManualLocation(getApplicationContext())); /** Main sharing switch**/ locationSharing.setOnPreferenceChangeListener((buttonView, newValue) -> { PrefUtils.storeEnableSharingLocalization(getApplicationContext(), (Boolean) newValue); @@ -176,11 +179,12 @@ public class SharingFragment extends PreferenceFragment { /** Custom manual location list change listener **/ manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> { ListPreference lp = (ListPreference) preference; - + CharSequence[] entries = lp.getEntries(); PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter(p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).toList().get(0); - PrefUtils.putManualLocation(getApplicationContext(), temp.getGeoData(), temp.getApproximatedLocation() ); PrefUtils.putCurrentManualLocation(getApplicationContext(),temp.getPredefinedCoordinateId()); + PrefUtils.putCurrentManualLocationName(getApplicationContext(), (String )lp.getEntries()[Integer.parseInt((String) newValue)]); + lp.setSummary(lp.getEntries()[Integer.parseInt((String) newValue)]); return true; }); @@ -198,7 +202,7 @@ public class SharingFragment extends PreferenceFragment { ListPreference lp = (ListPreference) preference; CharSequence[] entries = lp.getEntries(); PrefUtils.storeStatus(getApplicationContext(), (String) entries[Integer.parseInt((String) newValue)]); - + lp.setSummary(entries[Integer.parseInt((String) newValue)]); return true; }); /** Custom status list change listener **/ diff --git a/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java b/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java index b60ffbc..76e281e 100644 --- a/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java +++ b/app/src/main/java/com/uam/wmi/findmytutor/utils/PrefUtils.java @@ -188,5 +188,13 @@ public class PrefUtils { public static String getCurrentManualLocation(Context context) { return getSharedPreferences(context).getString("current_manual_location", null); } + public static void putCurrentManualLocationName(Context context, String locationName) { + SharedPreferences.Editor editor = getSharedPreferences(context).edit(); + editor.putString("current_manual_location_name", locationName); + editor.apply(); + } + public static String getCurrentManualLocationName(Context context) { + return getSharedPreferences(context).getString("current_manual_location_name", null); + } } \ No newline at end of file -- 2.20.1