summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2019-08-03 19:09:26 +0200
committercyBerta <cyberta@riseup.net>2019-08-03 19:09:26 +0200
commite45a11bb75d81ed4c395e4a1a9a80226a85b8742 (patch)
tree601eefd198f7a735c2546b00e3bf85d7e61e17af
parent37f9cf65b3267f081c4b80c62240fc7754a30325 (diff)
rewrite Navigation drawer - improves layout on small screens, fixes switch entry UI bug
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java246
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java302
-rw-r--r--app/src/main/res/layout/f_drawer_main.xml142
3 files changed, 215 insertions, 475 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java b/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java
deleted file mode 100644
index e2b21db9..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/**
- * Copyright (c) 2018 LEAP Encryption Access Project and contributers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package se.leap.bitmaskclient;
-
-import android.content.Context;
-import android.graphics.drawable.Drawable;
-import android.support.annotation.DrawableRes;
-import android.support.annotation.NonNull;
-import android.support.v7.widget.SwitchCompat;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.BaseAdapter;
-import android.widget.CompoundButton;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import java.util.ArrayList;
-
-/**
- * Created by cyberta on 21.02.18.
- */
-
-public class DrawerSettingsAdapter extends BaseAdapter {
-
- //item types
- public static final int NONE = -1;
- public static final int SWITCH_PROVIDER = 0;
- public static final int LOG = 1;
- public static final int ABOUT = 2;
- public static final int BATTERY_SAVER = 3;
- public static final int ALWAYS_ON = 4;
- public static final int DONATE = 5;
- public static final int PLUGGABLE_TRANSPORTS = 6;
-
- //view types
- public final static int VIEW_SIMPLE_TEXT = 0;
- public final static int VIEW_SWITCH = 1;
-
- public static class DrawerSettingsItem {
- private String description = "";
- private int viewType = VIEW_SIMPLE_TEXT;
- private boolean isChecked = false;
- private int itemType = NONE;
- private CompoundButton.OnCheckedChangeListener callback;
- private Drawable iconResource;
-
- private DrawerSettingsItem(Context context, String description, @DrawableRes int iconResource, int viewType, boolean isChecked, int itemType, CompoundButton.OnCheckedChangeListener callback) {
- this.description = description;
- this.viewType = viewType;
- this.isChecked = isChecked;
- this.itemType = itemType;
- this.callback = callback;
- try {
- this.iconResource = context.getResources().getDrawable(iconResource);
- } catch (RuntimeException e) {
- e.printStackTrace();
- }
- }
-
- public static DrawerSettingsItem getSimpleTextInstance(Context context, String description, @DrawableRes int iconResource, int itemType) {
- return new DrawerSettingsItem(context, description, iconResource, VIEW_SIMPLE_TEXT, false, itemType, null);
- }
-
- public static DrawerSettingsItem getSwitchInstance(Context context, String description, @DrawableRes int iconResource, boolean isChecked, int itemType, CompoundButton.OnCheckedChangeListener callback) {
- return new DrawerSettingsItem(context, description, iconResource, VIEW_SWITCH, isChecked, itemType, callback);
- }
-
- public int getItemType() {
- return itemType;
- }
-
- public void setChecked(boolean checked) {
- isChecked = checked;
- }
-
- public boolean isChecked() {
- return isChecked;
- }
- }
-
- private ArrayList<DrawerSettingsItem> mData = new ArrayList<>();
- private LayoutInflater mInflater;
-
- public DrawerSettingsAdapter(LayoutInflater layoutInflater) {
- mInflater = layoutInflater;
- }
-
- public void addItem(final DrawerSettingsItem item) {
- mData.add(item);
- notifyDataSetChanged();
- }
-
- @Override
- public int getItemViewType(int position) {
- DrawerSettingsItem item = mData.get(position);
- return item.viewType;
- }
-
- @Override
- public int getViewTypeCount() {
- boolean hasSwitchItem = false;
- for (DrawerSettingsItem item : mData) {
- if (item.viewType == VIEW_SWITCH) {
- hasSwitchItem = true;
- break;
- }
- }
- return hasSwitchItem ? 2 : 1;
- }
-
- @Override
- public int getCount() {
- return mData.size();
- }
-
- @Override
- public DrawerSettingsItem getItem(int position) {
- return mData.get(position);
- }
-
- @Override
- public long getItemId(int position) {
- return position;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
-
- DrawerSettingsItem drawerSettingsItem = mData.get(position);
- ViewHolder holder = null;
- int type = getItemViewType(position);
- if (convertView == null) {
- holder = new ViewHolder();
- switch(type) {
- case VIEW_SIMPLE_TEXT:
- convertView = initTextViewBinding(holder);
- bindSimpleText(drawerSettingsItem, holder);
- break;
- case VIEW_SWITCH:
- convertView = initSwitchBinding(holder);
- bindSwitch(drawerSettingsItem, holder);
- break;
- }
- convertView.setTag(holder);
- } else {
- holder = (ViewHolder)convertView.getTag();
- switch (type) {
- case VIEW_SIMPLE_TEXT:
- if (holder.isSwitchViewHolder()) {
- holder.resetSwitchView();
- convertView = initTextViewBinding(holder);
- }
- bindSimpleText(drawerSettingsItem, holder);
- break;
- case VIEW_SWITCH:
- if (!holder.isSwitchViewHolder()) {
- holder.resetTextView();
- convertView = initSwitchBinding(holder);
- }
- bindSwitch(drawerSettingsItem, holder);
- break;
- }
- convertView.setTag(holder);
- }
- return convertView;
- }
-
- private void bindSimpleText(DrawerSettingsItem drawerSettingsItem, ViewHolder holder) {
- holder.textView.setText(drawerSettingsItem.description);
- if (drawerSettingsItem.iconResource != null) {
- holder.iconView.setImageDrawable(drawerSettingsItem.iconResource);
- }
- }
-
- private void bindSwitch(DrawerSettingsItem drawerSettingsItem, ViewHolder holder) {
- holder.switchView.setChecked(drawerSettingsItem.isChecked);
- holder.textView.setText(drawerSettingsItem.description);
- holder.switchView.setOnCheckedChangeListener(drawerSettingsItem.callback);
- if (drawerSettingsItem.iconResource != null) {
- holder.iconView.setImageDrawable(drawerSettingsItem.iconResource);
- }
- }
-
- @NonNull
- private View initSwitchBinding(ViewHolder holder) {
- View convertView = mInflater.inflate(R.layout.v_switch_list_item, null);
- holder.switchView = convertView.findViewById(R.id.option_switch);
- holder.textView = convertView.findViewById(android.R.id.text1);
- holder.iconView = convertView.findViewById(R.id.material_icon);
- return convertView;
- }
-
- @NonNull
- private View initTextViewBinding(ViewHolder holder) {
- View convertView = mInflater.inflate(R.layout.v_icon_text_list_item, null);
- holder.textView = convertView.findViewById(android.R.id.text1);
- holder.iconView = convertView.findViewById(R.id.material_icon);
- return convertView;
- }
-
- public DrawerSettingsItem getDrawerItem(int elementType) {
- for (DrawerSettingsItem item : mData) {
- if (item.itemType == elementType) {
- return item;
- }
- }
- return null;
- }
-
- static class ViewHolder {
- TextView textView;
- ImageView iconView;
- SwitchCompat switchView;
-
- boolean isSwitchViewHolder() {
- return switchView != null;
- }
-
- void resetSwitchView() {
- switchView.setOnCheckedChangeListener(null);
- switchView = null;
- }
-
- void resetTextView() {
- textView = null;
- }
- }
-}
-
-
-
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 8c022b98..380b765e 100644
--- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2018 LEAP Encryption Access Project and contributers
+ * Copyright (c) 2019 LEAP Encryption Access Project and contributers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,7 +18,6 @@ package se.leap.bitmaskclient.drawer;
import android.app.Activity;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
@@ -44,12 +43,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-import se.leap.bitmaskclient.DrawerSettingsAdapter;
-import se.leap.bitmaskclient.DrawerSettingsAdapter.DrawerSettingsItem;
import se.leap.bitmaskclient.EipFragment;
import se.leap.bitmaskclient.FragmentManagerEnhanced;
import se.leap.bitmaskclient.MainActivity;
@@ -60,32 +54,22 @@ import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.fragments.AboutFragment;
import se.leap.bitmaskclient.fragments.AlwaysOnDialog;
import se.leap.bitmaskclient.fragments.LogFragment;
-import se.leap.bitmaskclient.utils.PreferenceHelper;
+import se.leap.bitmaskclient.views.IconSwitchEntry;
+import se.leap.bitmaskclient.views.IconTextEntry;
import static android.content.Context.MODE_PRIVATE;
+import static android.view.View.GONE;
+import static android.view.View.VISIBLE;
import static se.leap.bitmaskclient.BitmaskApp.getRefWatcher;
import static se.leap.bitmaskclient.Constants.DONATION_URL;
import static se.leap.bitmaskclient.Constants.ENABLE_DONATION;
import static se.leap.bitmaskclient.Constants.PROVIDER_KEY;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_SWITCH_PROVIDER;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
-import static se.leap.bitmaskclient.DrawerSettingsAdapter.ABOUT;
-import static se.leap.bitmaskclient.DrawerSettingsAdapter.ALWAYS_ON;
-import static se.leap.bitmaskclient.DrawerSettingsAdapter.BATTERY_SAVER;
-import static se.leap.bitmaskclient.DrawerSettingsAdapter.DONATE;
-import static se.leap.bitmaskclient.DrawerSettingsAdapter.DrawerSettingsItem.getSimpleTextInstance;
-import static se.leap.bitmaskclient.DrawerSettingsAdapter.DrawerSettingsItem.getSwitchInstance;
-import static se.leap.bitmaskclient.DrawerSettingsAdapter.LOG;
-import static se.leap.bitmaskclient.DrawerSettingsAdapter.PLUGGABLE_TRANSPORTS;
-import static se.leap.bitmaskclient.DrawerSettingsAdapter.SWITCH_PROVIDER;
import static se.leap.bitmaskclient.R.string.about_fragment_title;
-import static se.leap.bitmaskclient.R.string.donate_title;
import static se.leap.bitmaskclient.R.string.log_fragment_title;
-import static se.leap.bitmaskclient.R.string.switch_provider_menu_option;
import static se.leap.bitmaskclient.utils.ConfigHelper.isDefaultBitmask;
-import static se.leap.bitmaskclient.utils.PreferenceHelper.getProviderName;
import static se.leap.bitmaskclient.utils.PreferenceHelper.getSaveBattery;
-import static se.leap.bitmaskclient.utils.PreferenceHelper.getSavedProviderFromSharedPreferences;
import static se.leap.bitmaskclient.utils.PreferenceHelper.getShowAlwaysOnDialog;
import static se.leap.bitmaskclient.utils.PreferenceHelper.getUsePluggableTransports;
import static se.leap.bitmaskclient.utils.PreferenceHelper.saveBattery;
@@ -114,11 +98,10 @@ public class NavigationDrawerFragment extends Fragment {
private DrawerLayout drawerLayout;
private View drawerView;
- private ListView drawerAccountsListView;
private View fragmentContainerView;
- private ArrayAdapter<String> accountListAdapter;
- private DrawerSettingsAdapter settingsListAdapter;
private Toolbar toolbar;
+ private IconTextEntry account;
+ private IconSwitchEntry saveBattery;
private boolean userLearnedDrawer;
private volatile boolean wasPaused;
@@ -188,14 +171,8 @@ public class NavigationDrawerFragment extends Fragment {
this.drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
toolbar = this.drawerLayout.findViewById(R.id.toolbar);
- final ActionBar actionBar = setupActionBar();
- setupSettingsListAdapter();
- setupSettingsListView();
- accountListAdapter = new ArrayAdapter<>(actionBar.getThemedContext(),
- R.layout.v_icon_text_list_item,
- android.R.id.text1);
- refreshAccountListAdapter();
- setupAccountsListView();
+ setupActionBar();
+ setupEntries();
setupActionBarDrawerToggle(activity);
if (!userLearnedDrawer) {
@@ -245,51 +222,123 @@ public class NavigationDrawerFragment extends Fragment {
};
}
- private void setupAccountsListView() {
- drawerAccountsListView = drawerView.findViewById(R.id.accountList);
- drawerAccountsListView.setAdapter(accountListAdapter);
- drawerAccountsListView.setOnItemClickListener((parent, view, position, id) -> selectItem(parent, position));
+ private void setupEntries() {
+ initAccountEntry();
+ initSwitchProviderEntry();
+ initUseBridgesEntry();
+ initSaveBatteryEntry();
+ initAlwaysOnVpnEntry();
+ initDonateEntry();
+ initLogEntry();
+ initAboutEntry();
}
- private void setupSettingsListView() {
- ListView drawerSettingsListView = drawerView.findViewById(R.id.settingsList);
- drawerSettingsListView.setOnItemClickListener((parent, view, position, id) -> selectItem(parent, position));
- drawerSettingsListView.setAdapter(settingsListAdapter);
+ private void initAccountEntry() {
+ account = drawerView.findViewById(R.id.account);
+ FragmentManagerEnhanced fragmentManager = new FragmentManagerEnhanced(getActivity().getSupportFragmentManager());
+ Provider currentProvider = ProviderObservable.getInstance().getCurrentProvider();
+ account.setText(currentProvider.getName());
+ account.setOnClickListener((buttonView) -> {
+ Fragment fragment = new EipFragment();
+ Bundle arguments = new Bundle();
+ arguments.putParcelable(PROVIDER_KEY, currentProvider);
+ fragment.setArguments(arguments);
+ hideActionBarSubTitle();
+ fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG);
+ closeDrawer();
+ });
}
- private void setupSettingsListAdapter() {
- settingsListAdapter = new DrawerSettingsAdapter(getLayoutInflater());
- if (getContext() == null) {
- return;
+ private void initSwitchProviderEntry() {
+ if (isDefaultBitmask()) {
+ IconTextEntry switchProvider = drawerView.findViewById(R.id.switch_provider);
+ switchProvider.setVisibility(VISIBLE);
+ switchProvider.setOnClickListener(v ->
+ getActivity().startActivityForResult(new Intent(getActivity(), ProviderListActivity.class), REQUEST_CODE_SWITCH_PROVIDER));
}
+ }
- Provider currentProvider = ProviderObservable.getInstance().getCurrentProvider();
- if (currentProvider.supportsPluggableTransports()) {
- settingsListAdapter.addItem(getSwitchInstance(getContext(),
- getString(R.string.nav_drawer_obfuscated_connection),
- R.drawable.ic_bridge_36,
- getUsePluggableTransports(getContext()),
- PLUGGABLE_TRANSPORTS,
- (buttonView, newStateIsChecked) -> onSwitchItemSelected(PLUGGABLE_TRANSPORTS, newStateIsChecked)));
+ private void initUseBridgesEntry() {
+ IconSwitchEntry useBridges = drawerView.findViewById(R.id.bridges_switch);
+ if (ProviderObservable.getInstance().getCurrentProvider().supportsPluggableTransports()) {
+ useBridges.setVisibility(VISIBLE);
+ useBridges.setChecked(getUsePluggableTransports(getContext()));
+ useBridges.setOnCheckedChangeListener((buttonView, isChecked) ->
+ usePluggableTransports(getContext(), isChecked));
+ } else {
+ useBridges.setVisibility(GONE);
}
+ }
- settingsListAdapter.addItem(getSwitchInstance(getContext(),
- getString(R.string.save_battery),
- R.drawable.ic_battery_36,
- getSaveBattery(getContext()),
- BATTERY_SAVER,
- (buttonView, newStateIsChecked) -> onSwitchItemSelected(BATTERY_SAVER, newStateIsChecked)));
+ private void initSaveBatteryEntry() {
+ saveBattery = drawerView.findViewById(R.id.battery_switch);
+ saveBattery.setChecked(getSaveBattery(getContext()));
+ saveBattery.setOnCheckedChangeListener(((buttonView, isChecked) -> {
+ if (isChecked) {
+ showExperimentalFeatureAlert();
+ } else {
+ saveBattery(getContext(), false);
+ }
+ }));
+ }
+
+ private void initAlwaysOnVpnEntry() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(R.string.always_on_vpn), R.drawable.ic_always_on_36, ALWAYS_ON));
- }
- if (isDefaultBitmask()) {
- settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(switch_provider_menu_option), R.drawable.ic_switch_provider_36, SWITCH_PROVIDER));
+ IconTextEntry alwaysOnVpn = drawerView.findViewById(R.id.always_on_vpn);
+ alwaysOnVpn.setVisibility(VISIBLE);
+ alwaysOnVpn.setOnClickListener((buttonView) -> {
+ closeDrawer();
+ if (getShowAlwaysOnDialog(getContext())) {
+ showAlwaysOnDialog();
+ } else {
+ Intent intent = new Intent("android.net.vpn.SETTINGS");
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(intent);
+ }
+ });
}
- settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(log_fragment_title), R.drawable.ic_log_36, LOG));
+ }
+
+ private void initDonateEntry() {
if (ENABLE_DONATION) {
- settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(donate_title), R.drawable.ic_donate_36, DONATE));
+ IconTextEntry donate = drawerView.findViewById(R.id.donate);
+ donate.setVisibility(VISIBLE);
+ donate.setOnClickListener((buttonView) -> {
+ closeDrawer();
+ Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(DONATION_URL));
+ startActivity(browserIntent);
+
+ });
+ }
+ }
+
+ private void initLogEntry() {
+ IconTextEntry log = drawerView.findViewById(R.id.log);
+ FragmentManagerEnhanced fragmentManager = new FragmentManagerEnhanced(getActivity().getSupportFragmentManager());
+ log.setOnClickListener((buttonView) -> {
+ closeDrawer();
+ Fragment fragment = new LogFragment();
+ setActionBarTitle(log_fragment_title);
+ fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG);
+ });
+
+ }
+
+ private void initAboutEntry() {
+ IconTextEntry about = drawerView.findViewById(R.id.about);
+ FragmentManagerEnhanced fragmentManager = new FragmentManagerEnhanced(getActivity().getSupportFragmentManager());
+ about.setOnClickListener((buttonView) -> {
+ closeDrawer();
+ Fragment fragment = new AboutFragment();
+ setActionBarTitle(about_fragment_title);
+ fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG);
+ });
+ }
+
+ private void closeDrawer() {
+ if (drawerLayout != null) {
+ drawerLayout.closeDrawer(fragmentContainerView);
}
- settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(about_fragment_title), R.drawable.ic_about_36, ABOUT));
}
private ActionBar setupActionBar() {
@@ -337,16 +386,6 @@ public class NavigationDrawerFragment extends Fragment {
}, TWO_SECONDS);
}
- private void selectItem(AdapterView<?> list, int position) {
- if (list != null) {
- ((ListView) list).setItemChecked(position, true);
- }
- if (drawerLayout != null) {
- drawerLayout.closeDrawer(fragmentContainerView);
- }
- onTextItemSelected(list, position);
- }
-
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@@ -374,17 +413,11 @@ public class NavigationDrawerFragment extends Fragment {
.setTitle(activity.getString(R.string.save_battery))
.setMessage(activity.getString(R.string.save_battery_message))
.setPositiveButton((android.R.string.yes), (dialog, which) -> {
- DrawerSettingsItem item = settingsListAdapter.getDrawerItem(BATTERY_SAVER);
- item.setChecked(true);
- settingsListAdapter.notifyDataSetChanged();
- saveBattery(getContext(), item.isChecked());
+ saveBattery(getContext(), true);
})
- .setNegativeButton(activity.getString(android.R.string.no), (dialog, which) -> disableSwitch(BATTERY_SAVER)).setOnDismissListener(new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- showEnableExperimentalFeature = false;
- }
- }).setOnCancelListener(dialog -> disableSwitch(BATTERY_SAVER)).show();
+ .setNegativeButton(activity.getString(android.R.string.no), (dialog, which) -> saveBattery.setCheckedQuietly(false))
+ .setOnDismissListener(dialog -> showEnableExperimentalFeature = false)
+ .setOnCancelListener(dialog -> saveBattery.setCheckedQuietly(false)).show();
} catch (IllegalStateException e) {
e.printStackTrace();
}
@@ -447,87 +480,6 @@ public class NavigationDrawerFragment extends Fragment {
return ((AppCompatActivity) getActivity()).getSupportActionBar();
}
- private void onSwitchItemSelected(int elementType, boolean newStateIsChecked) {
- switch (elementType) {
- case BATTERY_SAVER:
- if (getSaveBattery(getContext()) == newStateIsChecked) {
- //initial ui setup, ignore
- return;
- }
- if (newStateIsChecked) {
- showExperimentalFeatureAlert();
- } else {
- saveBattery(getContext(), false);
- disableSwitch(BATTERY_SAVER);
- }
- break;
- case PLUGGABLE_TRANSPORTS:
- if (getUsePluggableTransports(getContext()) == newStateIsChecked) {
- //initial ui setup, ignore
- return;
- }
- usePluggableTransports(getContext(), newStateIsChecked);
- default:
- break;
- }
- }
-
- private void disableSwitch(int elementType) {
- DrawerSettingsItem item = settingsListAdapter.getDrawerItem(elementType);
- item.setChecked(false);
- settingsListAdapter.notifyDataSetChanged();
- }
-
- public void onTextItemSelected(AdapterView<?> parent, int position) {
- // update the main content by replacing fragments
- FragmentManagerEnhanced fragmentManager = new FragmentManagerEnhanced(getActivity().getSupportFragmentManager());
- Fragment fragment = null;
-
- if (parent == drawerAccountsListView) {
- fragment = new EipFragment();
- Bundle arguments = new Bundle();
- Provider currentProvider = getSavedProviderFromSharedPreferences(preferences);
- arguments.putParcelable(PROVIDER_KEY, currentProvider);
- fragment.setArguments(arguments);
- hideActionBarSubTitle();
- } else {
- DrawerSettingsItem settingsItem = settingsListAdapter.getItem(position);
- switch (settingsItem.getItemType()) {
- case SWITCH_PROVIDER:
- getActivity().startActivityForResult(new Intent(getActivity(), ProviderListActivity.class), REQUEST_CODE_SWITCH_PROVIDER);
- break;
- case LOG:
- fragment = new LogFragment();
- setActionBarTitle(log_fragment_title);
- break;
- case ABOUT:
- fragment = new AboutFragment();
- setActionBarTitle(about_fragment_title);
- break;
- case ALWAYS_ON:
- if (getShowAlwaysOnDialog(getContext())) {
- showAlwaysOnDialog();
- } else {
- Intent intent = new Intent("android.net.vpn.SETTINGS");
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(intent);
- }
- break;
- case DONATE:
- Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(DONATION_URL));
- startActivity(browserIntent);
- break;
- default:
- break;
- }
- }
-
- if (fragment != null) {
- fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG);
- }
-
- }
-
private void setActionBarTitle(@StringRes int resId) {
ActionBar actionBar = getActionBar();
if (actionBar != null) {
@@ -542,22 +494,10 @@ public class NavigationDrawerFragment extends Fragment {
}
}
-
public void refresh() {
- refreshAccountListAdapter();
- accountListAdapter.notifyDataSetChanged();
- drawerAccountsListView.setAdapter(accountListAdapter);
- }
-
- private void refreshAccountListAdapter() {
- accountListAdapter.clear();
- String providerName = getProviderName(preferences);
- if (providerName == null) {
- //TODO: ADD A header to the ListView containing a useful message.
- //TODO 2: disable switchProvider
- } else {
- accountListAdapter.add(providerName);
- }
+ Provider currentProvider = ProviderObservable.getInstance().getCurrentProvider();
+ account.setText(currentProvider.getName());
+ initUseBridgesEntry();
}
}
diff --git a/app/src/main/res/layout/f_drawer_main.xml b/app/src/main/res/layout/f_drawer_main.xml
index b04d7b87..e4862ca8 100644
--- a/app/src/main/res/layout/f_drawer_main.xml
+++ b/app/src/main/res/layout/f_drawer_main.xml
@@ -1,70 +1,116 @@
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
android:layout_height="match_parent"
- android:orientation="vertical"
+ android:layout_width="match_parent"
android:background="@color/colorBackground"
tools:context="se.leap.bitmaskclient.drawer.NavigationDrawerFragment"
android:clickable="true"
- android:focusable="true">
+ android:focusable="true"
+ android:fillViewport="true"
+ >
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="150dp">
- <android.support.v7.widget.AppCompatImageView
- android:id="@+id/background"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:adjustViewBounds="false"
- android:cropToPadding="false"
- android:scaleType="fitXY"
- app:srcCompat="@drawable/background_drawer" />
-
- <android.support.v7.widget.AppCompatImageView
- android:id="@+id/foreground"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scaleType="centerInside"
- app:srcCompat="@drawable/drawer_logo" />
- </FrameLayout>
- <RelativeLayout
+ <LinearLayout
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ >
- <ListView
- android:id="@+id/accountList"
+ <FrameLayout
android:layout_width="match_parent"
+ android:layout_height="150dp">
+
+ <android.support.v7.widget.AppCompatImageView
+ android:id="@+id/background"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:adjustViewBounds="false"
+ android:cropToPadding="false"
+ android:scaleType="fitXY"
+ app:srcCompat="@drawable/background_drawer" />
+
+ <android.support.v7.widget.AppCompatImageView
+ android:id="@+id/foreground"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:scaleType="centerInside"
+ app:srcCompat="@drawable/drawer_logo" />
+ </FrameLayout>
+
+ <se.leap.bitmaskclient.views.IconTextEntry
+ android:id="@+id/account"
android:layout_height="wrap_content"
- android:isScrollContainer="false"
+ android:layout_width="wrap_content"
/>
- <View
- android:id="@+id/divider"
- android:layout_below="@id/accountList"
- android:layout_width="match_parent"
- android:layout_height="1px"
- android:background="@android:color/darker_gray"
+ <se.leap.bitmaskclient.views.IconTextEntry
+ android:id="@+id/switch_provider"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ app:text="@string/switch_provider_menu_option"
+ app:icon="@drawable/ic_switch_provider_36"
+ android:visibility="gone"
/>
- <FrameLayout
+ <Space
android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ />
+
+ <se.leap.bitmaskclient.views.IconSwitchEntry
+ android:id="@+id/bridges_switch"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_alignTop="@id/divider"
- android:layout_alignParentBottom="true"
- >
- <ListView
- android:id="@+id/settingsList"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom"
- />
- </FrameLayout>
+ app:text="@string/nav_drawer_obfuscated_connection"
+ app:icon="@drawable/ic_bridge_36"
+ android:visibility="gone"
+ />
+
+ <se.leap.bitmaskclient.views.IconSwitchEntry
+ android:id="@+id/battery_switch"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ app:text="@string/save_battery"
+ app:icon="@drawable/ic_battery_36"
+ />
+
+ <se.leap.bitmaskclient.views.IconTextEntry
+ android:id="@+id/always_on_vpn"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ app:text="@string/always_on_vpn"
+ app:icon="@drawable/ic_always_on_36"
+ android:visibility="gone"
+ />
+ <se.leap.bitmaskclient.views.IconTextEntry
+ android:id="@+id/donate"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ app:text="@string/donate_title"
+ app:icon="@drawable/ic_donate_36"
+ android:visibility="gone"
+ />
+
+ <se.leap.bitmaskclient.views.IconTextEntry
+ android:id="@+id/log"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ app:text="@string/log_fragment_title"
+ app:icon="@drawable/ic_log_36"
+ />
+
+ <se.leap.bitmaskclient.views.IconTextEntry
+ android:id="@+id/about"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ app:text="@string/about_fragment_title"
+ app:icon="@drawable/ic_about_36"
+ />
- </RelativeLayout>
+ </LinearLayout>
-</LinearLayout> \ No newline at end of file
+</ScrollView>