1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-11-23 19:26:31 -06:00

Add messages forwarding (#288)

This commit is contained in:
Kacper Ziubryniewicz 2019-03-21 22:55:47 +01:00 committed by Mikołaj Pich
parent 5add95ece1
commit cd1ceea860
10 changed files with 71 additions and 24 deletions

View File

@ -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,

View File

@ -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)) }
}

View File

@ -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)
}
}

View File

@ -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?)
}

View File

@ -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 {

View File

@ -30,18 +30,25 @@ class SendMessagePresenter @Inject constructor(
private val analytics: FirebaseAnalyticsHelper
) : BasePresenter<SendMessageView>(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<Recipient> = emptyList()
var selectedRecipient: List<Recipient> = 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)

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,8V4l8,8 -8,8v-4H4V8z" />
</vector>

View File

@ -7,4 +7,10 @@
android:orderInCategory="1"
android:title="@string/message_reply"
app:showAsAction="ifRoom" />
<item
android:id="@+id/messagePreviewMenuForward"
android:icon="@drawable/ic_message_forward_24dp"
android:orderInCategory="1"
android:title="@string/message_forward"
app:showAsAction="ifRoom" />
</menu>

View File

@ -140,6 +140,7 @@
<string name="message_to">Do:</string>
<string name="message_date">Data: %s</string>
<string name="message_reply">Odpowiedz</string>
<string name="message_forward">Prześlij dalej</string>
<string name="message_subject">Temat</string>
<string name="message_content">Treść</string>
<string name="message_send_successful">Wiadomość wysłana pomyślnie</string>

View File

@ -134,6 +134,7 @@
<string name="message_to">To:</string>
<string name="message_date">Date: %s</string>
<string name="message_reply">Reply</string>
<string name="message_forward">Forward</string>
<string name="message_subject">Subject</string>
<string name="message_content">Content</string>
<string name="message_send_successful">Message sent successfully</string>