change vote buttons to items

This commit is contained in:
caneleex 2021-04-22 20:19:00 +02:00
parent 03f6e496b9
commit f4808a9778

View File

@ -201,25 +201,30 @@ public abstract class SponsorBlockUtils {
final Context context = ((AlertDialog) dialog).getContext(); final Context context = ((AlertDialog) dialog).getContext();
final SponsorSegment segment = sponsorSegmentsOfCurrentVideo[which]; final SponsorSegment segment = sponsorSegmentsOfCurrentVideo[which];
new AlertDialog.Builder(context) // negative and positive are switched for more intuitive order final VoteOption[] voteOptions = VoteOption.values();
.setNegativeButton(str("vote_upvote"), new DialogInterface.OnClickListener() { String[] items = new String[voteOptions.length];
for (int i = 0; i < voteOptions.length; i++) {
items[i] = voteOptions[i].title;
}
new AlertDialog.Builder(context)
.setItems(items, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, str("vote_started"), Toast.LENGTH_SHORT).show(); switch (voteOptions[which]) {
voteForSegment(segment, true, null); case UPVOTE:
} Toast.makeText(context, str("vote_started"), Toast.LENGTH_SHORT).show();
}) voteForSegment(segment, true, null);
.setPositiveButton(str("vote_downvote"), new DialogInterface.OnClickListener() { break;
@Override case DOWNVOTE:
public void onClick(DialogInterface dialog, int which) { Toast.makeText(context, str("vote_started"), Toast.LENGTH_SHORT).show();
Toast.makeText(context, str("vote_started"), Toast.LENGTH_SHORT).show(); voteForSegment(segment, false, null);
voteForSegment(segment, false, null); break;
} case CATEGORY_CHANGE:
}) onNewCategorySelect(segment, context);
.setNeutralButton(str("vote_category"), new DialogInterface.OnClickListener() { break;
@Override }
public void onClick(DialogInterface dialog, int which) {
onNewCategorySelect(segment, context);
} }
}) })
.show(); .show();
@ -563,6 +568,18 @@ public abstract class SponsorBlockUtils {
} }
} }
private enum VoteOption {
UPVOTE(str("vote_upvote")),
DOWNVOTE(str("vote_downvote")),
CATEGORY_CHANGE(str("vote_category"));
public final String title;
VoteOption(String title) {
this.title = title;
}
}
private static class EditByHandSaveDialogListener implements DialogInterface.OnClickListener { private static class EditByHandSaveDialogListener implements DialogInterface.OnClickListener {
public boolean settingStart; public boolean settingStart;
public WeakReference<EditText> editText; public WeakReference<EditText> editText;