summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Dryomov <artur.dryomov@gmail.com>2013-08-03 16:39:25 +0300
committerArtur Dryomov <artur.dryomov@gmail.com>2013-08-03 19:02:00 +0300
commit38a3eba78d3aa0fe34268a84e14a5af2823aa342 (patch)
treea5e657e38995cfbcaaf7b0b89f8828a8f427bc66
parentef5342c677e2d28f46401dac02fc5a3d4c0c1bd0 (diff)
Change the Preferences class.
* Remove context dependency. * Modify the interface for easy usage. Change-Id: I9dfabbea1ec9ec9224dc8238a1884fdf695fc8db
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java14
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java19
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java45
3 files changed, 34 insertions, 44 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java b/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java
index 7329fd24d3f5..e81d3b77645f 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/PairingProvider.java
@@ -15,10 +15,10 @@ import android.os.Build;
import org.libreoffice.impressremote.util.Preferences;
final class PairingProvider {
- private final Context mContext;
+ private final Preferences mAuthorizedServersPreferences;
private PairingProvider(Context aContext) {
- mContext = aContext;
+ mAuthorizedServersPreferences = Preferences.getAuthorizedServersInstance(aContext);
}
public static boolean isPairingNecessary(Server aServer) {
@@ -46,17 +46,11 @@ final class PairingProvider {
}
private String getSavedPin(Server aServer) {
- String aLocation = Preferences.Locations.AUTHORIZED_REMOTES;
- String aServerAddress = aServer.getAddress();
-
- return Preferences.getString(mContext, aLocation, aServerAddress);
+ return mAuthorizedServersPreferences.get(aServer.getAddress());
}
private void savePin(Server aServer, String aPin) {
- String aLocation = Preferences.Locations.AUTHORIZED_REMOTES;
- String aServerAddress = aServer.getAddress();
-
- Preferences.set(mContext, aLocation, aServerAddress, aPin);
+ mAuthorizedServersPreferences.set(aServer.getAddress(), aPin);
}
public static String getPairingDeviceName(Context aContext) {
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
index 337c05cf2ae4..459f4e6ebee7 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ServersManager.java
@@ -22,20 +22,18 @@ import android.content.Context;
import org.libreoffice.impressremote.util.Preferences;
class ServersManager implements Comparator<Server> {
- private final Context mContext;
-
private final ServersFinder mBluetoothServersFinder;
private final ServersFinder mTcpServersFinder;
private final Set<Server> mBlacklistedServers;
+ private final Preferences mSavedServersPreferences;
public ServersManager(Context aContext) {
- mContext = aContext;
-
- mBluetoothServersFinder = new BluetoothServersFinder(mContext);
- mTcpServersFinder = new TcpServersFinder(mContext);
+ mBluetoothServersFinder = new BluetoothServersFinder(aContext);
+ mTcpServersFinder = new TcpServersFinder(aContext);
mBlacklistedServers = new HashSet<Server>();
+ mSavedServersPreferences = Preferences.getSavedServersInstance(aContext);
}
public void startServersSearch() {
@@ -63,8 +61,7 @@ class ServersManager implements Comparator<Server> {
}
private List<Server> getManualAddedTcpServers() {
- Map<String, ?> aServersEntries = Preferences
- .getAll(mContext, Preferences.Locations.STORED_SERVERS);
+ Map<String, ?> aServersEntries = mSavedServersPreferences.getAll();
return buildTcpServers(aServersEntries);
}
@@ -104,8 +101,7 @@ class ServersManager implements Comparator<Server> {
}
public void addTcpServer(String aAddress, String aName) {
- Preferences.set(mContext, Preferences.Locations.STORED_SERVERS,
- aAddress, aName);
+ mSavedServersPreferences.set(aAddress, aName);
}
public void removeServer(Server aServer) {
@@ -129,8 +125,7 @@ class ServersManager implements Comparator<Server> {
}
private void removeManualAddedServer(Server aServer) {
- Preferences.remove(mContext, Preferences.Locations.STORED_SERVERS,
- aServer.getAddress());
+ mSavedServersPreferences.remove(aServer.getAddress());
}
private void blacklistServer(Server aServer) {
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
index 749d3ab36b77..9c7c7f8074b2 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/util/Preferences.java
@@ -14,45 +14,46 @@ import android.content.Context;
import android.content.SharedPreferences;
public final class Preferences {
- public static final class Locations {
+ private static final class Locations {
private Locations() {
}
- public static final String AUTHORIZED_REMOTES = "sdremote_authorisedremotes";
- public static final String STORED_SERVERS = "sdremote_storedServers";
+ public static final String AUTHORIZED_SERVERS = "authorized_servers";
+ public static final String SAVED_SERVERS = "saved_servers";
}
- private Preferences() {
- }
+ private final SharedPreferences mPreferences;
- private static SharedPreferences getPreferences(Context aContext, String aLocation) {
- return aContext.getSharedPreferences(aLocation, Context.MODE_PRIVATE);
+ public static Preferences getAuthorizedServersInstance(Context aContext) {
+ return new Preferences(aContext, Locations.AUTHORIZED_SERVERS);
}
- public static Map<String, ?> getAll(Context aContext, String aLocation) {
- return getPreferences(aContext, aLocation).getAll();
+ private Preferences(Context aContext, String aLocation) {
+ mPreferences = getPreferences(aContext, aLocation);
}
- public static String getString(Context aContext, String aLocation, String aKey) {
- return getPreferences(aContext, aLocation).getString(aKey, null);
+ private SharedPreferences getPreferences(Context aContext, String aLocation) {
+ return aContext.getSharedPreferences(aLocation, Context.MODE_PRIVATE);
}
- public static void set(Context aContext, String aLocation, String aKey, String aValue) {
- SharedPreferences.Editor aPreferencesEditor = getPreferences(aContext,
- aLocation).edit();
-
- aPreferencesEditor.putString(aKey, aValue);
+ public static Preferences getSavedServersInstance(Context aContext) {
+ return new Preferences(aContext, Locations.SAVED_SERVERS);
+ }
- aPreferencesEditor.commit();
+ public Map<String, ?> getAll() {
+ return mPreferences.getAll();
}
- public static void remove(Context aContext, String aLocation, String aKey) {
- SharedPreferences.Editor aPreferencesEditor = getPreferences(aContext,
- aLocation).edit();
+ public String get(String aKey) {
+ return mPreferences.getString(aKey, null);
+ }
- aPreferencesEditor.remove(aKey);
+ public void set(String aKey, String aValue) {
+ mPreferences.edit().putString(aKey, aValue).commit();
+ }
- aPreferencesEditor.commit();
+ public void remove(String aKey) {
+ mPreferences.edit().remove(aKey).commit();
}
}