@GET
fun checkUrl(@Url url: String):Observable<String>
fun getItems(){
_networkState.postValue(NetworkState.LOADING)
try {
compositeDisposable.add(
apiService.getItems()
.observeOn(Schedulers.io())
.subscribeOn(Schedulers.io())
.flatMapObservable { items ->
Observable.fromIterable(items)
.switchMap {
apiService.checkUrl(it)
.observeOn(Schedulers.io())
.subscribeOn(Schedulers.io())
.onErrorResumeNext (Observable.just("empty_url"))
}
}
.toList()
.subscribe({ urlList ->
Log.i(TAG, "getItems: $urlList")
val itemsResponse = itemsResponseConverter.getItemResponse(urlList)
_downloadedItemsResponse.postValue(itemsResponse)
_networkState.postValue(NetworkState.LOADED)
},
{
Log.i(TAG, "Error - $it")
_networkState.postValue(NetworkState.ERROR)
})
)
}catch (e: Exception) {
Log.e(TAG, e.message.toString())
}
}
interface AlefApiService {
@GET("task-m-001/list.php")
fun getItems(): Single<List<String>>
}
@PreviewScope
class MediaPreviewAdapter @Inject constructor(
val providerFactory: ViewModelProviderFactory,
val picasso: Picasso,
val searchParams: SearchParams,
val previewFragment: PreviewMediaFragment
) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
val viewModel =
ViewModelProviders.of(previewFragment, providerFactory)
.get(PreviewMediaViewModel::class.java)
...
}
@PreviewScope
@Subcomponent(modules = [ViewModelFactoryModule::class, PreviewMediaViewModulesModule::class, PreviewModule::class])
interface PreviewComponent {
@Subcomponent.Factory
interface Factory {
fun create(@BindsInstance fragment: PreviewMediaFragment): PreviewComponent
}
fun inject(previewMediaFragment: PreviewMediaFragment)
}
override fun onAttach(context: Context) {
super.onAttach(context)
Log.i(TAG, "onAttach: ")
(requireActivity().application as BaseApplication).appComponent.getPreviewComponent()
.create(this).inject(this)
}
class SearchSettingsFragment @Inject constructor() : DialogFragment() {
private var activityContract: Activity? = null
@Inject
lateinit var searchParams: SearchParams
...
}
private val _downloadedMediaDetailsResponse = MutableLiveData<MediaDetail>()
val downloadedMediaResponse: LiveData<MediaDetail>
get() = _downloadedMediaDetailsResponse