Skip to content

Commit

Permalink
Updated dependencies, migrated to Kotlin > 2.0, migrated to ksp
Browse files Browse the repository at this point in the history
  • Loading branch information
nsmirosh committed Dec 22, 2024
1 parent e12d356 commit 92813f0
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 118 deletions.
1 change: 1 addition & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 37 additions & 26 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import java.util.Properties
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
kotlin("kapt")
kotlin("plugin.serialization") version "1.9.25"
id("com.google.devtools.ksp")
id("org.jetbrains.kotlin.plugin.compose")
// kotlin("kapt")
// kotlin("ksp")
kotlin("plugin.serialization") version "2.0.21"
}

android {
namespace = "nick.mirosh.newsapp"
compileSdk = 34
compileSdk = 35

defaultConfig {
applicationId = "nick.mirosh.newsapp"
minSdk = 24
targetSdk = 34
targetSdk = 35
versionCode = 1
versionName = "1.0"

Expand Down Expand Up @@ -76,23 +79,23 @@ android {
}

dependencies {
implementation("androidx.navigation:navigation-compose:2.8.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0")

// Lifecycle
val lifecycle = "2.8.6"
val lifecycle = "2.8.7"
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle")
implementation("androidx.lifecycle:lifecycle-runtime-compose:$lifecycle")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle")

implementation("io.coil-kt:coil-compose:2.5.0")

implementation("androidx.navigation:navigation-compose:2.8.5")

val koin = "4.0.0"
implementation ("io.insert-koin:koin-android:$koin")
implementation ("io.insert-koin:koin-androidx-compose:$koin")

val ktor = "2.3.7"
val ktor = "3.0.2"
implementation("io.ktor:ktor-client-core:$ktor")
implementation("io.ktor:ktor-client-cio:$ktor")
implementation("io.ktor:ktor-client-okhttp:$ktor")
Expand All @@ -101,42 +104,50 @@ dependencies {


//Room
val room_version = "2.6.1"
val room= "2.6.1"

implementation("androidx.room:room-runtime:$room_version")
annotationProcessor("androidx.room:room-compiler:$room_version")
implementation("androidx.room:room-ktx:$room_version")
implementation("androidx.room:room-runtime:$room")
annotationProcessor("androidx.room:room-compiler:$room")
implementation("androidx.room:room-ktx:$room")


// To use Kotlin annotation processing tool (kapt)
kapt("androidx.room:room-compiler:$room_version")
// kapt("androidx.room:room-compiler:$room")
ksp("androidx.room:room-compiler:$room")
val bom = "2024.12.01"

implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.core:core-ktx:1.15.0")
implementation("androidx.activity:activity-compose:1.9.3")
implementation(platform("androidx.compose:compose-bom:2024.10.00"))
implementation(platform("androidx.compose:compose-bom:$bom"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")

testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0")
testImplementation("app.cash.turbine:turbine:1.0.0")
testImplementation("org.mockito.kotlin:mockito-kotlin:5.1.0")

val coroutines = "1.10.0"

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines")

testImplementation("junit:junit:4.13.2")
testImplementation("org.hamcrest:hamcrest-library:2.2")
testImplementation("junit:junit:4.13.2")

androidTestImplementation("com.google.dagger:hilt-android-testing:2.48.1")

val mockk = "1.13.14"
testImplementation ("io.mockk:mockk-android:$mockk")
testImplementation ("io.mockk:mockk-agent:$mockk")

androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2024.10.00"))
androidTestImplementation(platform("androidx.compose:compose-bom:$bom"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.7.4")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.4")
androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.7.6")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.6")
}

kapt {
correctErrorTypes = true
}
//kapt {
// correctErrorTypes = true
//}

This file was deleted.

1 change: 1 addition & 0 deletions app/src/main/java/nick/mirosh/newsapp/NewsApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class NewsApplication : Application() {
androidLogger()
androidContext(this@NewsApplication)
modules(appModule, networkModule, dispatcherModule, repositoryModule)

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@ import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import kotlinx.coroutines.flow.Flow
import nick.mirosh.newsapp.data.models.DatabaseArticle

@Dao
interface ArticleDao {
@Query("SELECT * FROM articles")
suspend fun getAllArticles(): List<DatabaseArticle>
fun getAllArticles(): List<DatabaseArticle>

@Query("SELECT * FROM articles WHERE liked = 1")
suspend fun getLikedArticles(): List<DatabaseArticle>
fun getLikedArticles(): Flow<List<DatabaseArticle>>

@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insertAll(articles: List<DatabaseArticle>): List<Long>
fun insertAll(articles: List<DatabaseArticle>): List<Long>

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(article: DatabaseArticle): Long

@Delete
suspend fun delete(article: DatabaseArticle)
fun insert(article: DatabaseArticle): Long
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package nick.mirosh.newsapp.data.repository

import android.util.Log
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import nick.mirosh.newsapp.data.database.ArticleDao
import nick.mirosh.newsapp.domain.ErrorType
import nick.mirosh.newsapp.domain.Result
Expand All @@ -12,7 +14,7 @@ import nick.mirosh.newsapp.domain.feed.model.asDatabaseModel

const val TAG = "NewsRepository"

class NewsRepositoryImpl (
class NewsRepositoryImpl(
private val newsRemoteDataSource: NewsRemoteDataSource,
private val newsLocalDataSource: ArticleDao,
private val databaseToDomainArticleMapper: DatabaseToDomainArticleMapper,
Expand All @@ -33,17 +35,16 @@ class NewsRepositoryImpl (
}


override suspend fun getFavoriteArticles() =
override suspend fun getFavoriteArticles() = flow {
try {
Result.Success(
databaseToDomainArticleMapper.map(
newsLocalDataSource.getLikedArticles()
)
)
newsLocalDataSource.getLikedArticles().collect {
emit(Result.Success(databaseToDomainArticleMapper.map(it)))
}
} catch (e: Exception) {
Log.e(TAG, e.message.toString())
Result.Error(ErrorType.General)
emit(Result.Error(ErrorType.General))
}
}

override suspend fun updateArticle(article: Article) =
try {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/nick/mirosh/newsapp/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val appModule = module {

factory { FetchArticlesUsecase(get(), get(named(IO))) }
factory { LikeArticleUsecase(get(), get(named(IO))) }
factory { FetchFavoriteArticlesUsecase(get(), get(named(IO))) }
factory { FetchFavoriteArticlesUsecase(get() ) }
factoryOf(::NetworkConnectivityUseCase)

viewModelOf(::FeedViewModel)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package nick.mirosh.newsapp.domain.feed.repository

import kotlinx.coroutines.flow.Flow
import nick.mirosh.newsapp.domain.Result
import nick.mirosh.newsapp.domain.feed.model.Article

interface NewsRepository {
suspend fun getNewsArticles(country: String): Result<List<Article>>
suspend fun getFavoriteArticles(): Result<List<Article>>
suspend fun getFavoriteArticles(): Flow<Result<List<Article>>>
suspend fun updateArticle(article: Article): Result<Article>
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package nick.mirosh.newsapp.domain.usecase.articles

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import kotlinx.coroutines.flow.Flow
import nick.mirosh.newsapp.domain.Result
import nick.mirosh.newsapp.domain.feed.model.Article
import nick.mirosh.newsapp.domain.feed.repository.NewsRepository

class FetchFavoriteArticlesUsecase (
private val repository: NewsRepository,
private val coroutineDispatcher: CoroutineDispatcher,
) {

suspend operator fun invoke(): Result<List<Article>> {
return withContext(coroutineDispatcher) {
repository.getFavoriteArticles()
}
}
suspend operator fun invoke(): Flow<Result<List<Article>>> = repository.getFavoriteArticles()

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ class FavoriteArticlesViewModel (

init {
viewModelScope.launch {
when (val result = fetchFavoriteArticlesUsecase()) {
is Result.Success ->
_uiState.value = if (result.data.isEmpty())
FavoriteArticlesUIState.FavoriteArticlesEmpty
else
FavoriteArticlesUIState.FavoriteArticles(result.data)
fetchFavoriteArticlesUsecase().collect { result ->
when(result) {
is Result.Success ->
_uiState.value = if (result.data.isEmpty())
FavoriteArticlesUIState.FavoriteArticlesEmpty
else
FavoriteArticlesUIState.FavoriteArticles(result.data)

is Result.Error -> {
_uiState.value = FavoriteArticlesUIState.Failed
MyLogger.e("FavoriteArticlesViewModel", "Error = ${result.error}")
is Result.Error -> {
_uiState.value = FavoriteArticlesUIState.Failed
MyLogger.e("FavoriteArticlesViewModel", "Error = ${result.error}")
}
}

}
}
}
Expand Down
Loading

0 comments on commit 92813f0

Please sign in to comment.