Skip to content

Commit

Permalink
feat: (OONI Run v2) Add Link uninstall warning
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Mar 20, 2024
1 parent f4f11df commit 001740a
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 001740a

Please sign in to comment.