mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Fixed a couple of bugs in settings.
This commit is contained in:
@@ -42,6 +42,7 @@ import static android.content.Context.NOTIFICATION_SERVICE;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.fragment.SettingsFragment.SETTINGS_NAMESPACE;
|
||||
|
||||
class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
Service, EventListener {
|
||||
@@ -97,7 +98,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
dbExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
settings = db.getSettings("settings-activity");
|
||||
settings = db.getSettings(SETTINGS_NAMESPACE);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
@@ -135,7 +136,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof SettingsUpdatedEvent) {
|
||||
loadSettings();
|
||||
SettingsUpdatedEvent s = (SettingsUpdatedEvent) e;
|
||||
if (s.getNamespace().equals(SETTINGS_NAMESPACE)) loadSettings();
|
||||
} else if (e instanceof MessageValidatedEvent) {
|
||||
MessageValidatedEvent m = (MessageValidatedEvent) e;
|
||||
if (m.isValid() && !m.isLocal()) {
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.briarproject.android.util.ListLoadingProgressBar;
|
||||
import org.briarproject.api.db.DatabaseComponent;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.SettingsUpdatedEvent;
|
||||
import org.briarproject.api.settings.Settings;
|
||||
import org.briarproject.api.settings.SettingsManager;
|
||||
@@ -38,6 +37,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static android.graphics.Typeface.DEFAULT_BOLD;
|
||||
import static android.media.RingtoneManager.ACTION_RINGTONE_PICKER;
|
||||
import static android.media.RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI;
|
||||
@@ -55,16 +55,15 @@ import static android.widget.LinearLayout.VERTICAL;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.TestingConstants.SHOW_TESTING_ACTIVITY;
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
||||
|
||||
public class SettingsFragment extends BaseFragment implements
|
||||
public class SettingsFragment extends BaseEventFragment implements
|
||||
View.OnClickListener {
|
||||
|
||||
public final static String TAG = "SettingsFragment";
|
||||
|
||||
public static final String TAG = "SettingsFragment";
|
||||
public static final int REQUEST_RINGTONE = 2;
|
||||
public static final String SETTINGS_NAMESPACE = "android-ui";
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(SettingsFragment.class.getName());
|
||||
@@ -82,9 +81,8 @@ public class SettingsFragment extends BaseFragment implements
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile DatabaseComponent db;
|
||||
@Inject private volatile SettingsManager settingsManager;
|
||||
@Inject private volatile EventBus eventBus;
|
||||
private volatile Settings settings;
|
||||
private volatile boolean bluetoothSetting = true, torSetting = false;
|
||||
private volatile boolean bluetoothSetting = false, torSetting = false;
|
||||
|
||||
public static SettingsFragment newInstance() {
|
||||
|
||||
@@ -282,7 +280,7 @@ public class SettingsFragment extends BaseFragment implements
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
settings = settingsManager.getSettings("settings-activity");
|
||||
settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||
Settings btSettings = settingsManager.getSettings("bt");
|
||||
Settings torSettings = settingsManager.getSettings("tor");
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
@@ -360,7 +358,8 @@ public class SettingsFragment extends BaseFragment implements
|
||||
notifyPrivateMessages.isChecked());
|
||||
storeSettings(s);
|
||||
} else if (view == panicSettings || view == panicSettingsHint) {
|
||||
startActivity(new Intent(getActivity(), PanicPreferencesActivity.class));
|
||||
startActivity(new Intent(getActivity(),
|
||||
PanicPreferencesActivity.class));
|
||||
} else if (view == notifyForumPosts) {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean("notifyForumPosts", notifyForumPosts.isChecked());
|
||||
@@ -431,8 +430,7 @@ public class SettingsFragment extends BaseFragment implements
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
settingsManager
|
||||
.mergeSettings(settings, "settings-activity");
|
||||
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Merging settings took " + duration + " ms");
|
||||
@@ -475,10 +473,15 @@ public class SettingsFragment extends BaseFragment implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof SettingsUpdatedEvent) {
|
||||
LOG.info("Settings updated");
|
||||
loadSettings();
|
||||
String namespace = ((SettingsUpdatedEvent) e).getNamespace();
|
||||
if (namespace.equals("bt") || namespace.equals("tor")
|
||||
|| namespace.equals(SETTINGS_NAMESPACE)) {
|
||||
LOG.info("Settings updated");
|
||||
loadSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,8 +596,10 @@ class TorPlugin implements DuplexPlugin, EventHandler,
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof SettingsUpdatedEvent) {
|
||||
// Wifi setting may have been updated
|
||||
updateConnectionStatus();
|
||||
if (((SettingsUpdatedEvent) e).getNamespace().equals("tor")) {
|
||||
// Wifi setting may have been updated
|
||||
updateConnectionStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,4 +3,13 @@ package org.briarproject.api.event;
|
||||
/** An event that is broadcast when one or more settings are updated. */
|
||||
public class SettingsUpdatedEvent extends Event {
|
||||
|
||||
private final String namespace;
|
||||
|
||||
public SettingsUpdatedEvent(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return namespace;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -930,15 +930,11 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
}
|
||||
|
||||
public void mergeSettings(Settings s, String namespace) throws DbException {
|
||||
boolean changed = false;
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
T txn = db.startTransaction();
|
||||
try {
|
||||
if (!s.equals(db.getSettings(txn, namespace))) {
|
||||
db.mergeSettings(txn, s, namespace);
|
||||
changed = true;
|
||||
}
|
||||
db.mergeSettings(txn, s, namespace);
|
||||
db.commitTransaction(txn);
|
||||
} catch (DbException e) {
|
||||
db.abortTransaction(txn);
|
||||
@@ -947,7 +943,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
if (changed) eventBus.broadcast(new SettingsUpdatedEvent());
|
||||
eventBus.broadcast(new SettingsUpdatedEvent(namespace));
|
||||
}
|
||||
|
||||
public void receiveAck(ContactId c, Ack a) throws DbException {
|
||||
|
||||
Reference in New Issue
Block a user