insert fetched conversations in db
This commit is contained in:
parent
f638fa06f2
commit
7a7b1aab32
|
@ -221,12 +221,13 @@ fun Context.getConversations(): ArrayList<Conversation> {
|
|||
val photoUri = if (phoneNumbers.size == 1) simpleContactHelper.getPhotoUriFromPhoneNumber(phoneNumbers.first()) else ""
|
||||
val isGroupConversation = phoneNumbers.size > 1
|
||||
val read = cursor.getIntValue(Threads.READ) == 1
|
||||
val conversation = Conversation(0, id, snippet, date.toInt(), read, title, photoUri, isGroupConversation, phoneNumbers.first())
|
||||
val conversation = Conversation(null, id, snippet, date.toInt(), read, title, photoUri, isGroupConversation, phoneNumbers.first())
|
||||
|
||||
conversations.add(conversation)
|
||||
}
|
||||
|
||||
conversations.sortByDescending { it.date }
|
||||
conversationsDB.insertAll(conversations)
|
||||
return conversations
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
package com.simplemobiletools.smsmessenger.interfaces
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.simplemobiletools.smsmessenger.models.Conversation
|
||||
|
||||
@Dao
|
||||
interface ConversationsDao
|
||||
interface ConversationsDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insert(conversation: Conversation): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertAll(conversations: List<Conversation>)
|
||||
|
||||
@Query("SELECT * FROM conversations")
|
||||
fun getAll(): List<Conversation>
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import androidx.room.Entity
|
|||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "conversations", indices = [(Index(value = ["id"], unique = true))])
|
||||
@Entity(tableName = "conversations", indices = [(Index(value = ["system_id"], unique = true))])
|
||||
data class Conversation(
|
||||
@PrimaryKey(autoGenerate = true) var id: Long?,
|
||||
@ColumnInfo(name = "system_id") var system_id: Int,
|
||||
|
|
Loading…
Reference in New Issue