-
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate
QuickChat
to Compose (#1419)
- Loading branch information
Showing
7 changed files
with
351 additions
and
338 deletions.
There are no files selected for viewing
27 changes: 12 additions & 15 deletions
27
app/src/main/java/com/geeksville/mesh/database/QuickChatActionRepository.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,38 +1,35 @@ | ||
package com.geeksville.mesh.database | ||
|
||
import com.geeksville.mesh.CoroutineDispatchers | ||
import com.geeksville.mesh.database.dao.QuickChatActionDao | ||
import com.geeksville.mesh.database.entity.QuickChatAction | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flowOn | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
|
||
class QuickChatActionRepository @Inject constructor(private val quickChatDaoLazy: dagger.Lazy<QuickChatActionDao>) { | ||
class QuickChatActionRepository @Inject constructor( | ||
private val quickChatDaoLazy: dagger.Lazy<QuickChatActionDao>, | ||
private val dispatchers: CoroutineDispatchers, | ||
) { | ||
private val quickChatActionDao by lazy { | ||
quickChatDaoLazy.get() | ||
} | ||
|
||
suspend fun getAllActions(): Flow<List<QuickChatAction>> = withContext(Dispatchers.IO) { | ||
quickChatActionDao.getAll() | ||
} | ||
fun getAllActions() = quickChatActionDao.getAll().flowOn(dispatchers.io) | ||
|
||
suspend fun insert(action: QuickChatAction) = withContext(Dispatchers.IO) { | ||
quickChatActionDao.insert(action) | ||
suspend fun upsert(action: QuickChatAction) = withContext(dispatchers.io) { | ||
quickChatActionDao.upsert(action) | ||
} | ||
|
||
suspend fun deleteAll() = withContext(Dispatchers.IO) { | ||
suspend fun deleteAll() = withContext(dispatchers.io) { | ||
quickChatActionDao.deleteAll() | ||
} | ||
|
||
suspend fun delete(action: QuickChatAction) = withContext(Dispatchers.IO) { | ||
suspend fun delete(action: QuickChatAction) = withContext(dispatchers.io) { | ||
quickChatActionDao.delete(action) | ||
} | ||
|
||
suspend fun update(action: QuickChatAction) = withContext(Dispatchers.IO) { | ||
quickChatActionDao.update(action) | ||
} | ||
|
||
suspend fun setItemPosition(uuid: Long, newPos: Int) = withContext(Dispatchers.IO) { | ||
suspend fun setItemPosition(uuid: Long, newPos: Int) = withContext(dispatchers.io) { | ||
quickChatActionDao.updateActionPosition(uuid, newPos) | ||
} | ||
} |
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.