mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
[android] make transport plugin toggles functional
This commit is contained in:
@@ -36,6 +36,7 @@ import org.briarproject.bramble.util.AndroidUtils;
|
|||||||
import org.briarproject.bramble.util.StringUtils;
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
import org.briarproject.briar.android.account.LockManagerImpl;
|
import org.briarproject.briar.android.account.LockManagerImpl;
|
||||||
import org.briarproject.briar.android.keyagreement.ContactExchangeModule;
|
import org.briarproject.briar.android.keyagreement.ContactExchangeModule;
|
||||||
|
import org.briarproject.briar.android.navdrawer.NavDrawerModule;
|
||||||
import org.briarproject.briar.android.viewmodel.ViewModelModule;
|
import org.briarproject.briar.android.viewmodel.ViewModelModule;
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
import org.briarproject.briar.api.android.DozeWatchdog;
|
import org.briarproject.briar.api.android.DozeWatchdog;
|
||||||
@@ -64,7 +65,11 @@ import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_ONIO
|
|||||||
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_PUBLIC_KEY_HEX;
|
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_PUBLIC_KEY_HEX;
|
||||||
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||||
|
|
||||||
@Module(includes = {ContactExchangeModule.class, ViewModelModule.class})
|
@Module(includes = {
|
||||||
|
NavDrawerModule.class,
|
||||||
|
ContactExchangeModule.class,
|
||||||
|
ViewModelModule.class
|
||||||
|
})
|
||||||
public class AppModule {
|
public class AppModule {
|
||||||
|
|
||||||
static class EagerSingletons {
|
static class EagerSingletons {
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import org.briarproject.briar.android.controller.DbController;
|
|||||||
import org.briarproject.briar.android.controller.DbControllerImpl;
|
import org.briarproject.briar.android.controller.DbControllerImpl;
|
||||||
import org.briarproject.briar.android.login.ChangePasswordController;
|
import org.briarproject.briar.android.login.ChangePasswordController;
|
||||||
import org.briarproject.briar.android.login.ChangePasswordControllerImpl;
|
import org.briarproject.briar.android.login.ChangePasswordControllerImpl;
|
||||||
import org.briarproject.briar.android.navdrawer.NavDrawerController;
|
|
||||||
import org.briarproject.briar.android.navdrawer.NavDrawerControllerImpl;
|
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
@@ -67,14 +65,6 @@ public class ActivityModule {
|
|||||||
return dbController;
|
return dbController;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ActivityScope
|
|
||||||
@Provides
|
|
||||||
NavDrawerController provideNavDrawerController(
|
|
||||||
NavDrawerControllerImpl navDrawerController) {
|
|
||||||
activity.addLifecycleController(navDrawerController);
|
|
||||||
return navDrawerController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ActivityScope
|
@ActivityScope
|
||||||
@Provides
|
@Provides
|
||||||
BriarServiceConnection provideBriarServiceConnection() {
|
BriarServiceConnection provideBriarServiceConnection() {
|
||||||
|
|||||||
@@ -19,14 +19,11 @@ import org.briarproject.bramble.api.db.DbException;
|
|||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
import org.briarproject.briar.android.blog.FeedFragment;
|
import org.briarproject.briar.android.blog.FeedFragment;
|
||||||
import org.briarproject.briar.android.contact.ContactListFragment;
|
import org.briarproject.briar.android.contact.ContactListFragment;
|
||||||
import org.briarproject.briar.android.controller.handler.UiResultHandler;
|
|
||||||
import org.briarproject.briar.android.forum.ForumListFragment;
|
import org.briarproject.briar.android.forum.ForumListFragment;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||||
@@ -47,6 +44,8 @@ import androidx.core.app.ActivityCompat;
|
|||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.lifecycle.ViewModelProviders;
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.INVISIBLE;
|
import static android.view.View.INVISIBLE;
|
||||||
@@ -65,8 +64,7 @@ import static org.briarproject.briar.android.util.UiUtils.getDaysUntilExpiry;
|
|||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class NavDrawerActivity extends BriarActivity implements
|
public class NavDrawerActivity extends BriarActivity implements
|
||||||
BaseFragmentListener, TransportStateListener,
|
BaseFragmentListener, OnNavigationItemSelectedListener {
|
||||||
OnNavigationItemSelectedListener {
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(NavDrawerActivity.class.getName());
|
getLogger(NavDrawerActivity.class.getName());
|
||||||
@@ -84,10 +82,11 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
public static Uri SIGN_OUT_URI =
|
public static Uri SIGN_OUT_URI =
|
||||||
Uri.parse("briar-content://org.briarproject.briar/sign-out");
|
Uri.parse("briar-content://org.briarproject.briar/sign-out");
|
||||||
|
|
||||||
|
private NavDrawerViewModel viewModel;
|
||||||
private ActionBarDrawerToggle drawerToggle;
|
private ActionBarDrawerToggle drawerToggle;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
NavDrawerController controller;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
@Inject
|
@Inject
|
||||||
LifecycleManager lifecycleManager;
|
LifecycleManager lifecycleManager;
|
||||||
|
|
||||||
@@ -106,6 +105,14 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
exitIfStartupFailed(getIntent());
|
exitIfStartupFailed(getIntent());
|
||||||
setContentView(R.layout.activity_nav_drawer);
|
setContentView(R.layout.activity_nav_drawer);
|
||||||
|
|
||||||
|
viewModel = ViewModelProviders.of(this, viewModelFactory)
|
||||||
|
.get(NavDrawerViewModel.class);
|
||||||
|
|
||||||
|
viewModel.showExpiryWarning().observe(this, this::showExpiryWarning);
|
||||||
|
viewModel.shouldAskForDozeWhitelisting().observe(this, ask -> {
|
||||||
|
if (ask) showDozeDialog(getString(R.string.setup_doze_intro));
|
||||||
|
});
|
||||||
|
|
||||||
drawerScrollView = findViewById(R.id.drawerScrollView);
|
drawerScrollView = findViewById(R.id.drawerScrollView);
|
||||||
drawerScrollView.getViewTreeObserver().addOnGlobalLayoutListener(
|
drawerScrollView.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||||
new OnGlobalLayoutListener() {
|
new OnGlobalLayoutListener() {
|
||||||
@@ -122,6 +129,7 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
.removeOnGlobalLayoutListener(this);
|
.removeOnGlobalLayoutListener(this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
new PluginViewController(drawerScrollView, this, viewModel);
|
||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
drawerLayout = findViewById(R.id.drawer_layout);
|
drawerLayout = findViewById(R.id.drawer_layout);
|
||||||
@@ -156,12 +164,7 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
lockManager.checkIfLockable();
|
lockManager.checkIfLockable();
|
||||||
controller.showExpiryWarning(new UiResultHandler<Boolean>(this) {
|
viewModel.checkExpiryWarning();
|
||||||
@Override
|
|
||||||
public void onResultUi(Boolean expiry) {
|
|
||||||
if (expiry) showExpiryWarning();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -169,16 +172,7 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
@Nullable Intent data) {
|
@Nullable Intent data) {
|
||||||
super.onActivityResult(request, result, data);
|
super.onActivityResult(request, result, data);
|
||||||
if (request == REQUEST_PASSWORD && result == RESULT_OK) {
|
if (request == REQUEST_PASSWORD && result == RESULT_OK) {
|
||||||
controller.shouldAskForDozeWhitelisting(this,
|
viewModel.checkDozeWhitelisting();
|
||||||
new UiResultHandler<Boolean>(this) {
|
|
||||||
@Override
|
|
||||||
public void onResultUi(Boolean ask) {
|
|
||||||
if (ask) {
|
|
||||||
showDozeDialog(
|
|
||||||
getString(R.string.setup_doze_intro));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,33 +342,31 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
if (item != null) item.setVisible(visible);
|
if (item != null) item.setVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showExpiryWarning() {
|
private void showExpiryWarning(boolean show) {
|
||||||
int daysUntilExpiry = getDaysUntilExpiry();
|
int daysUntilExpiry = getDaysUntilExpiry();
|
||||||
if (daysUntilExpiry < 0) signOut();
|
if (daysUntilExpiry < 0) {
|
||||||
|
signOut();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// show expiry warning text
|
|
||||||
ViewGroup expiryWarning = findViewById(R.id.expiryWarning);
|
ViewGroup expiryWarning = findViewById(R.id.expiryWarning);
|
||||||
TextView expiryWarningText =
|
if (show) {
|
||||||
expiryWarning.findViewById(R.id.expiryWarningText);
|
// show expiry warning text
|
||||||
// make close button functional
|
TextView expiryWarningText =
|
||||||
ImageView expiryWarningClose =
|
expiryWarning.findViewById(R.id.expiryWarningText);
|
||||||
expiryWarning.findViewById(R.id.expiryWarningClose);
|
String text = getResources().getQuantityString(
|
||||||
|
R.plurals.expiry_warning, daysUntilExpiry, daysUntilExpiry);
|
||||||
expiryWarningText.setText(getResources()
|
expiryWarningText.setText(text);
|
||||||
.getQuantityString(R.plurals.expiry_warning,
|
// make close button functional
|
||||||
daysUntilExpiry, daysUntilExpiry));
|
ImageView expiryWarningClose =
|
||||||
|
expiryWarning.findViewById(R.id.expiryWarningClose);
|
||||||
expiryWarningClose.setOnClickListener(v -> {
|
expiryWarningClose.setOnClickListener(v ->
|
||||||
controller.expiryWarningDismissed();
|
viewModel.expiryWarningDismissed()
|
||||||
|
);
|
||||||
|
expiryWarning.setVisibility(VISIBLE);
|
||||||
|
} else {
|
||||||
expiryWarning.setVisibility(GONE);
|
expiryWarning.setVisibility(GONE);
|
||||||
});
|
}
|
||||||
|
|
||||||
expiryWarning.setVisibility(VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stateUpdate(TransportId id, State state) {
|
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package org.briarproject.briar.android.navdrawer;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
|
||||||
import org.briarproject.briar.android.controller.ActivityLifecycleController;
|
|
||||||
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
public interface NavDrawerController extends ActivityLifecycleController {
|
|
||||||
|
|
||||||
State getTransportState(TransportId transportId);
|
|
||||||
|
|
||||||
void showExpiryWarning(ResultHandler<Boolean> handler);
|
|
||||||
|
|
||||||
void expiryWarningDismissed();
|
|
||||||
|
|
||||||
void shouldAskForDozeWhitelisting(Context ctx,
|
|
||||||
ResultHandler<Boolean> handler);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package org.briarproject.briar.android.navdrawer;
|
||||||
|
|
||||||
|
import org.briarproject.briar.android.viewmodel.ViewModelKey;
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel;
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.multibindings.IntoMap;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class NavDrawerModule {
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
@IntoMap
|
||||||
|
@ViewModelKey(NavDrawerViewModel.class)
|
||||||
|
abstract ViewModel bindNavDrawerViewModel(
|
||||||
|
NavDrawerViewModel navDrawerViewModel);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,31 +1,35 @@
|
|||||||
package org.briarproject.briar.android.navdrawer;
|
package org.briarproject.briar.android.navdrawer;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
import org.briarproject.bramble.api.event.EventListener;
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.plugin.BluetoothConstants;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.plugin.LanTcpConstants;
|
||||||
import org.briarproject.bramble.api.plugin.Plugin;
|
import org.briarproject.bramble.api.plugin.Plugin;
|
||||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||||
import org.briarproject.bramble.api.plugin.PluginManager;
|
import org.briarproject.bramble.api.plugin.PluginManager;
|
||||||
|
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.plugin.event.TransportStateEvent;
|
import org.briarproject.bramble.api.plugin.event.TransportStateEvent;
|
||||||
import org.briarproject.bramble.api.settings.Settings;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||||
import org.briarproject.briar.android.controller.DbControllerImpl;
|
|
||||||
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.DAYS;
|
import static java.util.concurrent.TimeUnit.DAYS;
|
||||||
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;
|
||||||
@@ -38,52 +42,53 @@ import static org.briarproject.briar.android.controller.BriarControllerImpl.DOZE
|
|||||||
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@NotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
public class NavDrawerViewModel extends AndroidViewModel
|
||||||
public class NavDrawerControllerImpl extends DbControllerImpl
|
implements EventListener {
|
||||||
implements NavDrawerController, EventListener {
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(NavDrawerControllerImpl.class.getName());
|
getLogger(NavDrawerViewModel.class.getName());
|
||||||
|
|
||||||
private static final String EXPIRY_DATE_WARNING = "expiryDateWarning";
|
private static final String EXPIRY_DATE_WARNING = "expiryDateWarning";
|
||||||
|
static final TransportId[] TRANSPORT_IDS =
|
||||||
|
{TorConstants.ID, LanTcpConstants.ID, BluetoothConstants.ID};
|
||||||
|
|
||||||
private final PluginManager pluginManager;
|
@DatabaseExecutor
|
||||||
|
private final Executor dbExecutor;
|
||||||
private final SettingsManager settingsManager;
|
private final SettingsManager settingsManager;
|
||||||
|
private final PluginManager pluginManager;
|
||||||
private final EventBus eventBus;
|
private final EventBus eventBus;
|
||||||
|
|
||||||
// UI thread
|
private final MutableLiveData<Boolean> showExpiryWarning =
|
||||||
private TransportStateListener listener;
|
new MutableLiveData<>();
|
||||||
|
private final MutableLiveData<Boolean> shouldAskForDozeWhitelisting =
|
||||||
|
new MutableLiveData<>();
|
||||||
|
|
||||||
|
private final MutableLiveData<Plugin.State> torPluginState =
|
||||||
|
new MutableLiveData<>();
|
||||||
|
private final MutableLiveData<Plugin.State> wifiPluginState =
|
||||||
|
new MutableLiveData<>();
|
||||||
|
private final MutableLiveData<Plugin.State> btPluginState =
|
||||||
|
new MutableLiveData<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
NavDrawerControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
NavDrawerViewModel(Application app, @DatabaseExecutor Executor dbExecutor,
|
||||||
LifecycleManager lifecycleManager, PluginManager pluginManager,
|
SettingsManager settingsManager, PluginManager pluginManager,
|
||||||
SettingsManager settingsManager, EventBus eventBus) {
|
EventBus eventBus) {
|
||||||
super(dbExecutor, lifecycleManager);
|
super(app);
|
||||||
this.pluginManager = pluginManager;
|
this.dbExecutor = dbExecutor;
|
||||||
this.settingsManager = settingsManager;
|
this.settingsManager = settingsManager;
|
||||||
|
this.pluginManager = pluginManager;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreate(Activity activity) {
|
|
||||||
listener = (TransportStateListener) activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityStart() {
|
|
||||||
eventBus.addListener(this);
|
eventBus.addListener(this);
|
||||||
|
updatePluginStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityStop() {
|
protected void onCleared() {
|
||||||
eventBus.removeListener(this);
|
eventBus.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityDestroy() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void eventOccurred(Event e) {
|
public void eventOccurred(Event e) {
|
||||||
if (e instanceof TransportStateEvent) {
|
if (e instanceof TransportStateEvent) {
|
||||||
@@ -93,17 +98,22 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
|||||||
if (LOG.isLoggable(INFO)) {
|
if (LOG.isLoggable(INFO)) {
|
||||||
LOG.info("TransportStateEvent: " + id + " is " + state);
|
LOG.info("TransportStateEvent: " + id + " is " + state);
|
||||||
}
|
}
|
||||||
listener.stateUpdate(id, state);
|
MutableLiveData<Plugin.State> liveData = getPluginLiveData(id);
|
||||||
|
if (liveData != null) liveData.postValue(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
LiveData<Boolean> showExpiryWarning() {
|
||||||
public void showExpiryWarning(ResultHandler<Boolean> handler) {
|
return showExpiryWarning;
|
||||||
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
void checkExpiryWarning() {
|
||||||
if (!IS_DEBUG_BUILD) {
|
if (!IS_DEBUG_BUILD) {
|
||||||
handler.onResult(false);
|
showExpiryWarning.setValue(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
runOnDbThread(() -> {
|
dbExecutor.execute(() -> {
|
||||||
try {
|
try {
|
||||||
Settings settings =
|
Settings settings =
|
||||||
settingsManager.getSettings(SETTINGS_NAMESPACE);
|
settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||||
@@ -111,7 +121,7 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
|||||||
|
|
||||||
if (warningInt == 0) {
|
if (warningInt == 0) {
|
||||||
// we have not warned before
|
// we have not warned before
|
||||||
handler.onResult(true);
|
showExpiryWarning.postValue(true);
|
||||||
} else {
|
} else {
|
||||||
long warningLong = warningInt * 1000L;
|
long warningLong = warningInt * 1000L;
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
@@ -121,12 +131,12 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
|||||||
(EXPIRY_DATE - now) / DAYS.toMillis(1);
|
(EXPIRY_DATE - now) / DAYS.toMillis(1);
|
||||||
|
|
||||||
if (daysSinceLastWarning >= 30) {
|
if (daysSinceLastWarning >= 30) {
|
||||||
handler.onResult(true);
|
showExpiryWarning.postValue(true);
|
||||||
} else if (daysBeforeExpiry <= 3 &&
|
} else if (daysBeforeExpiry <= 3 &&
|
||||||
daysSinceLastWarning > 0) {
|
daysSinceLastWarning > 0) {
|
||||||
handler.onResult(true);
|
showExpiryWarning.postValue(true);
|
||||||
} else {
|
} else {
|
||||||
handler.onResult(false);
|
showExpiryWarning.postValue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
@@ -135,9 +145,10 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@UiThread
|
||||||
public void expiryWarningDismissed() {
|
void expiryWarningDismissed() {
|
||||||
runOnDbThread(() -> {
|
showExpiryWarning.setValue(false);
|
||||||
|
dbExecutor.execute(() -> {
|
||||||
try {
|
try {
|
||||||
Settings settings = new Settings();
|
Settings settings = new Settings();
|
||||||
int date = (int) (System.currentTimeMillis() / 1000L);
|
int date = (int) (System.currentTimeMillis() / 1000L);
|
||||||
@@ -149,31 +160,64 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
LiveData<Boolean> shouldAskForDozeWhitelisting() {
|
||||||
public void shouldAskForDozeWhitelisting(Context ctx,
|
return shouldAskForDozeWhitelisting;
|
||||||
ResultHandler<Boolean> handler) {
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
void checkDozeWhitelisting() {
|
||||||
// check this first, to hit the DbThread only when really necessary
|
// check this first, to hit the DbThread only when really necessary
|
||||||
if (!needsDozeWhitelisting(ctx)) {
|
if (!needsDozeWhitelisting(getApplication())) {
|
||||||
handler.onResult(false);
|
shouldAskForDozeWhitelisting.setValue(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
runOnDbThread(() -> {
|
dbExecutor.execute(() -> {
|
||||||
try {
|
try {
|
||||||
Settings settings =
|
Settings settings =
|
||||||
settingsManager.getSettings(SETTINGS_NAMESPACE);
|
settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||||
boolean ask = settings.getBoolean(DOZE_ASK_AGAIN, true);
|
boolean ask = settings.getBoolean(DOZE_ASK_AGAIN, true);
|
||||||
handler.onResult(ask);
|
shouldAskForDozeWhitelisting.postValue(ask);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
handler.onResult(true);
|
shouldAskForDozeWhitelisting.postValue(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void updatePluginStates() {
|
||||||
public State getTransportState(TransportId transportId) {
|
for (TransportId t : TRANSPORT_IDS) {
|
||||||
Plugin plugin = pluginManager.getPlugin(transportId);
|
MutableLiveData<Plugin.State> liveData = getPluginLiveData(t);
|
||||||
|
if (liveData == null) throw new AssertionError();
|
||||||
|
liveData.setValue(getTransportState(t));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private State getTransportState(TransportId id) {
|
||||||
|
Plugin plugin = pluginManager.getPlugin(id);
|
||||||
return plugin == null ? DISABLED : plugin.getState();
|
return plugin == null ? DISABLED : plugin.getState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private MutableLiveData<State> getPluginLiveData(TransportId t) {
|
||||||
|
if (t.equals(TorConstants.ID)) {
|
||||||
|
return torPluginState;
|
||||||
|
} else if (t.equals(LanTcpConstants.ID)) {
|
||||||
|
return wifiPluginState;
|
||||||
|
} else if (t.equals(BluetoothConstants.ID)) {
|
||||||
|
return btPluginState;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LiveData<State> getPluginState(TransportId t) {
|
||||||
|
LiveData<Plugin.State> liveData = getPluginLiveData(t);
|
||||||
|
if (liveData == null) throw new AssertionError();
|
||||||
|
return liveData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPluginEnabled(TransportId t, boolean enabled) {
|
||||||
|
pluginManager.setPluginEnabled(t, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package org.briarproject.briar.android.navdrawer;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.plugin.BluetoothConstants;
|
||||||
|
import org.briarproject.bramble.api.plugin.LanTcpConstants;
|
||||||
|
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||||
|
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||||
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
|
import org.briarproject.briar.R;
|
||||||
|
|
||||||
|
import androidx.appcompat.widget.SwitchCompat;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
|
||||||
|
import static androidx.core.content.ContextCompat.getColor;
|
||||||
|
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||||
|
import static org.briarproject.bramble.api.plugin.Plugin.State.DISABLED;
|
||||||
|
import static org.briarproject.bramble.api.plugin.Plugin.State.ENABLING;
|
||||||
|
import static org.briarproject.briar.android.navdrawer.NavDrawerViewModel.TRANSPORT_IDS;
|
||||||
|
|
||||||
|
class PluginViewController {
|
||||||
|
|
||||||
|
private final ImageView torIcon, wifiIcon, btIcon;
|
||||||
|
private final SwitchCompat torSwitch, wifiSwitch, btSwitch;
|
||||||
|
|
||||||
|
PluginViewController(View v, LifecycleOwner owner,
|
||||||
|
NavDrawerViewModel viewModel) {
|
||||||
|
|
||||||
|
torIcon = v.findViewById(R.id.torIcon);
|
||||||
|
wifiIcon = v.findViewById(R.id.wifiIcon);
|
||||||
|
btIcon = v.findViewById(R.id.btIcon);
|
||||||
|
|
||||||
|
torSwitch = v.findViewById(R.id.torSwitch);
|
||||||
|
wifiSwitch = v.findViewById(R.id.wifiSwitch);
|
||||||
|
btSwitch = v.findViewById(R.id.btSwitch);
|
||||||
|
|
||||||
|
for (TransportId t : TRANSPORT_IDS) {
|
||||||
|
// a OnCheckedChangeListener would get triggered on programmatic updates
|
||||||
|
SwitchCompat switchCompat = getSwitch(t);
|
||||||
|
switchCompat.setOnClickListener(buttonView ->
|
||||||
|
// TODO check reason first and change settings if needed
|
||||||
|
viewModel.setPluginEnabled(t, switchCompat.isChecked())
|
||||||
|
);
|
||||||
|
viewModel.getPluginState(t)
|
||||||
|
.observe(owner, state -> stateUpdate(t, state));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stateUpdate(TransportId id, State state) {
|
||||||
|
updateIcon(getIcon(id), state);
|
||||||
|
updateSwitch(getSwitch(id), state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SwitchCompat getSwitch(TransportId id) {
|
||||||
|
if (id == TorConstants.ID) return torSwitch;
|
||||||
|
if (id == BluetoothConstants.ID) return btSwitch;
|
||||||
|
if (id == LanTcpConstants.ID) return wifiSwitch;
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSwitch(SwitchCompat switchCompat, State state) {
|
||||||
|
switchCompat.setChecked(state != DISABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImageView getIcon(TransportId id) {
|
||||||
|
if (id == TorConstants.ID) return torIcon;
|
||||||
|
if (id == BluetoothConstants.ID) return btIcon;
|
||||||
|
if (id == LanTcpConstants.ID) return wifiIcon;
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateIcon(ImageView icon, State state) {
|
||||||
|
int colorRes;
|
||||||
|
if (state == ACTIVE) {
|
||||||
|
colorRes = R.color.briar_green_light;
|
||||||
|
} else if (state == ENABLING) {
|
||||||
|
colorRes = R.color.briar_yellow;
|
||||||
|
} else {
|
||||||
|
colorRes = android.R.color.tertiary_text_light;
|
||||||
|
}
|
||||||
|
int color = getColor(icon.getContext(), colorRes);
|
||||||
|
icon.setColorFilter(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package org.briarproject.briar.android.navdrawer;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
|
|
||||||
interface TransportStateListener {
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
void stateUpdate(TransportId id, State state);
|
|
||||||
}
|
|
||||||
@@ -20,8 +20,6 @@ import org.briarproject.bramble.api.event.EventBus;
|
|||||||
import org.briarproject.bramble.api.event.EventListener;
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.BluetoothConstants;
|
|
||||||
import org.briarproject.bramble.api.plugin.LanTcpConstants;
|
|
||||||
import org.briarproject.bramble.api.plugin.TorConstants;
|
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||||
import org.briarproject.bramble.api.settings.Settings;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||||
@@ -42,6 +40,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.text.TextUtilsCompat;
|
import androidx.core.text.TextUtilsCompat;
|
||||||
@@ -73,7 +72,6 @@ import static android.widget.Toast.LENGTH_SHORT;
|
|||||||
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_LTR;
|
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_LTR;
|
||||||
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.bramble.api.plugin.Plugin.PREF_PLUGIN_ENABLE;
|
|
||||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_MOBILE;
|
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_MOBILE;
|
||||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK;
|
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK;
|
||||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK_AUTOMATIC;
|
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK_AUTOMATIC;
|
||||||
@@ -112,15 +110,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
"pref_key_lock_timeout";
|
"pref_key_lock_timeout";
|
||||||
public static final String NOTIFY_SIGN_IN = "pref_key_notify_sign_in";
|
public static final String NOTIFY_SIGN_IN = "pref_key_notify_sign_in";
|
||||||
|
|
||||||
private static final String BT_NAMESPACE =
|
|
||||||
BluetoothConstants.ID.getString();
|
|
||||||
private static final String BT_ENABLE = "pref_key_bluetooth";
|
|
||||||
|
|
||||||
private static final String WIFI_NAMESPACE = LanTcpConstants.ID.getString();
|
|
||||||
private static final String WIFI_ENABLE = "pref_key_wifi";
|
|
||||||
|
|
||||||
private static final String TOR_NAMESPACE = TorConstants.ID.getString();
|
private static final String TOR_NAMESPACE = TorConstants.ID.getString();
|
||||||
private static final String TOR_ENABLE = "pref_key_tor_enable";
|
|
||||||
private static final String TOR_NETWORK = "pref_key_tor_network";
|
private static final String TOR_NETWORK = "pref_key_tor_network";
|
||||||
private static final String TOR_MOBILE = "pref_key_tor_mobile_data";
|
private static final String TOR_MOBILE = "pref_key_tor_mobile_data";
|
||||||
private static final String TOR_ONLY_WHEN_CHARGING =
|
private static final String TOR_ONLY_WHEN_CHARGING =
|
||||||
@@ -131,9 +121,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
|
|
||||||
private SettingsActivity listener;
|
private SettingsActivity listener;
|
||||||
private ListPreference language;
|
private ListPreference language;
|
||||||
private SwitchPreference enableBluetooth;
|
|
||||||
private SwitchPreference enableWifi;
|
|
||||||
private SwitchPreference enableTor;
|
|
||||||
private ListPreference torNetwork;
|
private ListPreference torNetwork;
|
||||||
private SwitchPreference torMobile;
|
private SwitchPreference torMobile;
|
||||||
private SwitchPreference torOnlyWhenCharging;
|
private SwitchPreference torOnlyWhenCharging;
|
||||||
@@ -148,7 +135,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
private Preference notifySound;
|
private Preference notifySound;
|
||||||
|
|
||||||
// Fields that are accessed from background threads must be volatile
|
// Fields that are accessed from background threads must be volatile
|
||||||
private volatile Settings settings, btSettings, wifiSettings, torSettings;
|
private volatile Settings settings, torSettings;
|
||||||
private volatile boolean settingsLoaded = false;
|
private volatile boolean settingsLoaded = false;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -177,9 +164,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
language = findPreference(LANGUAGE);
|
language = findPreference(LANGUAGE);
|
||||||
setLanguageEntries();
|
setLanguageEntries();
|
||||||
ListPreference theme = findPreference("pref_key_theme");
|
ListPreference theme = findPreference("pref_key_theme");
|
||||||
enableBluetooth = findPreference(BT_ENABLE);
|
|
||||||
enableWifi = findPreference(WIFI_ENABLE);
|
|
||||||
enableTor = findPreference(TOR_ENABLE);
|
|
||||||
torNetwork = findPreference(TOR_NETWORK);
|
torNetwork = findPreference(TOR_NETWORK);
|
||||||
torMobile = findPreference(TOR_MOBILE);
|
torMobile = findPreference(TOR_MOBILE);
|
||||||
torOnlyWhenCharging = findPreference(TOR_ONLY_WHEN_CHARGING);
|
torOnlyWhenCharging = findPreference(TOR_ONLY_WHEN_CHARGING);
|
||||||
@@ -211,9 +195,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
enableBluetooth.setOnPreferenceChangeListener(this);
|
|
||||||
enableWifi.setOnPreferenceChangeListener(this);
|
|
||||||
enableTor.setOnPreferenceChangeListener(this);
|
|
||||||
torNetwork.setOnPreferenceChangeListener(this);
|
torNetwork.setOnPreferenceChangeListener(this);
|
||||||
torMobile.setOnPreferenceChangeListener(this);
|
torMobile.setOnPreferenceChangeListener(this);
|
||||||
torOnlyWhenCharging.setOnPreferenceChangeListener(this);
|
torOnlyWhenCharging.setOnPreferenceChangeListener(this);
|
||||||
@@ -256,8 +237,9 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater,
|
||||||
Bundle savedInstanceState) {
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
ColorDrawable divider = new ColorDrawable(
|
ColorDrawable divider = new ColorDrawable(
|
||||||
ContextCompat.getColor(requireContext(), R.color.divider));
|
ContextCompat.getColor(requireContext(), R.color.divider));
|
||||||
@@ -359,8 +341,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
try {
|
try {
|
||||||
long start = now();
|
long start = now();
|
||||||
settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||||
btSettings = settingsManager.getSettings(BT_NAMESPACE);
|
|
||||||
wifiSettings = settingsManager.getSettings(WIFI_NAMESPACE);
|
|
||||||
torSettings = settingsManager.getSettings(TOR_NAMESPACE);
|
torSettings = settingsManager.getSettings(TOR_NAMESPACE);
|
||||||
settingsLoaded = true;
|
settingsLoaded = true;
|
||||||
logDuration(LOG, "Loading settings", start);
|
logDuration(LOG, "Loading settings", start);
|
||||||
@@ -376,18 +356,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
// due to events, we might try to display before a load completed
|
// due to events, we might try to display before a load completed
|
||||||
if (!settingsLoaded) return;
|
if (!settingsLoaded) return;
|
||||||
|
|
||||||
boolean btEnabledSetting =
|
|
||||||
btSettings.getBoolean(PREF_PLUGIN_ENABLE, false);
|
|
||||||
enableBluetooth.setChecked(btEnabledSetting);
|
|
||||||
|
|
||||||
boolean wifiEnabledSetting =
|
|
||||||
wifiSettings.getBoolean(PREF_PLUGIN_ENABLE, false);
|
|
||||||
enableWifi.setChecked(wifiEnabledSetting);
|
|
||||||
|
|
||||||
boolean torEnabledSetting =
|
|
||||||
torSettings.getBoolean(PREF_PLUGIN_ENABLE, true);
|
|
||||||
enableTor.setChecked(torEnabledSetting);
|
|
||||||
|
|
||||||
int torNetworkSetting = torSettings.getInt(PREF_TOR_NETWORK,
|
int torNetworkSetting = torSettings.getInt(PREF_TOR_NETWORK,
|
||||||
PREF_TOR_NETWORK_AUTOMATIC);
|
PREF_TOR_NETWORK_AUTOMATIC);
|
||||||
torNetwork.setValue(Integer.toString(torNetworkSetting));
|
torNetwork.setValue(Integer.toString(torNetworkSetting));
|
||||||
@@ -459,9 +427,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
// preferences partly needed here, because they have their own logic
|
// preferences partly needed here, because they have their own logic
|
||||||
// - pref_key_lock (screenLock -> displayScreenLockSetting())
|
// - pref_key_lock (screenLock -> displayScreenLockSetting())
|
||||||
// - pref_key_lock_timeout (screenLockTimeout)
|
// - pref_key_lock_timeout (screenLockTimeout)
|
||||||
enableBluetooth.setEnabled(enabled);
|
|
||||||
enableWifi.setEnabled(enabled);
|
|
||||||
enableTor.setEnabled(enabled);
|
|
||||||
torNetwork.setEnabled(enabled);
|
torNetwork.setEnabled(enabled);
|
||||||
torMobile.setEnabled(enabled);
|
torMobile.setEnabled(enabled);
|
||||||
torOnlyWhenCharging.setEnabled(enabled);
|
torOnlyWhenCharging.setEnabled(enabled);
|
||||||
@@ -563,15 +528,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
if (!language.getValue().equals(newValue))
|
if (!language.getValue().equals(newValue))
|
||||||
languageChanged((String) newValue);
|
languageChanged((String) newValue);
|
||||||
return false;
|
return false;
|
||||||
} else if (preference == enableBluetooth) {
|
|
||||||
boolean btSetting = (Boolean) newValue;
|
|
||||||
storeBluetoothSetting(btSetting);
|
|
||||||
} else if (preference == enableWifi) {
|
|
||||||
boolean wifiSetting = (Boolean) newValue;
|
|
||||||
storeWifiSetting(wifiSetting);
|
|
||||||
} else if (preference == enableTor) {
|
|
||||||
boolean torEnabledSetting = (Boolean) newValue;
|
|
||||||
storeTorEnabledSetting(torEnabledSetting);
|
|
||||||
} else if (preference == torNetwork) {
|
} else if (preference == torNetwork) {
|
||||||
int torNetworkSetting = Integer.valueOf((String) newValue);
|
int torNetworkSetting = Integer.valueOf((String) newValue);
|
||||||
storeTorNetworkSetting(torNetworkSetting);
|
storeTorNetworkSetting(torNetworkSetting);
|
||||||
@@ -635,12 +591,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeTorEnabledSetting(boolean torEnabledSetting) {
|
|
||||||
Settings s = new Settings();
|
|
||||||
s.putBoolean(PREF_PLUGIN_ENABLE, torEnabledSetting);
|
|
||||||
mergeSettings(s, TOR_NAMESPACE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void storeTorNetworkSetting(int torNetworkSetting) {
|
private void storeTorNetworkSetting(int torNetworkSetting) {
|
||||||
Settings s = new Settings();
|
Settings s = new Settings();
|
||||||
s.putInt(PREF_TOR_NETWORK, torNetworkSetting);
|
s.putInt(PREF_TOR_NETWORK, torNetworkSetting);
|
||||||
@@ -659,18 +609,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
mergeSettings(s, TOR_NAMESPACE);
|
mergeSettings(s, TOR_NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeBluetoothSetting(boolean btSetting) {
|
|
||||||
Settings s = new Settings();
|
|
||||||
s.putBoolean(PREF_PLUGIN_ENABLE, btSetting);
|
|
||||||
mergeSettings(s, BT_NAMESPACE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void storeWifiSetting(boolean wifiSetting) {
|
|
||||||
Settings s = new Settings();
|
|
||||||
s.putBoolean(PREF_PLUGIN_ENABLE, wifiSetting);
|
|
||||||
mergeSettings(s, WIFI_NAMESPACE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void storeSettings(Settings s) {
|
private void storeSettings(Settings s) {
|
||||||
mergeSettings(s, SETTINGS_NAMESPACE);
|
mergeSettings(s, SETTINGS_NAMESPACE);
|
||||||
}
|
}
|
||||||
@@ -729,14 +667,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
LOG.info("Settings updated");
|
LOG.info("Settings updated");
|
||||||
settings = s.getSettings();
|
settings = s.getSettings();
|
||||||
displaySettings();
|
displaySettings();
|
||||||
} else if (namespace.equals(BT_NAMESPACE)) {
|
|
||||||
LOG.info("Bluetooth settings updated");
|
|
||||||
btSettings = s.getSettings();
|
|
||||||
displaySettings();
|
|
||||||
} else if (namespace.equals(WIFI_NAMESPACE)) {
|
|
||||||
LOG.info("Wifi settings updated");
|
|
||||||
wifiSettings = s.getSettings();
|
|
||||||
displaySettings();
|
|
||||||
} else if (namespace.equals(TOR_NAMESPACE)) {
|
} else if (namespace.equals(TOR_NAMESPACE)) {
|
||||||
LOG.info("Tor settings updated");
|
LOG.info("Tor settings updated");
|
||||||
torSettings = s.getSettings();
|
torSettings = s.getSettings();
|
||||||
|
|||||||
@@ -14,12 +14,12 @@
|
|||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:background="@color/divider"
|
android:background="@color/divider"
|
||||||
android:src="@drawable/chevron_down_white"
|
android:src="@drawable/chevron_down_white"
|
||||||
app:tint="?attr/colorControlNormal"
|
|
||||||
app:layout_constraintBottom_toTopOf="@+id/longRangeLabel"
|
app:layout_constraintBottom_toTopOf="@+id/longRangeLabel"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/navigation"
|
app:layout_constraintTop_toBottomOf="@+id/navigation"
|
||||||
app:layout_constraintVertical_bias="1.0"
|
app:layout_constraintVertical_bias="1.0"
|
||||||
|
app:tint="?attr/colorControlNormal"
|
||||||
tools:ignore="ContentDescription"
|
tools:ignore="ContentDescription"
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
|
|
||||||
@@ -54,8 +54,8 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="@+id/torSwitch"
|
app:layout_constraintBottom_toBottomOf="@+id/torSwitch"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="@+id/torSwitch"
|
app:layout_constraintTop_toTopOf="@+id/torSwitch"
|
||||||
app:tint="@color/briar_green"
|
tools:ignore="ContentDescription"
|
||||||
tools:ignore="ContentDescription" />
|
tools:tint="@color/briar_green" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
android:id="@+id/torSwitch"
|
android:id="@+id/torSwitch"
|
||||||
@@ -94,9 +94,9 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="@+id/wifiSwitch"
|
app:layout_constraintBottom_toBottomOf="@+id/wifiSwitch"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="@+id/wifiSwitch"
|
app:layout_constraintTop_toTopOf="@+id/wifiSwitch"
|
||||||
app:tint="@color/briar_green"
|
|
||||||
tools:checked="true"
|
tools:checked="true"
|
||||||
tools:ignore="ContentDescription" />
|
tools:ignore="ContentDescription"
|
||||||
|
tools:tint="@color/briar_green" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
android:id="@+id/wifiSwitch"
|
android:id="@+id/wifiSwitch"
|
||||||
@@ -123,9 +123,9 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="@+id/btSwitch"
|
app:layout_constraintBottom_toBottomOf="@+id/btSwitch"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="@+id/btSwitch"
|
app:layout_constraintTop_toTopOf="@+id/btSwitch"
|
||||||
app:tint="@color/briar_green"
|
|
||||||
tools:checked="true"
|
tools:checked="true"
|
||||||
tools:ignore="ContentDescription" />
|
tools:ignore="ContentDescription"
|
||||||
|
tools:tint="@color/briar_green" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
android:id="@+id/btSwitch"
|
android:id="@+id/btSwitch"
|
||||||
|
|||||||
@@ -29,33 +29,8 @@
|
|||||||
android:layout="@layout/preferences_category"
|
android:layout="@layout/preferences_category"
|
||||||
android:title="@string/network_settings_title">
|
android:title="@string/network_settings_title">
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:defaultValue="false"
|
|
||||||
android:key="pref_key_bluetooth"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/bluetooth_setting"
|
|
||||||
android:widgetLayout="@layout/preference_switch_compat"
|
|
||||||
app:iconSpaceReserved="false"/>
|
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:defaultValue="false"
|
|
||||||
android:key="pref_key_wifi"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/wifi_setting"
|
|
||||||
android:widgetLayout="@layout/preference_switch_compat"
|
|
||||||
app:iconSpaceReserved="false"/>
|
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:key="pref_key_tor_enable"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/tor_enable_title"
|
|
||||||
android:widgetLayout="@layout/preference_switch_compat"
|
|
||||||
app:iconSpaceReserved="false"/>
|
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:defaultValue="0"
|
android:defaultValue="0"
|
||||||
android:dependency="pref_key_tor_enable"
|
|
||||||
android:entries="@array/tor_network_setting_names"
|
android:entries="@array/tor_network_setting_names"
|
||||||
android:entryValues="@array/tor_network_setting_values"
|
android:entryValues="@array/tor_network_setting_values"
|
||||||
android:key="pref_key_tor_network"
|
android:key="pref_key_tor_network"
|
||||||
@@ -66,7 +41,6 @@
|
|||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:dependency="pref_key_tor_enable"
|
|
||||||
android:key="pref_key_tor_mobile_data"
|
android:key="pref_key_tor_mobile_data"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/tor_mobile_data_title"
|
android:title="@string/tor_mobile_data_title"
|
||||||
@@ -75,7 +49,6 @@
|
|||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:dependency="pref_key_tor_enable"
|
|
||||||
android:key="pref_key_tor_only_when_charging"
|
android:key="pref_key_tor_only_when_charging"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/tor_only_when_charging_title"
|
android:title="@string/tor_only_when_charging_title"
|
||||||
|
|||||||
Reference in New Issue
Block a user