TunnelEditor: fix nits
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
500a705531
commit
124f186983
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -218,12 +218,13 @@
|
||||
|
||||
<Button
|
||||
style="@style/Widget.AppCompat.Button.Borderless.Colored"
|
||||
android:id="@+id/set_excluded_applications"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="-8dp"
|
||||
android:layout_below="@+id/dns_servers_text"
|
||||
android:onClick="@{fragment::onRequestSetExcludedApplications}"
|
||||
android:text="@{fragment.excludedApplications().length == 0 ? @string/set_excluded_applications : String.format(@string/x_excluded_applications, fragment.excludedApplications().length)}" />
|
||||
android:text="@{@plurals/set_excluded_applications(config.interfaceSection.excludedApplicationsCount, config.interfaceSection.excludedApplicationsCount)}" />
|
||||
</RelativeLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
|
@ -69,7 +69,10 @@
|
||||
<string name="restore_on_boot_summary">Bring up previously-enabled tunnels on boot</string>
|
||||
<string name="restore_on_boot_title">Restore on boot</string>
|
||||
<string name="save">Save</string>
|
||||
<string name="set_excluded_applications">Set Excluded Applications</string>
|
||||
<plurals name="set_excluded_applications">
|
||||
<item quantity="one">%d Excluded Application</item>
|
||||
<item quantity="other">%d Excluded Applications</item>
|
||||
</plurals>
|
||||
<string name="set_exclusions">Set Exclusions</string>
|
||||
<string name="settings">Settings</string>
|
||||
<string name="toggle_error">Error toggling WireGuard tunnel: %s</string>
|
||||
|
Loading…
Reference in New Issue
Block a user