package com.application.zhangshi_app_android.model;
|
|
import androidx.annotation.NonNull;
|
import androidx.annotation.VisibleForTesting;
|
|
import com.android.app_base.base.model.BaseModel;
|
import com.application.zhangshi_app_android.model.source.HttpDataSource;
|
import com.application.zhangshi_app_android.model.source.LocalDataSource;
|
import com.application.zhangshi_app_android.model.source.http.HttpDataSourceImpl;
|
import com.application.zhangshi_app_android.model.source.local.LocalDataSourceImpl;
|
|
/**
|
* @author Ljj
|
* @date 2023.03.01. 20:58
|
* @desc 数据仓库,包含网络数据和本地数据
|
*/
|
public class DataRepository extends BaseModel implements HttpDataSource, LocalDataSource {
|
|
private volatile static DataRepository INSTANCE = null;
|
private final HttpDataSource mHttpDataSource;
|
private final LocalDataSource mLocalDataSource;
|
|
private DataRepository(@NonNull HttpDataSource httpDataSource,
|
@NonNull LocalDataSource localDataSource) {
|
this.mHttpDataSource = httpDataSource;
|
this.mLocalDataSource = localDataSource;
|
}
|
|
public static DataRepository getInstance() {
|
if (INSTANCE == null) {
|
synchronized (DataRepository.class) {
|
if (INSTANCE == null) {
|
INSTANCE = new DataRepository(HttpDataSourceImpl.getInstance(), LocalDataSourceImpl.getInstance());
|
}
|
}
|
}
|
return INSTANCE;
|
}
|
|
|
@Override
|
public void onCleared() {
|
INSTANCE = null;
|
}
|
}
|