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