-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add coroutine flow and refactor code π
- Loading branch information
1 parent
75b01e1
commit 447d399
Showing
23 changed files
with
312 additions
and
96 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
app/src/main/java/com/grevi/masakapa/db/RecipesDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
package com.grevi.masakapa.db | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import com.grevi.masakapa.db.entity.Category | ||
import com.grevi.masakapa.db.entity.Recipes | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface RecipesDataSource { | ||
suspend fun insertRecipes(recipes: Recipes) | ||
suspend fun isExistRecipes(key : String) : Boolean | ||
suspend fun getMarkRecipes() : List<Recipes> | ||
suspend fun getMarkRecipes() : MutableList<Recipes> | ||
suspend fun deleteRecipes(recipes: Recipes) | ||
suspend fun getFlowRecipes() : Flow<List<Recipes>> | ||
suspend fun insertCategory(category: Category) | ||
suspend fun getAllCategory() : MutableList<Category> | ||
suspend fun getFlowCategory() : Flow<MutableList<Category>> | ||
} |
25 changes: 22 additions & 3 deletions
25
app/src/main/java/com/grevi/masakapa/db/RecipesDataSourceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
package com.grevi.masakapa.db | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import com.grevi.masakapa.db.entity.Category | ||
import com.grevi.masakapa.db.entity.Recipes | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import javax.inject.Inject | ||
|
||
class RecipesDataSourceImpl @Inject constructor(private val recipesDAO: RecipesDAO) : RecipesDataSource { | ||
override suspend fun insertRecipes(recipes: Recipes) = recipesDAO.insertRecipes(recipes) | ||
override suspend fun isExistRecipes(key: String) : Boolean = recipesDAO.isExistsRecipes(key) | ||
override suspend fun getMarkRecipes() : List<Recipes> = recipesDAO.getAllMarkRecipes() | ||
override suspend fun getMarkRecipes() : MutableList<Recipes> = recipesDAO.getAllMarkRecipes() | ||
override suspend fun deleteRecipes(recipes: Recipes) = recipesDAO.deleteRecipes(recipes) | ||
override suspend fun getFlowRecipes(): Flow<List<Recipes>> { | ||
return flow { | ||
emit(recipesDAO.getAllMarkRecipes()) | ||
} | ||
} | ||
|
||
override suspend fun insertCategory(category: Category) = recipesDAO.insertCategory(category) | ||
|
||
override suspend fun getAllCategory(): MutableList<Category> { | ||
return recipesDAO.getAllCategory() | ||
} | ||
|
||
override suspend fun getFlowCategory(): Flow<MutableList<Category>> { | ||
return flow { | ||
emit(recipesDAO.getAllCategory()) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/grevi/masakapa/db/entity/Category.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.grevi.masakapa.db.entity | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "category") | ||
data class Category( | ||
@PrimaryKey @ColumnInfo(name = "key") var key : String, | ||
@ColumnInfo(name = "category") var category : String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.