Overview
The Space Flight News app provides several Kotlin extension functions to simplify common Android operations. These extensions enhance readability and reduce boilerplate code. Package:com.bsvillarraga.spaceflightnews.core.extensions
Context Extensions
Source: ContextExtensions.ktisPermissionGranted
Checks if a specific permission is granted.The permission string to check (e.g.,
Manifest.permission.CAMERA)true if the permission is granted, false otherwise
Example:
Date Extensions
Source: DateExtensions.kttoFormattedDate
Converts an ISO 8601 date string to a human-readable format.yyyy-MM-dd'T'HH:mm:ss'Z' (ISO 8601 UTC)
Output Format: dd/MM/yyyy hh:mm a (e.g., “04/03/2026 02:30 PM”)
Returns: Formatted date string, or the original string if parsing fails
Example:
Image Extensions
Source: ImageExtensions.kttoResourceGlide
Loads an image from a local resource using Glide. Supports both regular images and GIFs.Android context for Glide
Resource ID of the image (e.g.,
R.drawable.placeholder)toNetworkGlide
Loads an image from a URL using Glide.Android context for Glide
URL of the image to load
RecyclerView Extensions
Source: RecyclerViewExtensions.ktinit
Initializes a RecyclerView with a LinearLayoutManager and adapter.The adapter to set on the RecyclerView
Context for creating the LinearLayoutManager
onLoadMoreScrollListener
Adds a scroll listener that triggers pagination when the user scrolls to the bottom.Callback function invoked when the user reaches the bottom of the list
SearchView Extensions
Source: SearchViewExtensions.ktqueryTextListener
Configures a SearchView with callbacks for query submission and text changes.Callback invoked when the user submits a search query
Callback invoked when the search text is cleared (empty or null)
Dependencies
These extensions use the following libraries:- Glide - Image loading (for Image extensions)
- AndroidX - Core Android libraries
- RecyclerView - List components