From cd1ceea8606427311a1bc50abff4dd9d463ff155 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Thu, 21 Mar 2019 22:55:47 +0100 Subject: [PATCH] Add messages forwarding (#288) --- .../data/db/migrations/Migration11.kt | 2 +- .../message/preview/MessagePreviewFragment.kt | 16 ++++++++--- .../preview/MessagePreviewPresenter.kt | 19 ++++++++----- .../message/preview/MessagePreviewView.kt | 4 ++- .../message/send/SendMessageActivity.kt | 9 ++++--- .../message/send/SendMessagePresenter.kt | 27 ++++++++++++------- .../res/drawable/ic_message_forward_24dp.xml | 10 +++++++ .../res/menu/action_menu_message_preview.xml | 6 +++++ app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 10 files changed, 71 insertions(+), 24 deletions(-) create mode 100644 app/src/main/res/drawable/ic_message_forward_24dp.xml diff --git a/app/src/main/java/io/github/wulkanowy/data/db/migrations/Migration11.kt b/app/src/main/java/io/github/wulkanowy/data/db/migrations/Migration11.kt index cb437c0e..6d129bca 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/migrations/Migration11.kt +++ b/app/src/main/java/io/github/wulkanowy/data/db/migrations/Migration11.kt @@ -8,7 +8,7 @@ class Migration11 : Migration(10, 11) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL(""" CREATE TABLE IF NOT EXISTS Grades_temp ( - id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + id INTEGER PRIMARY KEY NOT NULL, is_read INTEGER NOT NULL, is_notified INTEGER NOT NULL, semester_id INTEGER NOT NULL, diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewFragment.kt index 102567ed..9afb744f 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewFragment.kt @@ -25,6 +25,7 @@ class MessagePreviewFragment : BaseSessionFragment(), MessagePreviewView, MainVi lateinit var presenter: MessagePreviewPresenter private var menuReplyButton: MenuItem? = null + private var menuForwardButton: MenuItem? = null override val titleStringId: Int get() = R.string.message_title @@ -60,12 +61,16 @@ class MessagePreviewFragment : BaseSessionFragment(), MessagePreviewView, MainVi override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { inflater?.inflate(R.menu.action_menu_message_preview, menu) menuReplyButton = menu?.findItem(R.id.messagePreviewMenuReply) + menuForwardButton = menu?.findItem(R.id.messagePreviewMenuForward) presenter.onCreateOptionsMenu() } override fun onOptionsItemSelected(item: MenuItem?): Boolean { - return if (item?.itemId == R.id.messagePreviewMenuReply) presenter.onReply() - else false + return when (item?.itemId) { + R.id.messagePreviewMenuReply -> presenter.onReply() + R.id.messagePreviewMenuForward -> presenter.onForward() + else -> false + } } override fun setSubject(subject: String) { @@ -92,8 +97,9 @@ class MessagePreviewFragment : BaseSessionFragment(), MessagePreviewView, MainVi messagePreviewProgress.visibility = if (show) VISIBLE else GONE } - override fun showReplyButton(show: Boolean) { + override fun showOptions(show: Boolean) { menuReplyButton?.isVisible = show + menuForwardButton?.isVisible = show } override fun showMessageError() { @@ -101,6 +107,10 @@ class MessagePreviewFragment : BaseSessionFragment(), MessagePreviewView, MainVi } override fun openMessageReply(message: Message?) { + context?.let { it.startActivity(SendMessageActivity.getStartIntent(it, message, true)) } + } + + override fun openMessageForward(message: Message?) { context?.let { it.startActivity(SendMessageActivity.getStartIntent(it, message)) } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewPresenter.kt index a5ed9f28..534c7ad3 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewPresenter.kt @@ -22,7 +22,7 @@ class MessagePreviewPresenter @Inject constructor( var messageId: Int = 0 - private var replyMessage: Message? = null + private var message: Message? = null fun onAttachView(view: MessagePreviewView, id: Int) { super.onAttachView(view) @@ -41,13 +41,13 @@ class MessagePreviewPresenter @Inject constructor( .doFinally { view?.showProgress(false) } .subscribe({ message -> Timber.i("Loading message $id preview result: Success ") - replyMessage = message + this@MessagePreviewPresenter.message = message view?.run { message.let { setSubject(if (it.subject.isNotBlank()) it.subject else noSubjectString) setDate(it.date.toFormattedString("yyyy-MM-dd HH:mm:ss")) setContent(it.content.orEmpty()) - showReplyButton(true) + showOptions(true) if (it.recipient.isNotBlank()) setRecipient(it.recipient) else setSender(it.sender) @@ -63,13 +63,20 @@ class MessagePreviewPresenter @Inject constructor( } fun onReply(): Boolean { - return if (replyMessage != null) { - view?.openMessageReply(replyMessage) + return if (message != null) { + view?.openMessageReply(message) + true + } else false + } + + fun onForward(): Boolean { + return if (message != null) { + view?.openMessageForward(message) true } else false } fun onCreateOptionsMenu() { - view?.showReplyButton(replyMessage != null) + view?.showOptions(message != null) } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewView.kt index 464ea168..3ff73396 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/message/preview/MessagePreviewView.kt @@ -19,9 +19,11 @@ interface MessagePreviewView : BaseSessionView { fun showProgress(show: Boolean) - fun showReplyButton(show: Boolean) + fun showOptions(show: Boolean) fun showMessageError() fun openMessageReply(message: Message?) + + fun openMessageForward(message: Message?) } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/message/send/SendMessageActivity.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/message/send/SendMessageActivity.kt index edf14dd6..6ac7e226 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/message/send/SendMessageActivity.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/message/send/SendMessageActivity.kt @@ -26,11 +26,14 @@ class SendMessageActivity : BaseActivity(), SendMessageView { companion object { private const val EXTRA_MESSAGE = "EXTRA_MESSAGE" + private const val EXTRA_REPLY = "EXTRA_REPLY" fun getStartIntent(context: Context) = Intent(context, SendMessageActivity::class.java) - fun getStartIntent(context: Context, message: Message?): Intent { - return getStartIntent(context).putExtra(EXTRA_MESSAGE, message) + fun getStartIntent(context: Context, message: Message?, reply: Boolean = false): Intent { + return getStartIntent(context) + .putExtra(EXTRA_MESSAGE, message) + .putExtra(EXTRA_REPLY, reply) } } @@ -59,7 +62,7 @@ class SendMessageActivity : BaseActivity(), SendMessageView { supportActionBar?.setDisplayHomeAsUpEnabled(true) messageContainer = sendMessageContainer - presenter.onAttachView(this, intent.getSerializableExtra(EXTRA_MESSAGE) as? Message) + presenter.onAttachView(this, intent.getSerializableExtra(EXTRA_MESSAGE) as? Message, intent.getSerializableExtra(EXTRA_REPLY) as Boolean) } override fun onCreateOptionsMenu(menu: Menu?): Boolean { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/message/send/SendMessagePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/message/send/SendMessagePresenter.kt index a3715aaa..f57848d6 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/message/send/SendMessagePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/message/send/SendMessagePresenter.kt @@ -30,18 +30,25 @@ class SendMessagePresenter @Inject constructor( private val analytics: FirebaseAnalyticsHelper ) : BasePresenter(errorHandler) { - fun onAttachView(view: SendMessageView, message: Message?) { + fun onAttachView(view: SendMessageView, message: Message?, reply: Boolean) { super.onAttachView(view) Timber.i("Send message view is attached") - loadData(message) + loadData(message, reply) view.apply { message?.let { - setSubject("RE: ${message.subject}") - if (preferencesRepository.fillMessageContent) { - setContent(when (message.sender.isNotEmpty()) { - true -> "\n\nOd: ${message.sender}\n" - false -> "\n\nDo: ${message.recipient}\n" - } + "Data: ${message.date.toFormattedString("yyyy-MM-dd HH:mm:ss")}\n\n${message.content}") + setSubject(when (reply) { + true -> "RE: " + false -> "FE: " + } + message.subject) + if (preferencesRepository.fillMessageContent || !reply) { + setContent( + when (reply) { + true -> "\n\n" + false -> "" + } + when (message.sender.isNotEmpty()) { + true -> "Od: ${message.sender}\n" + false -> "Do: ${message.recipient}\n" + } + "Data: ${message.date.toFormattedString("yyyy-MM-dd HH:mm:ss")}\n\n${message.content}") } } } @@ -52,7 +59,7 @@ class SendMessagePresenter @Inject constructor( return true } - private fun loadData(message: Message?) { + private fun loadData(message: Message?, reply: Boolean) { var reportingUnit: ReportingUnit? = null var recipients: List = emptyList() var selectedRecipient: List = emptyList() @@ -69,7 +76,7 @@ class SendMessagePresenter @Inject constructor( recipients = it } .flatMapCompletable { - if (message == null) Completable.complete() + if (message == null || !reply) Completable.complete() else recipientRepository.getMessageRecipients(student, message) .doOnSuccess { Timber.i("Loaded message recipients to reply result: Success, fetched %d recipients", it.size) diff --git a/app/src/main/res/drawable/ic_message_forward_24dp.xml b/app/src/main/res/drawable/ic_message_forward_24dp.xml new file mode 100644 index 00000000..2b7c32c7 --- /dev/null +++ b/app/src/main/res/drawable/ic_message_forward_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/menu/action_menu_message_preview.xml b/app/src/main/res/menu/action_menu_message_preview.xml index 4c2f5920..6ba2c828 100644 --- a/app/src/main/res/menu/action_menu_message_preview.xml +++ b/app/src/main/res/menu/action_menu_message_preview.xml @@ -7,4 +7,10 @@ android:orderInCategory="1" android:title="@string/message_reply" app:showAsAction="ifRoom" /> + diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index dcc73526..16ec15ff 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -140,6 +140,7 @@ Do: Data: %s Odpowiedz + Prześlij dalej Temat Treść Wiadomość wysłana pomyślnie diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1debed7b..98bef391 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -134,6 +134,7 @@ To: Date: %s Reply + Forward Subject Content Message sent successfully