Skip to content

Commit

Permalink
Added MsgsLoadStateAdapter. Refactored code.| #1806
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed May 18, 2022
1 parent 9084d31 commit d158daa
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import com.flowcrypt.email.ui.activity.fragment.base.BaseFragment
import com.flowcrypt.email.ui.activity.fragment.base.ListProgressBehaviour
import com.flowcrypt.email.ui.activity.fragment.dialog.InfoDialogFragment
import com.flowcrypt.email.ui.activity.fragment.dialog.TwoWayDialogFragment
import com.flowcrypt.email.ui.adapter.MsgsLoadStateAdapter
import com.flowcrypt.email.ui.adapter.MsgsPagedListAdapter
import com.flowcrypt.email.ui.adapter.selection.CustomStableIdKeyProvider
import com.flowcrypt.email.ui.adapter.selection.MsgItemDetailsLookup
Expand Down Expand Up @@ -572,7 +573,7 @@ class MessagesListFragment : BaseFragment<FragmentMessagesListBinding>(),
binding?.recyclerViewMsgs?.addItemDecoration(
DividerItemDecoration(context, layoutManager.orientation)
)
binding?.recyclerViewMsgs?.adapter = adapter
binding?.recyclerViewMsgs?.adapter = adapter.withLoadStateFooter(MsgsLoadStateAdapter())
setupItemTouchHelper()
//setupSelectionTracker()
setupBottomOverScroll()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected]
* Contributors: DenBond7
*/

package com.flowcrypt.email.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.paging.LoadState
import androidx.paging.LoadStateAdapter
import androidx.recyclerview.widget.RecyclerView
import com.flowcrypt.email.R
import com.flowcrypt.email.databinding.LoadMsgsProgressBinding
import com.flowcrypt.email.extensions.visibleOrGone

/**
* @author Denis Bondarenko
* Date: 5/18/22
* Time: 6:23 PM
* E-mail: [email protected]
*/
class MsgsLoadStateAdapter : LoadStateAdapter<MsgsLoadStateAdapter.ViewHolder>() {
override fun onBindViewHolder(holder: ViewHolder, loadState: LoadState) {
holder.bind(loadState)
}

override fun onCreateViewHolder(parent: ViewGroup, loadState: LoadState): ViewHolder {
return ViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.load_msgs_progress, parent, false)
)
}

inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val binding: LoadMsgsProgressBinding = LoadMsgsProgressBinding.bind(itemView)

fun bind(loadState: LoadState) {
binding.progressBar.visibleOrGone(loadState is LoadState.Loading)
}
}
}
23 changes: 23 additions & 0 deletions FlowCrypt/src/main/res/layout/load_msgs_progress.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected]
~ Contributors: DenBond7
-->

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin_content_small"
android:layout_marginBottom="@dimen/default_margin_content_small"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit d158daa

Please sign in to comment.