mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-23 06:08:52 +01:00
Create mms preview view
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
package presentation.common.widget
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import com.moez.QKSMS.R
|
||||||
|
import common.util.GlideApp
|
||||||
|
import common.util.extensions.setVisible
|
||||||
|
import data.model.MmsPart
|
||||||
|
import kotlinx.android.synthetic.main.mms_preview_view.view.*
|
||||||
|
|
||||||
|
class MmsPreviewView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs) {
|
||||||
|
|
||||||
|
var parts: List<MmsPart> = ArrayList()
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
|
||||||
|
val images = value.mapNotNull { it.image }
|
||||||
|
setVisible(images.isNotEmpty())
|
||||||
|
|
||||||
|
images.firstOrNull()?.let {
|
||||||
|
GlideApp.with(context).load(it).into(image)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
View.inflate(context, R.layout.mms_preview_view, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -27,7 +27,6 @@ import com.jakewharton.rxbinding2.view.RxView
|
|||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import common.util.Colors
|
import common.util.Colors
|
||||||
import common.util.DateFormatter
|
import common.util.DateFormatter
|
||||||
import common.util.GlideApp
|
|
||||||
import common.util.extensions.dpToPx
|
import common.util.extensions.dpToPx
|
||||||
import common.util.extensions.setBackgroundTint
|
import common.util.extensions.setBackgroundTint
|
||||||
import common.util.extensions.setPadding
|
import common.util.extensions.setPadding
|
||||||
@@ -114,7 +113,7 @@ class MessagesAdapter @Inject constructor(
|
|||||||
}
|
}
|
||||||
RxView.longClicks(view).subscribe { longClicks.onNext(message) }
|
RxView.longClicks(view).subscribe { longClicks.onNext(message) }
|
||||||
|
|
||||||
bindImages(view, position)
|
bindMmsPreview(view, position)
|
||||||
bindStatus(view, position)
|
bindStatus(view, position)
|
||||||
bindGrouping(view, position)
|
bindGrouping(view, position)
|
||||||
|
|
||||||
@@ -124,7 +123,7 @@ class MessagesAdapter @Inject constructor(
|
|||||||
view.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
view.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun bindImages(view: View, position: Int) {
|
private fun bindMmsPreview(view: View, position: Int) {
|
||||||
val message = getItem(position)!!
|
val message = getItem(position)!!
|
||||||
|
|
||||||
// If it's an MMS and the parts haven't been loaded, kick off a load
|
// If it's an MMS and the parts haven't been loaded, kick off a load
|
||||||
@@ -132,11 +131,7 @@ class MessagesAdapter @Inject constructor(
|
|||||||
loadMmsParts.execute(message.id)
|
loadMmsParts.execute(message.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
view.image.setVisible(false)
|
view.mmsPreview.parts = message.parts
|
||||||
message.parts.firstOrNull { it.image != null }?.let { part ->
|
|
||||||
view.image.setVisible(true)
|
|
||||||
GlideApp.with(context).load(part.image).into(view.image)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun bindStatus(view: View, position: Int) {
|
private fun bindStatus(view: View, position: Int) {
|
||||||
|
|||||||
@@ -60,8 +60,8 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:backgroundTint="@color/tools_theme">
|
tools:backgroundTint="@color/tools_theme">
|
||||||
|
|
||||||
<ImageView
|
<presentation.common.widget.MmsPreviewView
|
||||||
android:id="@+id/image"
|
android:id="@+id/mmsPreview"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintBottom_toTopOf="@id/body"
|
app:layout_constraintBottom_toTopOf="@id/body"
|
||||||
|
|||||||
@@ -54,8 +54,8 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:backgroundTint="@color/white">
|
tools:backgroundTint="@color/white">
|
||||||
|
|
||||||
<ImageView
|
<presentation.common.widget.MmsPreviewView
|
||||||
android:id="@+id/image"
|
android:id="@+id/mmsPreview"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintBottom_toTopOf="@id/body"
|
app:layout_constraintBottom_toTopOf="@id/body"
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:parentTag="presentation.common.widget.MmsPreviewView">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/image"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
</merge>
|
||||||
Reference in New Issue
Block a user