ArticlesFragment
com.bsvillarraga.spaceflightnews.presentation.ui.articles.ArticlesFragment
Main fragment displaying a searchable list of space flight news articles with pagination and voice search support.
Inheritance: Extends Fragment, implements MenuProvider
Injection: Annotated with @AndroidEntryPoint for Hilt dependency injection
Properties
binding: FragmentArticlesBinding- View binding for fragment layoutadapter: ArticleAdapter- RecyclerView adapter for article listviewModel: ArticlesViewModel- ViewModel instance (by viewModels() delegate)searchView: SearchView?- Reference to search view in toolbarsearchMenuItem: MenuItem?- Reference to search menu itempermissionHandler: PermissionHandler- Handles runtime permissions
Lifecycle Methods
onCreateView()
ArticlesFragment.kt:52
onViewCreated()
- Configures search menu
- Initializes RecyclerView with adapter
- Fetches initial articles
- Observes article data changes
ArticlesFragment.kt:61
Setup Methods
setupSearch()
ArticlesFragment.kt:71
setupRecyclerView()
- ArticleAdapter with click listener for navigation
- Load more scroll listener for pagination
ArticlesFragment.kt:77
Data Loading
fetchArticle()
ArticlesFragment.kt:98
loadMoreArticle()
- Checks if adapter has items
- Shows loading indicator
- Requests more articles from ViewModel
ArticlesFragment.kt:91
observeArticle()
ArticlesFragment.kt:103
UI State Management
handleResource()
Resource.Error→ Shows error stateResource.Loading→ Shows loading animationResource.Success→ Loads data into adapter
ArticlesFragment.kt:110
loadData()
ArticlesFragment.kt:119
showLoading(), hideLoading(), showError(), showWithoutInformation()
Utility methods for managing different UI states with appropriate animations and error handling. Sources:ArticlesFragment.kt:152-165
Navigation
navigateArticlesToArticleDetail()
article- Selected article to display
articleId- Article IDnewsSite- News site name for toolbar title
ArticlesFragment.kt:168
Menu Implementation
onCreateMenu()
- SearchView with query hint
- Text change listener for real-time search
- Submit listener for search execution
ArticlesFragment.kt:177
onMenuItemSelected()
ArticlesFragment.kt:194
Voice Search
requestRecordAudio()
ArticlesFragment.kt:206
startVoiceSearch()
- Free-form language model
- Custom prompt
- Exception handling for unsupported devices
ArticlesFragment.kt:220
voiceSearchLauncher
- Extracts spoken text
- Expands SearchView
- Sets query and triggers search
ArticlesFragment.kt:240
ArticleDetailFragment
com.bsvillarraga.spaceflightnews.presentation.ui.articles.ArticleDetailFragment
Fragment displaying detailed information about a single article.
Inheritance: Extends Fragment
Injection: Annotated with @AndroidEntryPoint for Hilt dependency injection
Properties
articleId: Long- ID of article to display (from navigation arguments)titleToolbar: String?- News site name for toolbar titlebinding: FragmentArticleDetailsBinding- View bindingviewModel: ArticleDetailsViewModel- ViewModel instance
Lifecycle Methods
onCreate()
articleId- Article ID (default: -1L)newsSite- News site name for toolbar
ArticleDetailFragment.kt:32
onCreateView()
ArticleDetailFragment.kt:45
onViewCreated()
- Sets toolbar title
- Fetches article details
- Observes article data
ArticleDetailFragment.kt:53
Setup Methods
setupToolbar()
ArticleDetailFragment.kt:63
Data Loading
fetchArticle()
ArticleDetailFragment.kt:68
observeArticle()
ArticleDetailFragment.kt:73
UI State Management
handleResource()
Resource.Error→ Shows error state with retryResource.Loading→ Shows loading animationResource.Success→ Loads article data into UI
ArticleDetailFragment.kt:80
loadData()
- Title, published date, authors
- Summary/content
- Header image using Glide
- “Continue Reading” button with URL handler
ArticleDetailFragment.kt:89
showLoading(), hideLoading(), showError()
Utility methods for UI state transitions with appropriate animations. Sources:ArticleDetailFragment.kt:118-144
User Actions
openWebPage()
- Creates Intent with ACTION_VIEW
- Checks for available browser
- Shows toast if no browser found
url- Article URL to open
ArticleDetailFragment.kt:147
showToast()
ArticleDetailFragment.kt:157