summaryrefslogtreecommitdiff
path: root/app/src/main/java/se
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2019-07-12 07:50:59 -0700
committercyberta <cyberta@riseup.net>2019-07-12 07:50:59 -0700
commit144244cab15014d495985f396c618729209a8f8a (patch)
treef00ca9565e5e7c27f1019b637b82caee026fd049 /app/src/main/java/se
parent7ac4446d834786b0139cb8565b22279ed6955d42 (diff)
parentce69a6c81f69801c20ac9e05faa86f5d4db4ba44 (diff)
Merge branch 'UI_tweaks' into 'master'
Ui tweaks See merge request leap/bitmask_android!90
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java33
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java44
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java9
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/MainActivity.java19
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/OkHttpClientGenerator.java6
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java10
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java3
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/StartActivity.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java46
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java8
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/userstatus/User.java46
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java127
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java8
13 files changed, 119 insertions, 242 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java b/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java
index 36dd5868..28e5f5af 100644
--- a/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java
@@ -62,25 +62,22 @@ public abstract class AbstractProviderDetailActivity extends ConfigWizardBaseAct
android.R.id.text1,
optionsList.toArray(new String[optionsList.size()])
));
- options.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- String text = ((TextView) view).getText().toString();
- Intent intent;
- if (text.equals(getString(R.string.login_to_profile))) {
- Log.d(TAG, "login selected");
- intent = new Intent(getApplicationContext(), LoginActivity.class);
- } else if (text.equals(getString(R.string.create_profile))) {
- Log.d(TAG, "signup selected");
- intent = new Intent(getApplicationContext(), SignupActivity.class);
- } else {
- onAnonymouslySelected();
- return;
- }
- intent.putExtra(PROVIDER_KEY, provider);
- intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
- startActivityForResult(intent, REQUEST_CODE_CONFIGURE_LEAP);
+ options.setOnItemClickListener((parent, view, position, id) -> {
+ String text = ((TextView) view).getText().toString();
+ Intent intent;
+ if (text.equals(getString(R.string.login_to_profile))) {
+ Log.d(TAG, "login selected");
+ intent = new Intent(getApplicationContext(), LoginActivity.class);
+ } else if (text.equals(getString(R.string.create_profile))) {
+ Log.d(TAG, "signup selected");
+ intent = new Intent(getApplicationContext(), SignupActivity.class);
+ } else {
+ onAnonymouslySelected();
+ return;
}
+ intent.putExtra(PROVIDER_KEY, provider);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
+ startActivityForResult(intent, REQUEST_CODE_CONFIGURE_LEAP);
});
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java b/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java
index 01b10575..89aeb4be 100644
--- a/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java
+++ b/app/src/main/java/se/leap/bitmaskclient/DrawerSettingsAdapter.java
@@ -16,6 +16,9 @@
*/
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;
@@ -23,6 +26,7 @@ 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;
@@ -52,21 +56,27 @@ public class DrawerSettingsAdapter extends BaseAdapter {
private boolean isChecked = false;
private int itemType = NONE;
private CompoundButton.OnCheckedChangeListener callback;
+ private Drawable iconResource;
- private DrawerSettingsItem(String description, int viewType, boolean isChecked, int itemType, CompoundButton.OnCheckedChangeListener callback) {
+ 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(String description, int itemType) {
- return new DrawerSettingsItem(description, VIEW_SIMPLE_TEXT, false, itemType, null);
+ 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(String description, boolean isChecked, int itemType, CompoundButton.OnCheckedChangeListener callback) {
- return new DrawerSettingsItem(description, VIEW_SWITCH, isChecked, itemType, callback);
+ 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() {
@@ -138,7 +148,7 @@ public class DrawerSettingsAdapter extends BaseAdapter {
switch(type) {
case VIEW_SIMPLE_TEXT:
convertView = initTextViewBinding(holder);
- holder.textView.setText(drawerSettingsItem.description);
+ bindSimpleText(drawerSettingsItem, holder);
break;
case VIEW_SWITCH:
convertView = initSwitchBinding(holder);
@@ -154,7 +164,7 @@ public class DrawerSettingsAdapter extends BaseAdapter {
holder.resetSwitchView();
convertView = initTextViewBinding(holder);
}
- holder.textView.setText(drawerSettingsItem.description);
+ bindSimpleText(drawerSettingsItem, holder);
break;
case VIEW_SWITCH:
if (!holder.isSwitchViewHolder()) {
@@ -169,23 +179,36 @@ public class DrawerSettingsAdapter extends BaseAdapter {
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.switchView.setText(drawerSettingsItem.description);
+ 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(android.R.id.text1);
+ 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_single_list_item, null);
+ 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;
}
@@ -200,6 +223,7 @@ public class DrawerSettingsAdapter extends BaseAdapter {
static class ViewHolder {
TextView textView;
+ ImageView iconView;
SwitchCompat switchView;
boolean isSwitchViewHolder() {
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 69d81ccf..11ad8da3 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -32,14 +32,15 @@ import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
+import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
+import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
@@ -61,12 +62,12 @@ import se.leap.bitmaskclient.views.VpnStateImage;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_NONETWORK;
+import static se.leap.bitmaskclient.Constants.ASK_TO_CANCEL_VPN;
import static se.leap.bitmaskclient.Constants.EIP_RESTART_ON_BOOT;
import static se.leap.bitmaskclient.Constants.PROVIDER_KEY;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_CONFIGURE_LEAP;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_LOG_IN;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_SWITCH_PROVIDER;
-import static se.leap.bitmaskclient.Constants.ASK_TO_CANCEL_VPN;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
import static se.leap.bitmaskclient.EipSetupObserver.connectionRetry;
import static se.leap.bitmaskclient.EipSetupObserver.gatewayOrder;
@@ -92,7 +93,7 @@ public class EipFragment extends Fragment implements Observer {
VpnStateImage vpnStateImage;
@InjectView(R.id.vpn_main_button)
- Button mainButton;
+ AppCompatButton mainButton;
@InjectView(R.id.routed_text)
AppCompatTextView routedText;
@@ -537,7 +538,7 @@ public class EipFragment extends Fragment implements Observer {
private void setVpnRouteText() {
String vpnRouteString = provider.getName();
VpnProfile vpnProfile = ProfileManager.getLastConnectedVpn();
- if (vpnProfile != null && vpnProfile.mName != null) {
+ if (vpnProfile != null && !TextUtils.isEmpty(vpnProfile.mName)) {
vpnRouteString += " (" + vpnProfile.mName + ")";
}
vpnRoute.setText(vpnRouteString);
diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
index 32b4562a..f2e333ab 100644
--- a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
@@ -20,10 +20,12 @@ package se.leap.bitmaskclient;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
+import android.support.annotation.StringRes;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
+import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
@@ -108,6 +110,7 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener,
bundle.putParcelable(PROVIDER_KEY, provider);
eipFragment.setArguments(bundle);
fragmentManagerEnhanced.replace(R.id.main_container, eipFragment, MainActivity.TAG);
+ hideActionBarSubTitle();
} else {
super.onBackPressed();
}
@@ -135,9 +138,11 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener,
}
bundle.putParcelable(PROVIDER_KEY, provider);
fragment.setArguments(bundle);
+ hideActionBarSubTitle();
break;
case ACTION_SHOW_LOG_FRAGMENT:
fragment = new LogFragment();
+ setActionBarTitle(R.string.log_fragment_title);
break;
default:
break;
@@ -152,6 +157,19 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener,
}
}
+ private void hideActionBarSubTitle() {
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setSubtitle(null);
+ }
+ }
+ private void setActionBarTitle(@StringRes int stringId) {
+ ActionBar actionBar = getSupportActionBar();
+ if (actionBar != null) {
+ actionBar.setSubtitle(stringId);
+ }
+ }
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -190,6 +208,7 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener,
fragment.setArguments(arguments);
new FragmentManagerEnhanced(getSupportFragmentManager())
.replace(R.id.main_container, fragment, EipFragment.TAG);
+ hideActionBarSubTitle();
}
@Override
diff --git a/app/src/main/java/se/leap/bitmaskclient/OkHttpClientGenerator.java b/app/src/main/java/se/leap/bitmaskclient/OkHttpClientGenerator.java
index 7d1054f1..69270140 100644
--- a/app/src/main/java/se/leap/bitmaskclient/OkHttpClientGenerator.java
+++ b/app/src/main/java/se/leap/bitmaskclient/OkHttpClientGenerator.java
@@ -52,7 +52,7 @@ import static se.leap.bitmaskclient.R.string.error_io_exception_user_message;
import static se.leap.bitmaskclient.R.string.error_no_such_algorithm_exception_user_message;
import static se.leap.bitmaskclient.R.string.keyChainAccessError;
import static se.leap.bitmaskclient.R.string.server_unreachable_message;
-import static se.leap.bitmaskclient.R.string.warning_corrupted_provider_cert;
+import static se.leap.bitmaskclient.utils.ConfigHelper.getProviderFormattedString;
/**
* Created by cyberta on 08.01.18.
@@ -92,7 +92,7 @@ public class OkHttpClientGenerator {
} catch (IllegalArgumentException e) {
e.printStackTrace();
// TODO ca cert is invalid - show better error ?!
- addErrorMessageToJson(initError, resources.getString(certificate_error));
+ addErrorMessageToJson(initError, getProviderFormattedString(resources, certificate_error));
} catch (IllegalStateException | KeyManagementException | KeyStoreException e) {
e.printStackTrace();
addErrorMessageToJson(initError, String.format(resources.getString(keyChainAccessError), e.getLocalizedMessage()));
@@ -102,7 +102,7 @@ public class OkHttpClientGenerator {
} catch (CertificateException e) {
e.printStackTrace();
// TODO ca cert is invalid - show better error ?!
- addErrorMessageToJson(initError, resources.getString(certificate_error));
+ addErrorMessageToJson(initError, getProviderFormattedString(resources, certificate_error));
} catch (UnknownHostException e) {
e.printStackTrace();
addErrorMessageToJson(initError, resources.getString(server_unreachable_message));
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
index 15c7457e..37adbe93 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java
@@ -107,6 +107,7 @@ import static se.leap.bitmaskclient.R.string.warning_corrupted_provider_cert;
import static se.leap.bitmaskclient.R.string.warning_corrupted_provider_details;
import static se.leap.bitmaskclient.R.string.warning_expired_provider_cert;
import static se.leap.bitmaskclient.utils.ConfigHelper.getFingerprintFromCertificate;
+import static se.leap.bitmaskclient.utils.ConfigHelper.getProviderFormattedString;
import static se.leap.bitmaskclient.utils.ConfigHelper.parseRsaKeyFromString;
import static se.leap.bitmaskclient.utils.PreferenceHelper.deleteProviderDetailsFromPreferences;
import static se.leap.bitmaskclient.utils.PreferenceHelper.getFromPersistedProvider;
@@ -237,8 +238,8 @@ public abstract class ProviderApiManagerBase {
deleteProviderDetailsFromPreferences(preferences, provider.getDomain());
}
- String formatErrorMessage(final int toastStringId) {
- return formatErrorMessage(resources.getString(toastStringId));
+ String formatErrorMessage(final int errorStringId) {
+ return formatErrorMessage(getProviderFormattedString(resources, errorStringId));
}
private String formatErrorMessage(String errorMessage) {
@@ -751,10 +752,11 @@ public abstract class ProviderApiManagerBase {
Bundle setErrorResult(Bundle result, int errorMessageId, String errorId) {
JSONObject errorJson = new JSONObject();
+ String errorMessage = getProviderFormattedString(resources, errorMessageId);
if (errorId != null) {
- addErrorMessageToJson(errorJson, resources.getString(errorMessageId), errorId);
+ addErrorMessageToJson(errorJson, errorMessage, errorId);
} else {
- addErrorMessageToJson(errorJson, resources.getString(errorMessageId));
+ addErrorMessageToJson(errorJson, errorMessage);
}
result.putString(ERRORS, errorJson.toString());
result.putBoolean(BROADCAST_RESULT_KEY, false);
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java
index 961957d2..55a1da93 100644
--- a/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java
@@ -46,7 +46,6 @@ import org.json.JSONException;
import butterknife.InjectView;
import butterknife.OnClick;
import se.leap.bitmaskclient.Constants.CREDENTIAL_ERRORS;
-import se.leap.bitmaskclient.userstatus.User;
import static android.text.TextUtils.isEmpty;
import static android.view.View.GONE;
@@ -250,14 +249,12 @@ public abstract class ProviderCredentialsBaseActivity extends ConfigWizardBaseAc
}
void login(String username, String password) {
- User.setUserName(username);
Bundle parameters = bundleUsernameAndPassword(username, password);
ProviderAPICommand.execute(this, LOG_IN, parameters, provider);
}
public void signUp(String username, String password) {
- User.setUserName(username);
Bundle parameters = bundleUsernameAndPassword(username, password);
ProviderAPICommand.execute(this, SIGN_UP, parameters, provider);
diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
index d30b98a0..d8aca351 100644
--- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
@@ -30,7 +30,6 @@ import java.lang.annotation.RetentionPolicy;
import de.blinkt.openvpn.core.VpnStatus;
import se.leap.bitmaskclient.eip.EipCommand;
-import se.leap.bitmaskclient.userstatus.User;
import static se.leap.bitmaskclient.Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE;
import static se.leap.bitmaskclient.Constants.EIP_RESTART_ON_BOOT;
@@ -90,7 +89,6 @@ public class StartActivity extends Activity{
// initialize app necessities
VpnStatus.initLogCache(getApplicationContext().getCacheDir());
- User.init(getString(R.string.default_username));
prepareEIP();
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 21d061d1..640c143a 100644
--- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java
@@ -27,6 +27,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
+import android.support.annotation.StringRes;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
@@ -118,8 +119,6 @@ public class NavigationDrawerFragment extends Fragment {
private volatile boolean wasPaused;
private volatile boolean shouldCloseOnResume;
- private String title;
-
private SharedPreferences preferences;
private final static String KEY_SHOW_ENABLE_EXPERIMENTAL_FEATURE = "KEY_SHOW_ENABLE_EXPERIMENTAL_FEATURE";
@@ -188,7 +187,7 @@ public class NavigationDrawerFragment extends Fragment {
setupSettingsListAdapter();
setupSettingsListView();
accountListAdapter = new ArrayAdapter<>(actionBar.getThemedContext(),
- R.layout.v_single_list_item,
+ R.layout.v_icon_text_list_item,
android.R.id.text1);
refreshAccountListAdapter();
setupAccountsListView();
@@ -244,12 +243,7 @@ public class NavigationDrawerFragment extends Fragment {
private void setupAccountsListView() {
drawerAccountsListView = drawerView.findViewById(R.id.accountList);
drawerAccountsListView.setAdapter(accountListAdapter);
- drawerAccountsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- selectItem(parent, position);
- }
- });
+ drawerAccountsListView.setOnItemClickListener((parent, view, position, id) -> selectItem(parent, position));
}
private void setupSettingsListView() {
@@ -261,22 +255,24 @@ public class NavigationDrawerFragment extends Fragment {
private void setupSettingsListAdapter() {
settingsListAdapter = new DrawerSettingsAdapter(getLayoutInflater());
if (getContext() != null) {
- settingsListAdapter.addItem(getSwitchInstance(getString(R.string.save_battery),
+ settingsListAdapter.addItem(getSwitchInstance(getContext(),
+ getString(R.string.save_battery),
+ R.drawable.ic_battery_36,
getSaveBattery(getContext()),
BATTERY_SAVER,
(buttonView, newStateIsChecked) -> onSwitchItemSelected(BATTERY_SAVER, newStateIsChecked)));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- settingsListAdapter.addItem(getSimpleTextInstance(getString(R.string.always_on_vpn), ALWAYS_ON));
+ settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(R.string.always_on_vpn), R.drawable.ic_always_on_36, ALWAYS_ON));
}
if (isDefaultBitmask()) {
- settingsListAdapter.addItem(getSimpleTextInstance(getString(switch_provider_menu_option), SWITCH_PROVIDER));
+ settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(switch_provider_menu_option), R.drawable.ic_switch_provider_36, SWITCH_PROVIDER));
}
- settingsListAdapter.addItem(getSimpleTextInstance(getString(log_fragment_title), LOG));
+ settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(log_fragment_title), R.drawable.ic_log_36, LOG));
if (ENABLE_DONATION) {
- settingsListAdapter.addItem(getSimpleTextInstance(getString(donate_title), DONATE));
+ settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(donate_title), R.drawable.ic_donate_36, DONATE));
}
- settingsListAdapter.addItem(getSimpleTextInstance(getString(about_fragment_title), ABOUT));
+ settingsListAdapter.addItem(getSimpleTextInstance(getContext(), getString(about_fragment_title), R.drawable.ic_about_36, ABOUT));
}
private ActionBar setupActionBar() {
@@ -285,6 +281,7 @@ public class NavigationDrawerFragment extends Fragment {
final ActionBar actionBar = activity.getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
+ actionBar.setDisplayShowTitleEnabled(true);
return actionBar;
}
@@ -464,12 +461,12 @@ public class NavigationDrawerFragment extends Fragment {
Fragment fragment = null;
if (parent == drawerAccountsListView) {
- title = getString(R.string.vpn_fragment_title);
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()) {
@@ -477,12 +474,12 @@ public class NavigationDrawerFragment extends Fragment {
getActivity().startActivityForResult(new Intent(getActivity(), ProviderListActivity.class), REQUEST_CODE_SWITCH_PROVIDER);
break;
case LOG:
- title = getString(log_fragment_title);
fragment = new LogFragment();
+ setActionBarTitle(log_fragment_title);
break;
case ABOUT:
- title = getString(about_fragment_title);
fragment = new AboutFragment();
+ setActionBarTitle(about_fragment_title);
break;
case ALWAYS_ON:
if (getShowAlwaysOnDialog(getContext())) {
@@ -506,14 +503,19 @@ public class NavigationDrawerFragment extends Fragment {
fragmentManager.replace(R.id.main_container, fragment, MainActivity.TAG);
}
- restoreActionBar();
}
- public void restoreActionBar() {
+ private void setActionBarTitle(@StringRes int resId) {
+ ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ actionBar.setSubtitle(resId);
+ }
+ }
+
+ private void hideActionBarSubTitle() {
ActionBar actionBar = getActionBar();
if (actionBar != null) {
- actionBar.setDisplayShowTitleEnabled(true);
- actionBar.setSubtitle(title);
+ actionBar.setSubtitle(null);
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
index a896197c..f6e3df7c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
@@ -40,6 +40,7 @@ import static se.leap.bitmaskclient.Constants.EIP_ACTION_START_BLOCKING_VPN;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_STOP_BLOCKING_VPN;
import static se.leap.bitmaskclient.Constants.EIP_IS_ALWAYS_ON;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
+import static se.leap.bitmaskclient.utils.ConfigHelper.getProviderFormattedString;
public class VoidVpnService extends VpnService implements Observer, VpnNotificationManager.VpnServiceCallback {
@@ -147,7 +148,7 @@ public class VoidVpnService extends VpnService implements Observer, VpnNotificat
private void establishBlockingVpn() {
try {
- VpnStatus.logInfo(getString(R.string.void_vpn_establish));
+ VpnStatus.logInfo(getProviderFormattedString(getResources(), R.string.void_vpn_establish));
VpnStatus.updateStateString(STATE_ESTABLISH, "",
R.string.void_vpn_establish, ConnectionStatus.LEVEL_BLOCKING);
Builder builder = prepareBlockingVpnProfile();
@@ -180,9 +181,10 @@ public class VoidVpnService extends VpnService implements Observer, VpnNotificat
}
if (eipStatus.isBlockingVpnEstablished()) {
+ String blockingMessage = getProviderFormattedString(getResources(), eipStatus.getLocalizedResId());
notificationManager.buildVoidVpnNotification(
- getString(eipStatus.getLocalizedResId()),
- getString(eipStatus.getLocalizedResId()),
+ blockingMessage,
+ blockingMessage,
eipStatus.getLevel());
} else {
notificationManager.stopNotifications(NOTIFICATION_CHANNEL_NEWSTATUS_ID);
diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/User.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/User.java
deleted file mode 100644
index 64ce0629..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/userstatus/User.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Copyright (c) 2013 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.userstatus;
-
-import se.leap.bitmaskclient.LeapSRPSession;
-
-public class User {
- private static String user_name;
- private static User user;
-
- public static User init(String default_username) {
- if (user == null) {
- user = new User();
- user.setUserName(default_username);
- }
- return user;
- }
-
- public static void setUserName(String user_name) {
- User.user_name = user_name;
- }
-
- private User() { }
-
- public static String userName() {
- return user_name;
- }
-
- public static boolean loggedIn() {
- return LeapSRPSession.loggedIn();
- }
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java
deleted file mode 100644
index 90ad0ffd..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatus.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- * Copyright (c) 2013 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.userstatus;
-
-import android.content.res.*;
-
-import java.util.*;
-
-import se.leap.bitmaskclient.R;
-
-public class UserStatus extends Observable {
- public static String TAG = UserStatus.class.getSimpleName();
- private static UserStatus current_status;
- private static Resources resources;
-
- public enum SessionStatus {
- LOGGED_IN,
- LOGGED_OUT,
- NOT_LOGGED_IN,
- DIDNT_LOG_OUT,
- LOGGING_IN,
- LOGGING_OUT,
- SIGNING_UP;
-
- @Override
- public String toString() {
- int id = 0;
- if(this == SessionStatus.LOGGED_IN)
- id = R.string.logged_in_user_status;
- else if(this == SessionStatus.LOGGED_OUT)
- id = R.string.logged_out_user_status;
- else if(this == SessionStatus.NOT_LOGGED_IN)
- id = R.string.not_logged_in_user_status;
- else if(this == SessionStatus.DIDNT_LOG_OUT)
- id = R.string.didnt_log_out_user_status;
- else if(this == SessionStatus.LOGGING_IN)
- id = R.string.logging_in_user_status;
- else if(this == SessionStatus.LOGGING_OUT)
- id = R.string.logging_out_user_status;
- else if(this == SessionStatus.SIGNING_UP)
- id = R.string.signingup_message;
-
- return resources.getString(id);
- }
- }
-
- private static SessionStatus session_status = SessionStatus.LOGGED_OUT;
-
- public static UserStatus getInstance(Resources resources) {
- if (current_status == null) {
- current_status = new UserStatus(resources);
- }
- return current_status;
- }
-
- private UserStatus(Resources resources) {
- UserStatus.resources = resources;
- }
-
- private void sessionStatus(SessionStatus session_status) {
- this.session_status = session_status;
- }
-
- public SessionStatus sessionStatus() {
- return session_status;
- }
-
- public boolean inProgress() {
- return session_status == SessionStatus.LOGGING_IN
- || session_status == SessionStatus.LOGGING_OUT;
- }
-
- public boolean isLoggedIn() {
- return session_status == SessionStatus.LOGGED_IN;
- }
-
- public boolean isLoggedOut() {
- return session_status == SessionStatus.LOGGED_OUT;
- }
-
- public boolean notLoggedIn() {
- return session_status == SessionStatus.NOT_LOGGED_IN;
- }
-
- public boolean didntLogOut() {
- return session_status == SessionStatus.DIDNT_LOG_OUT;
- }
-
- public static void updateStatus(SessionStatus session_status, Resources resources) {
- current_status = getInstance(resources);
- current_status.sessionStatus(session_status);
- current_status.setChanged();
- current_status.notifyObservers();
- }
-
- @Override
- public String toString() {
- String user_session_status = User.userName();
-
- String default_username = resources.getString(R.string.default_username, "");
- if(user_session_status.isEmpty() && !default_username.equalsIgnoreCase("null")) user_session_status = default_username;
- user_session_status += " " + session_status.toString();
-
- user_session_status = user_session_status.trim();
- if(User.userName().isEmpty())
- user_session_status = capitalize(user_session_status);
- return user_session_status;
- }
-
- private String capitalize(String to_be_capitalized) {
- return to_be_capitalized.substring(0,1).toUpperCase() + to_be_capitalized.substring(1);
- }
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java
index d1ac0eb3..da74c7c4 100644
--- a/app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java
@@ -17,8 +17,10 @@
package se.leap.bitmaskclient.utils;
import android.content.Context;
+import android.content.res.Resources;
import android.os.Looper;
import android.support.annotation.NonNull;
+import android.support.annotation.StringRes;
import org.json.JSONException;
import org.json.JSONObject;
@@ -43,6 +45,7 @@ import java.util.Calendar;
import se.leap.bitmaskclient.BuildConfig;
import se.leap.bitmaskclient.ProviderAPI;
+import se.leap.bitmaskclient.R;
import static se.leap.bitmaskclient.Constants.DEFAULT_BITMASK;
@@ -182,4 +185,9 @@ public class ConfigHelper {
public static int getCurrentTimezone() {
return Calendar.getInstance().get(Calendar.ZONE_OFFSET) / 3600000;
}
+
+ public static String getProviderFormattedString(Resources resources, @StringRes int resourceId) {
+ String appName = resources.getString(R.string.app_name);
+ return resources.getString(resourceId, appName);
+ }
}