PixabayX 🖼️ is an Android app that fetch and cache images from Pixabay API, this app shows the best practices when you want to apply paging and caching for the paginated data.
- Kotlin
based, Coroutines
- Flow for asynchronous tasks.
- Material Components for Android .
- Jetpack
- Android Architecture Components
- Lifecycle: Observe Android lifecycles and handle UI states based on the lifecycle changes.
- ViewModel: Manages UI-related data.
- DataBinding: support library that allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically.
- Room: used to construct reliable caching for offline support.
- Paging 3 helps you load and display pages of data from a larger dataset from local storage or over the network.
- Hilt: for DI (dependency injection) .
- Android Architecture Components
- Retrofit2 & OkHttp3: REST APIs.
- Moshi: A modern JSON library for Kotlin and Java.
- Coil: Loading images from network and caches it.
- Timber: A logger with a small API footprint.
- Architecture
- The bixapayX app follows MVVM - Repository Pattern Clean Architecture (View - ViewModel - Model) - Domain layer - Data layer.
-
The data is bumped directly from the database to the UI over the Paging 3 PagingSource Assisted with Remote Mediator which controls the process of loading new pages from the Remote Source and cache it on the database, then the database notifies the UI about the new changes over the Flow API, so based on this mechanism the database becomes the source of truth of the data in the app, and the remote mediator calculates the pages based on stored PagingKeys that contains:
- nextKey -> next page number - prevKey -> previous page number - currentPage -> current page number
The following image demonstrates the flow of the process
Copyright 2023 Nedal Hasan ABDALLAH (NedaluOf)
Licensed under the Apache License, Version 2.0 (the "License");
You won't be using this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific
language governing permissions and limitations under the License.