Package com.github.ygimenez.model.helper
Class LazyPaginateHelper
java.lang.Object
com.github.ygimenez.model.helper.BaseHelper<LazyPaginateHelper,List<Page>>
com.github.ygimenez.model.helper.LazyPaginateHelper
Helper class for building lazy-paginate events, safe for reuse.
-
Constructor Summary
ConstructorsConstructorDescriptionLazyPaginateHelper(ThrowingFunction<Integer,Page> pageLoader, boolean useButtons)Creates a new lazy-paginate event helper with the supplied page loader and default list implementation (ArrayList).LazyPaginateHelper(ThrowingFunction<Integer,Page> pageLoader, List<Page> initialPages, boolean useButtons)Creates a new lazy-paginate event helper with the supplied page loader and a list of initially loaded pages. -
Method Summary
Modifier and TypeMethodDescriptionAdds a new page to the list.<Out extends net.dv8tion.jda.api.utils.messages.MessageRequest<Out>>
List<net.dv8tion.jda.api.interactions.components.LayoutComponent>getComponents(Out action)Retrieves theListofComponents generated by this helper.Retrieves the configured page loader for this helper.load(int page)Loads the page represented by the specified index.booleanshouldUpdate(net.dv8tion.jda.api.entities.Message msg)Calculates whether theMessageneeds to have buttons applied onto or not.Methods inherited from class com.github.ygimenez.model.helper.BaseHelper
apply, canInteract, getContent, getTimeout, isCancellable, isUsingButtons, setCancellable, setCanInteract, setTimeout
-
Constructor Details
-
LazyPaginateHelper
Creates a new lazy-paginate event helper with the supplied page loader and default list implementation (ArrayList).- Parameters:
pageLoader- The lazy loader used to generate pages. The value supplied is the current page number.useButtons- Whether to use interaction buttons or legacy reaction-based buttons.
-
LazyPaginateHelper
public LazyPaginateHelper(ThrowingFunction<Integer,Page> pageLoader, @Nullable List<Page> initialPages, boolean useButtons)Creates a new lazy-paginate event helper with the supplied page loader and a list of initially loaded pages.- Parameters:
pageLoader- The lazy loader used to generate pages. The value supplied is the current page number.initialPages- AListcontaining the initially available pages.useButtons- Whether to use interaction buttons or legacy reaction-based buttons.
-
-
Method Details
-
addPage
Adds a new page to the list.- Parameters:
page- The page to be added.- Returns:
- The
LazyPaginateHelperinstance for chaining convenience.
-
getPageLoader
Retrieves the configured page loader for this helper.- Returns:
- The page loader
Function
-
load
Loads the page represented by the specified index. Might be null, meaning there's no page available for that index.- Parameters:
page- The page index.- Returns:
- The page returned by the loader.
-
getComponents
public <Out extends net.dv8tion.jda.api.utils.messages.MessageRequest<Out>> List<net.dv8tion.jda.api.interactions.components.LayoutComponent> getComponents(Out action)Description copied from class:BaseHelperRetrieves theListofComponents generated by this helper.- Specified by:
getComponentsin classBaseHelper<LazyPaginateHelper,List<Page>>- Type Parameters:
Out- Generic for aMessageRequest- Parameters:
action- A message event (either create or edit).- Returns:
- The list of components.
-
shouldUpdate
public boolean shouldUpdate(net.dv8tion.jda.api.entities.Message msg)Calculates whether theMessageneeds to have buttons applied onto or not.- Specified by:
shouldUpdatein classBaseHelper<LazyPaginateHelper,List<Page>>- Parameters:
msg- TheMessageto be checked.- Returns:
- Whether it needs to be updated or not.
-