diff options
author | cyBerta <cyberta@riseup.net> | 2023-10-30 18:38:28 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2023-10-31 18:53:25 +0100 |
commit | 48cf66f75e91d7bd017277bc249e6cbec0a4a078 (patch) | |
tree | 91b8bea046c8e179aa25edabda5ced937dbfac95 /app | |
parent | 751cae19707c9970b03edd14008c28b2045028ce (diff) |
Replace Butterknife references with ViewBinding
Diffstat (limited to 'app')
12 files changed, 62 insertions, 177 deletions
diff --git a/app/build.gradle b/app/build.gradle index 0b5165b0..aa9e0480 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -415,16 +415,10 @@ dependencies { androidTestImplementation 'tools.fastlane:screengrab:2.1.1' testImplementation 'tools.fastlane:screengrab:2.1.1' - testImplementation 'org.json:json:20180813' androidTestImplementation 'androidx.test.ext:junit:1.1.4' debugImplementation 'com.squareup.leakcanary:leakcanary-android-core:2.9.1' - annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3' - annotationProcessor 'com.squareup.dagger:dagger-compiler:1.2.2' - implementation 'com.jakewharton:butterknife:10.2.1' - //TODO: replace that library - compileOnly 'com.squareup.dagger:dagger-compiler:1.2.2' - implementation 'com.github.pedrovgs:renderers:1.5' + implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.squareup.okhttp3:okhttp:4.10.0' implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.10.0' diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/AboutFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/AboutFragment.java index e92aa703..275dc1c4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/AboutFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/AboutFragment.java @@ -1,5 +1,9 @@ package se.leap.bitmaskclient.base.fragments; +import static android.view.View.VISIBLE; +import static se.leap.bitmaskclient.R.string.about_fragment_title; +import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarSubtitle; + import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Bundle; @@ -7,42 +11,24 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import androidx.appcompat.widget.AppCompatTextView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; import se.leap.bitmaskclient.BuildConfig; import se.leap.bitmaskclient.R; - -import static android.view.View.VISIBLE; -import static se.leap.bitmaskclient.R.string.about_fragment_title; -import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarSubtitle; +import se.leap.bitmaskclient.databinding.FAboutBinding; public class AboutFragment extends Fragment { final public static String TAG = AboutFragment.class.getSimpleName(); final public static int VIEWED = 0; - private Unbinder unbinder; - - @BindView(R.id.version) - AppCompatTextView versionTextView; - - @BindView(R.id.terms_of_service) - AppCompatTextView termsOfService; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.f_about, container, false); - unbinder = ButterKnife.bind(this, view); + FAboutBinding binding = FAboutBinding.inflate(inflater); setActionBarSubtitle(this, about_fragment_title); - return view; - } - @Override - public void onStart() { - super.onStart(); String version; String name = "Bitmask"; try { @@ -54,18 +40,13 @@ public class AboutFragment extends Fragment { version = "error fetching version"; } - versionTextView.setText(getString(R.string.version_info, name, version)); + binding.version.setText(getString(R.string.version_info, name, version)); if (BuildConfig.FLAVOR_branding.equals("custom") && hasTermsOfServiceResource()) { - termsOfService.setText(getString(getTermsOfServiceResource())); - termsOfService.setVisibility(VISIBLE); + binding.termsOfService.setText(getString(getTermsOfServiceResource())); + binding.termsOfService.setVisibility(VISIBLE); } - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - unbinder.unbind(); + return binding.getRoot(); } private boolean hasTermsOfServiceResource() { diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/AlwaysOnDialog.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/AlwaysOnDialog.java index e68ba170..faa9950b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/AlwaysOnDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/AlwaysOnDialog.java @@ -1,26 +1,20 @@ package se.leap.bitmaskclient.base.fragments; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.saveShowAlwaysOnDialog; + import android.app.Dialog; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; -import android.widget.CheckBox; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatDialogFragment; -import androidx.appcompat.widget.AppCompatTextView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; import se.leap.bitmaskclient.R; -import se.leap.bitmaskclient.base.views.IconTextView; - -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.saveShowAlwaysOnDialog; +import se.leap.bitmaskclient.databinding.DCheckboxConfirmBinding; /** @@ -33,41 +27,24 @@ public class AlwaysOnDialog extends AppCompatDialogFragment { public final static String TAG = AlwaysOnDialog.class.getName(); - @BindView(R.id.do_not_show_again) - CheckBox doNotShowAgainCheckBox; - - @BindView(R.id.user_message) - IconTextView userMessage; - - @BindView(R.id.block_vpn_user_message) - AppCompatTextView blockVpnUserMessage; - - private Unbinder unbinder; - - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + LayoutInflater inflater = getActivity().getLayoutInflater(); - View view = inflater.inflate(R.layout.d_checkbox_confirm, null); - unbinder = ButterKnife.bind(this, view); + DCheckboxConfirmBinding binding = DCheckboxConfirmBinding.inflate(inflater); - userMessage.setIcon(R.drawable.ic_settings); - userMessage.setText(getString(R.string.always_on_vpn_user_message)); + binding.userMessage.setIcon(R.drawable.ic_settings); + binding.userMessage.setText(getString(R.string.always_on_vpn_user_message)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - blockVpnUserMessage.setVisibility(View.VISIBLE); + binding.blockVpnUserMessage.setVisibility(View.VISIBLE); } - builder.setView(view) + builder.setView(binding.getRoot()) .setPositiveButton(android.R.string.ok, (dialog, id) -> { - if (doNotShowAgainCheckBox.isChecked()) { + if (binding.doNotShowAgain.isChecked()) { saveShowAlwaysOnDialog(false); } Intent intent = new Intent("android.net.vpn.SETTINGS"); @@ -78,9 +55,4 @@ public class AlwaysOnDialog extends AppCompatDialogFragment { return builder.create(); } - @Override - public void onDestroyView() { - super.onDestroyView(); - unbinder.unbind(); - } } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/DonationReminderDialog.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/DonationReminderDialog.java index 08346791..6a0a63c5 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/DonationReminderDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/DonationReminderDialog.java @@ -1,5 +1,10 @@ package se.leap.bitmaskclient.base.fragments; +import static se.leap.bitmaskclient.base.models.Constants.DONATION_REMINDER_DURATION; +import static se.leap.bitmaskclient.base.models.Constants.DONATION_URL; +import static se.leap.bitmaskclient.base.models.Constants.ENABLE_DONATION; +import static se.leap.bitmaskclient.base.models.Constants.ENABLE_DONATION_REMINDER; + import android.app.Dialog; import android.content.ActivityNotFoundException; import android.content.Context; @@ -8,59 +13,32 @@ import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; -import android.view.View; -import android.widget.Button; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatDialogFragment; import java.text.ParseException; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; -import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.utils.DateHelper; import se.leap.bitmaskclient.base.utils.PreferenceHelper; - -import static se.leap.bitmaskclient.base.models.Constants.DONATION_REMINDER_DURATION; -import static se.leap.bitmaskclient.base.models.Constants.DONATION_URL; -import static se.leap.bitmaskclient.base.models.Constants.ENABLE_DONATION; -import static se.leap.bitmaskclient.base.models.Constants.ENABLE_DONATION_REMINDER; -import static se.leap.bitmaskclient.base.models.Constants.FIRST_TIME_USER_DATE; -import static se.leap.bitmaskclient.base.models.Constants.LAST_DONATION_REMINDER_DATE; +import se.leap.bitmaskclient.databinding.DonationReminderDialogBinding; public class DonationReminderDialog extends AppCompatDialogFragment { public final static String TAG = DonationReminderDialog.class.getName(); private static boolean isShown = false; - @BindView(R.id.btnDonate) - Button btnDonate; - - @BindView(R.id.btnLater) - Button btnLater; - - private Unbinder unbinder; - - @Override - public void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); - View view = inflater.inflate(R.layout.donation_reminder_dialog, null); - unbinder = ButterKnife.bind(this, view); + DonationReminderDialogBinding binding = DonationReminderDialogBinding.inflate(inflater); isShown = true; - builder.setView(view); - btnDonate.setOnClickListener(v -> { + builder.setView(binding.getRoot()); + binding.btnDonate.setOnClickListener(v -> { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(DONATION_URL)); try { startActivity(browserIntent); @@ -70,7 +48,7 @@ public class DonationReminderDialog extends AppCompatDialogFragment { PreferenceHelper.lastDonationReminderDate(DateHelper.getCurrentDateString()); dismiss(); }); - btnLater.setOnClickListener(v -> { + binding.btnLater.setOnClickListener(v -> { PreferenceHelper.lastDonationReminderDate(DateHelper.getCurrentDateString()); dismiss(); }); @@ -78,12 +56,6 @@ public class DonationReminderDialog extends AppCompatDialogFragment { return builder.create(); } - @Override - public void onDestroyView() { - super.onDestroyView(); - unbinder.unbind(); - } - public static boolean isCallable(Context context) { if (isShown) { return false; @@ -97,7 +69,6 @@ public class DonationReminderDialog extends AppCompatDialogFragment { Log.e(TAG, "context is null!"); return false; } - String firstTimeUserDate = PreferenceHelper.getFirstTimeUserDate(); if (firstTimeUserDate == null) { PreferenceHelper.firstTimeUserDate(DateHelper.getCurrentDateString()); diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/TetheringDialog.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/TetheringDialog.java index eb9d149f..588daa3f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/TetheringDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/TetheringDialog.java @@ -19,7 +19,6 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatDialogFragment; -import androidx.appcompat.widget.AppCompatTextView; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -28,13 +27,11 @@ import java.util.Observer; import java.util.regex.Matcher; import java.util.regex.Pattern; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; import de.blinkt.openvpn.core.VpnStatus; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.utils.PreferenceHelper; import se.leap.bitmaskclient.base.views.IconCheckboxEntry; +import se.leap.bitmaskclient.databinding.DListSelectionBinding; import se.leap.bitmaskclient.firewall.FirewallManager; import se.leap.bitmaskclient.tethering.TetheringObservable; @@ -59,17 +56,8 @@ public class TetheringDialog extends AppCompatDialogFragment implements Observer public final static String TAG = TetheringDialog.class.getName(); - @BindView(R.id.tvTitle) - AppCompatTextView title; - - @BindView(R.id.user_message) - AppCompatTextView userMessage; - - @BindView(R.id.selection_list_view) - RecyclerView selectionListView; DialogListAdapter adapter; private DialogListAdapter.ViewModel[] dataset; - private Unbinder unbinder; public static class DialogListAdapter extends RecyclerView.Adapter<DialogListAdapter.ViewHolder> { @@ -139,21 +127,19 @@ public class TetheringDialog extends AppCompatDialogFragment implements Observer public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); - View view = inflater.inflate(R.layout.d_list_selection, null); - unbinder = ButterKnife.bind(this, view); + DListSelectionBinding binding = DListSelectionBinding.inflate(inflater); - title.setText(R.string.tethering); - userMessage.setMovementMethod(LinkMovementMethod.getInstance()); - userMessage.setLinkTextColor(getContext().getResources().getColor(R.color.colorPrimary)); - userMessage.setText(createUserMessage()); + binding.tvTitle.setText(R.string.tethering); + binding.userMessage.setMovementMethod(LinkMovementMethod.getInstance()); + binding.userMessage.setLinkTextColor(getContext().getResources().getColor(R.color.colorPrimary)); + binding.userMessage.setText(createUserMessage()); initDataset(); adapter = new DialogListAdapter(dataset, this::onItemClick); - selectionListView.setAdapter(adapter); - selectionListView.setLayoutManager(new LinearLayoutManager(getActivity())); - + binding.selectionListView.setAdapter(adapter); + binding.selectionListView.setLayoutManager(new LinearLayoutManager(getActivity())); - builder.setView(view) + builder.setView(binding.getRoot()) .setPositiveButton(android.R.string.ok, (dialog, id) -> { PreferenceHelper.allowWifiTethering(dataset[0].checked); PreferenceHelper.allowUsbTethering(dataset[1].checked); @@ -190,12 +176,6 @@ public class TetheringDialog extends AppCompatDialogFragment implements Observer TetheringObservable.getInstance().deleteObserver(this); } - @Override - public void onDestroyView() { - super.onDestroyView(); - unbinder.unbind(); - } - public void onItemClick(DialogListAdapter.ViewModel item) { } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/IconCheckboxEntry.java b/app/src/main/java/se/leap/bitmaskclient/base/views/IconCheckboxEntry.java index 0957712b..ee1a6903 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/IconCheckboxEntry.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/IconCheckboxEntry.java @@ -5,31 +5,20 @@ import android.content.Context; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.LayoutInflater; -import android.view.View; import android.widget.LinearLayout; import androidx.annotation.Nullable; -import androidx.appcompat.widget.AppCompatImageView; -import androidx.appcompat.widget.AppCompatTextView; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; -import butterknife.BindView; -import butterknife.ButterKnife; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.fragments.TetheringDialog; +import se.leap.bitmaskclient.databinding.VIconSelectTextListItemBinding; public class IconCheckboxEntry extends LinearLayout { - @BindView(android.R.id.text1) - AppCompatTextView textView; - - @BindView(R.id.material_icon) - AppCompatImageView iconView; - - @BindView(R.id.checked_icon) - AppCompatImageView checkedIcon; + VIconSelectTextListItemBinding binding; public IconCheckboxEntry(Context context) { super(context); @@ -55,14 +44,13 @@ public class IconCheckboxEntry extends LinearLayout { void initLayout(Context context, AttributeSet attrs) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View rootview = inflater.inflate(R.layout.v_icon_select_text_list_item, this, true); - ButterKnife.bind(this, rootview); + binding = VIconSelectTextListItemBinding.inflate(inflater, this, true); } public void bind(TetheringDialog.DialogListAdapter.ViewModel model) { this.setEnabled(model.enabled); - textView.setText(model.text); - textView.setEnabled(model.enabled); + binding.text1.setText(model.text); + binding.text1.setEnabled(model.enabled); Drawable checkIcon = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_check_bold)).mutate(); if (model.enabled) { @@ -71,14 +59,14 @@ public class IconCheckboxEntry extends LinearLayout { DrawableCompat.setTint(checkIcon, ContextCompat.getColor(getContext(), R.color.colorDisabled)); } - iconView.setImageDrawable(model.image); - checkedIcon.setImageDrawable(checkIcon); + binding.materialIcon.setImageDrawable(model.image); + binding.checkedIcon.setImageDrawable(checkIcon); setChecked(model.checked); } public void setChecked(boolean checked) { - checkedIcon.setVisibility(checked ? VISIBLE : GONE); - checkedIcon.setContentDescription(checked ? "selected" : "unselected"); + binding.checkedIcon.setVisibility(checked ? VISIBLE : GONE); + binding.checkedIcon.setContentDescription(checked ? "selected" : "unselected"); } } diff --git a/app/src/main/res/layout-xlarge/f_about.xml b/app/src/main/res/layout-xlarge/f_about.xml index ed7f4f1a..90a263a0 100644 --- a/app/src/main/res/layout-xlarge/f_about.xml +++ b/app/src/main/res/layout-xlarge/f_about.xml @@ -1,3 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> + <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/aboutLayout" @@ -8,8 +10,7 @@ android:layout_marginStart="@dimen/stdpadding" android:layout_marginEnd="@dimen/stdpadding" android:layout_marginRight="@dimen/stdpadding" - tools:context=".base.MainActivity" - tools:viewBindingIgnore="true"> + tools:context=".base.MainActivity"> <LinearLayout android:layout_width="match_parent" diff --git a/app/src/main/res/layout/d_checkbox_confirm.xml b/app/src/main/res/layout/d_checkbox_confirm.xml index d8811226..e55d5267 100644 --- a/app/src/main/res/layout/d_checkbox_confirm.xml +++ b/app/src/main/res/layout/d_checkbox_confirm.xml @@ -2,8 +2,7 @@ <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - xmlns:tools="http://schemas.android.com/tools" - tools:viewBindingIgnore="true"> + xmlns:tools="http://schemas.android.com/tools"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" diff --git a/app/src/main/res/layout/d_list_selection.xml b/app/src/main/res/layout/d_list_selection.xml index 908c228f..6d87f1df 100644 --- a/app/src/main/res/layout/d_list_selection.xml +++ b/app/src/main/res/layout/d_list_selection.xml @@ -2,8 +2,7 @@ <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - xmlns:tools="http://schemas.android.com/tools" - tools:viewBindingIgnore="true"> + xmlns:tools="http://schemas.android.com/tools"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" diff --git a/app/src/main/res/layout/donation_reminder_dialog.xml b/app/src/main/res/layout/donation_reminder_dialog.xml index 1260a99e..a4f3667a 100644 --- a/app/src/main/res/layout/donation_reminder_dialog.xml +++ b/app/src/main/res/layout/donation_reminder_dialog.xml @@ -4,8 +4,7 @@ android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" - android:scrollbars="none" - tools:viewBindingIgnore="true"> + android:scrollbars="none"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" diff --git a/app/src/main/res/layout/f_about.xml b/app/src/main/res/layout/f_about.xml index e0193c1b..190ac758 100644 --- a/app/src/main/res/layout/f_about.xml +++ b/app/src/main/res/layout/f_about.xml @@ -1,3 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> + <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/aboutLayout" @@ -8,8 +10,7 @@ android:layout_marginStart="@dimen/stdpadding" android:layout_marginRight="@dimen/stdpadding" android:layout_marginEnd="@dimen/stdpadding" - tools:context=".base.MainActivity" - tools:viewBindingIgnore="true"> + tools:context=".base.MainActivity"> <LinearLayout android:layout_width="match_parent" diff --git a/app/src/main/res/layout/v_icon_select_text_list_item.xml b/app/src/main/res/layout/v_icon_select_text_list_item.xml index 60c5908c..46954b5e 100644 --- a/app/src/main/res/layout/v_icon_select_text_list_item.xml +++ b/app/src/main/res/layout/v_icon_select_text_list_item.xml @@ -1,10 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/item_container" android:layout_height="?android:attr/listPreferredItemHeightSmall" android:layout_width="match_parent" android:orientation="horizontal" - xmlns:tools="http://schemas.android.com/tools" - tools:viewBindingIgnore="true"> + xmlns:tools="http://schemas.android.com/tools"> <androidx.appcompat.widget.AppCompatImageView android:id="@+id/material_icon" |