Compose answer favorites

This commit is contained in:
M66B 2021-05-09 21:38:19 +02:00
parent f521b4bb68
commit 9bc70538fe
1 changed files with 17 additions and 1 deletions

View File

@ -1751,15 +1751,25 @@ public class FragmentCompose extends FragmentBase {
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), vwAnchorMenu);
Menu main = popupMenu.getMenu();
List<EntityAnswer> favorites = new ArrayList<>();
List<String> groups = new ArrayList<>();
for (EntityAnswer answer : answers)
if (answer.group != null && !groups.contains(answer.group))
if (answer.favorite)
favorites.add(answer);
else if (answer.group != null && !groups.contains(answer.group))
groups.add(answer.group);
Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(groups, collator);
Collections.sort(favorites, new Comparator<EntityAnswer>() {
@Override
public int compare(EntityAnswer a1, EntityAnswer a2) {
return collator.compare(a1.name, a2.name);
}
});
int order = 0;
Map<String, SubMenu> map = new HashMap<>();
@ -1767,6 +1777,8 @@ public class FragmentCompose extends FragmentBase {
map.put(group, main.addSubMenu(Menu.NONE, order, order++, group));
for (EntityAnswer answer : answers) {
if (answer.favorite)
continue;
order++;
if (answer.group == null)
main.add(Menu.NONE, order, order++, answer.toString())
@ -1778,6 +1790,10 @@ public class FragmentCompose extends FragmentBase {
}
}
for (EntityAnswer answer : favorites)
main.add(Menu.NONE, order, order++, answer.toString())
.setIntent(new Intent().putExtra("id", answer.id));
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {