forked from upstream-mirrors/quik
Align messages to correct side in list
This commit is contained in:
@@ -77,12 +77,23 @@ internal object MessageSyncManager {
|
||||
Realm.getDefaultInstance().executeTransaction {
|
||||
while (cursor.moveToNext()) {
|
||||
|
||||
val body = cursor.getString(columnsMap.mColumnSmsBody) ?: ""
|
||||
val type = cursor.getString(columnsMap.mColumnMsgType)
|
||||
if (type != "sms" && type != "mms") continue // If we can't read the type, don't use this message
|
||||
|
||||
it.insertOrUpdate(Message(
|
||||
cursor.getLong(columnsMap.mColumnMsgId),
|
||||
threadId,
|
||||
body))
|
||||
val isMms = type == "mms"
|
||||
val body = cursor.getString(columnsMap.mColumnSmsBody) ?: ""
|
||||
val errorType = cursor.getInt(columnsMap.mColumnMmsErrorType)
|
||||
|
||||
val boxId: Int
|
||||
|
||||
if (isMms) {
|
||||
boxId = cursor.getInt(columnsMap.mColumnMmsMessageBox)
|
||||
} else {
|
||||
boxId = cursor.getInt(columnsMap.mColumnSmsType)
|
||||
}
|
||||
|
||||
it.insertOrUpdate(
|
||||
Message(cursor.getLong(columnsMap.mColumnMsgId), threadId, boxId, type, body, errorType))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.moez.QKSMS.model
|
||||
|
||||
import android.provider.Telephony
|
||||
import android.provider.Telephony.Mms
|
||||
import android.provider.Telephony.Sms
|
||||
import io.realm.RealmObject
|
||||
import io.realm.annotations.PrimaryKey
|
||||
|
||||
@@ -7,6 +10,41 @@ open class Message(
|
||||
|
||||
@PrimaryKey var id: Long = 0,
|
||||
var threadId: Long = 0,
|
||||
var body: String = ""
|
||||
var boxId: Int = 0,
|
||||
var type: String = "",
|
||||
var body: String = "",
|
||||
var errorType: Int = 0
|
||||
|
||||
) : RealmObject()
|
||||
) : RealmObject() {
|
||||
|
||||
fun isMms(): Boolean = type == "mms"
|
||||
|
||||
fun isSms(): Boolean = type == "sms"
|
||||
|
||||
fun isMe(): Boolean {
|
||||
val isIncomingMms = isMms() && (boxId == Mms.MESSAGE_BOX_INBOX || boxId == Mms.MESSAGE_BOX_ALL)
|
||||
val isIncomingSms = isSms() && (boxId == Sms.MESSAGE_TYPE_INBOX || boxId == Sms.MESSAGE_TYPE_ALL)
|
||||
|
||||
return !(isIncomingMms || isIncomingSms)
|
||||
}
|
||||
|
||||
fun isOutgoingMessage(): Boolean {
|
||||
val isOutgoingMms = isMms() && boxId == Mms.MESSAGE_BOX_OUTBOX
|
||||
val isOutgoingSms = isSms() && (boxId == Sms.MESSAGE_TYPE_FAILED
|
||||
|| boxId == Sms.MESSAGE_TYPE_OUTBOX
|
||||
|| boxId == Sms.MESSAGE_TYPE_QUEUED)
|
||||
|
||||
return isOutgoingMms || isOutgoingSms
|
||||
}
|
||||
|
||||
fun isSending(): Boolean {
|
||||
return !isFailedMessage() && isOutgoingMessage()
|
||||
}
|
||||
|
||||
fun isFailedMessage(): Boolean {
|
||||
val isFailedMms = isMms() && errorType >= Telephony.MmsSms.ERR_TYPE_GENERIC_PERMANENT
|
||||
val isFailedSms = isSms() && boxId == Sms.MESSAGE_TYPE_FAILED
|
||||
return isFailedMms || isFailedSms
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.moez.QKSMS.ui.messages
|
||||
|
||||
import android.content.Context
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
@@ -11,14 +12,15 @@ import io.realm.RealmRecyclerViewAdapter
|
||||
class MessageAdapter(context: Context, data: OrderedRealmCollection<Message>?) :
|
||||
RealmRecyclerViewAdapter<Message, MessageViewHolder>(context, data, true) {
|
||||
|
||||
val mContext = context
|
||||
|
||||
override fun onBindViewHolder(viewHolder: MessageViewHolder, position: Int) {
|
||||
viewHolder.body.text = getItem(position)?.body
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MessageViewHolder {
|
||||
val layoutInflater = mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
val layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
return MessageViewHolder(layoutInflater.inflate(R.layout.message_list_item, parent, false))
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: MessageViewHolder, position: Int) {
|
||||
val message = getItem(position)!!
|
||||
|
||||
viewHolder.body.text = message.body
|
||||
viewHolder.body.gravity = if (message.isMe()) Gravity.RIGHT else Gravity.LEFT
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message_body"
|
||||
android:layout_width="wrap_content"
|
||||
android:padding="16dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Hey! How's it going?" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user