Rename `useThreadsArchive` to `isArchiveAvailable` for clarity

This commit is contained in:
Ensar Sarajčić 2023-10-03 09:46:10 +02:00
parent 0e68da2710
commit e41630e543
6 changed files with 15 additions and 15 deletions

View File

@ -187,7 +187,7 @@ class MainActivity : SimpleActivity() {
binding.mainMenu.getToolbar().menu.apply { binding.mainMenu.getToolbar().menu.apply {
findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(com.simplemobiletools.commons.R.bool.hide_google_relations) findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(com.simplemobiletools.commons.R.bool.hide_google_relations)
findItem(R.id.show_recycle_bin).isVisible = config.useRecycleBin findItem(R.id.show_recycle_bin).isVisible = config.useRecycleBin
findItem(R.id.show_archived).isVisible = config.useThreadsArchive findItem(R.id.show_archived).isVisible = config.isArchiveAvailable
} }
} }

View File

@ -249,12 +249,12 @@ class ThreadActivity : SimpleActivity() {
private fun refreshMenuItems() { private fun refreshMenuItems() {
val firstPhoneNumber = participants.firstOrNull()?.phoneNumbers?.firstOrNull()?.value val firstPhoneNumber = participants.firstOrNull()?.phoneNumbers?.firstOrNull()?.value
val useArchive = config.useThreadsArchive val archiveAvailable = config.isArchiveAvailable
binding.threadToolbar.menu.apply { binding.threadToolbar.menu.apply {
findItem(R.id.delete).isVisible = threadItems.isNotEmpty() findItem(R.id.delete).isVisible = threadItems.isNotEmpty()
findItem(R.id.restore).isVisible = threadItems.isNotEmpty() && isRecycleBin findItem(R.id.restore).isVisible = threadItems.isNotEmpty() && isRecycleBin
findItem(R.id.archive).isVisible = threadItems.isNotEmpty() && conversation?.isArchived == false && !isRecycleBin && useArchive findItem(R.id.archive).isVisible = threadItems.isNotEmpty() && conversation?.isArchived == false && !isRecycleBin && archiveAvailable
findItem(R.id.unarchive).isVisible = threadItems.isNotEmpty() && conversation?.isArchived == true && !isRecycleBin && useArchive findItem(R.id.unarchive).isVisible = threadItems.isNotEmpty() && conversation?.isArchived == true && !isRecycleBin && archiveAvailable
findItem(R.id.rename_conversation).isVisible = participants.size > 1 && conversation != null && !isRecycleBin findItem(R.id.rename_conversation).isVisible = participants.size > 1 && conversation != null && !isRecycleBin
findItem(R.id.conversation_details).isVisible = conversation != null && !isRecycleBin findItem(R.id.conversation_details).isVisible = conversation != null && !isRecycleBin
findItem(R.id.block_number).title = addLockedLabelIfNeeded(com.simplemobiletools.commons.R.string.block_number) findItem(R.id.block_number).title = addLockedLabelIfNeeded(com.simplemobiletools.commons.R.string.block_number)

View File

@ -28,7 +28,7 @@ class ConversationsAdapter(
val isSingleSelection = isOneItemSelected() val isSingleSelection = isOneItemSelected()
val selectedConversation = selectedItems.firstOrNull() ?: return val selectedConversation = selectedItems.firstOrNull() ?: return
val isGroupConversation = selectedConversation.isGroupConversation val isGroupConversation = selectedConversation.isGroupConversation
val useArchive = activity.config.useThreadsArchive val archiveAvailable = activity.config.isArchiveAvailable
menu.apply { menu.apply {
findItem(R.id.cab_block_number).title = activity.addLockedLabelIfNeeded(com.simplemobiletools.commons.R.string.block_number) findItem(R.id.cab_block_number).title = activity.addLockedLabelIfNeeded(com.simplemobiletools.commons.R.string.block_number)
@ -39,7 +39,7 @@ class ConversationsAdapter(
findItem(R.id.cab_rename_conversation).isVisible = isSingleSelection && isGroupConversation findItem(R.id.cab_rename_conversation).isVisible = isSingleSelection && isGroupConversation
findItem(R.id.cab_mark_as_read).isVisible = selectedItems.any { !it.read } findItem(R.id.cab_mark_as_read).isVisible = selectedItems.any { !it.read }
findItem(R.id.cab_mark_as_unread).isVisible = selectedItems.any { it.read } findItem(R.id.cab_mark_as_unread).isVisible = selectedItems.any { it.read }
findItem(R.id.cab_archive).isVisible = useArchive findItem(R.id.cab_archive).isVisible = archiveAvailable
checkPinBtnVisibility(this) checkPinBtnVisibility(this)
} }
} }

View File

@ -263,7 +263,7 @@ fun Context.getMMSSender(msgId: Long): String {
} }
fun Context.getConversations(threadId: Long? = null, privateContacts: ArrayList<SimpleContact> = ArrayList()): ArrayList<Conversation> { fun Context.getConversations(threadId: Long? = null, privateContacts: ArrayList<SimpleContact> = ArrayList()): ArrayList<Conversation> {
val useArchive = config.useThreadsArchive val archiveAvailable = config.isArchiveAvailable
val uri = Uri.parse("${Threads.CONTENT_URI}?simple=true") val uri = Uri.parse("${Threads.CONTENT_URI}?simple=true")
val projection = mutableListOf( val projection = mutableListOf(
@ -274,7 +274,7 @@ fun Context.getConversations(threadId: Long? = null, privateContacts: ArrayList<
Threads.RECIPIENT_IDS, Threads.RECIPIENT_IDS,
) )
if (useArchive) { if (archiveAvailable) {
projection += Threads.ARCHIVED projection += Threads.ARCHIVED
} }
@ -315,13 +315,13 @@ fun Context.getConversations(threadId: Long? = null, privateContacts: ArrayList<
val photoUri = if (phoneNumbers.size == 1) simpleContactHelper.getPhotoUriFromPhoneNumber(phoneNumbers.first()) else "" val photoUri = if (phoneNumbers.size == 1) simpleContactHelper.getPhotoUriFromPhoneNumber(phoneNumbers.first()) else ""
val isGroupConversation = phoneNumbers.size > 1 val isGroupConversation = phoneNumbers.size > 1
val read = cursor.getIntValue(Threads.READ) == 1 val read = cursor.getIntValue(Threads.READ) == 1
val archived = if (useArchive) cursor.getIntValue(Threads.ARCHIVED) == 1 else false val archived = if (archiveAvailable) cursor.getIntValue(Threads.ARCHIVED) == 1 else false
val conversation = Conversation(id, snippet, date.toInt(), read, title, photoUri, isGroupConversation, phoneNumbers.first(), isArchived = archived) val conversation = Conversation(id, snippet, date.toInt(), read, title, photoUri, isGroupConversation, phoneNumbers.first(), isArchived = archived)
conversations.add(conversation) conversations.add(conversation)
} }
} catch (sqliteException: SQLiteException) { } catch (sqliteException: SQLiteException) {
if (sqliteException.message?.contains("no such column: archived") == true && useArchive) { if (sqliteException.message?.contains("no such column: archived") == true && archiveAvailable) {
config.useThreadsArchive = false config.isArchiveAvailable = false
return getConversations(threadId, privateContacts) return getConversations(threadId, privateContacts)
} else { } else {
showErrorToast(sqliteException) showErrorToast(sqliteException)
@ -751,8 +751,8 @@ fun Context.updateConversationArchivedStatus(threadId: Long, archived: Boolean)
try { try {
contentResolver.update(uri, values, selection, selectionArgs) contentResolver.update(uri, values, selection, selectionArgs)
} catch (sqliteException: SQLiteException) { } catch (sqliteException: SQLiteException) {
if (sqliteException.message?.contains("no such column: archived") == true && config.useThreadsArchive) { if (sqliteException.message?.contains("no such column: archived") == true && config.isArchiveAvailable) {
config.useThreadsArchive = false config.isArchiveAvailable = false
return return
} else { } else {
throw sqliteException throw sqliteException

View File

@ -112,7 +112,7 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getLong(LAST_RECYCLE_BIN_CHECK, 0L) get() = prefs.getLong(LAST_RECYCLE_BIN_CHECK, 0L)
set(lastRecycleBinCheck) = prefs.edit().putLong(LAST_RECYCLE_BIN_CHECK, lastRecycleBinCheck).apply() set(lastRecycleBinCheck) = prefs.edit().putLong(LAST_RECYCLE_BIN_CHECK, lastRecycleBinCheck).apply()
var useThreadsArchive: Boolean var isArchiveAvailable: Boolean
get() = prefs.getBoolean(USE_THREADS_ARCHIVE, true) get() = prefs.getBoolean(USE_THREADS_ARCHIVE, true)
set(useThreadsArchive) = prefs.edit().putBoolean(USE_THREADS_ARCHIVE, useThreadsArchive).apply() set(useThreadsArchive) = prefs.edit().putBoolean(USE_THREADS_ARCHIVE, useThreadsArchive).apply()
} }

View File

@ -113,7 +113,7 @@ class SmsReceiver : BroadcastReceiver() {
subscriptionId subscriptionId
) )
context.messagesDB.insertOrUpdate(message) context.messagesDB.insertOrUpdate(message)
if (context.config.useThreadsArchive) { if (context.config.isArchiveAvailable) {
context.updateConversationArchivedStatus(threadId, false) context.updateConversationArchivedStatus(threadId, false)
} }
refreshMessages() refreshMessages()