diff options
author | Sean Leonard <meanderingcode@aetherislands.net> | 2013-02-07 01:34:49 -0700 |
---|---|---|
committer | Sean Leonard <meanderingcode@aetherislands.net> | 2013-02-07 01:34:49 -0700 |
commit | c107e15a1ca7707a7c2351a3c31f3dbd9f156b73 (patch) | |
tree | c9a818953f06ab574283cf9eb989fd729bb3c810 /src | |
parent | 6e0142a335eafe8a9b0e41b0e968038c0aeabd11 (diff) |
Rearrange singleton Provider.class pattern, Fix isolated SharedPreferences silos
Diffstat (limited to 'src')
-rw-r--r-- | src/se/leap/leapclient/ConfigHelper.java | 1 | ||||
-rw-r--r-- | src/se/leap/leapclient/Dashboard.java | 5 | ||||
-rw-r--r-- | src/se/leap/leapclient/Provider.java | 21 |
3 files changed, 17 insertions, 10 deletions
diff --git a/src/se/leap/leapclient/ConfigHelper.java b/src/se/leap/leapclient/ConfigHelper.java index b2baed67..eded2504 100644 --- a/src/se/leap/leapclient/ConfigHelper.java +++ b/src/se/leap/leapclient/ConfigHelper.java @@ -12,6 +12,7 @@ public class ConfigHelper { final static String provider_key = "provider"; final static String cert_key = "cert"; final static String eip_service_key = "eip"; + public static final String PREFERENCES_KEY = "LEAPPreferences"; static void saveSharedPref(String shared_preferences_key, JSONObject content) { diff --git a/src/se/leap/leapclient/Dashboard.java b/src/se/leap/leapclient/Dashboard.java index c3c6a07f..b6110aac 100644 --- a/src/se/leap/leapclient/Dashboard.java +++ b/src/se/leap/leapclient/Dashboard.java @@ -29,7 +29,7 @@ public class Dashboard extends Activity { super.onCreate(savedInstanceState); setContentView(R.layout.client_dashboard); - preferences = getPreferences(MODE_PRIVATE); + preferences = getSharedPreferences(ConfigHelper.PREFERENCES_KEY,MODE_PRIVATE); // Check if we have preferences, run configuration wizard if not // TODO We should do a better check for config that this! @@ -42,7 +42,8 @@ public class Dashboard extends Activity { private void buildDashboard() { // Get our provider - provider = Provider.getInstance(preferences); + provider = Provider.getInstance(); + provider.init( this ); // Set provider name in textview providerNameTV = (TextView) findViewById(R.id.providerName); diff --git a/src/se/leap/leapclient/Provider.java b/src/se/leap/leapclient/Provider.java index b5e81c9d..4235acfd 100644 --- a/src/se/leap/leapclient/Provider.java +++ b/src/se/leap/leapclient/Provider.java @@ -11,6 +11,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import android.app.Activity; import android.content.SharedPreferences; /** @@ -49,13 +50,24 @@ final class Provider implements Serializable { /** * */ - private Provider(SharedPreferences preferences) { + private Provider() {} + + protected static Provider getInstance(){ + if(instance==null){ + instance = new Provider(); + } + return instance; + } + + protected void init(Activity activity) { // Load our preferences from SharedPreferences // If there's nothing there, we will end up returning a rather empty object // to whoever called getInstance() and they can run the First Run Wizard //preferences = context.getgetPreferences(0); // 0 == MODE_PRIVATE, but we don't extend Android's classes... + // Load SharedPreferences + preferences = activity.getSharedPreferences(ConfigHelper.PREFERENCES_KEY,0); // We don't get MODE_PRIVATE by importing SharedPreferences; i guess it's in Activity? // Inflate our provider.json data try { definition = new JSONObject( preferences.getString("provider", "") ); @@ -66,13 +78,6 @@ final class Provider implements Serializable { } } - protected static Provider getInstance(SharedPreferences preferences){ - if(instance==null){ - instance = new Provider(preferences); - } - return instance; - } - protected String getName(){ // Should we pass the locale in, or query the system here? String lang = Locale.getDefault().getLanguage(); |