@@ -14,7 +14,7 @@ import com.prembros.swapi.sample_components.*
1414import com.prembros.swapi.sample_components.adapter.*
1515import com.prembros.swapi.sample_components.data.EndlessRecyclerViewScrollListener
1616import com.swapi.StarWarsSdk
17- import com.swapi.models.SWList
17+ import com.swapi.models.*
1818import com.swapi.network.RetrofitCallBack
1919import retrofit2.Response
2020import timber.log.Timber
@@ -48,7 +48,7 @@ abstract class SwapiListActivity(@LayoutRes contentLayoutId: Int = R.layout.acti
4848 const val LIST_TYPE = " list_type"
4949 }
5050
51- @Suppress( " DEPRECATION " ) override fun onCreate (savedInstanceState : Bundle ? ) {
51+ override fun onCreate (savedInstanceState : Bundle ? ) {
5252 super .onCreate(savedInstanceState)
5353 WindowCompat .setDecorFitsSystemWindows(window, false )
5454 page = 1
@@ -96,10 +96,19 @@ abstract class SwapiListActivity(@LayoutRes contentLayoutId: Int = R.layout.acti
9696 }
9797 }
9898
99+ @Suppress(" UNCHECKED_CAST" )
99100 private fun <DATA > retrofitCallBack (): RetrofitCallBack <SWList <DATA >>.() -> Unit = {
100101 onResponse {
101102 loaderProgressBar?.visibility = View .GONE
102103 onDataResponse(it)
104+ when (listType) {
105+ LIST_FILMS -> onAllFilmsResponse(it as Response <SWList <Film >>)
106+ LIST_PEOPLE -> onAllPeopleResponse(it as Response <SWList <People >>)
107+ LIST_PLANETS -> onAllPlanetsResponse(it as Response <SWList <Planet >>)
108+ LIST_SPECIES -> onAllSpeciesResponse(it as Response <SWList <Species >>)
109+ LIST_STARSHIPS -> onAllStarshipsResponse(it as Response <SWList <Starship >>)
110+ LIST_VEHICLES -> onAllVehiclesResponse(it as Response <SWList <Vehicle >>)
111+ }
103112 }
104113 // Called on failed response from server
105114 onFailure {
@@ -115,8 +124,41 @@ abstract class SwapiListActivity(@LayoutRes contentLayoutId: Int = R.layout.acti
115124
116125 abstract fun initRecyclerView ()
117126
127+ /* *
128+ * Common callback for all Swapi responses
129+ */
118130 abstract fun <DATA > onDataResponse (it : Response <SWList <DATA >>)
119131
132+ /* *
133+ * Dedicated callback for all [Film] response
134+ */
135+ open fun onAllFilmsResponse (response : Response <SWList <Film >>) {}
136+
137+ /* *
138+ * Dedicated callback for all [People] response
139+ */
140+ open fun onAllPeopleResponse (response : Response <SWList <People >>) {}
141+
142+ /* *
143+ * Dedicated callback for all [Planet] response
144+ */
145+ open fun onAllPlanetsResponse (response : Response <SWList <Planet >>) {}
146+
147+ /* *
148+ * Dedicated callback for all [Species] response
149+ */
150+ open fun onAllSpeciesResponse (response : Response <SWList <Species >>) {}
151+
152+ /* *
153+ * Dedicated callback for all [Starship] response
154+ */
155+ open fun onAllStarshipsResponse (response : Response <SWList <Starship >>) {}
156+
157+ /* *
158+ * Dedicated callback for all [Vehicle] response
159+ */
160+ open fun onAllVehiclesResponse (response : Response <SWList <Vehicle >>) {}
161+
120162 open fun onDataFailure (throwable : Throwable ) {
121163 Timber .e(throwable)
122164 }
0 commit comments