Skip to content

Commit

Permalink
Added a simple realization of 'swipe message to archive it'.| #504
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Jan 27, 2020
1 parent 2ede2ce commit 33de34f
Showing 1 changed file with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.paging.PagedList
import androidx.recyclerview.selection.SelectionTracker
import androidx.recyclerview.selection.StorageStrategy
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
Expand Down Expand Up @@ -539,16 +540,22 @@ class EmailListFragment : BaseSyncFragment(), SwipeRefreshLayout.OnRefreshListen

emptyView = view.findViewById(R.id.emptyView)
swipeRefreshLayout = view.findViewById(R.id.swipeRefreshLayout)
swipeRefreshLayout!!.setColorSchemeResources(R.color.colorPrimary, R.color.colorPrimary, R.color.colorPrimary)
swipeRefreshLayout!!.setOnRefreshListener(this)
swipeRefreshLayout?.setColorSchemeResources(
R.color.colorPrimary, R.color.colorPrimary, R.color.colorPrimary)
swipeRefreshLayout?.setOnRefreshListener(this)
}

private fun setupRecyclerView() {
val layoutManager = LinearLayoutManager(context)
recyclerViewMsgs?.layoutManager = layoutManager
recyclerViewMsgs?.setHasFixedSize(true)
recyclerViewMsgs?.addItemDecoration(DividerItemDecoration(context, layoutManager.orientation))
recyclerViewMsgs?.adapter = adapter
setupItemTouchHelper()
setupSelectionTracker()
}

private fun setupSelectionTracker() {
adapter.tracker = null
if (listener?.currentFolder?.searchQuery == null) {
recyclerViewMsgs?.let { recyclerView ->
Expand All @@ -569,6 +576,32 @@ class EmailListFragment : BaseSyncFragment(), SwipeRefreshLayout.OnRefreshListen
}
}

private fun setupItemTouchHelper() {
val itemTouchHelper = ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(
0, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) {
override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder): Boolean {
return false
}

override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
val position = viewHolder.adapterPosition
if (position != RecyclerView.NO_POSITION) {
val item = adapter.getItemId(position)
listener?.currentFolder?.let {
messagesViewModel.changeMsgsState(listOf(item), it, MessageState.PENDING_ARCHIVING)
}
}
}

override fun isItemViewSwipeEnabled(): Boolean {
return isArchiveActionEnabled()
}
})

itemTouchHelper.attachToRecyclerView(recyclerViewMsgs)
}

private fun genActionModeForMsgs(): ActionMode.Callback {
return object : ActionMode.Callback {
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean {
Expand Down Expand Up @@ -665,14 +698,12 @@ class EmailListFragment : BaseSyncFragment(), SwipeRefreshLayout.OnRefreshListen
var isEnabled = false

when (FoldersManager.getFolderType(listener?.currentFolder)) {
FoldersManager.FolderType.INBOX -> {
FoldersManager.FolderType.INBOX, FoldersManager.FolderType.SENT -> {
if (AccountDao.ACCOUNT_TYPE_GOOGLE == listener?.currentAccountDao?.accountType) {
isEnabled = true
}
}

FoldersManager.FolderType.SENT -> isEnabled = true

FoldersManager.FolderType.DRAFTS, FoldersManager.FolderType.OUTBOX -> {
isEnabled = false
}
Expand Down

0 comments on commit 33de34f

Please sign in to comment.