Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.82 KB | None | 0 0
  1.         val currentFilters = arrayOf(
  2.             Utils.MutablePair(
  3.                 getString(R.string.filtering_option_official_dealer),
  4.                 false
  5.             ),
  6.             Utils.MutablePair(
  7.                 getString(R.string.filtering_option_non_official_dealer),
  8.                 false
  9.             ),
  10.             Utils.MutablePair(
  11.                 getString(R.string.filtering_option_one_year_lease_duration),
  12.                 false
  13.             ),
  14.             Utils.MutablePair(
  15.                 getString(R.string.filtering_option_two_year_lease_duration),
  16.                 false
  17.             ),
  18.             Utils.MutablePair(
  19.                 getString(R.string.filtering_option_three_year_lease_duration),
  20.                 false
  21.             )
  22.         )
  23.  
  24.         val predicates = listOf<(CarLeasingResponse) -> Boolean>(
  25.             { listing ->
  26.                 if (currentFilters[0].active) {
  27.                     listing.tags != null && listing.tags.isNotEmpty() && listing.tags[0] == getString(
  28.                         R.string.filtering_option_official_dealer
  29.                     )
  30.                 } else {
  31.                     false
  32.                 }
  33.             }, { listing ->
  34.                 if (currentFilters[1].active) {
  35.                     listing.tags != null && listing.tags.isNotEmpty() && listing.tags[0] != getString(
  36.                         R.string.filtering_option_official_dealer
  37.                     )
  38.                 } else {
  39.                     false
  40.                 }
  41.             },
  42.             { listing ->
  43.                 if (currentFilters[2].active) {
  44.                     listing.lease_duration?.get(0).toString().toInt() == 1
  45.                 } else {
  46.                     false
  47.                 }
  48.             },
  49.             { listing ->
  50.                 if (currentFilters[3].active) {
  51.                     listing.lease_duration?.get(
  52.                         0
  53.                     ).toString().toInt() == 2
  54.                 } else {
  55.                     false
  56.                 }
  57.             },
  58.             { listing ->
  59.                 if (currentFilters[4].active) {
  60.                     listing.lease_duration?.get(
  61.                         0
  62.                     ).toString().toInt() == 3
  63.                 } else {
  64.                     false
  65.                 }
  66.             }
  67.         )
  68.  
  69.         val filteringOptionsAdapter = FilterResultsRecyclerAdapter(currentFilters) {
  70.             displayLeasingCars(
  71.                 ArrayList(
  72.                     originalListings.filter { listing ->
  73.                         predicates.all { predicate ->
  74.                             predicate.invoke(
  75.                                 listing
  76.                             )
  77.                         }
  78.                     }
  79.                 )
  80.                 , false
  81.             )
  82.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement