Merge branch 'master' into fix-import-binary-mime-type
This commit is contained in:
commit
8d306941a0
96 changed files with 3663 additions and 226 deletions
|
|
@ -71,9 +71,9 @@ class ManageBlockedKeywordsActivity : BaseSimpleActivity(), RefreshRecyclerViewL
|
|||
|
||||
private fun updateBlockedKeywords() {
|
||||
ensureBackgroundThread {
|
||||
val blockedKeywords = config.blockedKeywords
|
||||
val blockedKeywords = config.blockedKeywords.sorted().toArrayList()
|
||||
runOnUiThread {
|
||||
ManageBlockedKeywordsAdapter(this, blockedKeywords.toArrayList(), this, binding.manageBlockedKeywordsList) {
|
||||
ManageBlockedKeywordsAdapter(this, blockedKeywords, this, binding.manageBlockedKeywordsList) {
|
||||
addOrEditBlockedKeyword(it as String)
|
||||
}.apply {
|
||||
binding.manageBlockedKeywordsList.adapter = this
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ class SettingsActivity : SimpleActivity() {
|
|||
private fun setupMessagesExport() {
|
||||
binding.settingsExportMessagesHolder.setOnClickListener {
|
||||
ExportMessagesDialog(this) { fileName ->
|
||||
saveDocument.launch(fileName)
|
||||
saveDocument.launch("$fileName.json")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -278,11 +278,11 @@ fun Context.getConversations(threadId: Long? = null, privateContacts: ArrayList<
|
|||
projection += Threads.ARCHIVED
|
||||
}
|
||||
|
||||
var selection = "${Threads.MESSAGE_COUNT} > ?"
|
||||
var selectionArgs = arrayOf("0")
|
||||
var selection = "${Threads.MESSAGE_COUNT} > 0"
|
||||
var selectionArgs = arrayOf<String>()
|
||||
if (threadId != null) {
|
||||
selection += " AND ${Threads._ID} = ?"
|
||||
selectionArgs = arrayOf("0", threadId.toString())
|
||||
selectionArgs += threadId.toString()
|
||||
}
|
||||
|
||||
val sortOrder = "${Threads.DATE} DESC"
|
||||
|
|
@ -355,11 +355,10 @@ private fun Context.queryCursorUnsafe(
|
|||
fun Context.getConversationIds(): List<Long> {
|
||||
val uri = Uri.parse("${Threads.CONTENT_URI}?simple=true")
|
||||
val projection = arrayOf(Threads._ID)
|
||||
val selection = "${Threads.MESSAGE_COUNT} > ?"
|
||||
val selectionArgs = arrayOf("0")
|
||||
val selection = "${Threads.MESSAGE_COUNT} > 0"
|
||||
val sortOrder = "${Threads.DATE} ASC"
|
||||
val conversationIds = mutableListOf<Long>()
|
||||
queryCursor(uri, projection, selection, selectionArgs, sortOrder, true) { cursor ->
|
||||
queryCursor(uri, projection, selection, null, sortOrder, true) { cursor ->
|
||||
val id = cursor.getLongValue(Threads._ID)
|
||||
conversationIds.add(id)
|
||||
}
|
||||
|
|
@ -1058,16 +1057,9 @@ fun Context.insertOrUpdateConversation(
|
|||
conversation: Conversation,
|
||||
cachedConv: Conversation? = conversationsDB.getConversationWithThreadId(conversation.threadId)
|
||||
) {
|
||||
val updatedConv = if (cachedConv != null) {
|
||||
val usesCustomTitle = cachedConv.usesCustomTitle
|
||||
val title = if (usesCustomTitle) {
|
||||
cachedConv.title
|
||||
} else {
|
||||
conversation.title
|
||||
}
|
||||
conversation.copy(title = title, usesCustomTitle = usesCustomTitle)
|
||||
} else {
|
||||
conversation
|
||||
var updatedConv = conversation
|
||||
if (cachedConv != null && cachedConv.usesCustomTitle) {
|
||||
updatedConv = updatedConv.copy(title = cachedConv.title, usesCustomTitle = cachedConv.usesCustomTitle)
|
||||
}
|
||||
conversationsDB.insertOrUpdate(updatedConv)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package org.fossify.messages.helpers
|
||||
|
||||
import android.content.Context
|
||||
import org.fossify.messages.extensions.config
|
||||
|
||||
object ReceiverUtils {
|
||||
|
||||
fun isMessageFilteredOut(context: Context, body: String): Boolean {
|
||||
for (blockedKeyword in context.config.blockedKeywords) {
|
||||
if (body.contains(blockedKeyword, ignoreCase = true)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
@ -6,13 +6,14 @@ import android.os.Handler
|
|||
import android.os.Looper
|
||||
import com.bumptech.glide.Glide
|
||||
import com.klinker.android.send_message.MmsReceivedReceiver
|
||||
import org.fossify.commons.extensions.isNumberBlocked
|
||||
import org.fossify.commons.extensions.normalizePhoneNumber
|
||||
import org.fossify.commons.extensions.showErrorToast
|
||||
import org.fossify.commons.extensions.*
|
||||
import org.fossify.commons.helpers.SimpleContactsHelper
|
||||
import org.fossify.commons.helpers.ensureBackgroundThread
|
||||
import org.fossify.messages.R
|
||||
import org.fossify.messages.extensions.*
|
||||
import org.fossify.messages.helpers.ReceiverUtils.isMessageFilteredOut
|
||||
import org.fossify.messages.helpers.refreshMessages
|
||||
import org.fossify.messages.models.Message
|
||||
|
||||
// more info at https://github.com/klinker41/android-smsmms
|
||||
class MmsReceiver : MmsReceivedReceiver() {
|
||||
|
|
@ -27,29 +28,52 @@ class MmsReceiver : MmsReceivedReceiver() {
|
|||
val address = mms.getSender()?.phoneNumbers?.first()?.normalizedNumber ?: ""
|
||||
|
||||
val size = context.resources.getDimension(R.dimen.notification_large_icon_size).toInt()
|
||||
val privateCursor = context.getMyContactsCursor(false, true)
|
||||
ensureBackgroundThread {
|
||||
val glideBitmap = try {
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(mms.attachment!!.attachments.first().getUri())
|
||||
.centerCrop()
|
||||
.into(size, size)
|
||||
.get()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
context.showReceivedMessageNotification(mms.id, address, mms.body, mms.threadId, glideBitmap)
|
||||
val conversation = context.getConversations(mms.threadId).firstOrNull() ?: return@post
|
||||
ensureBackgroundThread {
|
||||
context.insertOrUpdateConversation(conversation)
|
||||
context.updateUnreadCountBadge(context.conversationsDB.getUnreadConversations())
|
||||
refreshMessages()
|
||||
if (context.baseConfig.blockUnknownNumbers) {
|
||||
val simpleContactsHelper = SimpleContactsHelper(context)
|
||||
simpleContactsHelper.exists(address, privateCursor) { exists ->
|
||||
if (exists) {
|
||||
handleMmsMessage(context, mms, size, address)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handleMmsMessage(context, mms, size, address)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onError(context: Context, error: String) = context.showErrorToast(context.getString(R.string.couldnt_download_mms))
|
||||
|
||||
private fun handleMmsMessage(
|
||||
context: Context,
|
||||
mms: Message,
|
||||
size: Int,
|
||||
address: String
|
||||
) {
|
||||
if (isMessageFilteredOut(context, mms.body)) {
|
||||
return
|
||||
}
|
||||
|
||||
val glideBitmap = try {
|
||||
Glide.with(context)
|
||||
.asBitmap()
|
||||
.load(mms.attachment!!.attachments.first().getUri())
|
||||
.centerCrop()
|
||||
.into(size, size)
|
||||
.get()
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
context.showReceivedMessageNotification(mms.id, address, mms.body, mms.threadId, glideBitmap)
|
||||
val conversation = context.getConversations(mms.threadId).firstOrNull() ?: return@post
|
||||
ensureBackgroundThread {
|
||||
context.insertOrUpdateConversation(conversation)
|
||||
context.updateUnreadCountBadge(context.conversationsDB.getUnreadConversations())
|
||||
refreshMessages()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import org.fossify.commons.helpers.ensureBackgroundThread
|
|||
import org.fossify.commons.models.PhoneNumber
|
||||
import org.fossify.commons.models.SimpleContact
|
||||
import org.fossify.messages.extensions.*
|
||||
import org.fossify.messages.helpers.ReceiverUtils.isMessageFilteredOut
|
||||
import org.fossify.messages.helpers.refreshMessages
|
||||
import org.fossify.messages.models.Message
|
||||
|
||||
|
|
@ -40,7 +41,6 @@ class SmsReceiver : BroadcastReceiver() {
|
|||
date = System.currentTimeMillis()
|
||||
threadId = context.getThreadId(address)
|
||||
}
|
||||
|
||||
if (context.baseConfig.blockUnknownNumbers) {
|
||||
val simpleContactsHelper = SimpleContactsHelper(context)
|
||||
simpleContactsHelper.exists(address, privateCursor) { exists ->
|
||||
|
|
@ -122,14 +122,4 @@ class SmsReceiver : BroadcastReceiver() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isMessageFilteredOut(context: Context, body: String): Boolean {
|
||||
for (blockedKeyword in context.config.blockedKeywords) {
|
||||
if (body.contains(blockedKeyword, ignoreCase = true)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue