forked from upstream-mirrors/quik
Merge remote-tracking branch 'upstream/master' into emoji-reacts
This commit is contained in:
+1
-1
@@ -32,7 +32,7 @@ buildscript {
|
||||
ext.rxjava_version = '2.1.4'
|
||||
ext.rxkotlin_version = '2.1.0'
|
||||
ext.rx_preferences_version = '2.0.0-RC3'
|
||||
ext.timber_version = '4.5.1'
|
||||
ext.timber_version = '5.0.1'
|
||||
ext.androidx_work_version = "2.8.0"
|
||||
|
||||
ext.abiCodes = ['armeabi-v7a': 1, 'arm64-v8a': 2]
|
||||
|
||||
@@ -36,7 +36,7 @@ class QkRealmMigration @Inject constructor(
|
||||
) : RealmMigration {
|
||||
|
||||
companion object {
|
||||
const val SchemaVersion: Long = 13
|
||||
const val SchemaVersion: Long = 14
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
@@ -239,10 +239,6 @@ class QkRealmMigration @Inject constructor(
|
||||
// Because there was never any property associated with which conversation/recipients a scheduled message was for,
|
||||
// we can't update this field on a realm migration. It will be set to a default of 0
|
||||
|
||||
version++
|
||||
}
|
||||
|
||||
if (version == 11L) {
|
||||
realm.schema.create("MessageContentFilter")
|
||||
.addField("id", Long::class.java, FieldAttribute.PRIMARY_KEY, FieldAttribute.REQUIRED)
|
||||
.addField("value", String::class.java, FieldAttribute.REQUIRED)
|
||||
@@ -254,6 +250,13 @@ class QkRealmMigration @Inject constructor(
|
||||
}
|
||||
|
||||
if (version == 12L) {
|
||||
realm.schema.get("Conversation")
|
||||
?.addField("draftDate", Long::class.java, FieldAttribute.REQUIRED)
|
||||
|
||||
version++
|
||||
}
|
||||
|
||||
if (version == 13L) {
|
||||
val emojiReactionTable = realm.schema.create("EmojiReaction")
|
||||
.addField("id", Long::class.java, FieldAttribute.PRIMARY_KEY, FieldAttribute.REQUIRED)
|
||||
.addField("reactionMessageId", Long::class.java, FieldAttribute.INDEXED, FieldAttribute.REQUIRED)
|
||||
|
||||
@@ -353,6 +353,7 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
|
||||
realm.executeTransaction {
|
||||
conversation?.takeIf { it.isValid }?.draft = draft
|
||||
conversation?.takeIf { it.isValid }?.draftDate = System.currentTimeMillis()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -173,9 +173,10 @@ open class MessageRepositoryImpl @Inject constructor(
|
||||
|
||||
val extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(part.type)
|
||||
?: return null
|
||||
val date = part.messages?.first()?.date
|
||||
val fileName = part.name?.takeIf { name -> name.endsWith(extension) }
|
||||
?: "${part.type.split("/").last()}_$date.$extension"
|
||||
// fileDateAndTime is divided by 1000 in order to remove the extra 0's after date and time
|
||||
// This way the file name isn't so long.
|
||||
val fileDateAndTime = (part.messages?.first()?.date)?.div(1000)
|
||||
val fileName = "QUIK_${part.type.split("/").last()}_$fileDateAndTime.$extension"
|
||||
|
||||
val values = contentValuesOf(
|
||||
MediaStore.MediaColumns.DISPLAY_NAME to fileName,
|
||||
|
||||
@@ -21,6 +21,8 @@ package dev.octoshrimpy.quik.repository
|
||||
import android.content.ContentResolver
|
||||
import android.content.ContentUris
|
||||
import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.provider.Telephony
|
||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||
import dev.octoshrimpy.quik.extensions.forEach
|
||||
@@ -51,6 +53,7 @@ import io.reactivex.subjects.Subject
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmList
|
||||
import io.realm.Sort
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@@ -75,181 +78,206 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
|
||||
override fun syncMessages() {
|
||||
|
||||
val oldBlockedSenders = rxPrefs.getStringSet("pref_key_blocked_senders")
|
||||
|
||||
// If the sync is already running, don't try to do another one
|
||||
if (syncProgress.blockingFirst() is SyncRepository.SyncProgress.Running) return
|
||||
syncProgress.onNext(SyncRepository.SyncProgress.Running(0, 0, true))
|
||||
|
||||
val realm = Realm.getDefaultInstance()
|
||||
realm.beginTransaction()
|
||||
val handlerThread = HandlerThread("RealmSyncThread")
|
||||
handlerThread.start()
|
||||
Handler(handlerThread.looper).post {
|
||||
Realm.getDefaultInstance().executeTransactionAsync(
|
||||
{ realm ->
|
||||
// Prepare existing conversation data
|
||||
val persistedData = realm.copyFromRealm(
|
||||
realm.where(Conversation::class.java)
|
||||
.beginGroup()
|
||||
.equalTo("archived", true)
|
||||
.or()
|
||||
.equalTo("blocked", true)
|
||||
.or()
|
||||
.equalTo("pinned", true)
|
||||
.or()
|
||||
.isNotEmpty("name")
|
||||
.or()
|
||||
.isNotNull("blockingClient")
|
||||
.or()
|
||||
.isNotEmpty("blockReason")
|
||||
.endGroup()
|
||||
.findAll()
|
||||
).associateBy { conversation -> conversation.id }.toMutableMap()
|
||||
|
||||
val persistedData = realm.copyFromRealm(realm.where(Conversation::class.java)
|
||||
.beginGroup()
|
||||
.equalTo("archived", true)
|
||||
.or()
|
||||
.equalTo("blocked", true)
|
||||
.or()
|
||||
.equalTo("pinned", true)
|
||||
.or()
|
||||
.isNotEmpty("name")
|
||||
.or()
|
||||
.isNotNull("blockingClient")
|
||||
.or()
|
||||
.isNotEmpty("blockReason")
|
||||
.endGroup()
|
||||
.findAll())
|
||||
.associateBy { conversation -> conversation.id }
|
||||
.toMutableMap()
|
||||
removeOldMessages(realm)
|
||||
|
||||
realm.delete(Contact::class.java)
|
||||
realm.delete(ContactGroup::class.java)
|
||||
realm.delete(Conversation::class.java)
|
||||
realm.delete(Message::class.java)
|
||||
realm.delete(MmsPart::class.java)
|
||||
realm.delete(Recipient::class.java)
|
||||
realm.delete(EmojiReaction::class.java)
|
||||
keys.reset()
|
||||
|
||||
keys.reset()
|
||||
val partsCursor = cursorToPart.getPartsCursor()
|
||||
val messageCursor = cursorToMessage.getMessagesCursor()
|
||||
val conversationCursor = cursorToConversation.getConversationsCursor()
|
||||
val recipientCursor = cursorToRecipient.getRecipientCursor()
|
||||
|
||||
val partsCursor = cursorToPart.getPartsCursor()
|
||||
val messageCursor = cursorToMessage.getMessagesCursor()
|
||||
val conversationCursor = cursorToConversation.getConversationsCursor()
|
||||
val recipientCursor = cursorToRecipient.getRecipientCursor()
|
||||
val max = (partsCursor?.count ?: 0) +
|
||||
(messageCursor?.count ?: 0) +
|
||||
(conversationCursor?.count ?: 0) +
|
||||
(recipientCursor?.count ?: 0)
|
||||
|
||||
val max = (partsCursor?.count ?: 0) +
|
||||
(messageCursor?.count ?: 0) +
|
||||
(conversationCursor?.count ?: 0) +
|
||||
(recipientCursor?.count ?: 0)
|
||||
var progress = 0
|
||||
|
||||
var progress = 0
|
||||
|
||||
// Sync message parts
|
||||
partsCursor?.use {
|
||||
partsCursor.forEach {
|
||||
tryOrNull {
|
||||
progress++
|
||||
val part = cursorToPart.map(partsCursor)
|
||||
realm.insertOrUpdate(part)
|
||||
// Sync message parts
|
||||
partsCursor?.use {
|
||||
partsCursor.forEach { cursor ->
|
||||
tryOrNull {
|
||||
val part = cursorToPart.map(partsCursor)
|
||||
realm.insertOrUpdate(part)
|
||||
progress++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sync messages
|
||||
messageCursor?.use {
|
||||
val messageColumns = CursorToMessage.MessageColumns(messageCursor)
|
||||
messageCursor.forEach { cursor ->
|
||||
tryOrNull {
|
||||
progress++
|
||||
syncProgress.onNext(SyncRepository.SyncProgress.Running(max, progress, false))
|
||||
val message = cursorToMessage.map(Pair(cursor, messageColumns)).apply {
|
||||
if (isMms()) {
|
||||
parts = RealmList<MmsPart>().apply {
|
||||
addAll(realm.where(MmsPart::class.java)
|
||||
.equalTo("messageId", contentId)
|
||||
.findAll())
|
||||
// Sync messages
|
||||
messageCursor?.use {
|
||||
val messageColumns = CursorToMessage.MessageColumns(messageCursor)
|
||||
messageCursor.forEach { cursor ->
|
||||
tryOrNull {
|
||||
syncProgress.onNext(
|
||||
SyncRepository.SyncProgress.Running(
|
||||
max,
|
||||
++progress,
|
||||
false
|
||||
)
|
||||
)
|
||||
val message = cursorToMessage.map(Pair(cursor, messageColumns)).apply {
|
||||
if (isMms()) {
|
||||
parts = RealmList<MmsPart>().apply {
|
||||
addAll(
|
||||
realm.where(MmsPart::class.java)
|
||||
.equalTo("messageId", contentId)
|
||||
.findAll()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(message)
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate blocked conversations from 2.7.3
|
||||
val oldBlockedSenders = rxPrefs.getStringSet("pref_key_blocked_senders")
|
||||
oldBlockedSenders.get()
|
||||
.map { threadIdString -> threadIdString.toLong() }
|
||||
.filter { threadId -> !persistedData.contains(threadId) }
|
||||
.forEach { threadId -> persistedData[threadId] = Conversation(id = threadId, blocked = true) }
|
||||
|
||||
// Sync conversations
|
||||
conversationCursor?.use {
|
||||
conversationCursor.forEach { cursor ->
|
||||
tryOrNull {
|
||||
progress++
|
||||
syncProgress.onNext(SyncRepository.SyncProgress.Running(max, progress, false))
|
||||
val conversation = cursorToConversation.map(cursor).apply {
|
||||
persistedData[id]?.let { persistedConversation ->
|
||||
archived = persistedConversation.archived
|
||||
blocked = persistedConversation.blocked
|
||||
pinned = persistedConversation.pinned
|
||||
name = persistedConversation.name
|
||||
blockingClient = persistedConversation.blockingClient
|
||||
blockReason = persistedConversation.blockReason
|
||||
}
|
||||
lastMessage = realm.where(Message::class.java)
|
||||
.sort("date", Sort.DESCENDING)
|
||||
.equalTo("threadId", id)
|
||||
.findFirst()
|
||||
// Migrate blocked conversations from 2.7.3
|
||||
oldBlockedSenders.get()
|
||||
.map { threadIdString -> threadIdString.toLong() }
|
||||
.filter { threadId -> !persistedData.contains(threadId) }
|
||||
.forEach { threadId ->
|
||||
persistedData[threadId] = Conversation(id = threadId, blocked = true)
|
||||
}
|
||||
realm.insertOrUpdate(conversation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sync recipients
|
||||
recipientCursor?.use {
|
||||
val contacts = realm.copyToRealmOrUpdate(getContacts())
|
||||
recipientCursor.forEach { cursor ->
|
||||
tryOrNull {
|
||||
progress++
|
||||
syncProgress.onNext(SyncRepository.SyncProgress.Running(max, progress, false))
|
||||
val recipient = cursorToRecipient.map(cursor).apply {
|
||||
contact = contacts.firstOrNull { contact ->
|
||||
contact.numbers.any { phoneNumberUtils.compare(address, it.address) }
|
||||
// Sync conversations
|
||||
conversationCursor?.use {
|
||||
conversationCursor.forEach { cursor ->
|
||||
tryOrNull {
|
||||
syncProgress.onNext(
|
||||
SyncRepository.SyncProgress.Running(
|
||||
max,
|
||||
++progress,
|
||||
false
|
||||
)
|
||||
)
|
||||
val conversation = cursorToConversation.map(cursor).apply {
|
||||
persistedData[id]?.let { persistedConversation ->
|
||||
archived = persistedConversation.archived
|
||||
blocked = persistedConversation.blocked
|
||||
pinned = persistedConversation.pinned
|
||||
name = persistedConversation.name
|
||||
blockingClient = persistedConversation.blockingClient
|
||||
blockReason = persistedConversation.blockReason
|
||||
}
|
||||
lastMessage = realm.where(Message::class.java)
|
||||
.sort("date", Sort.DESCENDING)
|
||||
.equalTo("threadId", id)
|
||||
.findFirst()
|
||||
}
|
||||
realm.insertOrUpdate(conversation)
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(recipient)
|
||||
}
|
||||
}
|
||||
|
||||
// Sync recipients
|
||||
val contacts = realm.copyToRealmOrUpdate(getContacts())
|
||||
recipientCursor?.use {
|
||||
recipientCursor.forEach { cursor ->
|
||||
tryOrNull {
|
||||
syncProgress.onNext(
|
||||
SyncRepository.SyncProgress.Running(
|
||||
max,
|
||||
++progress,
|
||||
false
|
||||
)
|
||||
)
|
||||
val rec = cursorToRecipient.map(cursor).apply {
|
||||
contact = contacts.firstOrNull { c ->
|
||||
c.numbers.any { num ->
|
||||
phoneNumberUtils.compare(
|
||||
address,
|
||||
num.address
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
realm.insertOrUpdate(rec)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
syncProgress.onNext(SyncRepository.SyncProgress.Running(0, 0, true))
|
||||
|
||||
// Now that we have all the messages, we can scan for emoji reactions
|
||||
val allMessages = realm.where(Message::class.java)
|
||||
.beginGroup()
|
||||
.beginGroup()
|
||||
.equalTo("type", "sms")
|
||||
.isNotEmpty("body")
|
||||
.endGroup()
|
||||
.or()
|
||||
.beginGroup()
|
||||
.equalTo("type", "mms")
|
||||
.isNotEmpty("parts.text")
|
||||
.endGroup()
|
||||
.endGroup()
|
||||
.sort("date", Sort.ASCENDING) // parse oldest to newest to handle reactions & removals properly
|
||||
.findAll()
|
||||
|
||||
allMessages.forEach { message ->
|
||||
val text = message.getText(false)
|
||||
val parsedReaction = EmojiReactionUtils.parseEmojiReaction(text)
|
||||
if (parsedReaction != null) {
|
||||
val targetMessage = EmojiReactionUtils.findTargetMessage(
|
||||
message.threadId,
|
||||
parsedReaction.originalMessage,
|
||||
realm
|
||||
)
|
||||
EmojiReactionUtils.saveEmojiReaction(
|
||||
message,
|
||||
parsedReaction,
|
||||
targetMessage,
|
||||
keys,
|
||||
realm,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
realm.insert(SyncLog())
|
||||
}, {
|
||||
handlerThread.quitSafely()
|
||||
oldBlockedSenders.delete()
|
||||
syncProgress.onNext(SyncRepository.SyncProgress.Idle)
|
||||
},
|
||||
{ error ->
|
||||
handlerThread.quitSafely()
|
||||
Timber.e(error, "syncMessages Failed")
|
||||
syncProgress.onNext(SyncRepository.SyncProgress.Idle)
|
||||
})
|
||||
}
|
||||
|
||||
syncProgress.onNext(SyncRepository.SyncProgress.Running(0, 0, true))
|
||||
|
||||
// Now that we have all the messages, we can scan for emoji reactions
|
||||
val allMessages = realm.where(Message::class.java)
|
||||
.beginGroup()
|
||||
.beginGroup()
|
||||
.equalTo("type", "sms")
|
||||
.isNotEmpty("body")
|
||||
.endGroup()
|
||||
.or()
|
||||
.beginGroup()
|
||||
.equalTo("type", "mms")
|
||||
.isNotEmpty("parts.text")
|
||||
.endGroup()
|
||||
.endGroup()
|
||||
.sort("date", Sort.ASCENDING) // parse oldest to newest to handle reactions & removals properly
|
||||
.findAll()
|
||||
|
||||
allMessages.forEach { message ->
|
||||
val text = message.getText(false)
|
||||
val parsedReaction = EmojiReactionUtils.parseEmojiReaction(text)
|
||||
if (parsedReaction != null) {
|
||||
val targetMessage = EmojiReactionUtils.findTargetMessage(
|
||||
message.threadId,
|
||||
parsedReaction.originalMessage,
|
||||
realm
|
||||
)
|
||||
EmojiReactionUtils.saveEmojiReaction(
|
||||
message,
|
||||
parsedReaction,
|
||||
targetMessage,
|
||||
keys,
|
||||
realm,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
realm.insert(SyncLog())
|
||||
realm.commitTransaction()
|
||||
realm.close()
|
||||
|
||||
// Only delete this after the sync has successfully completed
|
||||
oldBlockedSenders.delete()
|
||||
|
||||
syncProgress.onNext(SyncRepository.SyncProgress.Idle)
|
||||
}
|
||||
|
||||
override fun syncMessage(uri: Uri): Message? {
|
||||
|
||||
// If we don't have a valid type, return null
|
||||
@@ -403,4 +431,14 @@ class SyncRepositoryImpl @Inject constructor(
|
||||
return groups
|
||||
}
|
||||
|
||||
private fun removeOldMessages(realm: Realm) {
|
||||
realm.delete(Contact::class.java)
|
||||
realm.delete(ContactGroup::class.java)
|
||||
realm.delete(Conversation::class.java)
|
||||
realm.delete(Message::class.java)
|
||||
realm.delete(MmsPart::class.java)
|
||||
realm.delete(Recipient::class.java)
|
||||
realm.delete(EmojiReaction::class.java)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ open class Conversation(
|
||||
var recipients: RealmList<Recipient> = RealmList(),
|
||||
var lastMessage: Message? = null,
|
||||
var draft: String = "",
|
||||
var draftDate: Long = 0,
|
||||
|
||||
var blockingClient: Int? = null,
|
||||
var blockReason: String? = null,
|
||||
@@ -38,7 +39,7 @@ open class Conversation(
|
||||
var name: String = "" // For group chats, the user is allowed to set a custom title for the conversation
|
||||
) : RealmObject() {
|
||||
|
||||
val date: Long get() = lastMessage?.date ?: 0
|
||||
val date: Long get() = lastMessage?.date ?: if (draft.isNotEmpty()) draftDate else 0
|
||||
val snippet: String? get() = lastMessage?.getSummary()
|
||||
val unread: Boolean get() = lastMessage?.read == false
|
||||
val me: Boolean get() = lastMessage?.isMe() == true
|
||||
|
||||
@@ -201,6 +201,7 @@
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name=".feature.widget.WidgetProvider"
|
||||
android:label="@string/all_conversations_widget_title"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
|
||||
@@ -45,7 +45,7 @@ class FileLoggingTree @Inject constructor(
|
||||
|
||||
private var logFileUri: Uri? = null
|
||||
|
||||
override fun log(priority: Int, tag: String, message: String, t: Throwable?) {
|
||||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
||||
if (!prefs.logging.get()) return
|
||||
|
||||
Schedulers.io().scheduleDirect {
|
||||
|
||||
@@ -101,7 +101,7 @@ class ShortcutManagerImpl @Inject constructor(
|
||||
|
||||
@TargetApi(29)
|
||||
private fun createShortcutForConversation(conversation: Conversation): ShortcutInfoCompat {
|
||||
Timber.v("creating shortcut for conversation ${conversation.id} : ${conversation.getTitle()}")
|
||||
Timber.v("creating shortcut for conversation ${conversation.id}")
|
||||
val icon = when {
|
||||
conversation.recipients.size == 1 -> {
|
||||
val recipient = conversation.recipients.first()!!
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
package dev.octoshrimpy.quik.feature.blocking
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import dev.octoshrimpy.quik.R
|
||||
import dev.octoshrimpy.quik.blocking.BlockingClient
|
||||
import dev.octoshrimpy.quik.interactor.MarkBlocked
|
||||
|
||||
+2
-2
@@ -18,12 +18,12 @@
|
||||
*/
|
||||
package dev.octoshrimpy.quik.feature.blocking.messages
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import dev.octoshrimpy.quik.R
|
||||
import dev.octoshrimpy.quik.common.base.QkController
|
||||
import dev.octoshrimpy.quik.common.util.Colors
|
||||
@@ -107,7 +107,7 @@ class BlockedMessagesController : QkController<BlockedMessagesView, BlockedMessa
|
||||
|
||||
override fun showDeleteDialog(conversations: List<Long>) {
|
||||
val count = conversations.size
|
||||
AlertDialog.Builder(activity)
|
||||
AlertDialog.Builder(activity!!)
|
||||
.setTitle(R.string.dialog_delete_title)
|
||||
.setMessage(resources?.getQuantityString(R.plurals.dialog_delete_message, count, count))
|
||||
.setPositiveButton(R.string.button_delete) { _, _ -> confirmDeleteIntent.onNext(conversations) }
|
||||
|
||||
@@ -733,7 +733,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
|
||||
override fun showDeleteDialog(messages: List<Long>) {
|
||||
val count = messages.size
|
||||
android.app.AlertDialog.Builder(this)
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.dialog_delete_title)
|
||||
.setMessage(resources.getQuantityString(R.plurals.dialog_delete_chat, count, count))
|
||||
.setPositiveButton(R.string.button_delete) { _, _ -> confirmDeleteIntent.onNext(messages) }
|
||||
@@ -742,7 +742,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
}
|
||||
|
||||
override fun showClearCurrentMessageDialog() {
|
||||
android.app.AlertDialog.Builder(this)
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.dialog_clear_compose_title)
|
||||
.setMessage(R.string.dialog_clear_compose)
|
||||
.setPositiveButton(R.string.button_clear) { _, _ ->
|
||||
|
||||
@@ -20,7 +20,6 @@ package dev.octoshrimpy.quik.feature.main
|
||||
|
||||
import android.Manifest
|
||||
import android.animation.ObjectAnimator
|
||||
import android.app.AlertDialog
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.os.Build
|
||||
@@ -31,6 +30,7 @@ import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewStub
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.view.GravityCompat
|
||||
import androidx.core.view.isVisible
|
||||
|
||||
@@ -21,6 +21,7 @@ package dev.octoshrimpy.quik.feature.scheduled
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
@@ -111,7 +112,7 @@ class ScheduledActivity : QkThemedActivity(), ScheduledView {
|
||||
|
||||
override fun showDeleteDialog(messages: List<Long>) {
|
||||
val count = messages.size
|
||||
android.app.AlertDialog.Builder(this)
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.dialog_delete_title)
|
||||
.setMessage(resources.getQuantityString(R.plurals.dialog_delete_chat, count, count))
|
||||
.setPositiveButton(R.string.button_delete) { _, _ -> deleteScheduledMessages.onNext(messages) }
|
||||
@@ -121,7 +122,7 @@ class ScheduledActivity : QkThemedActivity(), ScheduledView {
|
||||
|
||||
override fun showSendNowDialog(messages: List<Long>) {
|
||||
val count = messages.size
|
||||
android.app.AlertDialog.Builder(this)
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.main_menu_send_now)
|
||||
.setMessage(resources.getQuantityString(R.plurals.dialog_send_now, count, count))
|
||||
.setPositiveButton(R.string.main_menu_send_now) { _, _ -> sendScheduledMessages.onNext(messages) }
|
||||
@@ -130,7 +131,7 @@ class ScheduledActivity : QkThemedActivity(), ScheduledView {
|
||||
}
|
||||
|
||||
override fun showEditMessageDialog(message: Long) {
|
||||
android.app.AlertDialog.Builder(this)
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(R.string.dialog_edit_scheduled_message_title)
|
||||
.setMessage(R.string.dialog_edit_scheduled_message)
|
||||
.setPositiveButton(R.string.dialog_edit_scheduled_message_positive_button) { _, _ ->
|
||||
|
||||
@@ -94,7 +94,7 @@ class WidgetAdapter(intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
||||
* we'll return the max count + 1, where the last row just shows "View more conversations"
|
||||
*/
|
||||
override fun getCount(): Int {
|
||||
val count = Math.min(conversations.size, MAX_CONVERSATIONS_COUNT)
|
||||
val count = conversations.size.coerceAtMost(MAX_CONVERSATIONS_COUNT)
|
||||
val shouldShowViewMore = count < conversations.size
|
||||
return count + if (shouldShowViewMore) 1 else 0
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import android.appwidget.AppWidgetProvider
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.widget.RemoteViews
|
||||
import dagger.android.AndroidInjection
|
||||
@@ -39,6 +39,7 @@ import dev.octoshrimpy.quik.receiver.StartActivityFromWidgetReceiver
|
||||
import dev.octoshrimpy.quik.util.Preferences
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import androidx.core.net.toUri
|
||||
|
||||
class WidgetProvider : AppWidgetProvider() {
|
||||
|
||||
@@ -109,8 +110,11 @@ class WidgetProvider : AppWidgetProvider() {
|
||||
Timber.v("updateWidget appWidgetId: $appWidgetId")
|
||||
val remoteViews = RemoteViews(context.packageName, R.layout.widget)
|
||||
|
||||
val nightModeFlags = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||
val isNightMode = nightModeFlags == Configuration.UI_MODE_NIGHT_YES
|
||||
|
||||
// Apply colors from theme
|
||||
val night = prefs.night.get()
|
||||
val night = prefs.night.get() || isNightMode
|
||||
val black = prefs.black.get()
|
||||
|
||||
remoteViews.setInt(R.id.background, "setColorFilter", context.getColorCompat(when {
|
||||
@@ -134,7 +138,7 @@ class WidgetProvider : AppWidgetProvider() {
|
||||
val intent = Intent(context, WidgetService::class.java)
|
||||
.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
|
||||
.putExtra("small_widget", smallWidget)
|
||||
intent.data = Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))
|
||||
intent.data = intent.toUri(Intent.URI_INTENT_SCHEME).toUri()
|
||||
remoteViews.setRemoteAdapter(R.id.conversations, intent)
|
||||
|
||||
// compose new message image color and on click intent
|
||||
|
||||
@@ -433,6 +433,7 @@
|
||||
|
||||
<string name="widget_loading">Loading…</string>
|
||||
<string name="widget_more">View more conversations</string>
|
||||
<string name="all_conversations_widget_title">All Conversations</string>
|
||||
|
||||
<string name="qkreply_menu_read">Mark read</string>
|
||||
<string name="qkreply_menu_call">Call</string>
|
||||
|
||||
Reference in New Issue
Block a user