Show all images in message

This commit is contained in:
Moez Bhatti
2018-02-28 19:09:40 -05:00
parent 9d5621a2ad
commit 52b4dae247
2 changed files with 13 additions and 46 deletions
@@ -20,16 +20,12 @@ package presentation.common.widget
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.widget.ImageView
import android.widget.LinearLayout import android.widget.LinearLayout
import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R
import common.di.appComponent import common.di.appComponent
import common.util.GlideApp import common.util.GlideApp
import common.util.extensions.mapNotNull
import common.util.extensions.setVisible import common.util.extensions.setVisible
import data.model.MmsPart import data.model.MmsPart
import kotlinx.android.synthetic.main.mms_preview_view.view.*
import presentation.common.Navigator import presentation.common.Navigator
import javax.inject.Inject import javax.inject.Inject
@@ -45,21 +41,23 @@ class MmsPreviewView @JvmOverloads constructor(context: Context, attrs: Attribut
init { init {
appComponent.inject(this) appComponent.inject(this)
View.inflate(context, R.layout.mms_preview_view, this) orientation = LinearLayout.VERTICAL
image.clicks()
.mapNotNull { parts.firstOrNull { it.image != null } }
.map { part -> part.id }
.doOnNext { partId -> navigator.showImage(partId) }
.subscribe()
} }
private fun updateView() { private fun updateView() {
val images = parts.mapNotNull { it.image } val images = parts.filter { it.image != null }
setVisible(images.isNotEmpty()) setVisible(images.isNotEmpty())
images.firstOrNull()?.let { if (childCount > 0) {
GlideApp.with(context).load(it).fitCenter().into(image) removeAllViews()
}
images.forEach { image ->
addView(ImageView(context).apply {
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
GlideApp.with(context).load(image.image).fitCenter().into(this)
setOnClickListener { navigator.showImage(image.id) }
})
} }
} }
@@ -1,31 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
~
~ This file is part of QKSMS.
~
~ QKSMS is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ QKSMS is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
-->
<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>