From 88c4f72b37317c427adf1b611682ccd584a12ff5 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 2 May 2019 04:06:59 -0400 Subject: [PATCH] Remove Butterknife --- app/build.gradle | 4 - .../view/dialogs/CustomAlertDialog.java | 72 ++++-------- .../view/dialogs/FingerprintAuthDialog.java | 18 +-- app/src/main/res/layout/alert_dialog.xml | 110 +++++++++--------- 4 files changed, 89 insertions(+), 115 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index dbc98c4fa..fbdb42cf9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -59,10 +59,6 @@ dependencies { implementation "com.github.topjohnwu.libsu:core:${libsuVersion}" implementation "com.github.topjohnwu.libsu:io:${libsuVersion}" - def butterKnifeVersion = '10.1.0' - implementation "com.jakewharton:butterknife-runtime:${butterKnifeVersion}" - kapt "com.jakewharton:butterknife-compiler:${butterKnifeVersion}" - def koin = "2.0.0-rc-2" implementation "org.koin:koin-core:${koin}" implementation "org.koin:koin-android:${koin}" diff --git a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/CustomAlertDialog.java b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/CustomAlertDialog.java index 2425f0e0c..2dd8a501c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/CustomAlertDialog.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/CustomAlertDialog.java @@ -4,18 +4,14 @@ import android.content.Context; import android.content.DialogInterface; import android.view.LayoutInflater; import android.view.View; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.topjohnwu.magisk.R; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.annotation.StyleRes; import androidx.appcompat.app.AlertDialog; -import butterknife.BindView; + +import com.topjohnwu.magisk.databinding.AlertDialogBinding; public class CustomAlertDialog extends AlertDialog.Builder { @@ -24,32 +20,16 @@ public class CustomAlertDialog extends AlertDialog.Builder { private DialogInterface.OnClickListener neutralListener; protected AlertDialog dialog; - protected ViewHolder vh; - - public class ViewHolder { - @BindView(R.id.dialog_layout) public LinearLayout dialogLayout; - @BindView(R.id.button_panel) public LinearLayout buttons; - - @BindView(R.id.message) public TextView messageView; - @BindView(R.id.negative) public Button negative; - @BindView(R.id.positive) public Button positive; - @BindView(R.id.neutral) public Button neutral; - - ViewHolder(View v) { - new CustomAlertDialog$ViewHolder_ViewBinding(this, v); - messageView.setVisibility(View.GONE); - negative.setVisibility(View.GONE); - positive.setVisibility(View.GONE); - neutral.setVisibility(View.GONE); - buttons.setVisibility(View.GONE); - } - } + protected AlertDialogBinding binding; { - View v = LayoutInflater.from(getContext()).inflate(R.layout.alert_dialog, null); - vh = new ViewHolder(v); - super.setView(v); - + binding = AlertDialogBinding.inflate(LayoutInflater.from(getContext())); + super.setView(binding.getRoot()); + binding.message.setVisibility(View.GONE); + binding.negative.setVisibility(View.GONE); + binding.positive.setVisibility(View.GONE); + binding.neutral.setVisibility(View.GONE); + binding.buttonPanel.setVisibility(View.GONE); } public CustomAlertDialog(@NonNull Context context) { @@ -60,10 +40,6 @@ public class CustomAlertDialog extends AlertDialog.Builder { super(context, themeResId); } - public ViewHolder getViewHolder() { - return vh; - } - @Override public CustomAlertDialog setView(int layoutResId) { return this; } @@ -72,8 +48,8 @@ public class CustomAlertDialog extends AlertDialog.Builder { @Override public CustomAlertDialog setMessage(@Nullable CharSequence message) { - vh.messageView.setVisibility(View.VISIBLE); - vh.messageView.setText(message); + binding.message.setVisibility(View.VISIBLE); + binding.message.setText(message); return this; } @@ -84,11 +60,11 @@ public class CustomAlertDialog extends AlertDialog.Builder { @Override public CustomAlertDialog setPositiveButton(CharSequence text, DialogInterface.OnClickListener listener) { - vh.buttons.setVisibility(View.VISIBLE); - vh.positive.setVisibility(View.VISIBLE); - vh.positive.setText(text); + binding.buttonPanel.setVisibility(View.VISIBLE); + binding.positive.setVisibility(View.VISIBLE); + binding.positive.setText(text); positiveListener = listener; - vh.positive.setOnClickListener(v -> { + binding.positive.setOnClickListener(v -> { if (positiveListener != null) { positiveListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE); } @@ -104,11 +80,11 @@ public class CustomAlertDialog extends AlertDialog.Builder { @Override public CustomAlertDialog setNegativeButton(CharSequence text, DialogInterface.OnClickListener listener) { - vh.buttons.setVisibility(View.VISIBLE); - vh.negative.setVisibility(View.VISIBLE); - vh.negative.setText(text); + binding.buttonPanel.setVisibility(View.VISIBLE); + binding.negative.setVisibility(View.VISIBLE); + binding.negative.setText(text); negativeListener = listener; - vh.negative.setOnClickListener(v -> { + binding.negative.setOnClickListener(v -> { if (negativeListener != null) { negativeListener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE); } @@ -124,11 +100,11 @@ public class CustomAlertDialog extends AlertDialog.Builder { @Override public CustomAlertDialog setNeutralButton(CharSequence text, DialogInterface.OnClickListener listener) { - vh.buttons.setVisibility(View.VISIBLE); - vh.neutral.setVisibility(View.VISIBLE); - vh.neutral.setText(text); + binding.buttonPanel.setVisibility(View.VISIBLE); + binding.neutral.setVisibility(View.VISIBLE); + binding.neutral.setText(text); neutralListener = listener; - vh.neutral.setOnClickListener(v -> { + binding.neutral.setOnClickListener(v -> { if (neutralListener != null) { neutralListener.onClick(dialog, DialogInterface.BUTTON_NEUTRAL); } diff --git a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java index eaf71b846..bd0fd0ad6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java +++ b/app/src/main/java/com/topjohnwu/magisk/view/dialogs/FingerprintAuthDialog.java @@ -36,9 +36,9 @@ public class FingerprintAuthDialog extends CustomAlertDialog { TypedArray ta = theme.obtainStyledAttributes(new int[] {R.attr.imageColorTint}); fingerprint.setTint(ta.getColor(0, Color.GRAY)); ta.recycle(); - vh.messageView.setCompoundDrawables(null, null, null, fingerprint); - vh.messageView.setCompoundDrawablePadding(Utils.dpInPx(20)); - vh.messageView.setGravity(Gravity.CENTER); + binding.message.setCompoundDrawables(null, null, null, fingerprint); + binding.message.setCompoundDrawablePadding(Utils.dpInPx(20)); + binding.message.setGravity(Gravity.CENTER); setMessage(R.string.auth_fingerprint); setNegativeButton(R.string.close, (d, w) -> { helper.cancel(); @@ -81,20 +81,20 @@ public class FingerprintAuthDialog extends CustomAlertDialog { @Override public void onAuthenticationError(int errorCode, CharSequence errString) { - vh.messageView.setTextColor(Color.RED); - vh.messageView.setText(errString); + binding.message.setTextColor(Color.RED); + binding.message.setText(errString); } @Override public void onAuthenticationHelp(int helpCode, CharSequence helpString) { - vh.messageView.setTextColor(Color.RED); - vh.messageView.setText(helpString); + binding.message.setTextColor(Color.RED); + binding.message.setText(helpString); } @Override public void onAuthenticationFailed() { - vh.messageView.setTextColor(Color.RED); - vh.messageView.setText(R.string.auth_fail); + binding.message.setTextColor(Color.RED); + binding.message.setText(R.string.auth_fail); } @Override diff --git a/app/src/main/res/layout/alert_dialog.xml b/app/src/main/res/layout/alert_dialog.xml index 87b9fa730..3a9ef0268 100644 --- a/app/src/main/res/layout/alert_dialog.xml +++ b/app/src/main/res/layout/alert_dialog.xml @@ -1,63 +1,65 @@ - - - - + + android:orientation="vertical" + android:paddingTop="5dp"> - + - + - + + + + + + + - - +