Merge branch 'master' into feature/451-recycle-bin
This commit is contained in:
commit
b29d664dc4
71 changed files with 1263 additions and 201 deletions
|
|
@ -0,0 +1,160 @@
|
|||
package com.simplemobiletools.smsmessenger.activities
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.adapters.ArchivedConversationsAdapter
|
||||
import com.simplemobiletools.smsmessenger.extensions.*
|
||||
import com.simplemobiletools.smsmessenger.helpers.*
|
||||
import com.simplemobiletools.smsmessenger.models.Conversation
|
||||
import com.simplemobiletools.smsmessenger.models.Events
|
||||
import kotlinx.android.synthetic.main.activity_archived_conversations.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
|
||||
class ArchivedConversationsActivity : SimpleActivity() {
|
||||
private var bus: EventBus? = null
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
isMaterialActivity = true
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_archived_conversations)
|
||||
setupOptionsMenu()
|
||||
|
||||
updateMaterialActivityViews(archive_coordinator, conversations_list, useTransparentNavigation = true, useTopSearchMenu = false)
|
||||
setupMaterialScrollListener(conversations_list, archive_toolbar)
|
||||
|
||||
loadArchivedConversations()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
setupToolbar(archive_toolbar, NavigationIcon.Arrow)
|
||||
updateMenuColors()
|
||||
|
||||
loadArchivedConversations()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
bus?.unregister(this)
|
||||
}
|
||||
|
||||
private fun setupOptionsMenu() {
|
||||
archive_toolbar.inflateMenu(R.menu.archive_menu)
|
||||
|
||||
archive_toolbar.setOnMenuItemClickListener { menuItem ->
|
||||
when (menuItem.itemId) {
|
||||
R.id.empty_archive -> removeAll()
|
||||
else -> return@setOnMenuItemClickListener false
|
||||
}
|
||||
return@setOnMenuItemClickListener true
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateOptionsMenu(conversations: ArrayList<Conversation>) {
|
||||
archive_toolbar.menu.apply {
|
||||
findItem(R.id.empty_archive).isVisible = conversations.isNotEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateMenuColors() {
|
||||
updateStatusbarColor(getProperBackgroundColor())
|
||||
}
|
||||
|
||||
private fun loadArchivedConversations() {
|
||||
ensureBackgroundThread {
|
||||
val conversations = try {
|
||||
conversationsDB.getAllArchived().toMutableList() as ArrayList<Conversation>
|
||||
} catch (e: Exception) {
|
||||
ArrayList()
|
||||
}
|
||||
|
||||
runOnUiThread {
|
||||
setupConversations(conversations)
|
||||
}
|
||||
}
|
||||
|
||||
bus = EventBus.getDefault()
|
||||
try {
|
||||
bus!!.register(this)
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeAll() {
|
||||
ConfirmationDialog(this, "", R.string.empty_archive_confirmation, R.string.yes, R.string.no) {
|
||||
removeAllArchivedConversations {
|
||||
loadArchivedConversations()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getOrCreateConversationsAdapter(): ArchivedConversationsAdapter {
|
||||
var currAdapter = conversations_list.adapter
|
||||
if (currAdapter == null) {
|
||||
hideKeyboard()
|
||||
currAdapter = ArchivedConversationsAdapter(
|
||||
activity = this,
|
||||
recyclerView = conversations_list,
|
||||
onRefresh = { notifyDatasetChanged() },
|
||||
itemClick = { handleConversationClick(it) }
|
||||
)
|
||||
|
||||
conversations_list.adapter = currAdapter
|
||||
if (areSystemAnimationsEnabled) {
|
||||
conversations_list.scheduleLayoutAnimation()
|
||||
}
|
||||
}
|
||||
return currAdapter as ArchivedConversationsAdapter
|
||||
}
|
||||
|
||||
private fun setupConversations(conversations: ArrayList<Conversation>) {
|
||||
val sortedConversations = conversations.sortedWith(
|
||||
compareByDescending<Conversation> { config.pinnedConversations.contains(it.threadId.toString()) }
|
||||
.thenByDescending { it.date }
|
||||
).toMutableList() as ArrayList<Conversation>
|
||||
|
||||
showOrHidePlaceholder(conversations.isEmpty())
|
||||
updateOptionsMenu(conversations)
|
||||
|
||||
try {
|
||||
getOrCreateConversationsAdapter().apply {
|
||||
updateConversations(sortedConversations)
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun showOrHidePlaceholder(show: Boolean) {
|
||||
conversations_fastscroller.beGoneIf(show)
|
||||
no_conversations_placeholder.beVisibleIf(show)
|
||||
no_conversations_placeholder.text = getString(R.string.no_archived_conversations)
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun notifyDatasetChanged() {
|
||||
getOrCreateConversationsAdapter().notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun handleConversationClick(any: Any) {
|
||||
Intent(this, ThreadActivity::class.java).apply {
|
||||
val conversation = any as Conversation
|
||||
putExtra(THREAD_ID, conversation.threadId)
|
||||
putExtra(THREAD_TITLE, conversation.title)
|
||||
putExtra(WAS_PROTECTION_HANDLED, true)
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun refreshMessages(event: Events.RefreshMessages) {
|
||||
loadArchivedConversations()
|
||||
}
|
||||
}
|
||||
|
|
@ -179,6 +179,7 @@ class MainActivity : SimpleActivity() {
|
|||
R.id.export_messages -> tryToExportMessages()
|
||||
R.id.more_apps_from_us -> launchMoreAppsFromUsIntent()
|
||||
R.id.show_recycle_bin -> launchRecycleBin()
|
||||
R.id.show_archived -> launchArchivedConversations()
|
||||
R.id.settings -> launchSettings()
|
||||
R.id.about -> launchAbout()
|
||||
else -> return@setOnMenuItemClickListener false
|
||||
|
|
@ -253,7 +254,10 @@ class MainActivity : SimpleActivity() {
|
|||
handlePermission(PERMISSION_READ_CONTACTS) {
|
||||
handleNotificationPermission { granted ->
|
||||
if (!granted) {
|
||||
PermissionRequiredDialog(this, R.string.allow_notifications_incoming_messages)
|
||||
PermissionRequiredDialog(
|
||||
activity = this,
|
||||
textId = R.string.allow_notifications_incoming_messages,
|
||||
positiveActionCallback = { openNotificationSettings() })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -291,15 +295,21 @@ class MainActivity : SimpleActivity() {
|
|||
private fun getCachedConversations() {
|
||||
ensureBackgroundThread {
|
||||
val conversations = try {
|
||||
conversationsDB.getAll().toMutableList() as ArrayList<Conversation>
|
||||
conversationsDB.getNonArchived().toMutableList() as ArrayList<Conversation>
|
||||
} catch (e: Exception) {
|
||||
ArrayList()
|
||||
}
|
||||
|
||||
val archived = try {
|
||||
conversationsDB.getAllArchived()
|
||||
} catch (e: Exception) {
|
||||
listOf()
|
||||
}
|
||||
|
||||
updateUnreadCountBadge(conversations)
|
||||
runOnUiThread {
|
||||
setupConversations(conversations, cached = true)
|
||||
getNewConversations(conversations)
|
||||
getNewConversations((conversations + archived).toMutableList() as ArrayList<Conversation>)
|
||||
}
|
||||
conversations.forEach {
|
||||
clearExpiredScheduledMessages(it.threadId)
|
||||
|
|
@ -353,7 +363,7 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
val allConversations = conversationsDB.getAll() as ArrayList<Conversation>
|
||||
val allConversations = conversationsDB.getNonArchived() as ArrayList<Conversation>
|
||||
runOnUiThread {
|
||||
setupConversations(allConversations)
|
||||
}
|
||||
|
|
@ -563,6 +573,11 @@ class MainActivity : SimpleActivity() {
|
|||
startActivity(Intent(applicationContext, RecycleBinConversationsActivity::class.java))
|
||||
}
|
||||
|
||||
private fun launchArchivedConversations() {
|
||||
hideKeyboard()
|
||||
startActivity(Intent(applicationContext, ArchivedConversationsActivity::class.java))
|
||||
}
|
||||
|
||||
private fun launchSettings() {
|
||||
hideKeyboard()
|
||||
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.simplemobiletools.smsmessenger.activities
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.app.AlarmManager
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
|
|
@ -44,6 +45,7 @@ import com.google.gson.Gson
|
|||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.FeatureLockedDialog
|
||||
import com.simplemobiletools.commons.dialogs.PermissionRequiredDialog
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
|
|
@ -51,6 +53,7 @@ import com.simplemobiletools.commons.models.PhoneNumber
|
|||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.commons.models.SimpleContact
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.smsmessenger.BuildConfig
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.adapters.AttachmentsAdapter
|
||||
import com.simplemobiletools.smsmessenger.adapters.AutoCompleteTextViewAdapter
|
||||
|
|
@ -244,6 +247,8 @@ class ThreadActivity : SimpleActivity() {
|
|||
val firstPhoneNumber = participants.firstOrNull()?.phoneNumbers?.firstOrNull()?.value
|
||||
thread_toolbar.menu.apply {
|
||||
findItem(R.id.delete).isVisible = threadItems.isNotEmpty()
|
||||
findItem(R.id.archive).isVisible = threadItems.isNotEmpty() && conversation?.isArchived == false
|
||||
findItem(R.id.unarchive).isVisible = threadItems.isNotEmpty() && conversation?.isArchived == true
|
||||
findItem(R.id.rename_conversation).isVisible = participants.size > 1 && conversation != null
|
||||
findItem(R.id.conversation_details).isVisible = conversation != null
|
||||
findItem(R.id.block_number).title = addLockedLabelIfNeeded(R.string.block_number)
|
||||
|
|
@ -268,6 +273,8 @@ class ThreadActivity : SimpleActivity() {
|
|||
when (menuItem.itemId) {
|
||||
R.id.block_number -> tryBlocking()
|
||||
R.id.delete -> askConfirmDelete()
|
||||
R.id.archive -> archiveConversation()
|
||||
R.id.unarchive -> unarchiveConversation()
|
||||
R.id.rename_conversation -> renameConversation()
|
||||
R.id.conversation_details -> showConversationDetails()
|
||||
R.id.add_number_to_contact -> addNumberToContact()
|
||||
|
|
@ -715,6 +722,25 @@ class ThreadActivity : SimpleActivity() {
|
|||
setupScheduleSendUi()
|
||||
}
|
||||
|
||||
private fun askForExactAlarmPermissionIfNeeded(callback: () -> Unit = {}) {
|
||||
if (isSPlus()) {
|
||||
val alarmManager: AlarmManager = getSystemService(ALARM_SERVICE) as AlarmManager
|
||||
if (alarmManager.canScheduleExactAlarms()) {
|
||||
callback()
|
||||
} else {
|
||||
PermissionRequiredDialog(
|
||||
activity = this,
|
||||
textId = R.string.allow_alarm_scheduled_messages,
|
||||
positiveActionCallback = {
|
||||
openRequestExactAlarmSettings(BuildConfig.APPLICATION_ID)
|
||||
},
|
||||
)
|
||||
}
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupAttachmentSizes() {
|
||||
messages.filter { it.attachment != null }.forEach { message ->
|
||||
message.attachment!!.attachments.forEach {
|
||||
|
|
@ -893,7 +919,8 @@ class ThreadActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun askConfirmDelete() {
|
||||
ConfirmationDialog(this, getString(R.string.delete_whole_conversation_confirmation)) {
|
||||
val confirmationMessage = R.string.delete_whole_conversation_confirmation
|
||||
ConfirmationDialog(this, getString(confirmationMessage)) {
|
||||
ensureBackgroundThread {
|
||||
deleteConversation(threadId)
|
||||
runOnUiThread {
|
||||
|
|
@ -904,6 +931,26 @@ class ThreadActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun archiveConversation() {
|
||||
ensureBackgroundThread {
|
||||
updateConversationArchivedStatus(threadId, true)
|
||||
runOnUiThread {
|
||||
refreshMessages()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun unarchiveConversation() {
|
||||
ensureBackgroundThread {
|
||||
updateConversationArchivedStatus(threadId, false)
|
||||
runOnUiThread {
|
||||
refreshMessages()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun dialNumber() {
|
||||
val phoneNumber = participants.first().phoneNumbers.first().normalizedNumber
|
||||
dialNumber(phoneNumber)
|
||||
|
|
@ -1126,7 +1173,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
contacts = arrayListOf(contact),
|
||||
showExportingToast = false,
|
||||
) {
|
||||
if (it == VcfExporter.ExportResult.EXPORT_OK) {
|
||||
if (it == ExportResult.EXPORT_OK) {
|
||||
val vCardUri = getMyFileUri(outputFile)
|
||||
runOnUiThread {
|
||||
addAttachment(vCardUri)
|
||||
|
|
@ -1332,6 +1379,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
messagesDB.insertOrUpdate(message)
|
||||
updateConversationArchivedStatus(message.threadId, false)
|
||||
}
|
||||
|
||||
// show selected contacts, properly split to new lines when appropriate
|
||||
|
|
@ -1534,10 +1582,12 @@ class ThreadActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun launchScheduleSendDialog(originalDateTime: DateTime? = null) {
|
||||
ScheduleMessageDialog(this, originalDateTime) { newDateTime ->
|
||||
if (newDateTime != null) {
|
||||
scheduledDateTime = newDateTime
|
||||
showScheduleMessageDialog()
|
||||
askForExactAlarmPermissionIfNeeded {
|
||||
ScheduleMessageDialog(this, originalDateTime) { newDateTime ->
|
||||
if (newDateTime != null) {
|
||||
scheduledDateTime = newDateTime
|
||||
showScheduleMessageDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue