mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-20 12:48:53 +01:00
Display messages in conversation after conversation is clicked
This commit is contained in:
@@ -20,6 +20,8 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".ui.messages.MessageListActivity" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -12,9 +12,9 @@ import com.karumi.dexter.listener.PermissionDeniedResponse
|
|||||||
import com.karumi.dexter.listener.PermissionGrantedResponse
|
import com.karumi.dexter.listener.PermissionGrantedResponse
|
||||||
import com.karumi.dexter.listener.PermissionRequest
|
import com.karumi.dexter.listener.PermissionRequest
|
||||||
import com.karumi.dexter.listener.single.PermissionListener
|
import com.karumi.dexter.listener.single.PermissionListener
|
||||||
|
import com.moez.QKSMS.data.sync.ConversationSyncManager
|
||||||
import com.moez.QKSMS.model.Conversation
|
import com.moez.QKSMS.model.Conversation
|
||||||
import com.moez.QKSMS.ui.conversations.ConversationAdapter
|
import com.moez.QKSMS.ui.conversations.ConversationAdapter
|
||||||
import com.moez.QKSMS.util.SyncManager
|
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
@@ -29,7 +29,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
.withListener(object : PermissionListener {
|
.withListener(object : PermissionListener {
|
||||||
override fun onPermissionGranted(response: PermissionGrantedResponse) {
|
override fun onPermissionGranted(response: PermissionGrantedResponse) {
|
||||||
Log.d(TAG, "Permission granted")
|
Log.d(TAG, "Permission granted")
|
||||||
SyncManager.dumpColumns(this@MainActivity)
|
ConversationSyncManager.copyToRealm(this@MainActivity)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPermissionDenied(response: PermissionDeniedResponse) {
|
override fun onPermissionDenied(response: PermissionDeniedResponse) {
|
||||||
@@ -46,6 +46,5 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val conversations = findViewById(R.id.conversation_list) as RecyclerView
|
val conversations = findViewById(R.id.conversation_list) as RecyclerView
|
||||||
conversations.layoutManager = LinearLayoutManager(this)
|
conversations.layoutManager = LinearLayoutManager(this)
|
||||||
conversations.adapter = ConversationAdapter(this, realmResults)
|
conversations.adapter = ConversationAdapter(this, realmResults)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,202 @@
|
|||||||
|
package com.moez.QKSMS.data.sync
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_ID
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_DELIVERY_REPORT
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_ERROR_TYPE
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_LOCKED
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_MESSAGE_BOX
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_MESSAGE_TYPE
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_READ_REPORT
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_STATUS
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_SUBJECT
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_SUBJECT_CHARSET
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MMS_TEXT_ONLY
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_MSG_TYPE
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_ADDRESS
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_BODY
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_DATE
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_DATE_SENT
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_ERROR_CODE
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_LOCKED
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_STATUS
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager.COLUMN_SMS_TYPE
|
||||||
|
|
||||||
|
class ColumnsMap {
|
||||||
|
private val TAG = "ColumnsMap"
|
||||||
|
private val DEBUG = false
|
||||||
|
|
||||||
|
var mColumnMsgType: Int = 0
|
||||||
|
var mColumnMsgId: Int = 0
|
||||||
|
var mColumnSmsAddress: Int = 0
|
||||||
|
var mColumnSmsBody: Int = 0
|
||||||
|
var mColumnSmsDate: Int = 0
|
||||||
|
var mColumnSmsDateSent: Int = 0
|
||||||
|
var mColumnSmsRead: Int = 0
|
||||||
|
var mColumnSmsType: Int = 0
|
||||||
|
var mColumnSmsStatus: Int = 0
|
||||||
|
var mColumnSmsLocked: Int = 0
|
||||||
|
var mColumnSmsErrorCode: Int = 0
|
||||||
|
var mColumnMmsSubject: Int = 0
|
||||||
|
var mColumnMmsSubjectCharset: Int = 0
|
||||||
|
var mColumnMmsDate: Int = 0
|
||||||
|
var mColumnMmsDateSent: Int = 0
|
||||||
|
var mColumnMmsRead: Int = 0
|
||||||
|
var mColumnMmsMessageType: Int = 0
|
||||||
|
var mColumnMmsMessageBox: Int = 0
|
||||||
|
var mColumnMmsDeliveryReport: Int = 0
|
||||||
|
var mColumnMmsReadReport: Int = 0
|
||||||
|
var mColumnMmsErrorType: Int = 0
|
||||||
|
var mColumnMmsLocked: Int = 0
|
||||||
|
var mColumnMmsStatus: Int = 0
|
||||||
|
var mColumnMmsTextOnly: Int = 0
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
mColumnMsgType = COLUMN_MSG_TYPE
|
||||||
|
mColumnMsgId = COLUMN_ID
|
||||||
|
mColumnSmsAddress = COLUMN_SMS_ADDRESS
|
||||||
|
mColumnSmsBody = COLUMN_SMS_BODY
|
||||||
|
mColumnSmsDate = COLUMN_SMS_DATE
|
||||||
|
mColumnSmsDateSent = COLUMN_SMS_DATE_SENT
|
||||||
|
mColumnSmsType = COLUMN_SMS_TYPE
|
||||||
|
mColumnSmsStatus = COLUMN_SMS_STATUS
|
||||||
|
mColumnSmsLocked = COLUMN_SMS_LOCKED
|
||||||
|
mColumnSmsErrorCode = COLUMN_SMS_ERROR_CODE
|
||||||
|
mColumnMmsSubject = COLUMN_MMS_SUBJECT
|
||||||
|
mColumnMmsSubjectCharset = COLUMN_MMS_SUBJECT_CHARSET
|
||||||
|
mColumnMmsMessageType = COLUMN_MMS_MESSAGE_TYPE
|
||||||
|
mColumnMmsMessageBox = COLUMN_MMS_MESSAGE_BOX
|
||||||
|
mColumnMmsDeliveryReport = COLUMN_MMS_DELIVERY_REPORT
|
||||||
|
mColumnMmsReadReport = COLUMN_MMS_READ_REPORT
|
||||||
|
mColumnMmsErrorType = COLUMN_MMS_ERROR_TYPE
|
||||||
|
mColumnMmsLocked = COLUMN_MMS_LOCKED
|
||||||
|
mColumnMmsStatus = COLUMN_MMS_STATUS
|
||||||
|
mColumnMmsTextOnly = COLUMN_MMS_TEXT_ONLY
|
||||||
|
}
|
||||||
|
|
||||||
|
@android.annotation.SuppressLint("InlinedApi")
|
||||||
|
constructor(cursor: android.database.Cursor) {
|
||||||
|
// Ignore all 'not found' exceptions since the custom columns
|
||||||
|
// may be just a subset of the default columns.
|
||||||
|
try {
|
||||||
|
mColumnMsgType = cursor.getColumnIndexOrThrow(android.provider.Telephony.MmsSms.TYPE_DISCRIMINATOR_COLUMN)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnMsgId = cursor.getColumnIndexOrThrow(android.provider.BaseColumns._ID)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnSmsAddress = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.ADDRESS)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnSmsBody = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.BODY)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnSmsDate = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.DATE)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnSmsDateSent = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.DATE_SENT)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnSmsType = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.TYPE)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnSmsStatus = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.STATUS)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnSmsLocked = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.LOCKED)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnSmsErrorCode = cursor.getColumnIndexOrThrow(android.provider.Telephony.Sms.ERROR_CODE)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnMmsSubject = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.SUBJECT)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnMmsSubjectCharset = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.SUBJECT_CHARSET)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnMmsMessageType = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.MESSAGE_TYPE)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnMmsMessageBox = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.MESSAGE_BOX)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnMmsDeliveryReport = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.DELIVERY_REPORT)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnMmsReadReport = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.READ_REPORT)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnMmsErrorType = cursor.getColumnIndexOrThrow(android.provider.Telephony.MmsSms.PendingMessages.ERROR_TYPE)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnMmsLocked = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.LOCKED)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnMmsStatus = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.STATUS)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mColumnMmsTextOnly = cursor.getColumnIndexOrThrow(android.provider.Telephony.Mms.TEXT_ONLY)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
if (DEBUG) Log.w(TAG, e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
-19
@@ -1,27 +1,12 @@
|
|||||||
package com.moez.QKSMS.util
|
package com.moez.QKSMS.data.sync
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.Telephony.Threads
|
|
||||||
import com.moez.QKSMS.model.Conversation
|
import com.moez.QKSMS.model.Conversation
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
|
|
||||||
internal object SyncManager {
|
internal object ConversationSyncManager {
|
||||||
val TAG = "SyncManager"
|
val TAG = "SyncManager"
|
||||||
|
|
||||||
val CONVERSATIONS_CONTENT_PROVIDER = Uri.parse("content://mms-sms/conversations?simple=true")
|
|
||||||
val ALL_THREADS_PROJECTION = arrayOf(
|
|
||||||
Threads._ID,
|
|
||||||
Threads.DATE,
|
|
||||||
Threads.MESSAGE_COUNT,
|
|
||||||
Threads.RECIPIENT_IDS,
|
|
||||||
Threads.SNIPPET,
|
|
||||||
Threads.SNIPPET_CHARSET,
|
|
||||||
Threads.READ,
|
|
||||||
Threads.ERROR,
|
|
||||||
Threads.HAS_ATTACHMENT)
|
|
||||||
|
|
||||||
val ID = 0
|
val ID = 0
|
||||||
val DATE = 1
|
val DATE = 1
|
||||||
val MESSAGE_COUNT = 2
|
val MESSAGE_COUNT = 2
|
||||||
@@ -32,9 +17,21 @@ internal object SyncManager {
|
|||||||
val ERROR = 7
|
val ERROR = 7
|
||||||
val HAS_ATTACHMENT = 8
|
val HAS_ATTACHMENT = 8
|
||||||
|
|
||||||
fun dumpColumns(context: Context) {
|
val CONVERSATIONS_CONTENT_PROVIDER = Uri.parse("content://mms-sms/conversations?simple=true")
|
||||||
|
val ALL_THREADS_PROJECTION = arrayOf(
|
||||||
|
android.provider.Telephony.Threads._ID,
|
||||||
|
android.provider.Telephony.Threads.DATE,
|
||||||
|
android.provider.Telephony.Threads.MESSAGE_COUNT,
|
||||||
|
android.provider.Telephony.Threads.RECIPIENT_IDS,
|
||||||
|
android.provider.Telephony.Threads.SNIPPET,
|
||||||
|
android.provider.Telephony.Threads.SNIPPET_CHARSET,
|
||||||
|
android.provider.Telephony.Threads.READ,
|
||||||
|
android.provider.Telephony.Threads.ERROR,
|
||||||
|
android.provider.Telephony.Threads.HAS_ATTACHMENT)
|
||||||
|
|
||||||
val cursor = context.contentResolver.query(CONVERSATIONS_CONTENT_PROVIDER, ALL_THREADS_PROJECTION, null, null, "date desc")
|
fun copyToRealm(context: android.content.Context) {
|
||||||
|
|
||||||
|
val cursor = context.contentResolver.query(ConversationSyncManager.CONVERSATIONS_CONTENT_PROVIDER, ConversationSyncManager.ALL_THREADS_PROJECTION, null, null, "date desc")
|
||||||
|
|
||||||
Realm.getDefaultInstance().executeTransaction {
|
Realm.getDefaultInstance().executeTransaction {
|
||||||
while (cursor.moveToNext())
|
while (cursor.moveToNext())
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package com.moez.QKSMS.data.sync
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.Uri
|
||||||
|
import android.provider.BaseColumns
|
||||||
|
import android.provider.Telephony
|
||||||
|
import com.moez.QKSMS.model.Message
|
||||||
|
import io.realm.Realm
|
||||||
|
|
||||||
|
|
||||||
|
internal object MessageSyncManager {
|
||||||
|
|
||||||
|
val COLUMN_MSG_TYPE = 0
|
||||||
|
val COLUMN_ID = 1
|
||||||
|
val COLUMN_THREAD_ID = 2
|
||||||
|
val COLUMN_SMS_ADDRESS = 3
|
||||||
|
val COLUMN_SMS_BODY = 4
|
||||||
|
val COLUMN_SMS_DATE = 5
|
||||||
|
val COLUMN_SMS_DATE_SENT = 6
|
||||||
|
val COLUMN_SMS_READ = 7
|
||||||
|
val COLUMN_SMS_TYPE = 8
|
||||||
|
val COLUMN_SMS_STATUS = 9
|
||||||
|
val COLUMN_SMS_LOCKED = 10
|
||||||
|
val COLUMN_SMS_ERROR_CODE = 11
|
||||||
|
val COLUMN_MMS_SUBJECT = 12
|
||||||
|
val COLUMN_MMS_SUBJECT_CHARSET = 13
|
||||||
|
val COLUMN_MMS_DATE = 14
|
||||||
|
val COLUMN_MMS_DATE_SENT = 15
|
||||||
|
val COLUMN_MMS_READ = 16
|
||||||
|
val COLUMN_MMS_MESSAGE_TYPE = 17
|
||||||
|
val COLUMN_MMS_MESSAGE_BOX = 18
|
||||||
|
val COLUMN_MMS_DELIVERY_REPORT = 19
|
||||||
|
val COLUMN_MMS_READ_REPORT = 20
|
||||||
|
val COLUMN_MMS_ERROR_TYPE = 21
|
||||||
|
val COLUMN_MMS_LOCKED = 22
|
||||||
|
val COLUMN_MMS_STATUS = 23
|
||||||
|
val COLUMN_MMS_TEXT_ONLY = 24
|
||||||
|
|
||||||
|
val MMS_SMS_CONTENT_PROVIDER = Uri.parse("content://mms-sms/conversations/")
|
||||||
|
|
||||||
|
@SuppressLint("InlinedApi")
|
||||||
|
val PROJECTION = arrayOf(
|
||||||
|
Telephony.MmsSms.TYPE_DISCRIMINATOR_COLUMN,
|
||||||
|
BaseColumns._ID,
|
||||||
|
Telephony.Sms.Conversations.THREAD_ID,
|
||||||
|
|
||||||
|
// For SMS
|
||||||
|
Telephony.Sms.ADDRESS,
|
||||||
|
Telephony.Sms.BODY,
|
||||||
|
Telephony.Sms.DATE,
|
||||||
|
Telephony.Sms.DATE_SENT,
|
||||||
|
Telephony.Sms.READ, Telephony.Sms.TYPE,
|
||||||
|
Telephony.Sms.STATUS,
|
||||||
|
Telephony.Sms.LOCKED,
|
||||||
|
Telephony.Sms.ERROR_CODE,
|
||||||
|
|
||||||
|
// For MMS
|
||||||
|
Telephony.Mms.SUBJECT,
|
||||||
|
Telephony.Mms.SUBJECT_CHARSET,
|
||||||
|
Telephony.Mms.DATE,
|
||||||
|
Telephony.Mms.DATE_SENT,
|
||||||
|
Telephony.Mms.READ,
|
||||||
|
Telephony.Mms.MESSAGE_TYPE,
|
||||||
|
Telephony.Mms.MESSAGE_BOX,
|
||||||
|
Telephony.Mms.DELIVERY_REPORT,
|
||||||
|
Telephony.Mms.READ_REPORT,
|
||||||
|
Telephony.MmsSms.PendingMessages.ERROR_TYPE,
|
||||||
|
Telephony.Mms.LOCKED,
|
||||||
|
Telephony.Mms.STATUS,
|
||||||
|
Telephony.Mms.TEXT_ONLY)
|
||||||
|
|
||||||
|
fun copyToRealm(context: Context, threadId: Long) {
|
||||||
|
val cursor = context.contentResolver.query(Uri.withAppendedPath(MMS_SMS_CONTENT_PROVIDER, threadId.toString()), PROJECTION, null, null, "date desc")
|
||||||
|
val columnsMap = ColumnsMap(cursor)
|
||||||
|
|
||||||
|
Realm.getDefaultInstance().executeTransaction {
|
||||||
|
while (cursor.moveToNext())
|
||||||
|
it.insertOrUpdate(Message(
|
||||||
|
cursor.getLong(columnsMap.mColumnMsgId),
|
||||||
|
threadId,
|
||||||
|
cursor.getString(columnsMap.mColumnSmsBody)))
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import io.realm.annotations.PrimaryKey
|
|||||||
open class Message(
|
open class Message(
|
||||||
|
|
||||||
@PrimaryKey var id: Long = 0,
|
@PrimaryKey var id: Long = 0,
|
||||||
|
var threadId: Long = 0,
|
||||||
var body: String = ""
|
var body: String = ""
|
||||||
|
|
||||||
) : RealmObject()
|
) : RealmObject()
|
||||||
|
|||||||
@@ -1,24 +1,34 @@
|
|||||||
package com.moez.QKSMS.ui.conversations
|
package com.moez.QKSMS.ui.conversations
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.model.Conversation
|
import com.moez.QKSMS.model.Conversation
|
||||||
|
import com.moez.QKSMS.ui.messages.MessageListActivity
|
||||||
import io.realm.OrderedRealmCollection
|
import io.realm.OrderedRealmCollection
|
||||||
import io.realm.RealmRecyclerViewAdapter
|
import io.realm.RealmRecyclerViewAdapter
|
||||||
|
|
||||||
class ConversationAdapter(context: Context, data: OrderedRealmCollection<Conversation>?) :
|
class ConversationAdapter(context: Context, data: OrderedRealmCollection<Conversation>) :
|
||||||
RealmRecyclerViewAdapter<Conversation, ConversationViewHolder>(context, data, true) {
|
RealmRecyclerViewAdapter<Conversation, ConversationViewHolder>(context, data, true) {
|
||||||
|
|
||||||
val mContext = context
|
val mContext = context
|
||||||
|
|
||||||
override fun onBindViewHolder(viewHolder: ConversationViewHolder, position: Int) {
|
|
||||||
viewHolder.snippet.text = getItem(position)?.snippet
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ConversationViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ConversationViewHolder {
|
||||||
val layoutInflater = mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
val layoutInflater = mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
return ConversationViewHolder(layoutInflater.inflate(R.layout.conversation_list_item, parent, false))
|
return ConversationViewHolder(layoutInflater.inflate(R.layout.conversation_list_item, parent, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(viewHolder: ConversationViewHolder, position: Int) {
|
||||||
|
val conversation = getItem(position)
|
||||||
|
|
||||||
|
viewHolder.snippet.text = conversation?.snippet
|
||||||
|
viewHolder.itemView.setOnClickListener {
|
||||||
|
val intent = Intent(mContext, MessageListActivity::class.java)
|
||||||
|
intent.putExtra("thread_id", conversation?.id)
|
||||||
|
|
||||||
|
mContext.startActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.moez.QKSMS.ui.messages
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.support.v7.app.AppCompatActivity
|
||||||
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
|
import android.support.v7.widget.RecyclerView
|
||||||
|
import com.moez.QKSMS.R
|
||||||
|
import com.moez.QKSMS.data.sync.MessageSyncManager
|
||||||
|
import com.moez.QKSMS.model.Message
|
||||||
|
import io.realm.Realm
|
||||||
|
|
||||||
|
class MessageListActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
|
val threadId = intent.getLongExtra("thread_id", 0)
|
||||||
|
|
||||||
|
MessageSyncManager.copyToRealm(this, threadId)
|
||||||
|
|
||||||
|
val realmResults = Realm.getDefaultInstance()
|
||||||
|
.where(Message::class.java)
|
||||||
|
.equalTo("threadId", threadId)
|
||||||
|
.findAll()
|
||||||
|
|
||||||
|
val messages = findViewById(R.id.conversation_list) as RecyclerView
|
||||||
|
messages.layoutManager = LinearLayoutManager(this)
|
||||||
|
messages.adapter = MessageAdapter(this, realmResults)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user