fixed choosing/viewing values from sharing tab

This commit is contained in:
Marcin Jedynski 2018-12-08 10:55:53 +01:00
parent f8abf61553
commit 3344449bf4
2 changed files with 15 additions and 3 deletions

View File

@ -143,6 +143,9 @@ public class SharingFragment extends PreferenceFragment {
statusMapping.put(1, "consultation"); statusMapping.put(1, "consultation");
statusMapping.put(2, "busy"); statusMapping.put(2, "busy");
statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext()));
manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext()));
// manualLocationList.setSummary(PrefUtils.getManualLocation(getApplicationContext()));
/** Main sharing switch**/ /** Main sharing switch**/
locationSharing.setOnPreferenceChangeListener((buttonView, newValue) -> { locationSharing.setOnPreferenceChangeListener((buttonView, newValue) -> {
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), (Boolean) newValue); PrefUtils.storeEnableSharingLocalization(getApplicationContext(), (Boolean) newValue);
@ -176,11 +179,12 @@ public class SharingFragment extends PreferenceFragment {
/** Custom manual location list change listener **/ /** Custom manual location list change listener **/
manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> { manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> {
ListPreference lp = (ListPreference) preference; 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); 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.putManualLocation(getApplicationContext(), temp.getGeoData(), temp.getApproximatedLocation() );
PrefUtils.putCurrentManualLocation(getApplicationContext(),temp.getPredefinedCoordinateId()); 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; return true;
}); });
@ -198,7 +202,7 @@ public class SharingFragment extends PreferenceFragment {
ListPreference lp = (ListPreference) preference; ListPreference lp = (ListPreference) preference;
CharSequence[] entries = lp.getEntries(); CharSequence[] entries = lp.getEntries();
PrefUtils.storeStatus(getApplicationContext(), (String) entries[Integer.parseInt((String) newValue)]); PrefUtils.storeStatus(getApplicationContext(), (String) entries[Integer.parseInt((String) newValue)]);
lp.setSummary(entries[Integer.parseInt((String) newValue)]);
return true; return true;
}); });
/** Custom status list change listener **/ /** Custom status list change listener **/

View File

@ -188,5 +188,13 @@ public class PrefUtils {
public static String getCurrentManualLocation(Context context) { public static String getCurrentManualLocation(Context context) {
return getSharedPreferences(context).getString("current_manual_location", null); 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);
}
} }