commit c6936875ee48d0358f7c8b502605bffe5b6ddf0c Author: Hashik Donthineni HashikDonthineni@gmail.com Date: Sat Jul 11 00:06:24 2020 +0530
Moved creation of shared preferences to GlobalApplication --- app/src/main/java/org/torproject/snowflake/GlobalApplication.java | 6 ++++++ app/src/main/java/org/torproject/snowflake/MainActivity.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/app/src/main/java/org/torproject/snowflake/GlobalApplication.java b/app/src/main/java/org/torproject/snowflake/GlobalApplication.java index b38393f..6f09db6 100644 --- a/app/src/main/java/org/torproject/snowflake/GlobalApplication.java +++ b/app/src/main/java/org/torproject/snowflake/GlobalApplication.java @@ -16,6 +16,7 @@ public class GlobalApplication extends Application { private final static String BROKER_URL = "http://10.0.2.2:8080"; //10.0.2.2 is used to access computer's local host from Android Emulator. private final static String WEBSOCKET_URL = "wss://snowflake.freehaven.net:443"; private static SharedPreferences sharedPreferences; + private static SharedPreferences appPreferences;
public static String getBrokerUrl() { //Checking to see if the switch is turned on. @@ -48,10 +49,15 @@ public class GlobalApplication extends Application { return map; }
+ public static SharedPreferences getAppPreferences() { + return appPreferences; + } + @Override public void onCreate() { Log.d(TAG, "onCreate: "); super.onCreate(); sharedPreferences = getDefaultSharedPreferences(this); + appPreferences = getSharedPreferences(getString(R.string.sharedpreference_file), MODE_PRIVATE); } } diff --git a/app/src/main/java/org/torproject/snowflake/MainActivity.java b/app/src/main/java/org/torproject/snowflake/MainActivity.java index 1f8070f..dcd3146 100644 --- a/app/src/main/java/org/torproject/snowflake/MainActivity.java +++ b/app/src/main/java/org/torproject/snowflake/MainActivity.java @@ -37,7 +37,7 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb setSupportActionBar(findViewById(R.id.toolbar)); settingsButton = findViewById(R.id.settings_button);
- sharedPreferences = getSharedPreferences(getString(R.string.sharedpreference_file), MODE_PRIVATE); + sharedPreferences = GlobalApplication.getAppPreferences();
//Creating notification channel if app is being run for the first time if (sharedPreferences.getBoolean(getString(R.string.initial_run_boolean), true)) {