diff --git a/build.gradle b/build.gradle index e048cd517..bf31068ba 100644 --- a/build.gradle +++ b/build.gradle @@ -70,7 +70,7 @@ allprojects { android { defaultConfig { - versionCode 37 + versionCode 38 versionName "1.1.3" compileSdkVersion 24 diff --git a/res/xml/changelog_master.xml b/res/xml/changelog_master.xml index f12771a0e..0273160c7 100644 --- a/res/xml/changelog_master.xml +++ b/res/xml/changelog_master.xml @@ -1,7 +1,7 @@ - + Remember selected means of transports for each network (Thanks kas70!) Fix problem with NVV/RMV network Prevent crash when turning screen during trip search diff --git a/src/de/grobox/liberario/Preferences.java b/src/de/grobox/liberario/Preferences.java index 9990ff8e7..bba610f93 100755 --- a/src/de/grobox/liberario/Preferences.java +++ b/src/de/grobox/liberario/Preferences.java @@ -23,7 +23,6 @@ import android.support.annotation.Nullable; import android.util.Log; -import java.io.Serializable; import java.util.EnumSet; import java.util.HashSet; import java.util.Set; @@ -33,18 +32,17 @@ public class Preferences { - public final static String PREFS = "LiberarioPrefs"; + private final static String PREFS = "LiberarioPrefs"; public final static String SHOW_ADV_DIRECTIONS = "ShowAdvDirections"; public final static String SORT_RECENT_TRIPS_COUNT = "SortRecentTripsCount"; public final static String THEME = "pref_key_theme"; public final static String LANGUAGE = "pref_key_language"; - public final static String WALK_SPEED = "pref_key_walk_speed"; - public final static String OPTIMIZE = "pref_key_optimize"; - public final static String EXIT_ON_BACK = "pref_key_exit_app_on_back_press"; - + private final static String WALK_SPEED = "pref_key_walk_speed"; + private final static String OPTIMIZE = "pref_key_optimize"; + private final static String EXIT_ON_BACK = "pref_key_exit_app_on_back_press"; private final static String SELECTED_PRODUCTS = "_selected_products"; - public static String getNetwork(Context context, int i) { + private static String getNetwork(Context context, int i) { SharedPreferences settings = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE); String str = ""; @@ -103,12 +101,13 @@ public static void setPref(Context context, String pref, boolean value) { SharedPreferences.Editor editor = settings.edit(); editor.putBoolean(pref, value); - editor.commit(); + editor.apply(); } public static EnumSet getProducts(Context context) { // check if there's a preference for selected products for the current network TransportNetwork current_network = getTransportNetwork(context); + if (current_network == null) return EnumSet.allOf(Product.class); String network_pref = current_network.getId().toString() + SELECTED_PRODUCTS; SharedPreferences sp = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE); // get the selected products from the pref @@ -131,12 +130,13 @@ public static void setProducts(Context context, EnumSet products) { if(products.size() == Product.values().length) return; // get the current network TransportNetwork current_network = getTransportNetwork(context); + if (current_network == null) return; String network_id = current_network.getId().toString(); SharedPreferences sp = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sp.edit(); String network_pref = network_id + SELECTED_PRODUCTS; // store the selected products in a string set - Set product_set = new HashSet(); + Set product_set = new HashSet<>(); for(Product p : products) { product_set.add(p.toString()); } @@ -164,7 +164,7 @@ public static void setNetworkId(Context context, NetworkId id) { editor.putString("NetworkId2", id1); editor.putString("NetworkId", id.name()); - editor.commit(); + editor.apply(); } public static boolean darkThemeEnabled(Context context) {