forked from upstream-mirrors/quik
#1012 - Show video attachments
This commit is contained in:
@@ -25,7 +25,6 @@ import android.net.Uri
|
|||||||
import android.provider.Telephony
|
import android.provider.Telephony
|
||||||
import model.MmsPart
|
import model.MmsPart
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import util.extensions.isImage
|
|
||||||
import util.extensions.isSmil
|
import util.extensions.isSmil
|
||||||
import util.extensions.isText
|
import util.extensions.isText
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
@@ -51,8 +50,6 @@ class CursorToPartImpl @Inject constructor(private val context: Context) : Curso
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
isImage() -> image = ContentUris.withAppendedId(CONTENT_URI, id).toString()
|
|
||||||
|
|
||||||
isText() -> {
|
isText() -> {
|
||||||
text = if (data == null) {
|
text = if (data == null) {
|
||||||
from.getString(from.getColumnIndexOrThrow("text"))
|
from.getString(from.getColumnIndexOrThrow("text"))
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
package migration
|
||||||
|
|
||||||
|
import io.realm.DynamicRealm
|
||||||
|
import io.realm.RealmMigration
|
||||||
|
|
||||||
|
|
||||||
|
class QkRealmMigration : RealmMigration {
|
||||||
|
|
||||||
|
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||||
|
var version = oldVersion
|
||||||
|
|
||||||
|
if (version == 0L) {
|
||||||
|
realm.schema.get("MmsPart")
|
||||||
|
?.removeField("image")
|
||||||
|
|
||||||
|
version++
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version < newVersion) {
|
||||||
|
throw IllegalStateException("Migration missing from v$oldVersion to v$newVersion")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -206,7 +206,6 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
.where(MmsPart::class.java)
|
.where(MmsPart::class.java)
|
||||||
.equalTo("messages.threadId", threadId)
|
.equalTo("messages.threadId", threadId)
|
||||||
.contains("type", "image/")
|
.contains("type", "image/")
|
||||||
.isNotEmpty("image")
|
|
||||||
.sort("id", Sort.DESCENDING)
|
.sort("id", Sort.DESCENDING)
|
||||||
.findAllAsync()
|
.findAllAsync()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,8 @@ fun MmsPart.isSmil() = ContentType.APP_SMIL == type
|
|||||||
|
|
||||||
fun MmsPart.isImage() = ContentType.isImageType(type)
|
fun MmsPart.isImage() = ContentType.isImageType(type)
|
||||||
|
|
||||||
fun MmsPart.isText() = ContentType.isTextType(type)
|
fun MmsPart.isVideo() = ContentType.isVideoType(type)
|
||||||
|
|
||||||
|
fun MmsPart.isText() = ContentType.isTextType(type)
|
||||||
|
|
||||||
|
fun MmsPart.hasThumbnails() = isImage() || isVideo()
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package interactor
|
package interactor
|
||||||
|
|
||||||
import androidx.net.toUri
|
|
||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import repository.ImageRepository
|
import repository.ImageRepository
|
||||||
import repository.MessageRepository
|
import repository.MessageRepository
|
||||||
@@ -32,8 +31,7 @@ class SaveImage @Inject constructor(
|
|||||||
override fun buildObservable(params: Long): Flowable<*> {
|
override fun buildObservable(params: Long): Flowable<*> {
|
||||||
return Flowable.just(params)
|
return Flowable.just(params)
|
||||||
.map { partId -> messageRepo.getPart(partId) }
|
.map { partId -> messageRepo.getPart(partId) }
|
||||||
.map { part -> part.image }
|
.map { part -> part.getUri() }
|
||||||
.map { uriString -> uriString.toUri() }
|
|
||||||
.doOnNext { uri -> imageRepository.saveImage(uri) }
|
.doOnNext { uri -> imageRepository.saveImage(uri) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package model
|
package model
|
||||||
|
|
||||||
|
import androidx.net.toUri
|
||||||
import io.realm.RealmObject
|
import io.realm.RealmObject
|
||||||
import io.realm.RealmResults
|
import io.realm.RealmResults
|
||||||
import io.realm.annotations.LinkingObjects
|
import io.realm.annotations.LinkingObjects
|
||||||
@@ -27,11 +28,11 @@ open class MmsPart : RealmObject() {
|
|||||||
|
|
||||||
@PrimaryKey var id: Long = 0
|
@PrimaryKey var id: Long = 0
|
||||||
var type: String = ""
|
var type: String = ""
|
||||||
|
|
||||||
var text: String? = null
|
var text: String? = null
|
||||||
var image: String? = null
|
|
||||||
|
|
||||||
@LinkingObjects("parts")
|
@LinkingObjects("parts")
|
||||||
val messages: RealmResults<Message>? = null
|
val messages: RealmResults<Message>? = null
|
||||||
|
|
||||||
|
fun getUri() = "content://mms/part/$id".toUri()
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -119,6 +119,13 @@ class Navigator @Inject constructor(private val context: Context, private val no
|
|||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showVideo(uri: Uri, type: String) {
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW, uri)
|
||||||
|
.setDataAndType(uri, type)
|
||||||
|
|
||||||
|
startActivityExternal(intent)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the attachment full-screen
|
* Shows the attachment full-screen
|
||||||
* The transitionName for the view should be the id of the image being displayed
|
* The transitionName for the view should be the id of the image being displayed
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import injection.appComponent
|
|||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.RealmConfiguration
|
import io.realm.RealmConfiguration
|
||||||
import manager.AnalyticsManager
|
import manager.AnalyticsManager
|
||||||
|
import migration.QkRealmMigration
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -52,17 +53,18 @@ class QKApplication : Application() {
|
|||||||
appVersion = BuildConfig.VERSION_NAME
|
appVersion = BuildConfig.VERSION_NAME
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Realm.init(this)
|
||||||
|
Realm.setDefaultConfiguration(RealmConfiguration.Builder()
|
||||||
|
.compactOnLaunch()
|
||||||
|
.migration(QkRealmMigration())
|
||||||
|
.schemaVersion(1)
|
||||||
|
.build())
|
||||||
|
|
||||||
AppComponentManager.init(this)
|
AppComponentManager.init(this)
|
||||||
appComponent.inject(this)
|
appComponent.inject(this)
|
||||||
|
|
||||||
nightModeManager.updateCurrentTheme()
|
nightModeManager.updateCurrentTheme()
|
||||||
|
|
||||||
Realm.init(this)
|
|
||||||
Realm.setDefaultConfiguration(RealmConfiguration.Builder()
|
|
||||||
.compactOnLaunch()
|
|
||||||
.deleteRealmIfMigrationNeeded()
|
|
||||||
.build())
|
|
||||||
|
|
||||||
val fontRequest = FontRequest(
|
val fontRequest = FontRequest(
|
||||||
"com.google.android.gms.fonts",
|
"com.google.android.gms.fonts",
|
||||||
"com.google.android.gms",
|
"com.google.android.gms",
|
||||||
|
|||||||
@@ -20,19 +20,26 @@ package common.widget
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.widget.ImageView
|
import android.view.LayoutInflater
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
import com.moez.QKSMS.R
|
||||||
import common.Navigator
|
import common.Navigator
|
||||||
import common.util.GlideApp
|
import common.util.GlideApp
|
||||||
import common.util.extensions.setVisible
|
import common.util.extensions.setVisible
|
||||||
import injection.appComponent
|
import injection.appComponent
|
||||||
|
import kotlinx.android.synthetic.main.mms_preview_list_item.view.*
|
||||||
import model.MmsPart
|
import model.MmsPart
|
||||||
|
import util.extensions.hasThumbnails
|
||||||
|
import util.extensions.isImage
|
||||||
|
import util.extensions.isVideo
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MmsPreviewView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs) {
|
class MmsPreviewView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs) {
|
||||||
|
|
||||||
@Inject lateinit var navigator: Navigator
|
@Inject lateinit var navigator: Navigator
|
||||||
|
|
||||||
|
private val layoutInflater = LayoutInflater.from(context)
|
||||||
|
|
||||||
var parts: List<MmsPart> = ArrayList()
|
var parts: List<MmsPart> = ArrayList()
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
@@ -48,19 +55,27 @@ class MmsPreviewView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateView() {
|
private fun updateView() {
|
||||||
val images = parts.filter { it.image != null }
|
val media = parts.filter { it.hasThumbnails() }
|
||||||
setVisible(images.isNotEmpty())
|
setVisible(media.isNotEmpty())
|
||||||
|
|
||||||
if (childCount > 0) {
|
if (childCount > 0) {
|
||||||
removeAllViews()
|
removeAllViews()
|
||||||
}
|
}
|
||||||
|
|
||||||
images.forEach { image ->
|
media.forEach { part ->
|
||||||
addView(ImageView(context).apply {
|
val view = layoutInflater.inflate(R.layout.mms_preview_list_item, this, false)
|
||||||
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
|
view.video.setVisible(part.isVideo())
|
||||||
GlideApp.with(context).load(image.image).fitCenter().into(this)
|
|
||||||
setOnClickListener { navigator.showImage(image.id) }
|
GlideApp.with(context).load(part.getUri()).fitCenter().into(view.thumbnail)
|
||||||
})
|
|
||||||
|
setOnClickListener {
|
||||||
|
when {
|
||||||
|
part.isImage() -> navigator.showImage(part.id)
|
||||||
|
part.isVideo() -> navigator.showVideo(part.getUri(), part.type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addView(view)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import android.telephony.PhoneNumberUtils
|
|||||||
import android.telephony.SmsMessage
|
import android.telephony.SmsMessage
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import androidx.net.toUri
|
|
||||||
import com.mlsdev.rximagepicker.RxImagePicker
|
import com.mlsdev.rximagepicker.RxImagePicker
|
||||||
import com.mlsdev.rximagepicker.Sources
|
import com.mlsdev.rximagepicker.Sources
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
@@ -323,7 +322,7 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
menuForward.actionId -> {
|
menuForward.actionId -> {
|
||||||
val images = message.parts.filter { it.isImage() }.mapNotNull { it.image?.toUri() }
|
val images = message.parts.filter { it.isImage() }.mapNotNull { it.getUri() }
|
||||||
navigator.showCompose(message.body, images)
|
navigator.showCompose(message.body, images)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ import kotlinx.android.synthetic.main.message_list_item_in.view.*
|
|||||||
import model.Conversation
|
import model.Conversation
|
||||||
import model.Message
|
import model.Message
|
||||||
import model.Recipient
|
import model.Recipient
|
||||||
import util.extensions.isImage
|
import util.extensions.hasThumbnails
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ class MessagesAdapter @Inject constructor(
|
|||||||
view.subject.setVisible(view.subject.text.isNotBlank())
|
view.subject.setVisible(view.subject.text.isNotBlank())
|
||||||
|
|
||||||
view.body.text = message.getText()
|
view.body.text = message.getText()
|
||||||
view.body.setVisible(message.isSms() || view.body.text.isNotEmpty() || message.parts.all { it.image == null })
|
view.body.setVisible(message.isSms() || view.body.text.isNotEmpty() || message.parts.all { !it.hasThumbnails() })
|
||||||
|
|
||||||
view.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
view.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ class MessagesAdapter @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we're showing any thumbnails, set clipToOutline to true
|
// If we're showing any thumbnails, set clipToOutline to true
|
||||||
val hasImages = message.parts.filter { it.isImage() }.any()
|
val hasImages = message.parts.filter { it.hasThumbnails() }.any()
|
||||||
view.messageBackground.clipToOutline = hasImages
|
view.messageBackground.clipToOutline = hasImages
|
||||||
|
|
||||||
// setClipToOutline doesn't work unless all of the corners have the same radius, so we have
|
// setClipToOutline doesn't work unless all of the corners have the same radius, so we have
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class ConversationMediaAdapter @Inject constructor(
|
|||||||
val view = holder.itemView
|
val view = holder.itemView
|
||||||
|
|
||||||
GlideApp.with(context)
|
GlideApp.with(context)
|
||||||
.load(part.image)
|
.load(part.getUri())
|
||||||
.fitCenter()
|
.fitCenter()
|
||||||
.into(view.thumbnail)
|
.into(view.thumbnail)
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class GalleryActivity : QkActivity<GalleryViewModel>(), GalleryView {
|
|||||||
|
|
||||||
if (image.drawable == null) {
|
if (image.drawable == null) {
|
||||||
GlideApp.with(this)
|
GlideApp.with(this)
|
||||||
.load(state.imagePath)
|
.load(state.imageUri)
|
||||||
.dontAnimate()
|
.dontAnimate()
|
||||||
.listener(GlideCompletionListener {
|
.listener(GlideCompletionListener {
|
||||||
startPostponedEnterTransition()
|
startPostponedEnterTransition()
|
||||||
|
|||||||
@@ -18,8 +18,10 @@
|
|||||||
*/
|
*/
|
||||||
package feature.gallery
|
package feature.gallery
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
|
||||||
data class GalleryState(
|
data class GalleryState(
|
||||||
val navigationVisible: Boolean = true,
|
val navigationVisible: Boolean = true,
|
||||||
val title: String = "",
|
val title: String = "",
|
||||||
val imagePath: String = ""
|
val imageUri: Uri? = null
|
||||||
)
|
)
|
||||||
@@ -49,8 +49,8 @@ class GalleryViewModel(intent: Intent) : QkViewModel<GalleryView, GalleryState>(
|
|||||||
|
|
||||||
disposables += partIdFlowable
|
disposables += partIdFlowable
|
||||||
.mapNotNull { partId -> messageRepo.getPart(partId) }
|
.mapNotNull { partId -> messageRepo.getPart(partId) }
|
||||||
.mapNotNull { part -> part.image }
|
.mapNotNull { part -> part.getUri() }
|
||||||
.subscribe { path -> newState { it.copy(imagePath = path) } }
|
.subscribe { uri -> newState { it.copy(imageUri = uri) } }
|
||||||
|
|
||||||
disposables += partIdFlowable
|
disposables += partIdFlowable
|
||||||
.mapNotNull { partId -> messageRepo.getMessageForPart(partId) }
|
.mapNotNull { partId -> messageRepo.getMessageForPart(partId) }
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<!--
|
||||||
|
~ 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/>.
|
||||||
|
-->
|
||||||
|
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||||
|
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="#FF000000" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM10,16.5v-9l6,4.5 -6,4.5z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?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/>.
|
||||||
|
-->
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/thumbnail"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:src="@tools:sample/backgrounds/scenic" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/video"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="top|end"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:src="@drawable/ic_play_circle_filled_white_24dp" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
Reference in New Issue
Block a user