mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Compress images before sending
This commit is contained in:
@@ -19,10 +19,11 @@
|
||||
package presentation.feature.compose
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.bumptech.glide.Glide
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import common.util.Colors
|
||||
@@ -40,9 +41,9 @@ import javax.inject.Inject
|
||||
class AttachmentAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val colors: Colors
|
||||
) : QkAdapter<Bitmap>() {
|
||||
) : QkAdapter<Uri>() {
|
||||
|
||||
val attachmentDeleted: Subject<Bitmap> = PublishSubject.create()
|
||||
val attachmentDeleted: Subject<Uri> = PublishSubject.create()
|
||||
|
||||
private val disposables = CompositeDisposable()
|
||||
|
||||
@@ -66,14 +67,14 @@ class AttachmentAdapter @Inject constructor(
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val bitmap = getItem(position)
|
||||
val uri = getItem(position)
|
||||
val view = holder.itemView
|
||||
|
||||
view.clicks().subscribe {
|
||||
attachmentDeleted.onNext(bitmap)
|
||||
attachmentDeleted.onNext(uri)
|
||||
}
|
||||
|
||||
view.thumbnail.setImageBitmap(bitmap)
|
||||
Glide.with(context).load(uri).into(view.thumbnail)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import android.app.AlertDialog
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.PorterDuff
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import android.support.v7.widget.RecyclerView
|
||||
@@ -64,7 +65,7 @@ class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
||||
override val copyTextIntent: Subject<Message> = PublishSubject.create()
|
||||
override val forwardMessageIntent: Subject<Message> = PublishSubject.create()
|
||||
override val deleteMessageIntent: Subject<Message> = PublishSubject.create()
|
||||
override val attachmentDeletedIntent: Subject<Bitmap> by lazy { attachmentAdapter.attachmentDeleted }
|
||||
override val attachmentDeletedIntent: Subject<Uri> by lazy { attachmentAdapter.attachmentDeleted }
|
||||
override val textChangedIntent by lazy { message.textChanges() }
|
||||
override val attachIntent by lazy { attach.clicks() }
|
||||
override val sendIntent by lazy { send.clicks() }
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
package presentation.feature.compose
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import data.model.Contact
|
||||
import data.model.Message
|
||||
import io.realm.RealmResults
|
||||
@@ -32,6 +32,6 @@ data class ComposeState(
|
||||
val title: String = "",
|
||||
val archived: Boolean = false,
|
||||
val messages: RealmResults<Message>? = null,
|
||||
val attachments: List<Bitmap> = ArrayList(),
|
||||
val attachments: List<Uri> = ArrayList(),
|
||||
val canSend: Boolean = false
|
||||
)
|
||||
@@ -19,6 +19,7 @@
|
||||
package presentation.feature.compose
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import data.model.Contact
|
||||
import data.model.Message
|
||||
import io.reactivex.Observable
|
||||
@@ -38,7 +39,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
val copyTextIntent: Subject<Message>
|
||||
val forwardMessageIntent: Subject<Message>
|
||||
val deleteMessageIntent: Subject<Message>
|
||||
val attachmentDeletedIntent: Subject<Bitmap>
|
||||
val attachmentDeletedIntent: Subject<Uri>
|
||||
val textChangedIntent: Observable<CharSequence>
|
||||
val attachIntent: Observable<Unit>
|
||||
val sendIntent: Observable<Unit>
|
||||
|
||||
@@ -20,8 +20,7 @@ package presentation.feature.compose
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import com.mlsdev.rximagepicker.RxImageConverters
|
||||
import android.net.Uri
|
||||
import com.mlsdev.rximagepicker.RxImagePicker
|
||||
import com.mlsdev.rximagepicker.Sources
|
||||
import com.moez.QKSMS.R
|
||||
@@ -68,7 +67,7 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
|
||||
@Inject lateinit var deleteMessage: DeleteMessage
|
||||
|
||||
private var draft: String = ""
|
||||
private val attachments: Subject<List<Bitmap>> = BehaviorSubject.createDefault(ArrayList())
|
||||
private val attachments: Subject<List<Uri>> = BehaviorSubject.createDefault(ArrayList())
|
||||
private val contacts: Observable<List<Contact>> by lazy { contactsRepo.getUnmanagedContacts().toObservable() }
|
||||
private val contactsReducer: Subject<(List<Contact>) -> List<Contact>> = PublishSubject.create()
|
||||
private val selectedContacts: Observable<List<Contact>>
|
||||
@@ -252,7 +251,6 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
|
||||
// Attach a photo
|
||||
view.attachIntent
|
||||
.flatMap { RxImagePicker.with(context).requestImage(Sources.GALLERY) }
|
||||
.flatMap { uri -> RxImageConverters.uriToBitmap(context, uri) }
|
||||
.withLatestFrom(attachments, { attachment, attachments -> attachments + attachment })
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { attachments.onNext(it) }
|
||||
|
||||
Reference in New Issue
Block a user