|
|
|
@ -27,13 +27,13 @@ import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow |
|
|
|
import net.pokeranalytics.android.util.Preferences |
|
|
|
import net.pokeranalytics.android.util.Preferences |
|
|
|
import net.pokeranalytics.android.util.extensions.sorted |
|
|
|
import net.pokeranalytics.android.util.extensions.sorted |
|
|
|
import timber.log.Timber |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open class FiltersFragment : RealmFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
open class FiltersFragment : RealmFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
const val REQUEST_CODE_FILTER_DETAILS = 100 |
|
|
|
const val REQUEST_CODE_FILTER_DETAILS = 100 |
|
|
|
|
|
|
|
const val MOST_USED_FILTERS_DISPLAYED = 6 |
|
|
|
|
|
|
|
|
|
|
|
var currentFilter: Filter? = null |
|
|
|
var currentFilter: Filter? = null |
|
|
|
|
|
|
|
|
|
|
|
@ -196,19 +196,19 @@ open class FiltersFragment : RealmFragment(), StaticRowRepresentableDataSource, |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun updateMostUsedFilters() { |
|
|
|
private fun updateMostUsedFilters() { |
|
|
|
|
|
|
|
|
|
|
|
if (isUpdating) { |
|
|
|
var nbChips = 0 |
|
|
|
|
|
|
|
val filters = getRealm().sorted(Filter::class.java) |
|
|
|
|
|
|
|
val currentFilterId = Preferences.getActiveFilterId(requireContext()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isUpdating || filters.isEmpty() || (filters.size == 1 && filters.first()?.id == currentFilterId)) { |
|
|
|
mostUsedFiltersLayout.visibility = View.GONE |
|
|
|
mostUsedFiltersLayout.visibility = View.GONE |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val filters = getRealm().sorted(Filter::class.java) |
|
|
|
|
|
|
|
val currentFilterId = Preferences.getActiveFilterId(requireContext()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mostUsedFilters.removeAllViews() |
|
|
|
mostUsedFilters.removeAllViews() |
|
|
|
|
|
|
|
|
|
|
|
var nbChips = 0 |
|
|
|
|
|
|
|
filters.forEach { filter -> |
|
|
|
filters.forEach { filter -> |
|
|
|
if (nbChips < 3) { |
|
|
|
if (nbChips < MOST_USED_FILTERS_DISPLAYED) { |
|
|
|
|
|
|
|
|
|
|
|
if (filter.id != currentFilterId) { |
|
|
|
if (filter.id != currentFilterId) { |
|
|
|
val chip = Chip(requireContext()) |
|
|
|
val chip = Chip(requireContext()) |
|
|
|
@ -220,7 +220,6 @@ open class FiltersFragment : RealmFragment(), StaticRowRepresentableDataSource, |
|
|
|
|
|
|
|
|
|
|
|
chip.isChecked = filter.id == currentFilterId |
|
|
|
chip.isChecked = filter.id == currentFilterId |
|
|
|
chip.setOnCloseIconClickListener { |
|
|
|
chip.setOnCloseIconClickListener { |
|
|
|
|
|
|
|
|
|
|
|
chip.isChecked = false |
|
|
|
chip.isChecked = false |
|
|
|
} |
|
|
|
} |
|
|
|
chip.setOnClickListener { |
|
|
|
chip.setOnClickListener { |
|
|
|
@ -235,7 +234,6 @@ open class FiltersFragment : RealmFragment(), StaticRowRepresentableDataSource, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -250,13 +248,10 @@ open class FiltersFragment : RealmFragment(), StaticRowRepresentableDataSource, |
|
|
|
* Validate the updates of the queryWith |
|
|
|
* Validate the updates of the queryWith |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun validateUpdates() { |
|
|
|
private fun validateUpdates() { |
|
|
|
Timber.d("Validate queryWith updates") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val realm = getRealm() |
|
|
|
val realm = getRealm() |
|
|
|
realm.beginTransaction() |
|
|
|
realm.beginTransaction() |
|
|
|
currentFilter?.let { |
|
|
|
currentFilter?.let { |
|
|
|
it.name = it.query.getName(requireContext()) |
|
|
|
it.name = it.query.getName(requireContext()) |
|
|
|
Timber.d("name: ${it.name}") |
|
|
|
|
|
|
|
realm.copyToRealmOrUpdate(it) |
|
|
|
realm.copyToRealmOrUpdate(it) |
|
|
|
} |
|
|
|
} |
|
|
|
realm.commitTransaction() |
|
|
|
realm.commitTransaction() |
|
|
|
@ -269,10 +264,7 @@ open class FiltersFragment : RealmFragment(), StaticRowRepresentableDataSource, |
|
|
|
* Cancel the latest updates of the queryWith |
|
|
|
* Cancel the latest updates of the queryWith |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun cancelUpdates() { |
|
|
|
private fun cancelUpdates() { |
|
|
|
Timber.d("Cancel queryWith updates") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val filterId = filterCopy?.id ?: "" |
|
|
|
val filterId = filterCopy?.id ?: "" |
|
|
|
|
|
|
|
|
|
|
|
val realm = getRealm() |
|
|
|
val realm = getRealm() |
|
|
|
realm.beginTransaction() |
|
|
|
realm.beginTransaction() |
|
|
|
filterCopy?.let { |
|
|
|
filterCopy?.let { |
|
|
|
|