Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put ThreadList adapters initialisations together #1850

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,24 @@ 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)
}
},
)

binding.mailRecyclerView.adapter = threadListAdapter.apply {
stateRestorationPolicy = StateRestorationPolicy.PREVENT_WHEN_EMPTY
}
NicolasBourdin88 marked this conversation as resolved.
Show resolved Hide resolved
}

private fun setupListeners() = with(binding) {
Expand Down Expand Up @@ -192,10 +209,10 @@ 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)
return trackSearchEvent(ThreadFilter.FOLDER.matomoValue, folder != null)
NicolasBourdin88 marked this conversation as resolved.
Show resolved Hide resolved
}

private fun updateFolderDropDownUi(folder: Folder?, title: String) = with(binding) {
Expand Down Expand Up @@ -246,23 +263,8 @@ 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)
}
}
}

mailRecyclerView.apply {
private fun setMessagesUi() {
binding.mailRecyclerView.apply {
disableDragDirection(DirectionFlag.UP)
disableDragDirection(DirectionFlag.DOWN)
disableDragDirection(DirectionFlag.LEFT)
Expand Down
Loading