mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Add position via dragging the recyclerview
This commit is contained in:
parent
1bdb6bf340
commit
01e24ff6a4
7 changed files with 46 additions and 49 deletions
|
|
@ -32,7 +32,7 @@ class QuickChatActionRepository @Inject constructor(private val quickChatDaoLazy
|
|||
quickChatActionDao.update(action)
|
||||
}
|
||||
|
||||
suspend fun moveAction(action: QuickChatAction, newPos: Int) = withContext(Dispatchers.IO) {
|
||||
quickChatActionDao.moveAction(action, newPos)
|
||||
suspend fun setItemPosition(uuid: Long, newPos: Int) = withContext(Dispatchers.IO) {
|
||||
quickChatActionDao.updateActionPosition(uuid, newPos)
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.Flow
|
|||
@Dao
|
||||
interface QuickChatActionDao {
|
||||
|
||||
@Query("Select * from quick_chat")
|
||||
@Query("Select * from quick_chat order by position asc")
|
||||
fun getAll(): Flow<List<QuickChatAction>>
|
||||
|
||||
@Insert
|
||||
|
|
@ -31,27 +31,7 @@ interface QuickChatActionDao {
|
|||
@Query("Update quick_chat set position=:position WHERE uuid=:uuid")
|
||||
fun updateActionPosition(uuid: Long, position: Int)
|
||||
|
||||
@Query("Update quick_chat set position=position+1 where position>=:startInclusive and position<:endExclusive")
|
||||
fun incrementPositionsBetween(startInclusive: Int, endExclusive: Int)
|
||||
|
||||
@Query("Update quick_chat SET position=position-1 where position>:startExclusive and position<=:endInclusive")
|
||||
fun decrementPositionsBetween(startExclusive: Int, endInclusive: Int)
|
||||
|
||||
@Query("Update quick_chat set position=position-1 where position>=:position")
|
||||
fun decrementPositionsAfter(position: Int)
|
||||
|
||||
@Transaction
|
||||
fun moveAction(action: QuickChatAction, newPos: Int) {
|
||||
// FIXME: Check newPos is valid
|
||||
if (newPos < action.position) {
|
||||
incrementPositionsBetween(newPos, action.position)
|
||||
updateActionPosition(action.uuid, newPos)
|
||||
} else if (newPos > action.position) {
|
||||
decrementPositionsBetween(action.position, newPos)
|
||||
updateActionPosition(action.uuid, newPos)
|
||||
} else {
|
||||
// Do nothing: moving to same position
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ import androidx.room.Entity
|
|||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "quick_chat", indices = [Index(value=["position"], unique=true)])
|
||||
@Entity(tableName = "quick_chat")
|
||||
data class QuickChatAction(
|
||||
@PrimaryKey(autoGenerate = true) val uuid: Long,
|
||||
@ColumnInfo(name="name") val name: String,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue