Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add pack sources #2

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
local.properties
.idea/
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ interface NewsDao {
@Delete
suspend fun delete(article: Article)

@Query("SELECT * FROM Article")
fun getArticles(): Flow<List<Article>>

@Query("SELECT * FROM Article WHERE url=:url")
suspend fun getArticle(url: String): Article?
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import info.octera.droidstorybox.domain.model.Article
import info.octera.droidstorybox.domain.model.PackSource

@Database(entities = [Article::class], version = 1)
@Database(entities = [Article::class, PackSource::class],version = 1,)
@TypeConverters(NewsTypeConverter::class)
abstract class NewsDatabase : RoomDatabase() {

abstract val newsDao: NewsDao
}

abstract val packSourcesDao: PackSourcesDao

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package info.octera.droidstorybox.data.local

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import info.octera.droidstorybox.domain.model.PackSource
import kotlinx.coroutines.flow.Flow

@Dao
interface PackSourcesDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun upsert(packSource: PackSource)

@Delete
suspend fun delete(packSource: PackSource)

@Query("SELECT * FROM PackSource")
fun getPackSource(): Flow<List<PackSource>>

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ class NewsRepositoryImpl(
newsDao.delete(article)
}

override fun getArticles(): Flow<List<Article>> {
return newsDao.getArticles()
}

override suspend fun getArticle(url: String): Article? {
return newsDao.getArticle(url = url)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package info.octera.droidstorybox.data.repository

import info.octera.droidstorybox.data.local.PackSourcesDao
import info.octera.droidstorybox.domain.model.PackSource
import info.octera.droidstorybox.domain.repository.PackSourcesRepository
import kotlinx.coroutines.flow.Flow

class PackSourcesRepositoryImpl(private val packSourcesDao: PackSourcesDao) :
PackSourcesRepository {

override suspend fun upsertPackSource(packSource: PackSource) {
packSourcesDao.upsert(packSource)
}

override suspend fun deletePackSource(packSource: PackSource) {
packSourcesDao.delete(packSource)
}

override fun getPackSources(): Flow<List<PackSource>> {
return packSourcesDao.getPackSource()
}
}
35 changes: 33 additions & 2 deletions app/src/main/java/info/octera/droidstorybox/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ import info.octera.droidstorybox.domain.usecases.news.GetNews
import info.octera.droidstorybox.domain.usecases.news.NewsUseCases
import info.octera.droidstorybox.domain.usecases.news.SearchNews
import info.octera.droidstorybox.domain.usecases.news.SelectArticle
import info.octera.droidstorybox.domain.usecases.news.SelectArticles
import info.octera.droidstorybox.domain.usecases.news.UpsertArticle
import info.octera.droidstorybox.util.Constants.BASE_URL
import info.octera.droidstorybox.util.Constants.NEW_DATABASE
import info.octera.droidstorybox.data.local.PackSourcesDao
import info.octera.droidstorybox.data.repository.PackSourcesRepositoryImpl
import info.octera.droidstorybox.domain.repository.PackSourcesRepository
import info.octera.droidstorybox.domain.usecases.pack_sources.DeletePackSource
import info.octera.droidstorybox.domain.usecases.pack_sources.GetPackSources
import info.octera.droidstorybox.domain.usecases.pack_sources.PackSourcesUseCases
import info.octera.droidstorybox.domain.usecases.pack_sources.UpsertPackSource
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import javax.inject.Singleton
Expand Down Expand Up @@ -55,6 +61,12 @@ object AppModule {
.create(NewsApi::class.java)
}

@Provides
@Singleton
fun providePackSourcesRepository(packSourcesDao: PackSourcesDao): PackSourcesRepository {
return PackSourcesRepositoryImpl(packSourcesDao)
}

@Provides
@Singleton
fun provideNewsRepository(
Expand All @@ -64,6 +76,18 @@ object AppModule {
return NewsRepositoryImpl(newsApi, newsDao)
}

@Provides
@Singleton
fun providePackSourcesUseCases(
packSourcesRepository: PackSourcesRepository,
): PackSourcesUseCases {
return PackSourcesUseCases(
getPackSources = GetPackSources(packSourcesRepository),
deletePackSource = DeletePackSource(packSourcesRepository),
upsertPackSource = UpsertPackSource(packSourcesRepository),
)
}

@Provides
@Singleton
fun provideNewsUseCases(newsRepository: NewsRepository): NewsUseCases {
Expand All @@ -72,7 +96,6 @@ object AppModule {
searchNews = SearchNews(newsRepository),
upsertArticle = UpsertArticle(newsRepository),
deleteArticle = DeleteArticle(newsRepository),
selectArticles = SelectArticles(newsRepository),
selectArticle = SelectArticle(newsRepository),
)
}
Expand All @@ -94,4 +117,12 @@ object AppModule {
fun provideNewsDao(newsDatabase: NewsDatabase): NewsDao {
return newsDatabase.newsDao
}

@Provides
@Singleton
fun providePackSourcesDao(
newsDatabase: NewsDatabase
): PackSourcesDao {
return newsDatabase.packSourcesDao
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package info.octera.droidstorybox.domain.model

import android.os.Parcelable
import androidx.room.Entity
import androidx.room.PrimaryKey
import kotlinx.parcelize.Parcelize

@Parcelize
@Entity
data class PackSource(
@PrimaryKey val url: String,
val name: String
): Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ interface NewsRepository {

suspend fun deleteArticle(article: Article)

fun getArticles(): Flow<List<Article>>

suspend fun getArticle(url: String): Article?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package info.octera.droidstorybox.domain.repository

import info.octera.droidstorybox.domain.model.PackSource
import kotlinx.coroutines.flow.Flow

interface PackSourcesRepository {
suspend fun upsertPackSource(packSource: PackSource)
suspend fun deletePackSource(packSource: PackSource)
fun getPackSources(): Flow<List<PackSource>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ data class NewsUseCases(
val searchNews: SearchNews,
val upsertArticle: UpsertArticle,
val deleteArticle: DeleteArticle,
val selectArticles: SelectArticles,
val selectArticle: SelectArticle,
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package info.octera.droidstorybox.domain.usecases.pack_sources

import info.octera.droidstorybox.domain.model.Article
import info.octera.droidstorybox.domain.model.PackSource
import info.octera.droidstorybox.domain.repository.PackSourcesRepository

class DeletePackSource(
private val packSourcesRepository: PackSourcesRepository
) {

suspend operator fun invoke(packSource: PackSource){
packSourcesRepository.deletePackSource(packSource)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package info.octera.droidstorybox.domain.usecases.pack_sources

import androidx.paging.PagingData
import info.octera.droidstorybox.domain.model.Article
import info.octera.droidstorybox.domain.model.PackSource
import info.octera.droidstorybox.domain.repository.PackSourcesRepository
import kotlinx.coroutines.flow.Flow

class GetPackSources(
private val packSourcesRepository: PackSourcesRepository
) {

operator fun invoke(): Flow<List<PackSource>> {
return packSourcesRepository.getPackSources()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package info.octera.droidstorybox.domain.usecases.pack_sources

data class PackSourcesUseCases (
val getPackSources: GetPackSources,
val upsertPackSource: UpsertPackSource,
val deletePackSource: DeletePackSource,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package info.octera.droidstorybox.domain.usecases.pack_sources

import info.octera.droidstorybox.domain.model.Article
import info.octera.droidstorybox.domain.model.PackSource
import info.octera.droidstorybox.domain.repository.NewsRepository
import info.octera.droidstorybox.domain.repository.PackSourcesRepository

class UpsertPackSource(
private val packSourcesRepository: PackSourcesRepository
) {

suspend operator fun invoke(packSource: PackSource){
packSourcesRepository.upsertPackSource(packSource)
}

}
Original file line number Diff line number Diff line change
@@ -1,51 +0,0 @@
package info.octera.droidstorybox.presentation.bookmark

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.text.font.FontWeight
import info.octera.droidstorybox.R
import info.octera.droidstorybox.domain.model.Article
import info.octera.droidstorybox.presentation.Dimens.MediumPadding1
import info.octera.droidstorybox.presentation.common.ArticlesList

@Composable
fun BookmarkScreen(
modifier: Modifier = Modifier,
state: BookmarkState,
navigateToDetails: (Article) -> Unit,
) {
Column(
modifier =
Modifier
.fillMaxWidth()
.statusBarsPadding()
.padding(top = MediumPadding1, start = MediumPadding1, end = MediumPadding1),
) {
Text(
text = "Bookmark",
style = MaterialTheme.typography.displayMedium.copy(fontWeight = FontWeight.Bold),
color =
colorResource(
id = R.color.text_title,
),
)

Spacer(modifier = Modifier.height(MediumPadding1))

ArticlesList(
articles = state.articles,
onClick = {
navigateToDetails(it)
},
)
}
}

This file was deleted.

This file was deleted.

Loading
Loading