summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2020-02-27 22:53:25 -0600
committercyberta <cyberta@riseup.net>2020-02-27 22:53:25 -0600
commit2b22e4ad47ae7df24b15ea28b08e60a4999a96cf (patch)
tree135dbaa026ceca6729e24ccfbd98ac6eb92cfdad /app/src/main/java
parentd41561376321d04ce585ac1f45221cb93446e55f (diff)
enable/disable save battery switch in navigation drawer depending on tethering state
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java27
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/views/IconSwitchEntry.java4
2 files changed, 30 insertions, 1 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java
index 104f1edc..1097addb 100644
--- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java
@@ -45,6 +45,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import java.util.Observable;
+import java.util.Observer;
import java.util.Set;
import de.blinkt.openvpn.core.VpnStatus;
@@ -63,6 +65,7 @@ import se.leap.bitmaskclient.fragments.AlwaysOnDialog;
import se.leap.bitmaskclient.fragments.ExcludeAppsFragment;
import se.leap.bitmaskclient.fragments.LogFragment;
import se.leap.bitmaskclient.fragments.TetheringDialog;
+import se.leap.bitmaskclient.tethering.TetheringObservable;
import se.leap.bitmaskclient.utils.PreferenceHelper;
import se.leap.bitmaskclient.views.IconSwitchEntry;
import se.leap.bitmaskclient.views.IconTextEntry;
@@ -92,7 +95,7 @@ import static se.leap.bitmaskclient.utils.PreferenceHelper.usePluggableTransport
* See the <a href="https://developer.android.com/design/patterns/navigation-drawer.html#Interaction">
* design guidelines</a> for a complete explanation of the behaviors implemented here.
*/
-public class NavigationDrawerFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener {
+public class NavigationDrawerFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener, Observer {
/**
* Per the design guidelines, you should show the drawer on launch until the user manually
@@ -149,9 +152,16 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen
Bundle savedInstanceState) {
drawerView = inflater.inflate(R.layout.f_drawer_main, container, false);
restoreFromSavedInstance(savedInstanceState);
+ TetheringObservable.getInstance().addObserver(this);
return drawerView;
}
+ @Override
+ public void onDestroyView() {
+ super.onDestroyView();
+ TetheringObservable.getInstance().deleteObserver(this);
+ }
+
public boolean isDrawerOpen() {
return drawerLayout != null && drawerLayout.isDrawerOpen(fragmentContainerView);
}
@@ -313,6 +323,13 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen
saveBattery(getContext(), false);
}
}));
+ boolean enableEntry = !TetheringObservable.getInstance().getTetheringState().isVpnTetheringRunning();
+ enableSaveBatteryEntry(enableEntry);
+ }
+
+ private void enableSaveBatteryEntry(boolean enabled) {
+ saveBattery.setEnabled(enabled);
+ saveBattery.showSubtitle(!enabled);
}
private void initAlwaysOnVpnEntry() {
@@ -630,4 +647,12 @@ public class NavigationDrawerFragment extends Fragment implements SharedPreferen
initUseBridgesEntry();
}
}
+
+ @Override
+ public void update(Observable o, Object arg) {
+ if (o instanceof TetheringObservable) {
+ TetheringObservable observable = (TetheringObservable) o;
+ enableSaveBatteryEntry(!observable.getTetheringState().isVpnTetheringRunning());
+ }
+ }
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/views/IconSwitchEntry.java b/app/src/main/java/se/leap/bitmaskclient/views/IconSwitchEntry.java
index 02347b05..8bb809fd 100644
--- a/app/src/main/java/se/leap/bitmaskclient/views/IconSwitchEntry.java
+++ b/app/src/main/java/se/leap/bitmaskclient/views/IconSwitchEntry.java
@@ -88,6 +88,10 @@ public class IconSwitchEntry extends LinearLayout {
textView.setText(id);
}
+ public void showSubtitle(boolean show) {
+ subtitleView.setVisibility(show ? VISIBLE : GONE);
+ }
+
public void setIcon(@DrawableRes int id) {
iconView.setImageResource(id);
}