forked from upstream-mirrors/quik
Save part to disk and share using content provider
Fixes #1508 and fixes #1468
This commit is contained in:
@@ -22,14 +22,8 @@ import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Matrix
|
||||
import android.media.MediaScannerConnection
|
||||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
import androidx.exifinterface.media.ExifInterface
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import javax.inject.Inject
|
||||
|
||||
class ImageRepostoryImpl @Inject constructor(private val context: Context) : ImageRepository {
|
||||
@@ -58,24 +52,4 @@ class ImageRepostoryImpl @Inject constructor(private val context: Context) : Ima
|
||||
return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true)
|
||||
}
|
||||
|
||||
override fun saveImage(uri: Uri) {
|
||||
val type = context.contentResolver.getType(uri)?.split("/") ?: return
|
||||
val dir = File(Environment.getExternalStorageDirectory(), "QKSMS/Media").apply { mkdirs() }
|
||||
val file = File(dir, "${type.first()}${System.currentTimeMillis()}.${type.last()}")
|
||||
|
||||
try {
|
||||
FileOutputStream(file).use { outputStream ->
|
||||
context.contentResolver.openInputStream(uri)?.use { inputStream ->
|
||||
inputStream.copyTo(outputStream, 1024)
|
||||
}
|
||||
}
|
||||
} catch (e: FileNotFoundException) {
|
||||
e.printStackTrace()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
MediaScannerConnection.scanFile(context, arrayOf(file.path), null, null)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,9 +25,12 @@ import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.media.MediaScannerConnection
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.provider.Telephony
|
||||
import android.telephony.SmsManager
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.core.content.contentValuesOf
|
||||
import com.google.android.mms.ContentType
|
||||
import com.google.android.mms.MMSPart
|
||||
@@ -54,6 +57,10 @@ import io.realm.Realm
|
||||
import io.realm.RealmResults
|
||||
import io.realm.Sort
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -132,6 +139,33 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
.findAllAsync()
|
||||
}
|
||||
|
||||
override fun savePart(id: Long): File? {
|
||||
val part = getPart(id) ?: return null
|
||||
|
||||
val extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(part.type) ?: return null
|
||||
val date = part.messages?.first()?.date
|
||||
val dir = File(Environment.getExternalStorageDirectory(), "QKSMS/Media").apply { mkdirs() }
|
||||
val fileName = part.name?.takeIf { name -> name.endsWith(extension) }
|
||||
?: "${part.type.split("/").last()}_$date.$extension"
|
||||
val file = File(dir, fileName)
|
||||
|
||||
try {
|
||||
FileOutputStream(file).use { outputStream ->
|
||||
context.contentResolver.openInputStream(part.getUri())?.use { inputStream ->
|
||||
inputStream.copyTo(outputStream, 1024)
|
||||
}
|
||||
}
|
||||
} catch (e: FileNotFoundException) {
|
||||
e.printStackTrace()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
MediaScannerConnection.scanFile(context, arrayOf(file.path), null, null)
|
||||
|
||||
return file.takeIf { it.exists() }
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the list of messages which should be shown in the notification
|
||||
* for a given conversation
|
||||
|
||||
@@ -18,21 +18,17 @@
|
||||
*/
|
||||
package com.moez.QKSMS.interactor
|
||||
|
||||
import com.moez.QKSMS.repository.ImageRepository
|
||||
import com.moez.QKSMS.repository.MessageRepository
|
||||
import io.reactivex.Flowable
|
||||
import javax.inject.Inject
|
||||
|
||||
class SaveImage @Inject constructor(
|
||||
private val imageRepository: ImageRepository,
|
||||
private val messageRepo: MessageRepository
|
||||
) : Interactor<Long>() {
|
||||
|
||||
override fun buildObservable(params: Long): Flowable<*> {
|
||||
return Flowable.just(params)
|
||||
.map { partId -> messageRepo.getPart(partId) }
|
||||
.map { part -> part.getUri() }
|
||||
.doOnNext { uri -> imageRepository.saveImage(uri) }
|
||||
.doOnNext { partId -> messageRepo.savePart(partId) }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,4 @@ interface ImageRepository {
|
||||
|
||||
fun loadImage(uri: Uri): Bitmap?
|
||||
|
||||
fun saveImage(uri: Uri)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.moez.QKSMS.model.Attachment
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import io.realm.RealmResults
|
||||
import java.io.File
|
||||
|
||||
interface MessageRepository {
|
||||
|
||||
@@ -37,6 +38,8 @@ interface MessageRepository {
|
||||
|
||||
fun getPartsForConversation(threadId: Long): RealmResults<MmsPart>
|
||||
|
||||
fun savePart(id: Long): File?
|
||||
|
||||
/**
|
||||
* Retrieves the list of messages which should be shown in the notification
|
||||
* for a given conversation
|
||||
@@ -95,4 +98,4 @@ interface MessageRepository {
|
||||
|
||||
fun deleteMessages(vararg messageIds: Long)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<manifest package="com.moez.QKSMS"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.moez.QKSMS">
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.CALL_PHONE" />
|
||||
@@ -165,10 +165,10 @@
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_info" />
|
||||
</receiver>
|
||||
<receiver android:name=".receiver.SendSmsReceiver" />
|
||||
|
||||
<service android:name="com.android.mms.transaction.TransactionService" />
|
||||
<service android:name=".feature.backup.RestoreBackupService" />
|
||||
<receiver android:name=".receiver.SendSmsReceiver" />
|
||||
<service
|
||||
android:name=".feature.widget.WidgetService"
|
||||
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
||||
@@ -202,6 +202,16 @@
|
||||
android:name="preloaded_fonts"
|
||||
android:resource="@array/preloaded_fonts" />
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/provider_paths" />
|
||||
</provider>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -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())
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2019 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/>.
|
||||
-->
|
||||
<paths>
|
||||
<external-path
|
||||
name="external_files"
|
||||
path="." />
|
||||
</paths>
|
||||
Reference in New Issue
Block a user