mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-16 19:18:52 +01:00
#1012 - Show video attachments
This commit is contained in:
@@ -119,6 +119,13 @@ class Navigator @Inject constructor(private val context: Context, private val no
|
||||
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
|
||||
* 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.RealmConfiguration
|
||||
import manager.AnalyticsManager
|
||||
import migration.QkRealmMigration
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -52,17 +53,18 @@ class QKApplication : Application() {
|
||||
appVersion = BuildConfig.VERSION_NAME
|
||||
})
|
||||
|
||||
Realm.init(this)
|
||||
Realm.setDefaultConfiguration(RealmConfiguration.Builder()
|
||||
.compactOnLaunch()
|
||||
.migration(QkRealmMigration())
|
||||
.schemaVersion(1)
|
||||
.build())
|
||||
|
||||
AppComponentManager.init(this)
|
||||
appComponent.inject(this)
|
||||
|
||||
nightModeManager.updateCurrentTheme()
|
||||
|
||||
Realm.init(this)
|
||||
Realm.setDefaultConfiguration(RealmConfiguration.Builder()
|
||||
.compactOnLaunch()
|
||||
.deleteRealmIfMigrationNeeded()
|
||||
.build())
|
||||
|
||||
val fontRequest = FontRequest(
|
||||
"com.google.android.gms.fonts",
|
||||
"com.google.android.gms",
|
||||
|
||||
@@ -20,19 +20,26 @@ package common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.ImageView
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.LinearLayout
|
||||
import com.moez.QKSMS.R
|
||||
import common.Navigator
|
||||
import common.util.GlideApp
|
||||
import common.util.extensions.setVisible
|
||||
import injection.appComponent
|
||||
import kotlinx.android.synthetic.main.mms_preview_list_item.view.*
|
||||
import model.MmsPart
|
||||
import util.extensions.hasThumbnails
|
||||
import util.extensions.isImage
|
||||
import util.extensions.isVideo
|
||||
import javax.inject.Inject
|
||||
|
||||
class MmsPreviewView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs) {
|
||||
|
||||
@Inject lateinit var navigator: Navigator
|
||||
|
||||
private val layoutInflater = LayoutInflater.from(context)
|
||||
|
||||
var parts: List<MmsPart> = ArrayList()
|
||||
set(value) {
|
||||
field = value
|
||||
@@ -48,19 +55,27 @@ class MmsPreviewView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||
}
|
||||
|
||||
private fun updateView() {
|
||||
val images = parts.filter { it.image != null }
|
||||
setVisible(images.isNotEmpty())
|
||||
val media = parts.filter { it.hasThumbnails() }
|
||||
setVisible(media.isNotEmpty())
|
||||
|
||||
if (childCount > 0) {
|
||||
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) }
|
||||
})
|
||||
media.forEach { part ->
|
||||
val view = layoutInflater.inflate(R.layout.mms_preview_list_item, this, false)
|
||||
view.video.setVisible(part.isVideo())
|
||||
|
||||
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.view.KeyEvent
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.net.toUri
|
||||
import com.mlsdev.rximagepicker.RxImagePicker
|
||||
import com.mlsdev.rximagepicker.Sources
|
||||
import com.moez.QKSMS.R
|
||||
@@ -323,7 +322,7 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ import kotlinx.android.synthetic.main.message_list_item_in.view.*
|
||||
import model.Conversation
|
||||
import model.Message
|
||||
import model.Recipient
|
||||
import util.extensions.isImage
|
||||
import util.extensions.hasThumbnails
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -139,7 +139,7 @@ class MessagesAdapter @Inject constructor(
|
||||
view.subject.setVisible(view.subject.text.isNotBlank())
|
||||
|
||||
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)
|
||||
|
||||
@@ -219,7 +219,7 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
// 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
|
||||
|
||||
GlideApp.with(context)
|
||||
.load(part.image)
|
||||
.load(part.getUri())
|
||||
.fitCenter()
|
||||
.into(view.thumbnail)
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class GalleryActivity : QkActivity<GalleryViewModel>(), GalleryView {
|
||||
|
||||
if (image.drawable == null) {
|
||||
GlideApp.with(this)
|
||||
.load(state.imagePath)
|
||||
.load(state.imageUri)
|
||||
.dontAnimate()
|
||||
.listener(GlideCompletionListener {
|
||||
startPostponedEnterTransition()
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
*/
|
||||
package feature.gallery
|
||||
|
||||
import android.net.Uri
|
||||
|
||||
data class GalleryState(
|
||||
val navigationVisible: Boolean = true,
|
||||
val title: String = "",
|
||||
val imagePath: String = ""
|
||||
val imageUri: Uri? = null
|
||||
)
|
||||
@@ -49,8 +49,8 @@ class GalleryViewModel(intent: Intent) : QkViewModel<GalleryView, GalleryState>(
|
||||
|
||||
disposables += partIdFlowable
|
||||
.mapNotNull { partId -> messageRepo.getPart(partId) }
|
||||
.mapNotNull { part -> part.image }
|
||||
.subscribe { path -> newState { it.copy(imagePath = path) } }
|
||||
.mapNotNull { part -> part.getUri() }
|
||||
.subscribe { uri -> newState { it.copy(imageUri = uri) } }
|
||||
|
||||
disposables += partIdFlowable
|
||||
.mapNotNull { partId -> messageRepo.getMessageForPart(partId) }
|
||||
|
||||
Reference in New Issue
Block a user