Hunter0x7c7
2023-08-11 198dd6e1b210758867eed417bf6e00ba733d47c0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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); //延迟
    }
 
}