Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Remove update
Browse files Browse the repository at this point in the history
  • Loading branch information
SanmerDev committed Aug 19, 2023
1 parent ec0362b commit 06e13e8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 19 deletions.
6 changes: 1 addition & 5 deletions app/src/main/kotlin/com/sanmer/mrepo/database/dao/RepoDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.sanmer.mrepo.database.entity.Repo
import kotlinx.coroutines.flow.Flow

Expand All @@ -20,12 +19,9 @@ interface RepoDao {
@Query("SELECT * FROM repos WHERE url = :url LIMIT 1")
fun getByUrl(url: String): Repo

@Insert(onConflict = OnConflictStrategy.IGNORE)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(value: Repo)

@Update
suspend fun update(value: Repo)

@Delete
suspend fun delete(value: Repo)
}
15 changes: 2 additions & 13 deletions app/src/main/kotlin/com/sanmer/mrepo/repository/LocalRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.sanmer.mrepo.model.online.OnlineModule
import com.sanmer.mrepo.utils.extensions.merge
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
Expand All @@ -41,21 +40,15 @@ class LocalRepository @Inject constructor(

init {
getLocalAllAsFlow()
.distinctUntilChanged()
.onEach { list ->
if (list.isEmpty()) return@onEach

_local = list
Timber.d("update local modules")
Timber.d("update local: ${list.size}")
}.launchIn(applicationScope)

getOnlineAllAsFlow()
.distinctUntilChanged()
.onEach { list ->
if (list.isEmpty()) return@onEach

_online = list
Timber.d("update online modules")
Timber.d("update online: ${list.size}")
}.launchIn(applicationScope)
}

Expand Down Expand Up @@ -89,10 +82,6 @@ class LocalRepository @Inject constructor(
repoDao.insert(value)
}

suspend fun updateRepo(value: Repo) = withContext(Dispatchers.IO) {
repoDao.update(value)
}

suspend fun deleteRepo(value: Repo) = withContext(Dispatchers.IO) {
repoDao.delete(value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class RepositoriesViewModel @Inject constructor(
}

fun update(repo: Repo) = viewModelScope.launch {
localRepository.updateRepo(repo)
localRepository.insertRepo(repo)
}

fun delete(repo: Repo) = viewModelScope.launch {
Expand Down

0 comments on commit 06e13e8

Please sign in to comment.