Skip to content

Commit

Permalink
feat: (OONI Run v2) Add Link uninstall warning (#699)
Browse files Browse the repository at this point in the history
- Fixes  ooni/run#147

## Proposed Changes

  - Add `ConfirmDialogFragment` on button click litenner


|.|.|
|-|-|
|
![Screenshot_20240320_165115](https://github.com/ooni/probe-android/assets/17911892/cf1b3894-e866-4be0-889d-d530fd4469f0)
|
![Screenshot_20240320_165136](https://github.com/ooni/probe-android/assets/17911892/55b6d363-b5af-4496-a165-894c93e29139)|
  • Loading branch information
aanorbel authored Mar 21, 2024
1 parent 902dfbf commit eafd4a6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}

Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ class OverviewTestsExpandableListViewAdapter(

view.findViewById<TextView>(R.id.text).apply {
text = getChild(groupPosition, childPosition)
setBackgroundColor(parent.context.resources.getColor(R.color.color_gray1))
}
return view
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eafd4a6

Please sign in to comment.