Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />

<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission
android:name="android.permission.USE_BIOMETRIC"
Expand Down
45 changes: 27 additions & 18 deletions app/src/main/kotlin/org/fossify/messages/activities/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.fossify.messages.activities

import android.annotation.SuppressLint
import android.app.Activity
import android.app.role.RoleManager
import android.content.Intent
import android.content.pm.ShortcutInfo
Expand Down Expand Up @@ -208,7 +207,7 @@ class MainActivity : SimpleActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
super.onActivityResult(requestCode, resultCode, resultData)
if (requestCode == MAKE_DEFAULT_APP_REQUEST) {
if (resultCode == Activity.RESULT_OK) {
if (resultCode == RESULT_OK) {
askPermissions()
} else {
finish()
Expand Down Expand Up @@ -251,7 +250,8 @@ class MainActivity : SimpleActivity() {
}
}

// while SEND_SMS and READ_SMS permissions are mandatory, READ_CONTACTS is optional. If we don't have it, we just won't be able to show the contact name in some cases
// while SEND_SMS and READ_SMS permissions are mandatory, READ_CONTACTS is optional.
// If we don't have it, we just won't be able to show the contact name in some cases
private fun askPermissions() {
handlePermission(PERMISSION_READ_SMS) {
if (it) {
Expand All @@ -271,7 +271,7 @@ class MainActivity : SimpleActivity() {
bus = EventBus.getDefault()
try {
bus!!.register(this)
} catch (ignored: Exception) {
} catch (_: Exception) {
}
}
} else {
Expand Down Expand Up @@ -302,20 +302,22 @@ class MainActivity : SimpleActivity() {
ensureBackgroundThread {
val conversations = try {
conversationsDB.getNonArchived().toMutableList() as ArrayList<Conversation>
} catch (e: Exception) {
} catch (_: Exception) {
ArrayList()
}

val archived = try {
conversationsDB.getAllArchived()
} catch (e: Exception) {
} catch (_: Exception) {
listOf()
}

updateUnreadCountBadge(conversations)
runOnUiThread {
setupConversations(conversations, cached = true)
getNewConversations((conversations + archived).toMutableList() as ArrayList<Conversation>)
getNewConversations(
(conversations + archived).toMutableList() as ArrayList<Conversation>
)
}
conversations.forEach {
clearExpiredScheduledMessages(it.threadId)
Expand Down Expand Up @@ -349,11 +351,14 @@ class MainActivity : SimpleActivity() {
val newConversation =
conversations.find { it.phoneNumber == cachedConversation.phoneNumber }
if (isTemporaryThread && newConversation != null) {
// delete the original temporary thread and move any scheduled messages to the new thread
// delete the original temporary thread and move any scheduled messages
// to the new thread
conversationsDB.deleteThreadId(threadId)
messagesDB.getScheduledThreadMessages(threadId)
.forEach { message ->
messagesDB.insertOrUpdate(message.copy(threadId = newConversation.threadId))
messagesDB.insertOrUpdate(
message.copy(threadId = newConversation.threadId)
)
}
insertOrUpdateConversation(newConversation, cachedConversation)
}
Expand All @@ -366,7 +371,8 @@ class MainActivity : SimpleActivity() {
)
}
if (conv != null) {
// FIXME: Scheduled message date is being reset here. Conversations with scheduled messages will have their original date.
// FIXME: Scheduled message date is being reset here. Conversations with
// scheduled messages will have their original date.
insertOrUpdateConversation(conv)
}
}
Expand Down Expand Up @@ -412,15 +418,18 @@ class MainActivity : SimpleActivity() {

private fun setupConversations(
conversations: ArrayList<Conversation>,
cached: Boolean = false
cached: Boolean = false,
) {
val sortedConversations = conversations.sortedWith(
compareByDescending<Conversation> { config.pinnedConversations.contains(it.threadId.toString()) }
.thenByDescending { it.date }
).toMutableList() as ArrayList<Conversation>
val sortedConversations = conversations
.sortedWith(
compareByDescending<Conversation> {
config.pinnedConversations.contains(it.threadId.toString())
}.thenByDescending { it.date }
).toMutableList() as ArrayList<Conversation>

if (cached && config.appRunCount == 1) {
// there are no cached conversations on the first run so we show the loading placeholder and progress until we are done loading from telephony
// there are no cached conversations on the first run so we show the
// loading placeholder and progress until we are done loading from telephony
showOrHideProgress(conversations.isEmpty())
} else {
showOrHideProgress(false)
Expand All @@ -435,7 +444,7 @@ class MainActivity : SimpleActivity() {
}
}
}
} catch (ignored: Exception) {
} catch (_: Exception) {
}
}

Expand Down Expand Up @@ -498,7 +507,7 @@ class MainActivity : SimpleActivity() {
try {
manager.dynamicShortcuts = listOf(newConversation)
config.lastHandledShortcutColor = appIconColor
} catch (ignored: Exception) {
} catch (_: Exception) {
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@ import android.net.Uri
import android.os.Bundle
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import org.fossify.commons.dialogs.ExportBlockedNumbersDialog
import org.fossify.commons.dialogs.FilePickerDialog
import org.fossify.commons.extensions.beVisibleIf
import org.fossify.commons.extensions.getFileOutputStream
import org.fossify.commons.extensions.getProperPrimaryColor
import org.fossify.commons.extensions.getTempFile
import org.fossify.commons.extensions.showErrorToast
import org.fossify.commons.extensions.toFileDirItem
import org.fossify.commons.extensions.toast
import org.fossify.commons.extensions.underlineText
import org.fossify.commons.extensions.updateTextColors
import org.fossify.commons.extensions.viewBinding
import org.fossify.commons.helpers.ExportResult
import org.fossify.commons.helpers.NavigationIcon
import org.fossify.commons.helpers.PERMISSION_READ_STORAGE
import org.fossify.commons.helpers.PERMISSION_WRITE_STORAGE
import org.fossify.commons.helpers.ensureBackgroundThread
import org.fossify.commons.helpers.isQPlus
import org.fossify.commons.interfaces.RefreshRecyclerViewListener
import org.fossify.messages.R
import org.fossify.messages.databinding.ActivityManageBlockedKeywordsBinding
Expand Down Expand Up @@ -96,7 +89,7 @@ class ManageBlockedKeywordsActivity : SimpleActivity(), RefreshRecyclerViewListe
}
}

private val exportActivityResultLauncher =
private val createDocument =
registerForActivityResult(ActivityResultContracts.CreateDocument("text/plain")) { uri ->
try {
val outputStream = uri?.let { contentResolver.openOutputStream(it) }
Expand All @@ -108,7 +101,7 @@ class ManageBlockedKeywordsActivity : SimpleActivity(), RefreshRecyclerViewListe
}
}

private val importActivityResultLauncher =
private val getContent =
registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
try {
if (uri != null) {
Expand All @@ -120,27 +113,13 @@ class ManageBlockedKeywordsActivity : SimpleActivity(), RefreshRecyclerViewListe
}

private fun tryImportBlockedKeywords() {
if (isQPlus()) {
val mimeType = "text/plain"
try {
importActivityResultLauncher.launch(mimeType)
} catch (e: ActivityNotFoundException) {
toast(org.fossify.commons.R.string.system_service_disabled, Toast.LENGTH_LONG)
} catch (e: Exception) {
showErrorToast(e)
}
} else {
handlePermission(PERMISSION_READ_STORAGE) { isAllowed ->
if (isAllowed) {
pickFileToImportBlockedKeywords()
}
}
}
}

private fun pickFileToImportBlockedKeywords() {
FilePickerDialog(this) {
importBlockedKeywords(it)
val mimeType = "text/plain"
try {
getContent.launch(mimeType)
} catch (_: ActivityNotFoundException) {
toast(org.fossify.commons.R.string.system_service_disabled, Toast.LENGTH_LONG)
} catch (e: Exception) {
showErrorToast(e)
}
}

Expand Down Expand Up @@ -200,32 +179,20 @@ class ManageBlockedKeywordsActivity : SimpleActivity(), RefreshRecyclerViewListe
}

private fun tryExportBlockedNumbers() {
if (isQPlus()) {
ExportBlockedKeywordsDialog(this, config.lastBlockedKeywordExportPath, true) { file ->
try {
exportActivityResultLauncher.launch(file.name)
} catch (e: ActivityNotFoundException) {
toast(
org.fossify.commons.R.string.system_service_disabled,
Toast.LENGTH_LONG
)
} catch (e: Exception) {
showErrorToast(e)
}
}
} else {
handlePermission(PERMISSION_WRITE_STORAGE) { isAllowed ->
if (isAllowed) {
ExportBlockedNumbersDialog(
this,
config.lastBlockedKeywordExportPath,
false
) { file ->
getFileOutputStream(file.toFileDirItem(this), true) { out ->
exportBlockedKeywordsTo(out)
}
}
}
ExportBlockedKeywordsDialog(
activity = this,
path = config.lastBlockedKeywordExportPath,
hidePath = true
) { file ->
try {
createDocument.launch(file.name)
} catch (_: ActivityNotFoundException) {
toast(
org.fossify.commons.R.string.system_service_disabled,
Toast.LENGTH_LONG
)
} catch (e: Exception) {
showErrorToast(e)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ abstract class BaseConversationsAdapter(

override fun getSelectableItemCount() = itemCount

protected fun getSelectedItems() =
currentList.filter { selectedKeys.contains(it.hashCode()) } as ArrayList<Conversation>
protected fun getSelectedItems() = currentList.filter {
selectedKeys.contains(it.hashCode())
} as ArrayList<Conversation>

override fun getIsItemSelectable(position: Int) = true

Expand Down Expand Up @@ -143,7 +144,9 @@ abstract class BaseConversationsAdapter(
draftIndicator.beVisibleIf(!smsDraft.isNullOrEmpty())
draftIndicator.setTextColor(properPrimaryColor)

pinIndicator.beVisibleIf(activity.config.pinnedConversations.contains(conversation.threadId.toString()))
pinIndicator.beVisibleIf(
activity.config.pinnedConversations.contains(conversation.threadId.toString())
)
pinIndicator.applyColorFilter(textColor)

conversationFrame.isSelected = selectedKeys.contains(conversation.hashCode())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.fossify.commons.extensions.setupDialogStuff
import org.fossify.commons.extensions.showErrorToast
import org.fossify.commons.extensions.toast
import org.fossify.commons.extensions.value
import org.fossify.commons.helpers.MEDIUM_ALPHA
import org.fossify.commons.helpers.ensureBackgroundThread
import org.fossify.messages.R
import org.fossify.messages.activities.SimpleActivity
Expand Down Expand Up @@ -72,7 +73,7 @@ class ExportMessagesDialog(
getButton(AlertDialog.BUTTON_NEGATIVE)
).forEach {
it.isEnabled = false
it.alpha = 0.6f
it.alpha = MEDIUM_ALPHA
}

binding.exportProgress.setIndicatorColor(activity.getProperPrimaryColor())
Expand Down Expand Up @@ -112,7 +113,7 @@ class ExportMessagesDialog(
// delete the file to avoid leaving behind an empty/corrupt file
try {
DocumentsContract.deleteDocument(activity.contentResolver, uri)
} catch (ignored: Exception) {
} catch (_: Exception) {
// ignored because we don't want to show two error messages
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.fossify.commons.extensions.getAlertDialogBuilder
import org.fossify.commons.extensions.getProperPrimaryColor
import org.fossify.commons.extensions.setupDialogStuff
import org.fossify.commons.extensions.toast
import org.fossify.commons.helpers.MEDIUM_ALPHA
import org.fossify.commons.helpers.ensureBackgroundThread
import org.fossify.messages.R
import org.fossify.messages.activities.SimpleActivity
Expand Down Expand Up @@ -65,7 +66,7 @@ class ImportMessagesDialog(
negativeButton
).forEach {
it.isEnabled = false
it.alpha = 0.6f
it.alpha = MEDIUM_ALPHA
}

ensureBackgroundThread {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fun Activity.dialNumber(phoneNumber: String, callback: (() -> Unit)? = null) {
try {
startActivity(this)
callback?.invoke()
} catch (e: ActivityNotFoundException) {
} catch (_: ActivityNotFoundException) {
toast(org.fossify.commons.R.string.no_app_found)
} catch (e: Exception) {
showErrorToast(e)
Expand All @@ -46,7 +46,7 @@ fun Activity.launchViewIntent(uri: Uri, mimetype: String, filename: String) {
try {
hideKeyboard()
startActivity(this)
} catch (e: ActivityNotFoundException) {
} catch (_: ActivityNotFoundException) {
val newMimetype = filename.getMimeType()
if (newMimetype.isNotEmpty() && mimetype != newMimetype) {
launchViewIntent(uri, newMimetype, filename)
Expand Down Expand Up @@ -110,4 +110,4 @@ fun Activity.launchConversationDetails(threadId: Long) {
putExtra(THREAD_ID, threadId)
startActivity(this)
}
}
}
Loading
Loading