v1.0.3 - Add options to customize no. of page jumper buttons

v2-dev 1.0.3
William 2 years ago
parent ef0f8c60c3
commit 7f5b9e42cc

@ -4,12 +4,10 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="1adcdbad-26db-47ae-b8e5-83088ba9f2ff" name="Changes" comment="Fix lower bounds handling of getNearestValidPage"> <list default="true" id="1adcdbad-26db-47ae-b8e5-83088ba9f2ff" name="Changes" comment="v1.0.2 - Fix issues with jumper buttons, add tests for them">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/build.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/build.gradle" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/william278/paginedown/ListOptions.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/william278/paginedown/ListOptions.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/net/william278/paginedown/ListOptions.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/william278/paginedown/ListOptions.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/net/william278/paginedown/PaginatedList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/william278/paginedown/PaginatedList.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/net/william278/paginedown/PaginatedList.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/net/william278/paginedown/PaginatedList.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/net/william278/paginedown/PaginatedListTests.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/net/william278/paginedown/PaginatedListTests.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -123,7 +121,8 @@
<updated>1660688177518</updated> <updated>1660688177518</updated>
<workItem from="1660688178768" duration="664000" /> <workItem from="1660688178768" duration="664000" />
<workItem from="1660734365241" duration="1564000" /> <workItem from="1660734365241" duration="1564000" />
<workItem from="1660746781694" duration="1536000" /> <workItem from="1660746781694" duration="1569000" />
<workItem from="1660750313226" duration="99000" />
</task> </task>
<task id="LOCAL-00001" summary="Make gradlew executable"> <task id="LOCAL-00001" summary="Make gradlew executable">
<created>1660688283740</created> <created>1660688283740</created>
@ -153,7 +152,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1660746908828</updated> <updated>1660746908828</updated>
</task> </task>
<option name="localTasksCounter" value="5" /> <task id="LOCAL-00005" summary="v1.0.2 - Fix issues with jumper buttons, add tests for them">
<created>1660748344882</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1660748344882</updated>
</task>
<option name="localTasksCounter" value="6" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -176,6 +182,7 @@
<MESSAGE value="Fix javadoc encoding and warnings" /> <MESSAGE value="Fix javadoc encoding and warnings" />
<MESSAGE value="Fix no builders for page button formats" /> <MESSAGE value="Fix no builders for page button formats" />
<MESSAGE value="Fix lower bounds handling of getNearestValidPage" /> <MESSAGE value="Fix lower bounds handling of getNearestValidPage" />
<option name="LAST_COMMIT_MESSAGE" value="Fix lower bounds handling of getNearestValidPage" /> <MESSAGE value="v1.0.2 - Fix issues with jumper buttons, add tests for them" />
<option name="LAST_COMMIT_MESSAGE" value="v1.0.2 - Fix issues with jumper buttons, add tests for them" />
</component> </component>
</project> </project>

@ -40,6 +40,10 @@ public class ListOptions {
protected String itemSeparator = "\n"; protected String itemSeparator = "\n";
protected int itemsPerPage = 10; protected int itemsPerPage = 10;
protected int pageJumperStartButtons = 3;
protected int pageJumperEndButtons = 3;
private ListOptions() { private ListOptions() {
} }
@ -150,6 +154,18 @@ public class ListOptions {
return this; return this;
} }
@NotNull
public Builder setPageJumperStartButtons(final int pageJumperStartButtons) {
options.pageJumperStartButtons = pageJumperStartButtons;
return this;
}
@NotNull
public Builder setPageJumperEndButtons(final int pageJumperEndButtons) {
options.pageJumperEndButtons = pageJumperEndButtons;
return this;
}
@NotNull @NotNull
public ListOptions build() { public ListOptions build() {
return options; return options;

@ -259,7 +259,7 @@ public class PaginatedList {
StringJoiner pages = new StringJoiner(options.pageJumperPageSeparator); StringJoiner pages = new StringJoiner(options.pageJumperPageSeparator);
int lastPage = 1; int lastPage = 1;
for (int i = 1; i <= getTotalPages(); i++) { for (int i = 1; i <= getTotalPages(); i++) {
if (i < 3 || i > getTotalPages() - 2 || page == i) { if (i <= options.pageJumperStartButtons || i > getTotalPages() - options.pageJumperEndButtons || page == i) {
if (i - lastPage > 1) { if (i - lastPage > 1) {
pageGroups.add(pages.toString()); pageGroups.add(pages.toString());
pages = new StringJoiner(options.pageJumperPageSeparator); pages = new StringJoiner(options.pageJumperPageSeparator);

@ -38,6 +38,8 @@ public class PaginatedListTests {
final PaginatedList longList = PaginatedList.of(generateListData(200, "Item #"), final PaginatedList longList = PaginatedList.of(generateListData(200, "Item #"),
new ListOptions.Builder() new ListOptions.Builder()
.setItemsPerPage(10) .setItemsPerPage(10)
.setPageJumperStartButtons(2)
.setPageJumperEndButtons(2)
.setPageJumperPageFormat("%target_page_index%") .setPageJumperPageFormat("%target_page_index%")
.setPageJumperCurrentPageFormat("%current_page%") .setPageJumperCurrentPageFormat("%current_page%")
.build()); .build());
@ -52,6 +54,8 @@ public class PaginatedListTests {
final PaginatedList mediumList = PaginatedList.of(generateListData(45, "Item #"), final PaginatedList mediumList = PaginatedList.of(generateListData(45, "Item #"),
new ListOptions.Builder() new ListOptions.Builder()
.setItemsPerPage(10) .setItemsPerPage(10)
.setPageJumperStartButtons(2)
.setPageJumperEndButtons(2)
.setPageJumperPageFormat("%target_page_index%") .setPageJumperPageFormat("%target_page_index%")
.setPageJumperCurrentPageFormat("%current_page%") .setPageJumperCurrentPageFormat("%current_page%")
.build()); .build());
@ -65,6 +69,8 @@ public class PaginatedListTests {
final PaginatedList shortList = PaginatedList.of(generateListData(20, "Item #"), final PaginatedList shortList = PaginatedList.of(generateListData(20, "Item #"),
new ListOptions.Builder() new ListOptions.Builder()
.setItemsPerPage(10) .setItemsPerPage(10)
.setPageJumperStartButtons(2)
.setPageJumperEndButtons(2)
.setPageJumperPageFormat("%target_page_index%") .setPageJumperPageFormat("%target_page_index%")
.setPageJumperCurrentPageFormat("%current_page%") .setPageJumperCurrentPageFormat("%current_page%")
.build()); .build());

Loading…
Cancel
Save