Skip to content

Commit

Permalink
Merge pull request #1850 from Infomaniak/fix-thread-list-adapter-cons…
Browse files Browse the repository at this point in the history
…tructor

Put ThreadList adapters initialisations together
  • Loading branch information
LunarX committed May 14, 2024
2 parents 2418350 + f1106b4 commit ee75ff5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ class ThreadListAdapter @Inject constructor(
private var swipingIsAuthorized: Boolean = true
private var isLoadMoreDisplayed = false

var onThreadClicked: ((thread: Thread) -> Unit)? = null
var onFlushClicked: ((dialogTitle: String) -> Unit)? = null
var onLoadMoreClicked: (() -> Unit)? = null
private var onThreadClicked: ((thread: Thread) -> Unit)? = null
private var onFlushClicked: ((dialogTitle: String) -> Unit)? = null
private var onLoadMoreClicked: (() -> Unit)? = null

private var folderRole: FolderRole? = null
private var onSwipeFinished: (() -> Unit)? = null
Expand All @@ -112,11 +112,17 @@ class ThreadListAdapter @Inject constructor(
onSwipeFinished: (() -> Unit)? = null,
multiSelection: MultiSelectionListener<Thread>? = null,
isFolderNameVisible: Boolean = false,
onThreadClicked: ((thread: Thread) -> Unit),
onFlushClicked: ((dialogTitle: String) -> Unit)? = null,
onLoadMoreClicked: (() -> Unit)? = null,
) {
this.folderRole = folderRole
this.onSwipeFinished = onSwipeFinished
this.multiSelection = multiSelection
this.isFolderNameVisible = isFolderNameVisible
this.onThreadClicked = onThreadClicked
this.onFlushClicked = onFlushClicked
this.onLoadMoreClicked = onLoadMoreClicked
}

override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,27 +296,8 @@ class ThreadListFragment : TwoPaneFragment(), SwipeRefreshLayout.OnRefreshListen
override val selectedItems by mainViewModel::selectedThreads
override val publishSelectedItems = mainViewModel::publishSelectedItems
},
)

binding.threadsList.apply {
adapter = threadListAdapter
layoutManager = LinearLayoutManager(context)
orientation = VERTICAL_LIST_WITH_VERTICAL_DRAGGING
disableDragDirection(DirectionFlag.UP)
disableDragDirection(DirectionFlag.DOWN)
disableDragDirection(DirectionFlag.RIGHT)
disableDragDirection(DirectionFlag.LEFT)
addStickyDateDecoration(threadListAdapter, localSettings.threadDensity)
}

threadListAdapter.apply {

stateRestorationPolicy = StateRestorationPolicy.PREVENT_WHEN_EMPTY

onThreadClicked = ::navigateToThread

onThreadClicked = ::navigateToThread,
onFlushClicked = { dialogTitle ->

val trackerName = when {
isCurrentFolderRole(FolderRole.TRASH) -> "emptyTrash"
isCurrentFolderRole(FolderRole.DRAFT) -> "emptyDraft"
Expand All @@ -334,12 +315,24 @@ class ThreadListFragment : TwoPaneFragment(), SwipeRefreshLayout.OnRefreshListen
mainViewModel.flushFolder()
},
)
}

},
onLoadMoreClicked = {
trackThreadListEvent("loadMore")
mainViewModel.getOnePageOfOldMessages()
}
},
)

threadListAdapter.stateRestorationPolicy = StateRestorationPolicy.PREVENT_WHEN_EMPTY

binding.threadsList.apply {
adapter = threadListAdapter
layoutManager = LinearLayoutManager(context)
orientation = VERTICAL_LIST_WITH_VERTICAL_DRAGGING
disableDragDirection(DirectionFlag.UP)
disableDragDirection(DirectionFlag.DOWN)
disableDragDirection(DirectionFlag.RIGHT)
disableDragDirection(DirectionFlag.LEFT)
addStickyDateDecoration(threadListAdapter, localSettings.threadDensity)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,22 @@ class SearchFragment : TwoPaneFragment() {
}

private fun setupAdapter() {
threadListAdapter(folderRole = null, isFolderNameVisible = true)
threadListAdapter(
folderRole = null,
isFolderNameVisible = true,
onThreadClicked = { thread ->
with(searchViewModel) {
if (!isLengthTooShort(currentSearchQuery)) history.value = currentSearchQuery
binding.searchBar.searchTextInput.apply {
hideKeyboard()
clearFocus()
}
navigateToThread(thread)
}
},
)

threadListAdapter.stateRestorationPolicy = StateRestorationPolicy.PREVENT_WHEN_EMPTY
}

private fun setupListeners() = with(binding) {
Expand Down Expand Up @@ -192,7 +207,7 @@ class SearchFragment : TwoPaneFragment() {
return popupMenu
}

private fun onFolderSelected(folder: Folder?, title: String) = with(binding) {
private fun onFolderSelected(folder: Folder?, title: String) {
updateFolderDropDownUi(folder, title)
searchViewModel.selectFolder(folder)
trackSearchEvent(ThreadFilter.FOLDER.matomoValue, folder != null)
Expand Down Expand Up @@ -246,23 +261,10 @@ class SearchFragment : TwoPaneFragment() {
}
}

private fun setMessagesUi() = with(binding) {

mailRecyclerView.adapter = threadListAdapter.apply {
stateRestorationPolicy = StateRestorationPolicy.PREVENT_WHEN_EMPTY
onThreadClicked = { thread ->
with(searchViewModel) {
if (!isLengthTooShort(currentSearchQuery)) history.value = currentSearchQuery
binding.searchBar.searchTextInput.apply {
hideKeyboard()
clearFocus()
}
navigateToThread(thread)
}
}
}
private fun setMessagesUi() {
binding.mailRecyclerView.apply {
adapter = threadListAdapter

mailRecyclerView.apply {
disableDragDirection(DirectionFlag.UP)
disableDragDirection(DirectionFlag.DOWN)
disableDragDirection(DirectionFlag.LEFT)
Expand Down

0 comments on commit ee75ff5

Please sign in to comment.