[Messages] Fix search in sent messages. Implement removing messages.

This commit is contained in:
Kuba Szczodrzyński 2020-04-05 23:39:32 +02:00
parent f07b12bd87
commit 0e4d609bbf
6 changed files with 54 additions and 15 deletions

View File

@ -15,9 +15,12 @@ import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ProgressBar
import android.widget.Toast
import androidx.appcompat.widget.PopupMenu
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import com.google.android.material.chip.Chip
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.mikepenz.iconics.IconicsColor
import com.mikepenz.iconics.IconicsDrawable
import com.mikepenz.iconics.IconicsSize
@ -37,6 +40,7 @@ import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent.Companion.T
import pl.szczodrzynski.edziennik.data.api.events.MessageGetEvent
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore
import pl.szczodrzynski.edziennik.data.db.entity.LoginStore.Companion.LOGIN_TYPE_IDZIENNIK
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_DELETED
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_RECEIVED
import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_SENT
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
@ -108,6 +112,23 @@ class MessageFragment : Fragment(), CoroutineScope {
"type" to "forward"
))
}
b.deleteButton.onClick {
MaterialAlertDialogBuilder(activity)
.setTitle(R.string.messages_delete_confirmation)
.setMessage(R.string.messages_delete_confirmation_text)
.setPositiveButton(R.string.ok) { _, _ ->
launch {
message.type = TYPE_DELETED
withContext(Dispatchers.Default) {
app.db.messageDao().replace(message)
}
Toast.makeText(activity, "Wiadomość przeniesiona do usuniętych", Toast.LENGTH_SHORT).show()
activity.navigateUp()
}
}
.setNegativeButton(R.string.cancel, null)
.show()
}
launch {
@ -217,7 +238,8 @@ class MessageFragment : Fragment(), CoroutineScope {
b.subject.text = message.subject
b.replyButton.visibility = if (message.type == TYPE_RECEIVED) View.VISIBLE else View.INVISIBLE
b.replyButton.isVisible = message.type == TYPE_RECEIVED
b.deleteButton.isVisible = message.type == TYPE_RECEIVED
if (message.type == TYPE_RECEIVED) {
activity.navView.apply {
bottomBar.apply {

View File

@ -14,6 +14,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.cleanDiacritics
import pl.szczodrzynski.edziennik.data.db.entity.Message
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
import pl.szczodrzynski.edziennik.ui.modules.grades.viewholder.BindableViewHolder
@ -138,12 +139,26 @@ class MessagesAdapter(
it.filterWeight = 100
it.searchHighlightText = null
var weight = getMatchWeight(it.senderName, prefixString)
if (weight != 100) {
if (weight == 3)
weight = 31
it.filterWeight = min(it.filterWeight, 10 + weight)
var weight: Int
if (it.type == Message.TYPE_SENT) {
it.recipients?.forEach { recipient ->
weight = getMatchWeight(recipient.fullName, prefixString)
if (weight != 100) {
if (weight == 3)
weight = 31
it.filterWeight = min(it.filterWeight, 10 + weight)
}
}
}
else {
weight = getMatchWeight(it.senderName, prefixString)
if (weight != 100) {
if (weight == 3)
weight = 31
it.filterWeight = min(it.filterWeight, 10 + weight)
}
}
weight = getMatchWeight(it.subject, prefixString)
if (weight != 100) {

View File

@ -69,6 +69,11 @@ class MessagesListFragment : LazyFragment(), CoroutineScope {
items.forEach { message ->
message.recipients?.removeAll { it.profileId != message.profileId }
message.recipients?.forEach { recipient ->
if (recipient.fullName == null) {
recipient.fullName = teachers.firstOrNull { it.id == recipient.id }?.fullName ?: ""
}
}
}
// load & configure the adapter

View File

@ -33,12 +33,6 @@ class MessageViewHolder(
override fun onBind(activity: AppCompatActivity, app: App, item: MessageFull, position: Int, adapter: MessagesAdapter) {
val manager = app.gradesManager
item.recipients?.forEach { recipient ->
if (recipient.fullName == null) {
recipient.fullName = adapter.teachers.firstOrNull { it.id == recipient.id }?.fullName ?: ""
}
}
b.messageSubject.text = item.subject
b.messageDate.text = Date.fromMillis(item.addedDate).formattedStringShort
b.messageAttachmentImage.isVisible = item.hasAttachments

View File

@ -309,7 +309,7 @@
android:layout_height="24dp"
android:padding="4dp"
app:iiv_color="?android:textColorSecondary"
app:iiv_icon="cmd-arrow-right-thick"
app:iiv_icon="cmd-arrow-right"
tools:srcCompat="@android:drawable/ic_media_ff" />
<TextView
@ -323,6 +323,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/deleteButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="4dp"
@ -335,14 +336,14 @@
android:paddingTop="8dp"
android:paddingRight="4dp"
android:paddingBottom="8dp"
android:visibility="invisible">
android:visibility="visible">
<com.mikepenz.iconics.view.IconicsImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:padding="4dp"
app:iiv_color="?android:textColorSecondary"
app:iiv_icon="cmd-delete"
app:iiv_icon="cmd-delete-outline"
tools:srcCompat="@android:drawable/ic_menu_delete" />
<TextView

View File

@ -1291,4 +1291,6 @@
<string name="messages_tab_deleted">Usunięte</string>
<string name="messages_search">Szukaj</string>
<string name="messages_search_results">Znaleziono %d wiadomości</string>
<string name="messages_delete_confirmation">Czy chcesz usunąć wiadomość?</string>
<string name="messages_delete_confirmation_text">Spowoduje to przeniesienie wiadomości do zakładki \"Usunięte\" w aplikacji. Zmiany nie wpłyną na wiadomość w e-dzienniku (nie zostanie ona tam usunięta).</string>
</resources>