summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--app/src/main/res/layout/f_drawer_main.xml1
-rw-r--r--app/src/main/res/values/strings.xml1
4 files changed, 32 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);
}
diff --git a/app/src/main/res/layout/f_drawer_main.xml b/app/src/main/res/layout/f_drawer_main.xml
index 191d547f..7e6291b7 100644
--- a/app/src/main/res/layout/f_drawer_main.xml
+++ b/app/src/main/res/layout/f_drawer_main.xml
@@ -65,6 +65,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:text="@string/save_battery"
+ app:subtitle="@string/subtitle_save_battery"
app:icon="@drawable/ic_battery_36"
/>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b5fc2fa2..61cedffb 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -102,6 +102,7 @@
<string name="vpn_certificate_is_invalid">VPN certificate is invalid. Try to download a new one.</string>
<string name="vpn_certificate_user_message">The VPN certificate is invalid. Please log in to download a new one.</string>
<string name="save_battery">Save battery</string>
+ <string name="subtitle_save_battery">Disabled while VPN Hotspot on</string>
<string name="save_battery_message">Background data connections will hibernate when your phone is inactive.</string>
<string name="always_on_vpn">Always-on VPN</string>
<string name="subtitle_always_on_vpn">Open Android System Settings</string>