summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-07-05 21:34:50 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-07-06 16:28:46 +0200
commit124f186983f95648867ba1fdd2bec1e098ae95ba (patch)
treecb23beeb6a7ccdad75eeb0c56b5317ef9aa18d58 /app/src/main/java/com/wireguard
parent500a705531a3210aa98b17b77085cf1ea86c274d (diff)
TunnelEditor: fix nits
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard')
-rw-r--r--app/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.java12
-rw-r--r--app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java30
-rw-r--r--app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java12
-rw-r--r--app/src/main/java/com/wireguard/android/model/ApplicationData.java10
-rw-r--r--app/src/main/java/com/wireguard/config/Interface.java6
5 files changed, 43 insertions, 27 deletions
diff --git a/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.java b/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.java
index 8917441f..48dd3895 100644
--- a/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.java
+++ b/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.java
@@ -1,3 +1,9 @@
+/*
+ * Copyright © 2018 Eric Kuck <eric@bluelinelabs.com>.
+ * Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
+ * SPDX-License-Identifier:
+ */
+
package com.wireguard.android.databinding;
import android.content.Context;
@@ -57,12 +63,12 @@ class ObservableKeyedRecyclerViewAdapter<K, E extends Keyed<? extends K>> extend
}
@NonNull @Override
- public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ public ViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
return new ViewHolder(DataBindingUtil.inflate(layoutInflater, layoutId, parent, false));
}
@Override
- public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
+ public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
holder.binding.setVariable(BR.collection, list);
holder.binding.setVariable(BR.key, getKey(position));
holder.binding.setVariable(BR.item, getItem(position));
@@ -125,7 +131,7 @@ class ObservableKeyedRecyclerViewAdapter<K, E extends Keyed<? extends K>> extend
public static class ViewHolder extends RecyclerView.ViewHolder {
final ViewDataBinding binding;
- public ViewHolder(ViewDataBinding binding) {
+ public ViewHolder(final ViewDataBinding binding) {
super(binding.getRoot());
this.binding = binding;
diff --git a/app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java b/app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java
index 7b238dd5..d7151c8d 100644
--- a/app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java
+++ b/app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java
@@ -1,3 +1,9 @@
+/*
+ * Copyright © 2018 Eric Kuck <eric@bluelinelabs.com>.
+ * Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
+ * SPDX-License-Identifier:
+ */
+
package com.wireguard.android.fragment;
import android.app.Activity;
@@ -33,20 +39,19 @@ public class AppListDialogFragment extends DialogFragment {
private static final String KEY_EXCLUDED_APPS = "excludedApps";
private List<String> currentlyExcludedApps;
- private Tunnel tunnel;
private final ObservableKeyedList<String, ApplicationData> appData = new ObservableKeyedArrayList<>();
- public static <T extends Fragment & AppExclusionListener> AppListDialogFragment newInstance(String[] excludedApps, T target) {
- Bundle extras = new Bundle();
+ public static <T extends Fragment & AppExclusionListener> AppListDialogFragment newInstance(final String[] excludedApps, final T target) {
+ final Bundle extras = new Bundle();
extras.putStringArray(KEY_EXCLUDED_APPS, excludedApps);
- AppListDialogFragment fragment = new AppListDialogFragment();
+ final AppListDialogFragment fragment = new AppListDialogFragment();
fragment.setTargetFragment(target, 0);
fragment.setArguments(extras);
return fragment;
}
@Override
- public void onCreate(@Nullable Bundle savedInstanceState) {
+ public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
currentlyExcludedApps = Arrays.asList(getArguments().getStringArray(KEY_EXCLUDED_APPS));
@@ -55,14 +60,11 @@ public class AppListDialogFragment extends DialogFragment {
@Override
public void onAttach(final Context context) {
super.onAttach(context);
- if (context instanceof BaseActivity) {
- tunnel = ((BaseActivity) context).getSelectedTunnel();
- }
}
@Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
+ public Dialog onCreateDialog(final Bundle savedInstanceState) {
+ final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
alertDialogBuilder.setTitle(R.string.excluded_applications);
AppListDialogFragmentBinding binding = AppListDialogFragmentBinding.inflate(getActivity().getLayoutInflater(), null, false);
@@ -88,11 +90,11 @@ public class AppListDialogFragment extends DialogFragment {
final PackageManager pm = activity.getPackageManager();
Application.getAsyncWorker().supplyAsync(() -> {
- Intent launcherIntent = new Intent(Intent.ACTION_MAIN, null);
+ final Intent launcherIntent = new Intent(Intent.ACTION_MAIN, null);
launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
- List<ResolveInfo> resolveInfos = pm.queryIntentActivities(launcherIntent, 0);
+ final List<ResolveInfo> resolveInfos = pm.queryIntentActivities(launcherIntent, 0);
- List<ApplicationData> appData = new ArrayList<>();
+ final List<ApplicationData> appData = new ArrayList<>();
for (ResolveInfo resolveInfo : resolveInfos) {
String packageName = resolveInfo.activityInfo.packageName;
appData.add(new ApplicationData(resolveInfo.loadIcon(pm), resolveInfo.loadLabel(pm).toString(), packageName, currentlyExcludedApps.contains(packageName)));
@@ -115,7 +117,7 @@ public class AppListDialogFragment extends DialogFragment {
void setExclusionsAndDismiss() {
final List<String> excludedApps = new ArrayList<>();
- for (ApplicationData data : appData) {
+ for (final ApplicationData data : appData) {
if (data.isExcludedFromTunnel()) {
excludedApps.add(data.getPackageName());
}
diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java
index c2778c36..981ac93f 100644
--- a/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java
+++ b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java
@@ -225,21 +225,17 @@ public class TunnelEditorFragment extends BaseFragment implements AppExclusionLi
}
public void onRequestSetExcludedApplications(@SuppressWarnings("unused") final View view) {
- FragmentManager fragmentManager = getFragmentManager();
+ final FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
- String[] excludedApps = excludedApplications();
- AppListDialogFragment fragment = AppListDialogFragment.newInstance(excludedApps, this);
+ final String[] excludedApps = Attribute.stringToList(binding.getConfig().getInterfaceSection().getExcludedApplications());
+ final AppListDialogFragment fragment = AppListDialogFragment.newInstance(excludedApps, this);
fragment.show(getFragmentManager(), null);
}
}
@Override
- public void onExcludedAppsSelected(List<String> excludedApps) {
+ public void onExcludedAppsSelected(final List<String> excludedApps) {
binding.getConfig().getInterfaceSection().setExcludedApplications(Attribute.iterableToString(excludedApps));
}
- public String[] excludedApplications() {
- return Attribute.stringToList(binding.getConfig().getInterfaceSection().getExcludedApplications());
- }
-
}
diff --git a/app/src/main/java/com/wireguard/android/model/ApplicationData.java b/app/src/main/java/com/wireguard/android/model/ApplicationData.java
index 77e8da33..07aebde2 100644
--- a/app/src/main/java/com/wireguard/android/model/ApplicationData.java
+++ b/app/src/main/java/com/wireguard/android/model/ApplicationData.java
@@ -1,3 +1,9 @@
+/*
+ * Copyright © 2018 Eric Kuck <eric@bluelinelabs.com>.
+ * Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
+ * SPDX-License-Identifier:
+ */
+
package com.wireguard.android.model;
import android.databinding.BaseObservable;
@@ -15,7 +21,7 @@ public class ApplicationData extends BaseObservable implements Keyed<String> {
@NonNull private final String packageName;
private boolean excludedFromTunnel;
- public ApplicationData(@NonNull Drawable icon, @NonNull String name, @NonNull String packageName, boolean excludedFromTunnel) {
+ public ApplicationData(@NonNull final Drawable icon, @NonNull final String name, @NonNull final String packageName, final boolean excludedFromTunnel) {
this.icon = icon;
this.name = name;
this.packageName = packageName;
@@ -42,7 +48,7 @@ public class ApplicationData extends BaseObservable implements Keyed<String> {
return excludedFromTunnel;
}
- public void setExcludedFromTunnel(boolean excludedFromTunnel) {
+ public void setExcludedFromTunnel(final boolean excludedFromTunnel) {
this.excludedFromTunnel = excludedFromTunnel;
notifyPropertyChanged(BR.excludedFromTunnel);
}
diff --git a/app/src/main/java/com/wireguard/config/Interface.java b/app/src/main/java/com/wireguard/config/Interface.java
index c3068dbb..214c90ad 100644
--- a/app/src/main/java/com/wireguard/config/Interface.java
+++ b/app/src/main/java/com/wireguard/config/Interface.java
@@ -292,6 +292,11 @@ public class Interface {
}
@Bindable
+ public int getExcludedApplicationsCount() {
+ return Attribute.stringToList(excludedApplications).length;
+ }
+
+ @Bindable
public String getListenPort() {
return listenPort;
}
@@ -334,6 +339,7 @@ public class Interface {
public void setExcludedApplications(final String excludedApplications) {
this.excludedApplications = excludedApplications;
notifyPropertyChanged(BR.excludedApplications);
+ notifyPropertyChanged(BR.excludedApplicationsCount);
}
public void setListenPort(final String listenPort) {