Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: (OONI Run v2) Add Link uninstall warning #699

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading