diff options
author | cyBerta <cyberta@riseup.net> | 2019-10-11 12:08:42 +0200 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2019-10-11 12:08:42 +0200 |
commit | 788d99b62ace71d24df1e44735d988ce475cdd42 (patch) | |
tree | 37eeb90c8856f163b32babf94787715d224e321d | |
parent | ed5c0385f9c9e7836b80eed6dda4dc798ec6c41c (diff) |
Add a red hint in navigation drawer if apps are currently excluded from VPN
5 files changed, 76 insertions, 32 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java index 95966b44..b163f1dd 100644 --- a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java @@ -24,10 +24,8 @@ 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; import org.json.JSONException; @@ -38,6 +36,7 @@ import java.util.Observer; import se.leap.bitmaskclient.drawer.NavigationDrawerFragment; import se.leap.bitmaskclient.eip.EipCommand; +import se.leap.bitmaskclient.fragments.ExcludeAppsFragment; import se.leap.bitmaskclient.fragments.LogFragment; import se.leap.bitmaskclient.utils.PreferenceHelper; @@ -60,7 +59,7 @@ import static se.leap.bitmaskclient.R.string.vpn_certificate_user_message; import static se.leap.bitmaskclient.utils.PreferenceHelper.storeProviderInPreferences; -public class MainActivity extends AppCompatActivity implements EipSetupListener, Observer { +public class MainActivity extends AppCompatActivity implements EipSetupListener, Observer, ExcludeAppsFragment.ExcludedAppsCallback { public final static String TAG = MainActivity.class.getSimpleName(); @@ -79,7 +78,7 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener, protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.a_main); - setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); + setSupportActionBar(findViewById(R.id.toolbar)); navigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); @@ -88,10 +87,7 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener, provider = ProviderObservable.getInstance().getCurrentProvider(); // Set up the drawer. - navigationDrawerFragment.setUp( - R.id.navigation_drawer, - (DrawerLayout) findViewById(R.id.drawer_layout)); - + navigationDrawerFragment.setUp(R.id.navigation_drawer, findViewById(R.id.drawer_layout)); handleIntentAction(getIntent()); } @@ -307,4 +303,10 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener, } startActivityForResult(intent, REQUEST_CODE_LOG_IN); } + + + @Override + public void onAppsExcluded(int number) { + navigationDrawerFragment.onAppsExcluded(number); + } } 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 c0652bb1..21a25997 100644 --- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java @@ -44,6 +44,8 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import java.util.Set; + import de.blinkt.openvpn.core.VpnStatus; import se.leap.bitmaskclient.EipFragment; import se.leap.bitmaskclient.FragmentManagerEnhanced; @@ -57,6 +59,7 @@ import se.leap.bitmaskclient.fragments.AboutFragment; import se.leap.bitmaskclient.fragments.AlwaysOnDialog; import se.leap.bitmaskclient.fragments.ExcludeAppsFragment; import se.leap.bitmaskclient.fragments.LogFragment; +import se.leap.bitmaskclient.utils.PreferenceHelper; import se.leap.bitmaskclient.views.IconSwitchEntry; import se.leap.bitmaskclient.views.IconTextEntry; @@ -315,6 +318,10 @@ public class NavigationDrawerFragment extends Fragment { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { IconTextEntry excludeApps = drawerView.findViewById(R.id.exclude_apps); excludeApps.setVisibility(VISIBLE); + Set<String> apps = PreferenceHelper.getExcludedApps(this.getContext()); + if (apps != null) { + updateExcludeAppsSubtitle(excludeApps, apps.size()); + } FragmentManagerEnhanced fragmentManager = new FragmentManagerEnhanced(getActivity().getSupportFragmentManager()); excludeApps.setOnClickListener((buttonView) -> { closeDrawer(); @@ -525,4 +532,19 @@ public class NavigationDrawerFragment extends Fragment { initUseBridgesEntry(); } + private void updateExcludeAppsSubtitle(IconTextEntry excludeApps, int number) { + if (number > 0) { + excludeApps.setSubtitle(getContext().getResources().getQuantityString(R.plurals.subtitle_exclude_apps, number, number)); + excludeApps.setSubtitleColor(R.color.colorError); + } else { + excludeApps.hideSubtitle(); + } + } + + public void onAppsExcluded(int number) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + IconTextEntry excludeApps = drawerView.findViewById(R.id.exclude_apps); + updateExcludeAppsSubtitle(excludeApps, number); + } + } } diff --git a/app/src/main/java/se/leap/bitmaskclient/fragments/ExcludeAppsFragment.java b/app/src/main/java/se/leap/bitmaskclient/fragments/ExcludeAppsFragment.java index 63b3908d..9dc838c6 100644 --- a/app/src/main/java/se/leap/bitmaskclient/fragments/ExcludeAppsFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/fragments/ExcludeAppsFragment.java @@ -7,12 +7,11 @@ package se.leap.bitmaskclient.fragments; import android.Manifest; import android.app.Activity; -import android.content.SharedPreferences; -import android.support.v4.app.Fragment; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; +import android.support.v4.app.Fragment; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; @@ -31,14 +30,12 @@ import android.widget.SearchView; import android.widget.TextView; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; import java.util.Vector; import de.blinkt.openvpn.VpnProfile; - import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.utils.PreferenceHelper; @@ -50,10 +47,22 @@ public class ExcludeAppsFragment extends Fragment implements AdapterView.OnItemC private VpnProfile mProfile; private PackageAdapter mListAdapter; - private SharedPreferences allow_apps; - private SharedPreferences.Editor allow_apps_editor; private Set<String> apps; + public interface ExcludedAppsCallback { + void onAppsExcluded(int number); + } + + private ExcludedAppsCallback callback; + + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (context instanceof ExcludedAppsCallback) { + callback = (ExcludedAppsCallback) context; + } + } + @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { AppViewHolder avh = (AppViewHolder) view.getTag(); @@ -82,9 +91,9 @@ public class ExcludeAppsFragment extends Fragment implements AdapterView.OnItemC // we want to bind data to. AppViewHolder holder = new AppViewHolder(); holder.rootView = convertView; - holder.appName = (TextView) convertView.findViewById(R.id.app_name); - holder.appIcon = (ImageView) convertView.findViewById(R.id.app_icon); - holder.checkBox = (CompoundButton) convertView.findViewById(R.id.app_selected); + holder.appName = convertView.findViewById(R.id.app_name); + holder.appIcon = convertView.findViewById(R.id.app_icon); + holder.checkBox = convertView.findViewById(R.id.app_selected); convertView.setTag(holder); return holder; @@ -110,9 +119,11 @@ public class ExcludeAppsFragment extends Fragment implements AdapterView.OnItemC apps.remove(packageName); } + if (callback != null) { + callback.onAppsExcluded(apps.size()); + } } - class PackageAdapter extends BaseAdapter implements Filterable { private Vector<ApplicationInfo> mPackages; private final LayoutInflater mInflater; @@ -295,13 +306,10 @@ public class ExcludeAppsFragment extends Fragment implements AdapterView.OnItemC return true; } }); - searchView.setOnCloseListener(new SearchView.OnCloseListener() { - @Override - public boolean onClose() { - mListView.clearTextFilter(); - mListAdapter.getFilter().filter(""); - return false; - } + searchView.setOnCloseListener(() -> { + mListView.clearTextFilter(); + mListAdapter.getFilter().filter(""); + return false; }); super.onCreateOptionsMenu(menu, inflater); @@ -319,12 +327,7 @@ public class ExcludeAppsFragment extends Fragment implements AdapterView.OnItemC mListView.setEmptyView(v.findViewById(R.id.loading_container)); - new Thread(new Runnable() { - @Override - public void run() { - mListAdapter.populateList(getActivity()); - } - }).start(); + new Thread(() -> mListAdapter.populateList(getActivity())).start(); return v; } diff --git a/app/src/main/java/se/leap/bitmaskclient/views/IconTextEntry.java b/app/src/main/java/se/leap/bitmaskclient/views/IconTextEntry.java index 0e86f506..cd151885 100644 --- a/app/src/main/java/se/leap/bitmaskclient/views/IconTextEntry.java +++ b/app/src/main/java/se/leap/bitmaskclient/views/IconTextEntry.java @@ -4,6 +4,7 @@ import android.annotation.TargetApi; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; +import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; import android.support.annotation.StringRes; @@ -81,6 +82,19 @@ public class IconTextEntry extends LinearLayout { textView.setText(id); } + public void setSubtitle(String text) { + subtitleView.setText(text); + subtitleView.setVisibility(VISIBLE); + } + + public void hideSubtitle() { + subtitleView.setVisibility(GONE); + } + + public void setSubtitleColor(@ColorRes int color) { + subtitleView.setTextColor(getContext().getResources().getColor(color)); + } + public void setText(CharSequence text) { textView.setText(text); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index be763133..1e4840c2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -118,5 +118,8 @@ <string name="nav_drawer_obfuscated_connection">Using Bridges</string> <string name="nav_drawer_subtitle_obfuscated_connection">Circumvent VPN filtering</string> <string name="warning_exclude_apps_message">Be careful of excluding apps from VPN. This will reveal your identity and compromise your security.</string> - + <plurals name="subtitle_exclude_apps"> + <item quantity="one">%d unprotected app</item> + <item quantity="other">%d unprotected apps</item> + </plurals> </resources> |