demo: https://youtube.com/shorts/DjLhwK-jyO4
This Android application is designed to demonstrate the retrieval and display of user data from the GitHub API. The app fetches a list of users, presents them in a RecyclerView, and allows users to tap on an individual user to view more detailed information. The app is built using modern Android development practices and libraries, including:
- MVVM Architecture: For a clear separation of concerns between the UI, data, and business logic.
- Dependency Injection (Hilt): For managing dependencies effectively and making the code more testable.
- Paging 3 Library (with RxJava): For efficiently loading and displaying large lists of data in a paginated manner, improving performance and user experience.
- RxJava 3: For handling asynchronous operations and data streams reactively.
- Navigation Component: For managing in-app navigation between screens.
- Retrofit: For making network requests to the GitHub API.
- Gson: For JSON handling.
- View Binding: For use view in a safe way.
Goal Addressed:
- "Please find out how to search or retrieve users from GitHub in GitHub User API."
- "Show users in list."
- "Limit results to 100 users in total, or you can choose to implement pagination feature (see details in Bonus section)."
- "In list, each row should at least show info including image from “avatar_url”, “login”, and “site_admin”."
Implementation Details:
-
UserApiInterface: This interface, defined using Retrofit, handles the communication with the GitHub API. It contains methods to:- Fetch a list of users:
getUsers(since: Int)for first page, andgetUsers()for all pages. - Fetch user details:
getDetail(login: String)for single users detail. UserRepository: This class is responsible for fetching data from the network. It makes the calls toUserApi.- It uses RxJava to use data as
SingleorFlowable. - It has two methods,
getUsers(int since)andgetUsers(), to get a list of users.getUsers(int since)is used to fetch the first page, andgetUsers()is used for subsequent pages. - It has a method,
getDetail(String login), to get the details of a specific user. - It has a method,
getSearchUser()to implement paging.
- Fetch a list of users:
-
UserPagingSource: This class extendsPagingSourceand is responsible for defining how data is loaded in pages from the GitHub API.- It loads data in pages based on the
sinceparameter (GitHub API's way of handling pagination). - It defines how to handle the
LoadParamsandLoadResultobjects used by the Paging library. - It gets data from the
UserRepository.
- It loads data in pages based on the
-
UserListViewModel: This ViewModel handles the logic of fetching paginated user data and exposing it to the UI.- It uses the
UserRepositoryto get the data. - It use
Flowable<PagingData<UserData>>to handle paging. - It uses
PagingRx.cachedInto cache data. - It exposes the
Flowable<PagingData<UserData>>through a public property calleduserDataFlowable. - It has a function
initto load data.
- It uses the