package com.github.hunter0x7c7.sync.model.data.source.http;
|
|
|
import com.github.hunter0x7c7.sync.model.bean.PhotoBean;
|
import com.github.hunter0x7c7.sync.model.data.result.ResultEntity;
|
import com.github.hunter0x7c7.sync.model.data.source.HttpDataSource;
|
import com.github.hunter0x7c7.sync.model.server.ServiceApi;
|
import io.reactivex.Observable;
|
|
import java.util.concurrent.TimeUnit;
|
|
/**
|
* ================================================================
|
* <p>
|
* 版 权: Hunter(c)2020
|
* <p>
|
* 作 者: Hunter
|
* <p>
|
* 版 本: V1.0
|
* <p>
|
* 创建日期: 2020/7/30 16:19
|
* <p>
|
* 描 述:网络数据源
|
* <p>
|
* <p>
|
* 修订历史:
|
* <p>
|
* ================================================================
|
*/
|
public class HttpDataSourceImpl implements HttpDataSource {
|
|
private ServiceApi apiService;
|
private volatile static HttpDataSourceImpl sInstance = null;
|
|
private HttpDataSourceImpl(ServiceApi apiService) {
|
this.apiService = apiService;
|
}
|
|
public static HttpDataSourceImpl getInstance(ServiceApi apiService) {
|
if (sInstance == null) {
|
synchronized (HttpDataSourceImpl.class) {
|
if (sInstance == null) {
|
sInstance = new HttpDataSourceImpl(apiService);
|
}
|
}
|
}
|
return sInstance;
|
}
|
|
public static void destroyInstance() {
|
sInstance = null;
|
}
|
|
public void setServiceApi(ServiceApi apiService) {
|
this.apiService = apiService;
|
}
|
|
@Override
|
public Observable<ResultEntity<PhotoBean>> getImageList(String mode, int index, int size, String key) {
|
return apiService.getImageList(mode, (index + 1) * size, size, key)
|
.delay(300, TimeUnit.MILLISECONDS); //延迟
|
}
|
|
}
|