Guest User

Untitled

a guest
Mar 11th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.70 KB | None | 0 0
  1.     override fun getCarTrims(
  2.         makeId: String?,
  3.         subModelId: String?,
  4.         anyString: String
  5.     ): Flowable<Pair<Array<String>, MutableList<CarTrimsResponse>>> {
  6.  
  7.         if (makeId != null) {
  8.             return database.carTrimsDao().getAllByMakeId(makeId).map { result ->
  9.                 val carTrimsMutable = result.toMutableList()
  10.  
  11.                 carTrimsMutable.add(
  12.                     0, CarTrimsResponse(
  13.                         name = anyString, id = null
  14.                     )
  15.                 )
  16.  
  17.                 val trimNames = carTrimsMutable.mapNotNull {
  18.                     it.name.takeUnless {
  19.                         it.isEmpty()
  20.                     }
  21.                 }.toTypedArray()
  22.  
  23.                 Pair(trimNames, carTrimsMutable)
  24.             }
  25.         } else if (subModelId != null) {
  26.             database.carSubModelsDao().findById(subModelId).map { subModel ->
  27.                 database.carTrimsDao().getAllByIds(subModel.trim_ids.map { it.toInt() }
  28.                     .toIntArray())
  29.                     .map { trims ->
  30.                         val carTrimsMutable = trims.toMutableList()
  31.  
  32.                         carTrimsMutable.add(
  33.                             0, CarTrimsResponse(
  34.                                 name = anyString, id = null
  35.                             )
  36.                         )
  37.  
  38.                         val trimNames = carTrimsMutable.mapNotNull {
  39.                             it.name.takeUnless {
  40.                                 it.isEmpty()
  41.                             }
  42.                         }.toTypedArray()
  43.  
  44.                         //RESULT OF INTEREST
  45.                         Pair(trimNames, carTrimsMutable)
  46.                     }
  47.             }
  48.         }
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment