Added favorite answers menu separator

pull/204/head
M66B 3 years ago
parent 37db782e3c
commit dd56ad86d7

@ -1803,6 +1803,7 @@ public class FragmentCompose extends FragmentBase {
return;
}
boolean grouped = BuildConfig.DEBUG;
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), vwAnchorMenu);
Menu main = popupMenu.getMenu();
@ -1821,7 +1822,7 @@ public class FragmentCompose extends FragmentBase {
Collections.sort(answers, new Comparator<EntityAnswer>() {
@Override
public int compare(EntityAnswer a1, EntityAnswer a2) {
if (!BuildConfig.DEBUG || a1.applied.equals(a2.applied))
if (!grouped || a1.applied.equals(a2.applied))
return collator.compare(a1.name, a2.name);
else
return -a1.applied.compareTo(a2.applied);
@ -1847,15 +1848,14 @@ public class FragmentCompose extends FragmentBase {
order++;
String name = answer.name;
if (BuildConfig.DEBUG && answer.applied > 0)
name += " ★";
MenuItem item;
if (answer.group == null)
item = main.add(Menu.NONE, order, order++, name);
else {
SubMenu smenu = map.get(answer.group);
item = smenu.add(Menu.NONE, smenu.size(), smenu.size() + 1, name);
item = smenu.add(answer.applied > 0 ? Menu.FIRST : Menu.NONE,
smenu.size(), smenu.size() + 1, name);
}
item.setIntent(new Intent().putExtra("id", answer.id));
}
@ -1922,6 +1922,9 @@ public class FragmentCompose extends FragmentBase {
}
}
if (grouped)
MenuCompat.setGroupDividerEnabled(popupMenu.getMenu(), true);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {

@ -122,6 +122,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.constraintlayout.widget.Group;
import androidx.core.graphics.ColorUtils;
import androidx.core.view.MenuCompat;
import androidx.core.view.MenuItemCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
@ -2744,6 +2745,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
});
snackbar.show();
} else {
boolean grouped = BuildConfig.DEBUG;
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabReply);
Menu main = popupMenu.getMenu();
@ -2759,7 +2761,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Collections.sort(answers, new Comparator<EntityAnswer>() {
@Override
public int compare(EntityAnswer a1, EntityAnswer a2) {
if (!BuildConfig.DEBUG || a1.applied.equals(a2.applied))
if (!grouped || a1.applied.equals(a2.applied))
return collator.compare(a1.name, a2.name);
else
return -a1.applied.compareTo(a2.applied);
@ -2776,19 +2778,21 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
order++;
String name = answer.name;
if (BuildConfig.DEBUG && answer.applied > 0)
name += " ★";
MenuItem item;
if (answer.group == null)
item = main.add(Menu.NONE, order, order++, name);
else {
SubMenu smenu = map.get(answer.group);
item = smenu.add(Menu.NONE, smenu.size(), smenu.size() + 1, name);
item = smenu.add(answer.applied > 0 ? Menu.FIRST : Menu.NONE,
smenu.size(), smenu.size() + 1, name);
}
item.setIntent(new Intent().putExtra("id", answer.id));
}
if (grouped)
MenuCompat.setGroupDividerEnabled(popupMenu.getMenu(), true);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {

Loading…
Cancel
Save