https://github.com/emmanueltobi/nytnews
A kotlin compose news application using the NYTNews api.
https://github.com/emmanueltobi/nytnews
Last synced: 6 days ago
JSON representation
A kotlin compose news application using the NYTNews api.
- Host: GitHub
- URL: https://github.com/emmanueltobi/nytnews
- Owner: EmmanuelTobi
- Created: 2025-02-06T16:36:43.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2025-02-08T09:26:51.000Z (2 months ago)
- Last Synced: 2025-04-16T21:42:01.408Z (7 days ago)
- Language: Kotlin
- Size: 923 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NYTimes News App
This is a simple Android application that fetches and displays the most popular news articles from the New York Times API. The app is built using modern Android development practices, including Jetpack Compose for the UI, Kotlin for the programming language, and other Jetpack libraries for enhanced functionality.
## Features
* **Displays Recent News:** Fetches and displays the most recent news articles from the NYTimes API.
* **Categorized News:** Allows users to view news from "Yesterday", "Last 7 days", and "Last 30 days".
* **Detailed News View:** Provides a detailed view of each news article, including the title, abstract, published date, and an image (if available).
* **Open in Browser:** Allows users to open the full article in their default web browser.
* **Loading State:** Shows a loading indicator while fetching news.
* **Error Handling:** Displays an error message if there's a problem fetching the news.
* **Modern UI:** The app uses Jetpack Compose to create a modern and responsive user interface.-------
![]()
![]()
![]()
![]()
## Tech Stack
* **Kotlin:** The primary programming language.
* **Jetpack Compose:** For building the user interface.
* **Jetpack Libraries:**
* `ViewModel`: For managing UI-related data in a lifecycle-conscious way.
* `LiveData`: For observing data changes.
* `Compose Runtime`: For the core of the compose framework.
* `Compose Material 3`: For the material design components.
* `Compose foundation`: For the basic building blocks of the UI.
* `Compose activity`: For the integration with the activity.
* `Compose lifecycle`: For the integration with the lifecycle.
* **Coil:** For image loading and caching.
* **NYTimes API:** For fetching news data.## Build Configuration and Local Properties
This project uses Gradle as its build system. Here's a summary of the key build configuration elements, focusing on Gradle versions and the use of local properties:
### Gradle Versions
* **Gradle Plugin:** The project uses version `8.7.0` of the Android Gradle plugin.
* **Kotlin Gradle Plugin:** The Kotlin Gradle plugin version used is `2.0.0`.
* **Gradle Wrapper:** The project is configured to use Gradle version `8.9`.### Local Properties (`local.properties`)
This project utilizes a `local.properties` file to manage sensitive information, such as API keys, that should not be committed to version control.
**How to Use:**
1. **Create `local.properties`:** If it doesn't exist (Note: Android studio will always automatically create this), create a file named `local.properties` in the root directory of your project.
2. **Add Properties:** Add your API keys or other sensitive information to this file in the format `key=value`. In this project's case, we added NYTimesAPIKey="{{Your news api key}}"
3. **Clean and rebuild:** Clea and Rebuild the project again to access NYTimesAPIKey in the BuildConfig## Testing
This project includes comprehensive UI tests written using Jetpack Compose UI testing framework. These tests verify the behavior and appearance of the app's UI.
### Test Coverage
The following aspects of the UI are covered by the tests:
* **Main Screen Elements:**
* The app title ("NYTimes News") is displayed.
* The default selected day ("Yesterday") is displayed.
* **Dropdown Menu Button:**
* The dropdown menu button (an `IconButton`) is displayed.
* The dropdown menu button has the correct content description ("More options").
* **Dropdown Menu Functionality:**
* Clicking the dropdown menu button opens the menu.
* All menu items ("Yesterday", "Last 7 days", "Last 30 days") are displayed in the menu.
* Selecting a menu item updates the displayed date filter.
* **Loading and News Display:**
* The loading indicator is displayed while data is being fetched.
* The loading indicator disappears when data is loaded.
* News items are displayed after the data is loaded.### Running the Tests
To run the UI tests:
1. Open the project in Android Studio.
2. Go to the `androidTest` directory (`app/src/androidTest/java/com/cosmic/nytnews`).
3. Right-click on the `ExampleInstrumentedTest.kt` file.
4. Select "Run 'testDropdownMenu'" or run all the test.