Skip to content

Commit

Permalink
MsgsPagedListAdapter. Restored OnMessageClickListener.| #1806
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed May 19, 2022
1 parent d158daa commit 98a6cfa
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ class MessagesListFragment : BaseFragment<FragmentMessagesListBinding>(),
private val currentFolder: LocalFolder?
get() = labelsViewModel.activeFolderLiveData.value

private val adapter by lazy { MsgsPagedListAdapter() }
private val adapter by lazy {
MsgsPagedListAdapter(null, object : MsgsPagedListAdapter.OnMessageClickListener {
override fun onMsgClick(msgEntity: MessageEntity) {
onMsgClicked(msgEntity)
}
})
}

private var keepSelectionInMemory = false
private var isForceSendingEnabled: Boolean = true
Expand Down Expand Up @@ -346,58 +352,6 @@ class MessagesListFragment : BaseFragment<FragmentMessagesListBinding>(),
}
}

/*override fun onMsgClick(msgEntity: MessageEntity) {
activeMsgEntity = msgEntity
if (tracker?.hasSelection() == true) {
return
}
val isOutbox =
JavaEmailConstants.FOLDER_OUTBOX.equals(currentFolder?.fullName, ignoreCase = true)
val isRawMsgAvailable = msgEntity.rawMessageWithoutAttachments?.isNotEmpty() ?: false
if (isOutbox || isRawMsgAvailable || GeneralUtil.isConnected(context)) {
when (msgEntity.msgState) {
MessageState.ERROR_ORIGINAL_MESSAGE_MISSING,
MessageState.ERROR_ORIGINAL_ATTACHMENT_NOT_FOUND,
MessageState.ERROR_CACHE_PROBLEM,
MessageState.ERROR_DURING_CREATION,
MessageState.ERROR_SENDING_FAILED,
MessageState.ERROR_PRIVATE_KEY_NOT_FOUND,
MessageState.ERROR_COPY_NOT_SAVED_IN_SENT_FOLDER,
MessageState.ERROR_PASSWORD_PROTECTED -> handleOutgoingMsgWhichHasSomeError(
msgEntity
)
else -> {
if (isOutbox && !isRawMsgAvailable) {
showTwoWayDialog(
requestCode = REQUEST_CODE_MESSAGE_DETAILS_UNAVAILABLE,
dialogTitle = "",
dialogMsg = getString(R.string.message_failed_to_create),
positiveButtonTitle = getString(R.string.delete_message),
negativeButtonTitle = getString(R.string.cancel),
isCancelable = true
)
} else {
currentFolder?.let { localFolder ->
navController?.navigate(
MessagesListFragmentDirections.actionMessagesListFragmentToMessageDetailsFragment(
messageEntity = msgEntity,
localFolder = localFolder
)
)
}
}
}
}
} else {
showInfoSnackbar(
view,
getString(R.string.internet_connection_is_not_available),
Snackbar.LENGTH_LONG
)
}
}*/

fun onDrawerStateChanged(slideOffset: Float, isOpened: Boolean) {
when {
slideOffset > 0 -> {
Expand Down Expand Up @@ -1291,6 +1245,58 @@ class MessagesListFragment : BaseFragment<FragmentMessagesListBinding>(),
}
}

private fun onMsgClicked(msgEntity: MessageEntity) {
activeMsgEntity = msgEntity
if (tracker?.hasSelection() == true) {
return
}

val isOutbox =
JavaEmailConstants.FOLDER_OUTBOX.equals(currentFolder?.fullName, ignoreCase = true)
val isRawMsgAvailable = msgEntity.rawMessageWithoutAttachments?.isNotEmpty() ?: false
if (isOutbox || isRawMsgAvailable || GeneralUtil.isConnected(context)) {
when (msgEntity.msgState) {
MessageState.ERROR_ORIGINAL_MESSAGE_MISSING,
MessageState.ERROR_ORIGINAL_ATTACHMENT_NOT_FOUND,
MessageState.ERROR_CACHE_PROBLEM,
MessageState.ERROR_DURING_CREATION,
MessageState.ERROR_SENDING_FAILED,
MessageState.ERROR_PRIVATE_KEY_NOT_FOUND,
MessageState.ERROR_COPY_NOT_SAVED_IN_SENT_FOLDER,
MessageState.ERROR_PASSWORD_PROTECTED -> handleOutgoingMsgWhichHasSomeError(
msgEntity
)
else -> {
if (isOutbox && !isRawMsgAvailable) {
showTwoWayDialog(
requestCode = REQUEST_CODE_MESSAGE_DETAILS_UNAVAILABLE,
dialogTitle = "",
dialogMsg = getString(R.string.message_failed_to_create),
positiveButtonTitle = getString(R.string.delete_message),
negativeButtonTitle = getString(R.string.cancel),
isCancelable = true
)
} else {
currentFolder?.let { localFolder ->
navController?.navigate(
MessagesListFragmentDirections.actionMessagesListFragmentToMessageDetailsFragment(
messageEntity = msgEntity,
localFolder = localFolder
)
)
}
}
}
}
} else {
showInfoSnackbar(
view,
getString(R.string.internet_connection_is_not_available),
Snackbar.LENGTH_LONG
)
}
}

companion object {
private const val REQUEST_CODE_RETRY_TO_SEND_MESSAGES = 11
private const val REQUEST_CODE_ERROR_DURING_CREATION = 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ import javax.mail.internet.InternetAddress
* Time: 4:48 PM
* E-mail: DenBond7@gmail.com
*/
class MsgsPagedListAdapter(var currentFolder: LocalFolder? = null) :
PagingDataAdapter<MessageEntity, MsgsPagedListAdapter.MessageViewHolder>(ITEM_CALLBACK) {
class MsgsPagedListAdapter(
var currentFolder: LocalFolder? = null,
private val onMessageClickListener: OnMessageClickListener? = null
) : PagingDataAdapter<MessageEntity, MsgsPagedListAdapter.MessageViewHolder>(ITEM_CALLBACK) {
private val senderNamePattern: Pattern = prepareSenderNamePattern()

override fun onBindViewHolder(holder: MessageViewHolder, position: Int) {
Expand Down Expand Up @@ -232,6 +234,10 @@ class MsgsPagedListAdapter(var currentFolder: LocalFolder? = null) :
fun bind(value: MessageEntity) {
val context = itemView.context

itemView.setOnClickListener {
onMessageClickListener?.onMsgClick(value)
}

val subject = if (TextUtils.isEmpty(value.subject)) {
context.getString(R.string.no_subject)
} else {
Expand Down Expand Up @@ -314,6 +320,10 @@ class MsgsPagedListAdapter(var currentFolder: LocalFolder? = null) :
}
}

interface OnMessageClickListener {
fun onMsgClick(msgEntity: MessageEntity)
}

companion object {
private val ITEM_CALLBACK = object : DiffUtil.ItemCallback<MessageEntity>() {
override fun areItemsTheSame(oldMsg: MessageEntity, newMsg: MessageEntity) =
Expand Down

0 comments on commit 98a6cfa

Please sign in to comment.