From 7d3c995c259de11396cde54fbc557fd58690f8e6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Nov 2025 00:22:26 +0000 Subject: [PATCH 1/7] Initial plan From f71f9abf28b33f74fd36b6ef01e34a58c45c0ee1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Nov 2025 00:34:05 +0000 Subject: [PATCH 2/7] Create Android app structure with Headlines landing screen Co-authored-by: param-virsingh <178531836+param-virsingh@users.noreply.github.com> --- .gitignore | 104 ++++++++ app/build.gradle.kts | 117 +++++++++ app/proguard-rules.pro | 21 ++ app/src/main/AndroidManifest.xml | 26 ++ .../articlesheadlines/ArticlesApplication.kt | 7 + .../articlesheadlines/MainActivity.kt | 134 ++++++++++ .../articlesheadlines/data/model/Article.kt | 16 ++ .../navigation/AppNavigation.kt | 33 +++ .../articlesheadlines/navigation/Screen.kt | 7 + .../ui/headlines/HeadlinesScreen.kt | 196 ++++++++++++++ .../ui/headlines/HeadlinesViewModel.kt | 84 ++++++ .../articlesheadlines/ui/saved/SavedScreen.kt | 22 ++ .../ui/sources/SourcesScreen.kt | 22 ++ .../articlesheadlines/ui/theme/Color.kt | 11 + .../articlesheadlines/ui/theme/Theme.kt | 58 ++++ .../articlesheadlines/ui/theme/Type.kt | 31 +++ .../res/drawable/ic_launcher_foreground.xml | 15 ++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../res/values/ic_launcher_background.xml | 4 + app/src/main/res/values/strings.xml | 11 + app/src/main/res/values/themes.xml | 4 + build.gradle.kts | 23 ++ gradle.properties | 23 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 63375 bytes gradle/wrapper/gradle-wrapper.properties | 7 + gradlew | 248 ++++++++++++++++++ settings.gradle.kts | 10 + 28 files changed, 1244 insertions(+) create mode 100644 .gitignore create mode 100644 app/build.gradle.kts create mode 100644 app/proguard-rules.pro create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/medibank/articlesheadlines/ArticlesApplication.kt create mode 100644 app/src/main/java/com/medibank/articlesheadlines/MainActivity.kt create mode 100644 app/src/main/java/com/medibank/articlesheadlines/data/model/Article.kt create mode 100644 app/src/main/java/com/medibank/articlesheadlines/navigation/AppNavigation.kt create mode 100644 app/src/main/java/com/medibank/articlesheadlines/navigation/Screen.kt create mode 100644 app/src/main/java/com/medibank/articlesheadlines/ui/headlines/HeadlinesScreen.kt create mode 100644 app/src/main/java/com/medibank/articlesheadlines/ui/headlines/HeadlinesViewModel.kt create mode 100644 app/src/main/java/com/medibank/articlesheadlines/ui/saved/SavedScreen.kt create mode 100644 app/src/main/java/com/medibank/articlesheadlines/ui/sources/SourcesScreen.kt create mode 100644 app/src/main/java/com/medibank/articlesheadlines/ui/theme/Color.kt create mode 100644 app/src/main/java/com/medibank/articlesheadlines/ui/theme/Theme.kt create mode 100644 app/src/main/java/com/medibank/articlesheadlines/ui/theme/Type.kt create mode 100644 app/src/main/res/drawable/ic_launcher_foreground.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/values/ic_launcher_background.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/themes.xml create mode 100644 build.gradle.kts create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 settings.gradle.kts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fcf7f23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,104 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties +*.apk +*.ap_ +*.aab + +# Built application files +*.apk +*.aar +*.ap_ +*.aab + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ +# Uncomment the following line in case you need and you don't have the release build type files in your app +# release/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +# Android Studio 3 in .gitignore file. +.idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Keystore files +# Uncomment the following lines if you do not want to check your keystore files in. +#*.jks +#*.keystore + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild +.cxx/ + +# Google Services (e.g. APIs or Firebase) +# google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..aa49aa4 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,117 @@ +plugins { + id("com.android.application") + id("kotlin-android") + id("kotlin-kapt") + id("dagger.hilt.android.plugin") +} + +android { + namespace = "com.medibank.articlesheadlines" + compileSdk = 34 + + defaultConfig { + applicationId = "com.medibank.articlesheadlines" + minSdk = 24 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + vectorDrawables { + useSupportLibrary = true + } + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + kotlinOptions { + jvmTarget = "17" + } + buildFeatures { + compose = true + } + composeOptions { + kotlinCompilerExtensionVersion = "1.4.6" + } + packaging { + resources { + excludes += "/META-INF/{AL2.0,LGPL2.1}" + } + } +} + +dependencies { + // Core Android + implementation("androidx.core:core-ktx:1.12.0") + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2") + implementation("androidx.activity:activity-compose:1.8.1") + + // Compose + implementation(platform("androidx.compose:compose-bom:2023.10.01")) + implementation("androidx.compose.ui:ui") + implementation("androidx.compose.ui:ui-graphics") + implementation("androidx.compose.ui:ui-tooling-preview") + implementation("androidx.compose.material3:material3") + implementation("androidx.compose.material:material-icons-extended") + + // Navigation + implementation("androidx.navigation:navigation-compose:2.7.5") + + // Lifecycle + implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2") + implementation("androidx.lifecycle:lifecycle-runtime-compose:2.6.2") + + // Hilt + implementation("com.google.dagger:hilt-android:2.46.1") + kapt("com.google.dagger:hilt-android-compiler:2.46.1") + implementation("androidx.hilt:hilt-navigation-compose:1.0.0") + + // Retrofit + implementation("com.squareup.retrofit2:retrofit:2.9.0") + implementation("com.squareup.retrofit2:converter-gson:2.9.0") + implementation("com.squareup.okhttp3:logging-interceptor:4.11.0") + + // Room + implementation("androidx.room:room-runtime:2.6.0") + implementation("androidx.room:room-ktx:2.6.0") + kapt("androidx.room:room-compiler:2.6.0") + + // DataStore + implementation("androidx.datastore:datastore-preferences:1.0.0") + + // Coil for image loading + implementation("io.coil-kt:coil-compose:2.5.0") + + // Accompanist WebView + implementation("com.google.accompanist:accompanist-webview:0.32.0") + + // Testing + testImplementation("junit:junit:4.13.2") + testImplementation("org.mockito:mockito-core:5.6.0") + testImplementation("org.mockito.kotlin:mockito-kotlin:5.1.0") + testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3") + testImplementation("androidx.arch.core:core-testing:2.2.0") + + androidTestImplementation("androidx.test.ext:junit:1.1.5") + androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") + androidTestImplementation(platform("androidx.compose:compose-bom:2023.10.01")) + androidTestImplementation("androidx.compose.ui:ui-test-junit4") + + debugImplementation("androidx.compose.ui:ui-tooling") + debugImplementation("androidx.compose.ui:ui-test-manifest") +} + +kapt { + correctErrorTypes = true +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..e9f55f7 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/medibank/articlesheadlines/ArticlesApplication.kt b/app/src/main/java/com/medibank/articlesheadlines/ArticlesApplication.kt new file mode 100644 index 0000000..2dfecec --- /dev/null +++ b/app/src/main/java/com/medibank/articlesheadlines/ArticlesApplication.kt @@ -0,0 +1,7 @@ +package com.medibank.articlesheadlines + +import android.app.Application +import dagger.hilt.android.HiltAndroidApp + +@HiltAndroidApp +class ArticlesApplication : Application() diff --git a/app/src/main/java/com/medibank/articlesheadlines/MainActivity.kt b/app/src/main/java/com/medibank/articlesheadlines/MainActivity.kt new file mode 100644 index 0000000..ee7dba2 --- /dev/null +++ b/app/src/main/java/com/medibank/articlesheadlines/MainActivity.kt @@ -0,0 +1,134 @@ +package com.medibank.articlesheadlines + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Bookmark +import androidx.compose.material.icons.filled.FeaturedPlayList +import androidx.compose.material.icons.filled.Source +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.NavigationBar +import androidx.compose.material3.NavigationBarItem +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.navigation.NavDestination.Companion.hierarchy +import androidx.navigation.NavGraph.Companion.findStartDestination +import androidx.navigation.compose.currentBackStackEntryAsState +import androidx.navigation.compose.rememberNavController +import com.medibank.articlesheadlines.navigation.AppNavigation +import com.medibank.articlesheadlines.navigation.Screen +import com.medibank.articlesheadlines.ui.theme.ArticlesHeadlinesTheme +import dagger.hilt.android.AndroidEntryPoint + +@AndroidEntryPoint +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + ArticlesHeadlinesTheme { + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colorScheme.background + ) { + MainScreen() + } + } + } + } +} + +@Composable +fun MainScreen() { + val navController = rememberNavController() + val navBackStackEntry by navController.currentBackStackEntryAsState() + val currentDestination = navBackStackEntry?.destination + + Scaffold( + bottomBar = { + NavigationBar { + NavigationBarItem( + icon = { + Icon( + imageVector = Icons.Default.FeaturedPlayList, + contentDescription = stringResource(R.string.headlines_tab) + ) + }, + label = { Text(stringResource(R.string.headlines_tab)) }, + selected = currentDestination?.hierarchy?.any { + it.route == Screen.Headlines.route + } == true, + onClick = { + navController.navigate(Screen.Headlines.route) { + popUpTo(navController.graph.findStartDestination().id) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + } + ) + + NavigationBarItem( + icon = { + Icon( + imageVector = Icons.Default.Source, + contentDescription = stringResource(R.string.sources_tab) + ) + }, + label = { Text(stringResource(R.string.sources_tab)) }, + selected = currentDestination?.hierarchy?.any { + it.route == Screen.Sources.route + } == true, + onClick = { + navController.navigate(Screen.Sources.route) { + popUpTo(navController.graph.findStartDestination().id) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + } + ) + + NavigationBarItem( + icon = { + Icon( + imageVector = Icons.Default.Bookmark, + contentDescription = stringResource(R.string.saved_tab) + ) + }, + label = { Text(stringResource(R.string.saved_tab)) }, + selected = currentDestination?.hierarchy?.any { + it.route == Screen.Saved.route + } == true, + onClick = { + navController.navigate(Screen.Saved.route) { + popUpTo(navController.graph.findStartDestination().id) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + } + ) + } + } + ) { paddingValues -> + Surface( + modifier = Modifier + .fillMaxSize() + .padding(paddingValues) + ) { + AppNavigation(navController = navController) + } + } +} diff --git a/app/src/main/java/com/medibank/articlesheadlines/data/model/Article.kt b/app/src/main/java/com/medibank/articlesheadlines/data/model/Article.kt new file mode 100644 index 0000000..74ea368 --- /dev/null +++ b/app/src/main/java/com/medibank/articlesheadlines/data/model/Article.kt @@ -0,0 +1,16 @@ +package com.medibank.articlesheadlines.data.model + +data class Article( + val title: String, + val description: String?, + val author: String?, + val url: String, + val urlToImage: String?, + val publishedAt: String, + val source: Source +) + +data class Source( + val id: String?, + val name: String +) diff --git a/app/src/main/java/com/medibank/articlesheadlines/navigation/AppNavigation.kt b/app/src/main/java/com/medibank/articlesheadlines/navigation/AppNavigation.kt new file mode 100644 index 0000000..f87b804 --- /dev/null +++ b/app/src/main/java/com/medibank/articlesheadlines/navigation/AppNavigation.kt @@ -0,0 +1,33 @@ +package com.medibank.articlesheadlines.navigation + +import androidx.compose.runtime.Composable +import androidx.navigation.NavHostController +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable +import com.medibank.articlesheadlines.ui.headlines.HeadlinesScreen +import com.medibank.articlesheadlines.ui.saved.SavedScreen +import com.medibank.articlesheadlines.ui.sources.SourcesScreen + +@Composable +fun AppNavigation(navController: NavHostController) { + NavHost( + navController = navController, + startDestination = Screen.Headlines.route + ) { + composable(Screen.Headlines.route) { + HeadlinesScreen( + onArticleClick = { article -> + // TODO: Navigate to article detail/webview + } + ) + } + + composable(Screen.Sources.route) { + SourcesScreen() + } + + composable(Screen.Saved.route) { + SavedScreen() + } + } +} diff --git a/app/src/main/java/com/medibank/articlesheadlines/navigation/Screen.kt b/app/src/main/java/com/medibank/articlesheadlines/navigation/Screen.kt new file mode 100644 index 0000000..99ea2fd --- /dev/null +++ b/app/src/main/java/com/medibank/articlesheadlines/navigation/Screen.kt @@ -0,0 +1,7 @@ +package com.medibank.articlesheadlines.navigation + +sealed class Screen(val route: String) { + object Headlines : Screen("headlines") + object Sources : Screen("sources") + object Saved : Screen("saved") +} diff --git a/app/src/main/java/com/medibank/articlesheadlines/ui/headlines/HeadlinesScreen.kt b/app/src/main/java/com/medibank/articlesheadlines/ui/headlines/HeadlinesScreen.kt new file mode 100644 index 0000000..70ea99c --- /dev/null +++ b/app/src/main/java/com/medibank/articlesheadlines/ui/headlines/HeadlinesScreen.kt @@ -0,0 +1,196 @@ +package com.medibank.articlesheadlines.ui.headlines + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.BookmarkBorder +import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import androidx.hilt.navigation.compose.hiltViewModel +import coil.compose.AsyncImage +import com.medibank.articlesheadlines.R +import com.medibank.articlesheadlines.data.model.Article + +@Composable +fun HeadlinesScreen( + viewModel: HeadlinesViewModel = hiltViewModel(), + onArticleClick: (Article) -> Unit = {} +) { + val uiState by viewModel.uiState.collectAsState() + + Box(modifier = Modifier.fillMaxSize()) { + when { + uiState.isLoading -> { + CircularProgressIndicator( + modifier = Modifier.align(Alignment.Center) + ) + } + uiState.error != null -> { + Text( + text = uiState.error ?: "", + modifier = Modifier.align(Alignment.Center), + style = MaterialTheme.typography.bodyLarge + ) + } + uiState.articles.isEmpty() -> { + Text( + text = stringResource(R.string.no_articles), + modifier = Modifier.align(Alignment.Center), + style = MaterialTheme.typography.bodyLarge + ) + } + else -> { + ArticlesList( + articles = uiState.articles, + onArticleClick = onArticleClick, + onSaveClick = { article -> viewModel.saveArticle(article) } + ) + } + } + } +} + +@Composable +fun ArticlesList( + articles: List
, + onArticleClick: (Article) -> Unit, + onSaveClick: (Article) -> Unit +) { + LazyColumn( + modifier = Modifier.fillMaxSize(), + verticalArrangement = Arrangement.spacedBy(8.dp) + ) { + items(articles) { article -> + ArticleItem( + article = article, + onClick = { onArticleClick(article) }, + onSaveClick = { onSaveClick(article) } + ) + } + } +} + +@Composable +fun ArticleItem( + article: Article, + onClick: () -> Unit, + onSaveClick: () -> Unit +) { + Card( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp, vertical = 4.dp) + .clickable(onClick = onClick), + elevation = CardDefaults.cardElevation(defaultElevation = 2.dp), + shape = RoundedCornerShape(8.dp) + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(12.dp) + ) { + // Article Image + AsyncImage( + model = article.urlToImage, + contentDescription = article.title, + modifier = Modifier + .size(80.dp) + .clip(RoundedCornerShape(4.dp)), + contentScale = ContentScale.Crop + ) + + Spacer(modifier = Modifier.width(12.dp)) + + // Article Content + Column( + modifier = Modifier + .weight(1f) + .align(Alignment.CenterVertically) + ) { + // Title + Text( + text = article.title, + style = MaterialTheme.typography.titleMedium, + maxLines = 2, + overflow = TextOverflow.Ellipsis + ) + + Spacer(modifier = Modifier.height(4.dp)) + + // Description + article.description?.let { description -> + Text( + text = description, + style = MaterialTheme.typography.bodyMedium, + maxLines = 2, + overflow = TextOverflow.Ellipsis, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + } + + Spacer(modifier = Modifier.height(8.dp)) + + // Author and Source + Row( + verticalAlignment = Alignment.CenterVertically + ) { + Text( + text = article.source.name, + style = MaterialTheme.typography.labelSmall, + color = MaterialTheme.colorScheme.primary + ) + + article.author?.let { author -> + Text( + text = " • $author", + style = MaterialTheme.typography.labelSmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + } + } + } + + // Save Button + IconButton( + onClick = onSaveClick, + modifier = Modifier.align(Alignment.Top) + ) { + Icon( + imageVector = Icons.Default.BookmarkBorder, + contentDescription = stringResource(R.string.save_article), + tint = MaterialTheme.colorScheme.primary + ) + } + } + } +} diff --git a/app/src/main/java/com/medibank/articlesheadlines/ui/headlines/HeadlinesViewModel.kt b/app/src/main/java/com/medibank/articlesheadlines/ui/headlines/HeadlinesViewModel.kt new file mode 100644 index 0000000..389b29d --- /dev/null +++ b/app/src/main/java/com/medibank/articlesheadlines/ui/headlines/HeadlinesViewModel.kt @@ -0,0 +1,84 @@ +package com.medibank.articlesheadlines.ui.headlines + +import androidx.lifecycle.ViewModel +import com.medibank.articlesheadlines.data.model.Article +import com.medibank.articlesheadlines.data.model.Source +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import javax.inject.Inject + +data class HeadlinesUiState( + val articles: List
= emptyList(), + val isLoading: Boolean = false, + val error: String? = null +) + +@HiltViewModel +class HeadlinesViewModel @Inject constructor() : ViewModel() { + + private val _uiState = MutableStateFlow(HeadlinesUiState()) + val uiState: StateFlow = _uiState.asStateFlow() + + init { + loadSampleData() + } + + private fun loadSampleData() { + // Sample data for initial display + val sampleArticles = listOf( + Article( + title = "Breaking: New Technology Advances in AI", + description = "Scientists have made groundbreaking discoveries in artificial intelligence that could revolutionize the tech industry.", + author = "Jane Smith", + url = "https://example.com/article1", + urlToImage = "https://picsum.photos/400/300?random=1", + publishedAt = "2024-01-15T10:30:00Z", + source = Source(id = "tech-news", name = "Tech News") + ), + Article( + title = "Global Climate Summit Reaches Historic Agreement", + description = "World leaders have agreed on new measures to combat climate change in a landmark international summit.", + author = "John Doe", + url = "https://example.com/article2", + urlToImage = "https://picsum.photos/400/300?random=2", + publishedAt = "2024-01-15T09:15:00Z", + source = Source(id = "world-news", name = "World News") + ), + Article( + title = "Stock Market Reaches All-Time High", + description = "The stock market has hit record highs as investors show renewed confidence in the economy.", + author = "Sarah Johnson", + url = "https://example.com/article3", + urlToImage = "https://picsum.photos/400/300?random=3", + publishedAt = "2024-01-15T08:00:00Z", + source = Source(id = "business", name = "Business Today") + ), + Article( + title = "New Medical Breakthrough in Cancer Treatment", + description = "Researchers announce a potential cure for certain types of cancer after years of clinical trials.", + author = "Dr. Emily Brown", + url = "https://example.com/article4", + urlToImage = "https://picsum.photos/400/300?random=4", + publishedAt = "2024-01-14T18:45:00Z", + source = Source(id = "health", name = "Health Today") + ), + Article( + title = "Space Mission Successfully Lands on Mars", + description = "A historic space mission has successfully landed on Mars, marking a new era in space exploration.", + author = "Michael Chen", + url = "https://example.com/article5", + urlToImage = "https://picsum.photos/400/300?random=5", + publishedAt = "2024-01-14T16:20:00Z", + source = Source(id = "science", name = "Science Daily") + ) + ) + + _uiState.value = HeadlinesUiState(articles = sampleArticles) + } + + fun saveArticle(article: Article) { + // TODO: Implement save functionality + } +} diff --git a/app/src/main/java/com/medibank/articlesheadlines/ui/saved/SavedScreen.kt b/app/src/main/java/com/medibank/articlesheadlines/ui/saved/SavedScreen.kt new file mode 100644 index 0000000..65074de --- /dev/null +++ b/app/src/main/java/com/medibank/articlesheadlines/ui/saved/SavedScreen.kt @@ -0,0 +1,22 @@ +package com.medibank.articlesheadlines.ui.saved + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier + +@Composable +fun SavedScreen() { + Box( + modifier = Modifier.fillMaxSize(), + contentAlignment = Alignment.Center + ) { + Text( + text = "Saved Articles Screen", + style = MaterialTheme.typography.titleLarge + ) + } +} diff --git a/app/src/main/java/com/medibank/articlesheadlines/ui/sources/SourcesScreen.kt b/app/src/main/java/com/medibank/articlesheadlines/ui/sources/SourcesScreen.kt new file mode 100644 index 0000000..b5af1a2 --- /dev/null +++ b/app/src/main/java/com/medibank/articlesheadlines/ui/sources/SourcesScreen.kt @@ -0,0 +1,22 @@ +package com.medibank.articlesheadlines.ui.sources + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier + +@Composable +fun SourcesScreen() { + Box( + modifier = Modifier.fillMaxSize(), + contentAlignment = Alignment.Center + ) { + Text( + text = "Sources Screen", + style = MaterialTheme.typography.titleLarge + ) + } +} diff --git a/app/src/main/java/com/medibank/articlesheadlines/ui/theme/Color.kt b/app/src/main/java/com/medibank/articlesheadlines/ui/theme/Color.kt new file mode 100644 index 0000000..38c1bd7 --- /dev/null +++ b/app/src/main/java/com/medibank/articlesheadlines/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package com.medibank.articlesheadlines.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) diff --git a/app/src/main/java/com/medibank/articlesheadlines/ui/theme/Theme.kt b/app/src/main/java/com/medibank/articlesheadlines/ui/theme/Theme.kt new file mode 100644 index 0000000..4f68b2d --- /dev/null +++ b/app/src/main/java/com/medibank/articlesheadlines/ui/theme/Theme.kt @@ -0,0 +1,58 @@ +package com.medibank.articlesheadlines.ui.theme + +import android.app.Activity +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowCompat + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 +) + +@Composable +fun ArticlesHeadlinesTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + val view = LocalView.current + if (!view.isInEditMode) { + SideEffect { + val window = (view.context as Activity).window + window.statusBarColor = colorScheme.primary.toArgb() + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme + } + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} diff --git a/app/src/main/java/com/medibank/articlesheadlines/ui/theme/Type.kt b/app/src/main/java/com/medibank/articlesheadlines/ui/theme/Type.kt new file mode 100644 index 0000000..5858c9b --- /dev/null +++ b/app/src/main/java/com/medibank/articlesheadlines/ui/theme/Type.kt @@ -0,0 +1,31 @@ +package com.medibank.articlesheadlines.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ), + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Bold, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) +) diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..8f11435 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..5ed0a2d --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..5ed0a2d --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/values/ic_launcher_background.xml b/app/src/main/res/values/ic_launcher_background.xml new file mode 100644 index 0000000..f42ada6 --- /dev/null +++ b/app/src/main/res/values/ic_launcher_background.xml @@ -0,0 +1,4 @@ + + + #FFFFFF + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..b03c82d --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,11 @@ + + + Articles Headlines + Headlines + Sources + Saved + No articles available + Save Article + Article saved + Loading... + diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..8194400 --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,4 @@ + + +