Skip to content

Commit

Permalink
Merge branch 'develop' into feature/bnav_blur
Browse files Browse the repository at this point in the history
  • Loading branch information
GoetzDeBouville committed Dec 25, 2023
2 parents e1bb213 + 5a3b0ef commit 794599b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ class SearchFragment : BaseFragment<FragmentSearchBinding, SearchViewModel>(Frag
private fun showData(content: SearchScreenState.Content) {
vacancyListAdapter.setScrollLoadingEnabled(content.currentPage != content.totalPages - 1)
vacancyListAdapter.setShowScrollRefresh(false)
if (content.currentPage == 0) {
vacancyListAdapter.clearAll()
}
vacancyListAdapter.setData(content.vacancies, content.currentPage)
binding.vacancyCount.apply {
text = resources.getQuantityString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ class VacancyAdapter(
diffResult.dispatchUpdatesTo(this)
}

fun clearAll() {
val diffCallback = VacancyDiffCallback(dataList, emptyList())
val diffResult = DiffUtil.calculateDiff(diffCallback)
dataList.clear()
diffResult.dispatchUpdatesTo(this)
}

fun clearPageCounter() {
currentPage = 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ open class SearchViewModel @Inject constructor(

fun handleInteraction(interaction: ViewModelInteractionState) {
var newSearchSettings = searchSettings
isLastUpdatePage = false
// переменная костыль, чтобы обработать setQuery при возвращении на фрагмент
// в таких случаях нам надо восстановить всё как было.
val t = isLastUpdatePage; isLastUpdatePage = false
when (interaction) {
is ViewModelInteractionState.setRegion -> {
newSearchSettings = newSearchSettings.copy(currentPage = 0)
Expand All @@ -191,27 +193,26 @@ open class SearchViewModel @Inject constructor(

is ViewModelInteractionState.setSalary -> {
newSearchSettings = newSearchSettings.copy(currentPage = 0)
newSearchSettings =
newSearchSettings.copy(currentSalary = interaction.salary)
newSearchSettings = newSearchSettings.copy(currentSalary = interaction.salary)
}

is ViewModelInteractionState.setSalaryOnly -> {
newSearchSettings = newSearchSettings.copy(currentPage = 0)
newSearchSettings =
newSearchSettings.copy(currentSalaryOnly = interaction.salaryOnly)
newSearchSettings = newSearchSettings.copy(currentSalaryOnly = interaction.salaryOnly)
}

is ViewModelInteractionState.setQuery -> {
if (interaction.query == searchSettings.currentQuery) {
isLastUpdatePage = t; return
}
showSnackBar = false
newSearchSettings = newSearchSettings.copy(currentPage = 0)
newSearchSettings =
newSearchSettings.copy(currentQuery = interaction.query)
newSearchSettings = newSearchSettings.copy(currentQuery = interaction.query)
}

is ViewModelInteractionState.setPage -> {
isLastUpdatePage = true
newSearchSettings =
newSearchSettings.copy(currentPage = interaction.page)
newSearchSettings = newSearchSettings.copy(currentPage = interaction.page)
}
}
if (newSearchSettings != searchSettings) {
Expand Down

0 comments on commit 794599b

Please sign in to comment.