Added clickable page numbers to lookup pagination

This commit is contained in:
Intelli 2022-02-08 19:25:07 -07:00
parent 673529df54
commit 19efdeff89
10 changed files with 103 additions and 9 deletions

View file

@ -148,7 +148,83 @@ public class Util extends Queue {
nextArrow = Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + (page + 1) + "|" + nextArrow + Chat.COMPONENT_TAG_CLOSE;
}
return message.append(Color.WHITE + backArrow + Phrase.build(Phrase.LOOKUP_PAGE, page + "/" + totalPages) + nextArrow).toString();
StringBuilder pagination = new StringBuilder();
if (totalPages > 1) {
pagination.append(Color.GREY + "(");
if (page > 3) {
pagination.append(Color.WHITE + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + 1 + "|" + "1 " + Chat.COMPONENT_TAG_CLOSE);
if (page > 4 && totalPages > 7) {
pagination.append(Color.GREY + "... ");
}
else {
pagination.append(Color.GREY + "| ");
}
}
int displayStart = (page - 2) < 1 ? 1 : (page - 2);
int displayEnd = (page + 2) > totalPages ? totalPages : (page + 2);
if (page > 999 || (page > 101 && totalPages > 99999)) { // limit to max 5 page numbers
displayStart = (displayStart + 1) < displayEnd ? (displayStart + 1) : displayStart;
displayEnd = (displayEnd - 1) > displayStart ? (displayEnd - 1) : displayEnd;
if (displayStart > (totalPages - 3)) {
displayStart = (totalPages - 3) < 1 ? 1 : (totalPages - 3);
}
}
else { // display at least 7 page numbers
if (displayStart > (totalPages - 5)) {
displayStart = (totalPages - 5) < 1 ? 1 : (totalPages - 5);
}
if (displayEnd < 6) {
displayEnd = 6 > totalPages ? totalPages : 6;
}
}
if (page > 99999) { // limit to max 3 page numbers
displayStart = (displayStart + 1) < displayEnd ? (displayStart + 1) : displayStart;
displayEnd = (displayEnd - 1) >= displayStart ? (displayEnd - 1) : displayEnd;
if (page == (totalPages - 1)) {
displayEnd = totalPages - 1;
}
if (displayStart < displayEnd) {
displayStart = displayEnd;
}
}
if (page > 3 && displayStart == 1) {
displayStart = 2;
}
for (int displayPage = displayStart; displayPage <= displayEnd; displayPage++) {
if (page != displayPage) {
pagination.append(Color.WHITE + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + displayPage + "|" + displayPage + (displayPage < totalPages ? " " : "") + Chat.COMPONENT_TAG_CLOSE);
}
else {
pagination.append(Color.WHITE + Color.UNDERLINE + displayPage + Color.RESET + (displayPage < totalPages ? " " : ""));
}
if (displayPage < displayEnd) {
pagination.append(Color.GREY + "| ");
}
}
if (displayEnd < totalPages) {
if (displayEnd < (totalPages - 1)) {
pagination.append(Color.GREY + "... ");
}
else {
pagination.append(Color.GREY + "| ");
}
if (page != totalPages) {
pagination.append(Color.WHITE + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_COMMAND + "|/" + command + " l " + totalPages + "|" + totalPages + Chat.COMPONENT_TAG_CLOSE);
}
else {
pagination.append(Color.WHITE + Color.UNDERLINE + totalPages);
}
}
pagination.append(Color.GREY + ")");
}
return message.append(Color.WHITE + backArrow + Color.DARK_AQUA + Phrase.build(Phrase.LOOKUP_PAGE, Color.WHITE + page + "/" + totalPages) + nextArrow + pagination).toString();
}
public static String getTimeSince(long resultTime, long currentTime, boolean component) {