Verified Commit 63ba408d authored by HashikD's avatar HashikD
Browse files

Reformated AppPreferenceConstants to AppPreferenceKeys

parent 27483cec
......@@ -16,7 +16,7 @@ import androidx.annotation.Nullable;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.torproject.snowflake.constants.AppPreferenceConstants;
import org.torproject.snowflake.constants.AppPreferenceKeys;
import org.torproject.snowflake.constants.BrokerConstants;
import org.torproject.snowflake.constants.ForegroundServiceConstants;
import org.torproject.snowflake.exceptions.EmptySIDException;
......@@ -81,7 +81,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(AppPreferenceConstants.IS_SERVICE_RUNNING_KEY, false);
isServiceStarted = sharedPreferences.getBoolean(AppPreferenceKeys.IS_SERVICE_RUNNING_KEY, false);
if (intent != null) {
if (intent.getAction().equals(ForegroundServiceConstants.ACTION_START))
......@@ -133,10 +133,10 @@ public class MyPersistentService extends Service {
if (setState == ForegroundServiceConstants.SERVICE_RUNNING) {
isServiceStarted = true;
editor.putBoolean(AppPreferenceConstants.IS_SERVICE_RUNNING_KEY, true);
editor.putBoolean(AppPreferenceKeys.IS_SERVICE_RUNNING_KEY, true);
} else {
isServiceStarted = false;
editor.putBoolean(AppPreferenceConstants.IS_SERVICE_RUNNING_KEY, false);
editor.putBoolean(AppPreferenceKeys.IS_SERVICE_RUNNING_KEY, false);
}
editor.apply();
}
......@@ -147,8 +147,8 @@ public class MyPersistentService extends Service {
private void updateServedCount() {
SharedPreferences sp = GlobalApplication.getAppPreferences();
sp.edit()
.putInt(AppPreferenceConstants.USER_SERVED_KEY,
sp.getInt(AppPreferenceConstants.USER_SERVED_KEY, 0) + 1)
.putInt(AppPreferenceKeys.USER_SERVED_KEY,
sp.getInt(AppPreferenceKeys.USER_SERVED_KEY, 0) + 1)
.apply();
}
......
package org.torproject.snowflake.constants;
public class AppPreferenceConstants {
public class AppPreferenceKeys {
public static final String USER_SERVED_KEY = "users_served";
public static final String DATE_KEY = "date";
public static final String INITIAL_RUN_KEY = "initial_run";
......
......@@ -4,7 +4,7 @@ import android.content.SharedPreferences;
import android.util.Log;
import org.torproject.snowflake.GlobalApplication;
import org.torproject.snowflake.constants.AppPreferenceConstants;
import org.torproject.snowflake.constants.AppPreferenceKeys;
import org.torproject.snowflake.mvp.MainActivityMVPContract;
import java.text.ParseException;
......@@ -44,19 +44,19 @@ public class MainActivityModel implements MainActivityMVPContract.Model {
}
public int getServedCount() {
return sharedPreferences.getInt(AppPreferenceConstants.USER_SERVED_KEY, 0);
return sharedPreferences.getInt(AppPreferenceKeys.USER_SERVED_KEY, 0);
}
public boolean getInitialRunBool() {
return sharedPreferences.getBoolean(AppPreferenceConstants.INITIAL_RUN_KEY, true);
return sharedPreferences.getBoolean(AppPreferenceKeys.INITIAL_RUN_KEY, true);
}
public void setInitialRunBool(boolean val) {
sharedPreferences.edit().putBoolean(AppPreferenceConstants.INITIAL_RUN_KEY, val).apply();
sharedPreferences.edit().putBoolean(AppPreferenceKeys.INITIAL_RUN_KEY, val).apply();
}
public boolean isServiceRunning() {
return sharedPreferences.getBoolean(AppPreferenceConstants.IS_SERVICE_RUNNING_KEY, false);
return sharedPreferences.getBoolean(AppPreferenceKeys.IS_SERVICE_RUNNING_KEY, false);
}
/**
......@@ -71,7 +71,7 @@ public class MainActivityModel implements MainActivityMVPContract.Model {
listener = (prefs, key) -> {
Log.d(TAG, "setListenerForCount: Listener: Key = " + key);
if (key.equals(AppPreferenceConstants.USER_SERVED_KEY)) {
if (key.equals(AppPreferenceKeys.USER_SERVED_KEY)) {
servedCount = sharedPreferences.getInt(key, 0);
if (presenter != null)
presenter.updateServedCount(servedCount);
......@@ -82,7 +82,7 @@ public class MainActivityModel implements MainActivityMVPContract.Model {
}
public String getDate() {
return sharedPreferences.getString(AppPreferenceConstants.DATE_KEY, "");
return sharedPreferences.getString(AppPreferenceKeys.DATE_KEY, "");
}
/**
......@@ -90,8 +90,8 @@ public class MainActivityModel implements MainActivityMVPContract.Model {
*/
public void setDateAndServed(String date, int value) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(AppPreferenceConstants.DATE_KEY, date);
editor.putInt(AppPreferenceConstants.USER_SERVED_KEY, value);
editor.putString(AppPreferenceKeys.DATE_KEY, date);
editor.putInt(AppPreferenceKeys.USER_SERVED_KEY, value);
editor.apply();
}
......
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