From 124f186983f95648867ba1fdd2bec1e098ae95ba Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 5 Jul 2018 21:34:50 +0200 Subject: [PATCH] TunnelEditor: fix nits Signed-off-by: Jason A. Donenfeld --- .../ObservableKeyedRecyclerViewAdapter.java | 12 ++++++-- .../fragment/AppListDialogFragment.java | 30 ++++++++++--------- .../fragment/TunnelEditorFragment.java | 12 +++----- .../android/model/ApplicationData.java | 10 +++++-- .../java/com/wireguard/config/Interface.java | 6 ++++ .../res/layout/tunnel_editor_fragment.xml | 3 +- app/src/main/res/values/strings.xml | 5 +++- 7 files changed, 49 insertions(+), 29 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 . + * Copyright © 2018 Jason A. Donenfeld . All Rights Reserved. + * SPDX-License-Identifier: + */ + package com.wireguard.android.databinding; import android.content.Context; @@ -57,12 +63,12 @@ class ObservableKeyedRecyclerViewAdapter> 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> 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 . + * Copyright © 2018 Jason A. Donenfeld . 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 currentlyExcludedApps; - private Tunnel tunnel; private final ObservableKeyedList appData = new ObservableKeyedArrayList<>(); - public static AppListDialogFragment newInstance(String[] excludedApps, T target) { - Bundle extras = new Bundle(); + public static 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 resolveInfos = pm.queryIntentActivities(launcherIntent, 0); + final List resolveInfos = pm.queryIntentActivities(launcherIntent, 0); - List appData = new ArrayList<>(); + final List 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 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 excludedApps) { + public void onExcludedAppsSelected(final List 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 . + * Copyright © 2018 Jason A. Donenfeld . 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 { @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 { 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 @@ -291,6 +291,11 @@ public class Interface { return excludedApplications; } + @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) { diff --git a/app/src/main/res/layout/tunnel_editor_fragment.xml b/app/src/main/res/layout/tunnel_editor_fragment.xml index cbdc46cf..5a2bfe34 100644 --- a/app/src/main/res/layout/tunnel_editor_fragment.xml +++ b/app/src/main/res/layout/tunnel_editor_fragment.xml @@ -218,12 +218,13 @@