change vote buttons to items

This commit is contained in:
caneleex 2021-04-22 20:19:00 +02:00
parent 5136350702
commit deccc86b95
1 changed files with 34 additions and 17 deletions

View File

@ -201,25 +201,30 @@ public abstract class SponsorBlockUtils {
final Context context = ((AlertDialog) dialog).getContext();
final SponsorSegment segment = sponsorSegmentsOfCurrentVideo[which];
new AlertDialog.Builder(context) // negative and positive are switched for more intuitive order
.setNegativeButton(str("vote_upvote"), new DialogInterface.OnClickListener() {
final VoteOption[] voteOptions = VoteOption.values();
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
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, str("vote_started"), Toast.LENGTH_SHORT).show();
voteForSegment(segment, true, null);
}
})
.setPositiveButton(str("vote_downvote"), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, str("vote_started"), Toast.LENGTH_SHORT).show();
voteForSegment(segment, false, null);
}
})
.setNeutralButton(str("vote_category"), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onNewCategorySelect(segment, context);
switch (voteOptions[which]) {
case UPVOTE:
Toast.makeText(context, str("vote_started"), Toast.LENGTH_SHORT).show();
voteForSegment(segment, true, null);
break;
case DOWNVOTE:
Toast.makeText(context, str("vote_started"), Toast.LENGTH_SHORT).show();
voteForSegment(segment, false, null);
break;
case CATEGORY_CHANGE:
onNewCategorySelect(segment, context);
break;
}
}
})
.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 {
public boolean settingStart;
public WeakReference<EditText> editText;