Verified Commit dafed99d authored by HashikD's avatar HashikD
Browse files

Moved and renamed String.xml SharedPreference keys

parent 689949d2
......@@ -58,17 +58,17 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
.observeOn(AndroidSchedulers.mainThread())
.subscribe((status) -> { //Runs on main thread
//By this point the servedCount must be reset or left as is after checking the dates.
servedCount = sharedPreferences.getInt(getString(R.string.users_served), 0);
servedCount = sharedPreferences.getInt(getString(R.string.users_served_key), 0);
setListenerForCount();
updateCountInFragment();
});
//Creating notification channel if app is being run for the first time
if (sharedPreferences.getBoolean(getString(R.string.initial_run_boolean), true)) {
if (sharedPreferences.getBoolean(getString(R.string.initial_run_boolean_key), true)) {
createNotificationChannel();
//Setting initial run to false.
sharedPreferences.edit().putBoolean(getString(R.string.initial_run_boolean), false).apply();
sharedPreferences.edit().putBoolean(getString(R.string.initial_run_boolean_key), false).apply();
}
settingsButton.setOnClickListener(new View.OnClickListener() {
......@@ -108,7 +108,7 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
listener = (prefs, key) -> {
Log.d(TAG, "setListenerForCount: Listener: Key = " + key);
if (key.equals(getString(R.string.users_served))) {
if (key.equals(getString(R.string.users_served_key))) {
servedCount = sharedPreferences.getInt(key, 0);
updateCountInFragment();
}
......@@ -158,7 +158,7 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
* @return boolean whether the service is running or not.
*/
public boolean isServiceRunning() {
return sharedPreferences.getBoolean(getString(R.string.is_service_running_bool), false);
return sharedPreferences.getBoolean(getString(R.string.is_service_running_bool_key), false);
}
/**
......@@ -202,12 +202,12 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
try {
String stringCurrentDate = simpleDateFormat.format(Calendar.getInstance().getTime());
String stringRecordedDate = sharedPreferences.getString(getString(R.string.served_date), "");
String stringRecordedDate = sharedPreferences.getString(getString(R.string.served_date_key), "");
//No value for key. Set the date value to current date and users served to 0.
if (stringRecordedDate.equals("")) {
editor.putString(getString(R.string.served_date), stringCurrentDate);
editor.putInt(getString(R.string.users_served), 0);
editor.putString(getString(R.string.served_date_key), stringCurrentDate);
editor.putInt(getString(R.string.users_served_key), 0);
} else {
//Check if the current system date is greater than recorded date, if so reset the "served" flag.
Date recordedDate = simpleDateFormat.parse(stringRecordedDate);
......@@ -221,8 +221,8 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb
return true;
} else {
//Current date is bigger than recorded date. Reset the values. i.e comparision > 0
editor.putString(getString(R.string.served_date), simpleDateFormat.format(currentDate));
editor.putInt(getString(R.string.users_served), 0);
editor.putString(getString(R.string.served_date_key), simpleDateFormat.format(currentDate));
editor.putInt(getString(R.string.users_served_key), 0);
}
}
......
......@@ -80,7 +80,7 @@ public class MyPersistentService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "onStartCommand: executed with startId: " + startId);
sharedPreferences = getSharedPreferences(getString(R.string.sharedpreference_file), MODE_PRIVATE);
isServiceStarted = sharedPreferences.getBoolean(getString(R.string.is_service_running_bool), false);
isServiceStarted = sharedPreferences.getBoolean(getString(R.string.is_service_running_bool_key), false);
if (intent != null) {
if (intent.getAction().equals(ForegroundServiceConstants.ACTION_START))
......@@ -132,10 +132,10 @@ public class MyPersistentService extends Service {
if (setState == ForegroundServiceConstants.SERVICE_RUNNING) {
isServiceStarted = true;
editor.putBoolean(getString(R.string.is_service_running_bool), true);
editor.putBoolean(getString(R.string.is_service_running_bool_key), true);
} else {
isServiceStarted = false;
editor.putBoolean(getString(R.string.is_service_running_bool), false);
editor.putBoolean(getString(R.string.is_service_running_bool_key), false);
}
editor.apply();
}
......@@ -146,8 +146,8 @@ public class MyPersistentService extends Service {
private void updateServedCount() {
SharedPreferences sp = GlobalApplication.getAppPreferences();
sp.edit()
.putInt(getString(R.string.users_served),
sp.getInt(getString(R.string.users_served), 0) + 1)
.putInt(getString(R.string.users_served_key),
sp.getInt(getString(R.string.users_served_key), 0) + 1)
.apply();
}
......
<resources>
<string name="app_name">Snowflake</string>
<string name="sharedpreference_file">org.torproject.snowflake.snowflake_preferences</string>
<string name="is_service_running_bool">is_service_running</string>
<string name="not_channel_desc">This Channel should not be muted. The Android system will consider Snowflake not import and will kill the service if it\'s muted.</string>
<string name="initial_run_boolean">initial_run</string>
<string name="not_channel_name">Snowflake Service</string>
<string name="users_served">users_served</string>
<string name="served_date">date</string>
<string name="users_served_text">Users you have helped circumvent censorship in the past day \n</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="sharedpreference_file">org.torproject.snowflake.snowflake_preferences</string>
<string name="users_served_key">users_served</string>
<string name="served_date_key">date</string>
<string name="initial_run_boolean_key">initial_run</string>
<string name="is_service_running_bool_key">is_service_running</string>
</resources>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment