forked from upstream-mirrors/quik
Save part to disk and share using content provider
Fixes #1508 and fixes #1468
This commit is contained in:
@@ -26,6 +26,8 @@ import android.os.Build
|
||||
import android.provider.ContactsContract
|
||||
import android.provider.Settings
|
||||
import android.provider.Telephony
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.core.content.FileProvider
|
||||
import com.moez.QKSMS.BuildConfig
|
||||
import com.moez.QKSMS.common.util.BillingManager
|
||||
import com.moez.QKSMS.feature.backup.BackupActivity
|
||||
@@ -40,10 +42,10 @@ import com.moez.QKSMS.feature.settings.SettingsActivity
|
||||
import com.moez.QKSMS.manager.AnalyticsManager
|
||||
import com.moez.QKSMS.manager.NotificationManager
|
||||
import com.moez.QKSMS.manager.PermissionManager
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
||||
@Singleton
|
||||
class Navigator @Inject constructor(
|
||||
private val context: Context,
|
||||
@@ -166,7 +168,6 @@ class Navigator @Inject constructor(
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
|
||||
fun showRating() {
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.moez.QKSMS"))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY
|
||||
@@ -176,7 +177,8 @@ class Navigator @Inject constructor(
|
||||
try {
|
||||
startActivity(intent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.moez.QKSMS")))
|
||||
val url = "http://play.google.com/store/apps/details?id=com.moez.QKSMS"
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,9 +247,12 @@ class Navigator @Inject constructor(
|
||||
startActivityExternal(intent)
|
||||
}
|
||||
|
||||
fun openFile(uri: Uri, contentType: String) {
|
||||
fun viewFile(file: File) {
|
||||
val data = FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", file)
|
||||
val type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(file.name.split(".").last())
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
.setDataAndType(uri, contentType)
|
||||
.setDataAndType(data, type)
|
||||
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
|
||||
startActivityExternal(intent)
|
||||
}
|
||||
@@ -272,4 +277,4 @@ class Navigator @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ import com.moez.QKSMS.common.util.extensions.showKeyboard
|
||||
import com.moez.QKSMS.model.Attachment
|
||||
import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import dagger.android.AndroidInjection
|
||||
@@ -91,6 +92,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
override val optionsItemIntent: Subject<Int> = PublishSubject.create()
|
||||
override val sendAsGroupIntent by lazy { sendAsGroupBackground.clicks() }
|
||||
override val messageClickIntent: Subject<Message> by lazy { messageAdapter.clicks }
|
||||
override val messagePartClickIntent: Subject<MmsPart> by lazy { messageAdapter.partClicks }
|
||||
override val messagesSelectedIntent by lazy { messageAdapter.selectionChanges }
|
||||
override val cancelSendingIntent: Subject<Message> by lazy { messageAdapter.cancelSending }
|
||||
override val attachmentDeletedIntent: Subject<Attachment> by lazy { attachmentAdapter.attachmentDeleted }
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.moez.QKSMS.common.base.QkView
|
||||
import com.moez.QKSMS.model.Attachment
|
||||
import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.Subject
|
||||
|
||||
@@ -40,6 +41,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
val optionsItemIntent: Observable<Int>
|
||||
val sendAsGroupIntent: Observable<*>
|
||||
val messageClickIntent: Subject<Message>
|
||||
val messagePartClickIntent: Subject<MmsPart>
|
||||
val messagesSelectedIntent: Observable<List<Long>>
|
||||
val cancelSendingIntent: Subject<Message>
|
||||
val attachmentDeletedIntent: Subject<Attachment>
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.moez.QKSMS.compat.SubscriptionManagerCompat
|
||||
import com.moez.QKSMS.compat.TelephonyCompat
|
||||
import com.moez.QKSMS.extensions.asObservable
|
||||
import com.moez.QKSMS.extensions.isImage
|
||||
import com.moez.QKSMS.extensions.isVideo
|
||||
import com.moez.QKSMS.extensions.mapNotNull
|
||||
import com.moez.QKSMS.extensions.removeAccents
|
||||
import com.moez.QKSMS.filter.ContactFilter
|
||||
@@ -424,6 +425,24 @@ class ComposeViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
// Media attachment clicks
|
||||
view.messagePartClickIntent
|
||||
.filter { part -> part.isImage() || part.isVideo() }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { part -> navigator.showMedia(part.id) }
|
||||
|
||||
// Non-media attachment clicks
|
||||
view.messagePartClickIntent
|
||||
.filter { part -> !part.isImage() && !part.isVideo() }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { part ->
|
||||
if (permissionManager.hasStorage()) {
|
||||
messageRepo.savePart(part.id)?.let(navigator::viewFile)
|
||||
} else {
|
||||
view.requestStoragePermission()
|
||||
}
|
||||
}
|
||||
|
||||
// Update the State when the message selected count changes
|
||||
view.messagesSelectedIntent
|
||||
.map { selection -> selection.size }
|
||||
|
||||
@@ -34,7 +34,6 @@ import android.widget.ProgressBar
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.base.QkRealmAdapter
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
@@ -54,6 +53,7 @@ import com.moez.QKSMS.feature.compose.BubbleUtils.getBubble
|
||||
import com.moez.QKSMS.feature.compose.part.PartsAdapter
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
@@ -64,13 +64,14 @@ import kotlinx.android.synthetic.main.message_list_item_in.view.*
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Provider
|
||||
|
||||
class MessagesAdapter @Inject constructor(
|
||||
subscriptionManager: SubscriptionManagerCompat,
|
||||
private val context: Context,
|
||||
private val colors: Colors,
|
||||
private val dateFormatter: DateFormatter,
|
||||
private val navigator: Navigator,
|
||||
private val partsAdapterProvider: Provider<PartsAdapter>,
|
||||
private val phoneNumberUtils: PhoneNumberUtils,
|
||||
private val prefs: Preferences,
|
||||
private val textViewStyler: TextViewStyler
|
||||
@@ -88,6 +89,7 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
|
||||
val clicks: Subject<Message> = PublishSubject.create()
|
||||
val partClicks: Subject<MmsPart> = PublishSubject.create()
|
||||
val cancelSending: Subject<Message> = PublishSubject.create()
|
||||
|
||||
var data: Pair<Conversation, RealmResults<Message>>? = null
|
||||
@@ -153,7 +155,9 @@ class MessagesAdapter @Inject constructor(
|
||||
view.body.hyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE
|
||||
}
|
||||
|
||||
view.attachments.adapter = PartsAdapter(context, navigator, theme)
|
||||
val partsAdapter = partsAdapterProvider.get()
|
||||
partsAdapter.clicks.subscribe(partClicks)
|
||||
view.attachments.adapter = partsAdapter
|
||||
view.attachments.setRecycledViewPool(partsViewPool)
|
||||
view.body.forwardTouches(view)
|
||||
|
||||
@@ -273,6 +277,7 @@ class MessagesAdapter @Inject constructor(
|
||||
|
||||
// Bind the attachments
|
||||
val partsAdapter = view.attachments.adapter as PartsAdapter
|
||||
partsAdapter.theme = theme
|
||||
partsAdapter.setData(message, previous, next, view)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,33 +19,28 @@
|
||||
package com.moez.QKSMS.feature.compose.part
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ContentUris
|
||||
import android.content.Context
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.feature.compose.BubbleUtils
|
||||
import com.moez.QKSMS.mapper.CursorToPartImpl
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.android.synthetic.main.mms_file_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class FileBinder(
|
||||
private val context: Context,
|
||||
private val navigator: Navigator,
|
||||
private val theme: Colors.Theme
|
||||
) : PartBinder {
|
||||
class FileBinder @Inject constructor(colors: Colors, private val context: Context) : PartBinder() {
|
||||
|
||||
override val partLayout = R.layout.mms_file_list_item
|
||||
override var theme = colors.theme()
|
||||
|
||||
// This is the last binder we check. If we're here, we can bind the part
|
||||
override fun canBindPart(part: MmsPart) = true
|
||||
@@ -58,11 +53,10 @@ class FileBinder(
|
||||
canGroupWithPrevious: Boolean,
|
||||
canGroupWithNext: Boolean
|
||||
) {
|
||||
val uri = ContentUris.withAppendedId(CursorToPartImpl.CONTENT_URI, part.id)
|
||||
val bubble = BubbleUtils.getBubble(false, canGroupWithPrevious, canGroupWithNext, message.isMe())
|
||||
BubbleUtils.getBubble(false, canGroupWithPrevious, canGroupWithNext, message.isMe())
|
||||
.let(view.fileBackground::setBackgroundResource)
|
||||
|
||||
view.setOnClickListener { navigator.openFile(uri, part.type) }
|
||||
view.fileBackground.setBackgroundResource(bubble)
|
||||
view.setOnClickListener { clicks.onNext(part) }
|
||||
|
||||
Observable.just(part.getUri())
|
||||
.map(context.contentResolver::openInputStream)
|
||||
|
||||
@@ -21,7 +21,7 @@ package com.moez.QKSMS.feature.compose.part
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.common.widget.BubbleImageView
|
||||
import com.moez.QKSMS.extensions.isImage
|
||||
@@ -30,16 +30,24 @@ import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import com.moez.QKSMS.util.GlideApp
|
||||
import kotlinx.android.synthetic.main.mms_preview_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class MediaBinder(private val context: Context, private val navigator: Navigator) : PartBinder {
|
||||
class MediaBinder @Inject constructor(colors: Colors, private val context: Context) : PartBinder() {
|
||||
|
||||
override val partLayout = R.layout.mms_preview_list_item
|
||||
override var theme = colors.theme()
|
||||
|
||||
override fun canBindPart(part: MmsPart) = part.isImage() || part.isVideo()
|
||||
|
||||
override fun bindPart(view: View, part: MmsPart, message: Message, canGroupWithPrevious: Boolean, canGroupWithNext: Boolean) {
|
||||
override fun bindPart(
|
||||
view: View,
|
||||
part: MmsPart,
|
||||
message: Message,
|
||||
canGroupWithPrevious: Boolean,
|
||||
canGroupWithNext: Boolean
|
||||
) {
|
||||
view.video.setVisible(part.isVideo())
|
||||
view.setOnClickListener { navigator.showMedia(part.id) }
|
||||
view.setOnClickListener { clicks.onNext(part) }
|
||||
|
||||
view.thumbnail.bubbleStyle = when {
|
||||
!canGroupWithPrevious && canGroupWithNext -> if (message.isMe()) BubbleImageView.Style.OUT_FIRST else BubbleImageView.Style.IN_FIRST
|
||||
|
||||
@@ -19,15 +19,28 @@
|
||||
package com.moez.QKSMS.feature.compose.part
|
||||
|
||||
import android.view.View
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
|
||||
interface PartBinder {
|
||||
abstract class PartBinder {
|
||||
|
||||
val partLayout: Int
|
||||
val clicks: Subject<MmsPart> = PublishSubject.create()
|
||||
|
||||
fun canBindPart(part: MmsPart): Boolean
|
||||
abstract val partLayout: Int
|
||||
|
||||
fun bindPart(view: View, part: MmsPart, message: Message, canGroupWithPrevious: Boolean, canGroupWithNext: Boolean)
|
||||
abstract var theme: Colors.Theme
|
||||
|
||||
}
|
||||
abstract fun canBindPart(part: MmsPart): Boolean
|
||||
|
||||
abstract fun bindPart(
|
||||
view: View,
|
||||
part: MmsPart,
|
||||
message: Message,
|
||||
canGroupWithPrevious: Boolean,
|
||||
canGroupWithNext: Boolean
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
@@ -18,11 +18,9 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.compose.part
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.base.QkAdapter
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
@@ -32,15 +30,26 @@ import com.moez.QKSMS.extensions.isText
|
||||
import com.moez.QKSMS.feature.compose.BubbleUtils.canGroup
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import io.reactivex.Observable
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class PartsAdapter(context: Context, navigator: Navigator, theme: Colors.Theme) : QkAdapter<MmsPart>() {
|
||||
class PartsAdapter @Inject constructor(
|
||||
colors: Colors,
|
||||
fileBinder: FileBinder,
|
||||
mediaBinder: MediaBinder,
|
||||
vCardBinder: VCardBinder
|
||||
) : QkAdapter<MmsPart>() {
|
||||
|
||||
private val partBinders = listOf(
|
||||
MediaBinder(context, navigator),
|
||||
VCardBinder(context, navigator, theme),
|
||||
FileBinder(context, navigator, theme)
|
||||
)
|
||||
private val partBinders = listOf(mediaBinder, vCardBinder, fileBinder)
|
||||
|
||||
var theme: Colors.Theme = colors.theme()
|
||||
set(value) {
|
||||
field = value
|
||||
partBinders.forEach { binder -> binder.theme = value }
|
||||
}
|
||||
|
||||
val clicks = Observable.merge(partBinders.map { it.clicks })
|
||||
|
||||
private lateinit var message: Message
|
||||
private var previous: Message? = null
|
||||
|
||||
@@ -18,13 +18,11 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.compose.part
|
||||
|
||||
import android.content.ContentUris
|
||||
import android.content.Context
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
@@ -32,7 +30,6 @@ import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.extensions.isVCard
|
||||
import com.moez.QKSMS.extensions.mapNotNull
|
||||
import com.moez.QKSMS.feature.compose.BubbleUtils
|
||||
import com.moez.QKSMS.mapper.CursorToPartImpl
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import ezvcard.Ezvcard
|
||||
@@ -40,14 +37,12 @@ import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.android.synthetic.main.mms_vcard_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class VCardBinder(
|
||||
private val context: Context,
|
||||
private val navigator: Navigator,
|
||||
private val theme: Colors.Theme
|
||||
) : PartBinder {
|
||||
class VCardBinder @Inject constructor(colors: Colors, private val context: Context) : PartBinder() {
|
||||
|
||||
override val partLayout = R.layout.mms_vcard_list_item
|
||||
override var theme = colors.theme()
|
||||
|
||||
override fun canBindPart(part: MmsPart) = part.isVCard()
|
||||
|
||||
@@ -58,13 +53,12 @@ class VCardBinder(
|
||||
canGroupWithPrevious: Boolean,
|
||||
canGroupWithNext: Boolean
|
||||
) {
|
||||
val uri = ContentUris.withAppendedId(CursorToPartImpl.CONTENT_URI, part.id)
|
||||
val bubble = BubbleUtils.getBubble(false, canGroupWithPrevious, canGroupWithNext, message.isMe())
|
||||
BubbleUtils.getBubble(false, canGroupWithPrevious, canGroupWithNext, message.isMe())
|
||||
.let(view.vCardBackground::setBackgroundResource)
|
||||
|
||||
view.setOnClickListener { navigator.openFile(uri, part.type) }
|
||||
view.vCardBackground.setBackgroundResource(bubble)
|
||||
view.setOnClickListener { clicks.onNext(part) }
|
||||
|
||||
Observable.just(uri)
|
||||
Observable.just(part.getUri())
|
||||
.map(context.contentResolver::openInputStream)
|
||||
.mapNotNull { inputStream -> inputStream.use { Ezvcard.parse(it).first() } }
|
||||
.subscribeOn(Schedulers.computation())
|
||||
|
||||
Reference in New Issue
Block a user