From 001740a1252f42cd996a28b524adcb0d126596d2 Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Wed, 20 Mar 2024 17:09:49 +0100 Subject: [PATCH] feat: (OONI Run v2) Add Link uninstall warning --- .../ooniprobe/activity/OverviewActivity.java | 24 ++++++++++- .../OverviewTestsExpandableListViewAdapter.kt | 1 - .../fragment/ConfirmDialogFragment.kt | 43 +++++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/OverviewActivity.java b/app/src/main/java/org/openobservatory/ooniprobe/activity/OverviewActivity.java index 344045758..646556874 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/OverviewActivity.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/OverviewActivity.java @@ -6,8 +6,10 @@ import static org.openobservatory.ooniprobe.common.PreferenceManagerExtensionKt.resolveStatus; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; +import android.os.Parcelable; import android.text.TextUtils; import android.text.format.DateUtils; import android.view.View; @@ -29,10 +31,12 @@ import org.openobservatory.ooniprobe.common.PreferenceManager; import org.openobservatory.ooniprobe.common.ReadMorePlugin; import org.openobservatory.ooniprobe.databinding.ActivityOverviewBinding; +import org.openobservatory.ooniprobe.fragment.ConfirmDialogFragment; import org.openobservatory.ooniprobe.model.database.InstalledDescriptor; import org.openobservatory.ooniprobe.model.database.Result; import org.openobservatory.ooniprobe.model.database.TestDescriptor; +import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.Locale; import java.util.Objects; @@ -41,7 +45,7 @@ import io.noties.markwon.Markwon; -public class OverviewActivity extends AbstractActivity { +public class OverviewActivity extends AbstractActivity implements ConfirmDialogFragment.OnClickListener { private static final String TEST = "test"; ActivityOverviewBinding binding; @@ -184,7 +188,16 @@ public void setThemeColor(int color) { private void setUpOnCLickListeners() { binding.customUrl.setOnClickListener(view -> customUrlClick()); - binding.uninstallLink.setOnClickListener(view -> viewModel.uninstallLinkClicked(this, (InstalledDescriptor) descriptor)); + binding.uninstallLink.setOnClickListener(view -> { + ConfirmDialogFragment.newInstance( + "Are you sure?", + "You will be able to install this link again only from the original link sent by the creator.", + "UNINSTALL LINK", + getString(android.R.string.cancel), + null + ) + .show(getSupportFragmentManager(), null); + }); binding.automaticUpdatesSwitch.setOnCheckedChangeListener((compoundButton, isChecked) -> viewModel.automaticUpdatesSwitchClicked(isChecked)); } @@ -203,4 +216,11 @@ public boolean onSupportNavigateUp() { void customUrlClick() { startActivity(new Intent(this, CustomWebsiteActivity.class)); } + + @Override + public void onConfirmDialogClick(@Nullable Serializable serializable, @Nullable Parcelable parcelable, int buttonClicked) { + if (buttonClicked == DialogInterface.BUTTON_POSITIVE) { + viewModel.uninstallLinkClicked(this, (InstalledDescriptor) descriptor); + } + } } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/overview/OverviewTestsExpandableListViewAdapter.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/overview/OverviewTestsExpandableListViewAdapter.kt index 5640144b2..1a1b60398 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/overview/OverviewTestsExpandableListViewAdapter.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/overview/OverviewTestsExpandableListViewAdapter.kt @@ -140,7 +140,6 @@ class OverviewTestsExpandableListViewAdapter( view.findViewById(R.id.text).apply { text = getChild(groupPosition, childPosition) - setBackgroundColor(parent.context.resources.getColor(R.color.color_gray1)) } return view } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/fragment/ConfirmDialogFragment.kt b/app/src/main/java/org/openobservatory/ooniprobe/fragment/ConfirmDialogFragment.kt index b951c6fd4..4f04a8e8b 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/fragment/ConfirmDialogFragment.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/fragment/ConfirmDialogFragment.kt @@ -27,6 +27,49 @@ class ConfirmDialogFragment( private const val NEUTRAL_BUTTON = "NEUTRAL_BUTTON" private const val SERIALIZABLE = "SERIALIZABLE" private const val PARCELABLE = "PARCELABLE" + + @JvmStatic + fun newInstance( + title: String, + message: String, + ) = ConfirmDialogFragment( + title = title, + message = message, + ) + + @JvmStatic + fun newInstance( + title: String, + message: String, + positiveButton: String? = null, + negativeButton: String? = null, + neutralButton: String? = null + ) = ConfirmDialogFragment( + title = title, + message = message, + positiveButton = positiveButton, + negativeButton = negativeButton, + neutralButton = neutralButton + ) + + @JvmStatic + fun newInstance( + serializable: Serializable? = null, + parcelable: Parcelable? = null, + title: String, + message: String, + positiveButton: String? = null, + negativeButton: String? = null, + neutralButton: String? = null + ) = ConfirmDialogFragment( + serializable, + parcelable, + title, + message, + positiveButton, + negativeButton, + neutralButton + ) } private val listener: OnClickListener