Classe de paginateur : Android

  • Rversion finale: Zurich
  • Mis à jour 31 juil. 2025
  • 4 minutes de lecture
  • La classe Paginator fournit des fonctions de pagination dans les résultats de retour renvoyés par un appel de point de terminaison REST, tels que ceux renvoyés par la classe NowTableService .

    Vous devez d’abord appeler la fonction OR NowTableService : paginateur<Modèle : décodable>(from tableName : Chaîne, chemin : Chaîne = Constants.resultPath, codeur : Codeur = .default, configuration : FetchConfiguration ? = nul) pour récupérer les NowTableService : paginator(from tableName : String, configuration : FetchConfiguration ? = nil) résultats de retour de pagination.

    Paginateur : first()

    Récupère la première page des résultats de retour.

    La méthode génère une PaginationError si elle ne peut pas récupérer la première page.

    Tableau 1. Paramètres
    Nom Type Description
    Aucun
    Tableau 2. Renvoie
    Type Description
    Aucun

    L’exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }
    
          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }
    
        })
        ?: throw Exception("Response is null")
    
      paginator.first()
    }

    Paginateur : hasNext()

    Vérifie s’il existe une page suivante dans les résultats de retour.

    Tableau 3. Paramètres
    Nom Type Description
    Aucun
    Tableau 4. Renvoie
    Type Description
    Booléen Marqueur indiquant s’il existe une page suivante dans les résultats de retour.
    Valeurs possibles :
    • true : page suivante disponible.
    • false : aucune page suivante disponible.

    L’exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }
    
          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }
    
        })
        ?: throw Exception("Response is null")
    
      if (paginator.hasNext() && !paginator.isBusy()) {
        paginator.next()
      }
    }

    Paginateur : hasPrevious()

    Vérifie s’il y a une page précédente dans les résultats de retour.

    Tableau 5. Paramètres
    Nom Type Description
    Aucun
    Tableau 6. Renvoie
    Type Description
    Booléen Marqueur indiquant s’il existe une page précédente dans les résultats de retour.
    Valeurs possibles :
    • true : page précédente disponible.
    • faux : aucune page précédente disponible.

    L’exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }
    
          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }
    
        })
        ?: throw Exception("Response is null")
    
      if (paginator.hasPrevious() && !paginator.isBusy()) {
        paginator.previous()
      }
    }

    Paginateur : isBusy()

    Vérifie si le paginateur est occupé à extraire des données.

    Tableau 7. Paramètres
    Nom Type Description
    Aucun
    Tableau 8. Renvoie
    Type Description
    Aucun Marqueur indiquant si le paginateur est occupé à extraire des données.
    Valeurs possibles :
    • vrai : occupé à extraire des données.
    • faux : Pas occupé.

    L’exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }
    
          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }
    
        })
        ?: throw Exception("Response is null")
    
      if (paginator.hasNext() && !paginator.isBusy()) {
        paginator.next()
      }
    }

    Paginateur : last()

    Récupère la dernière page des résultats de retour.

    La méthode lève une PaginationError si elle ne peut pas extraire la dernière page.

    Tableau 9. Paramètres
    Nom Type Description
    Aucun
    Tableau 10. Renvoie
    Type Description
    Aucun

    L’exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }
    
          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }
    
        })
        ?: throw Exception("Response is null")
    
      if !paginator.isBusy()) {
        paginator.last()
      }
    }

    Paginateur : next()

    Récupère la page suivante des résultats de retour.

    La méthode lève une PaginationError s’il n’y a plus de pages à extraire.

    Tableau 11. Paramètres
    Nom Type Description
    Aucun
    Tableau 12. Renvoie
    Type Description
    Aucun

    L’exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }
    
          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }
    
        })
        ?: throw Exception("Response is null")
    
      if (paginator.hasNext() && !paginator.isBusy()) {
        paginator.next()
      }
    }

    Paginateur : observe(callback : PaginatorCallBack<T>)

    Définit les rappels de l’objet Paginator. Vous devez appeler cette méthode avant d’appeler toute autre fonction Paginator.

    Tableau 13. Paramètres
    Nom Type Description
    rappel PaginatorCallBack Rappels à appeler en fonction de la réussite ou de l’échec de la création du paginateur.
    • Réussite : plaisir abstrait onSuccess(réponse : Réponse<Liste<T>>)
    • Échec : plaisir abstrait onFailure(e : NowDataError)
    Tableau 14. Renvoie
    Type Description
    Aucun

    L’exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginationCallBack = object : PaginatorCallBack<NowAttachmentMetadata> {
        override fun onFailure(e: NowDataError) {
          handleError(e)
        }
    
        override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
          handleResponse(response)
        }
    
      }
    
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(paginationCallBack)
        ?: throw Exception("Response is null")
    }

    Paginateur : previous()

    Récupère la page précédente des résultats de retour.

    La méthode génère une PaginationError si elle ne peut pas récupérer la page précédente.

    Tableau 15. Paramètres
    Nom Type Description
    Aucun
    Tableau 16. Renvoie
    Type Description
    Aucun

    L’exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }
    
          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }
    
        })
        ?: throw Exception("Response is null")
    
      if (paginator.hasPrevious() && !paginator.isBusy()) {
        paginator.previous()
      }
    }

    Paginateur : reset()

    Réinitialise le paginateur à la première page, mais ne renvoie pas la première page des résultats renvoyés.

    Tableau 17. Paramètres
    Nom Type Description
    Aucun
    Tableau 18. Renvoie
    Type Description
    Aucun

    L’exemple de code suivant montre comment appeler cette fonction.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
          override fun onFailure(e: NowDataError) {
            handleError(e)
          }
    
          override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
            handleResponse(response)
          }
    
        })
        ?: throw Exception("Response is null")
    
      paginator.reset()
    }