Initial commit
This commit is contained in:
153
sources/com/ubt/jimu/pack/repository/PackageRepository.java
Normal file
153
sources/com/ubt/jimu/pack/repository/PackageRepository.java
Normal file
@@ -0,0 +1,153 @@
|
||||
package com.ubt.jimu.pack.repository;
|
||||
|
||||
import android.content.Context;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.ubt.jimu.base.db.robot.PackageDbHandler;
|
||||
import com.ubt.jimu.base.entities.ApiResult;
|
||||
import com.ubt.jimu.base.entities.Constant;
|
||||
import com.ubt.jimu.base.entities.Package;
|
||||
import com.ubt.jimu.base.http.ApiClient;
|
||||
import com.ubt.jimu.base.http.ApiConstants;
|
||||
import com.ubt.jimu.base.http.ApiResponse;
|
||||
import com.ubt.jimu.base.http.service.PackageRobotService;
|
||||
import com.ubt.jimu.utils.NetWorkUtil;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.functions.BiFunction;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.functions.Function;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class PackageRepository {
|
||||
public static Observable<List<Package>> a(Context context) {
|
||||
try {
|
||||
if (!NetWorkUtil.b(context)) {
|
||||
return Observable.create(new ObservableOnSubscribe<List<Package>>() { // from class: com.ubt.jimu.pack.repository.PackageRepository.1
|
||||
@Override // io.reactivex.ObservableOnSubscribe
|
||||
public void subscribe(ObservableEmitter<List<Package>> observableEmitter) throws Exception {
|
||||
List<Package> packageList = PackageDbHandler.getPackageList();
|
||||
if (packageList == null || packageList.size() == 0) {
|
||||
observableEmitter.onError(new Throwable(" "));
|
||||
} else {
|
||||
observableEmitter.onNext(packageList);
|
||||
}
|
||||
observableEmitter.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
Observable<List<Package>> create = Observable.create(new ObservableOnSubscribe<List<Package>>() { // from class: com.ubt.jimu.pack.repository.PackageRepository.2
|
||||
@Override // io.reactivex.ObservableOnSubscribe
|
||||
public void subscribe(ObservableEmitter<List<Package>> observableEmitter) throws Exception {
|
||||
observableEmitter.onNext(PackageDbHandler.getPackageList());
|
||||
observableEmitter.onComplete();
|
||||
}
|
||||
});
|
||||
ObservableSource map = ((PackageRobotService) ApiClient.getService(PackageRobotService.class)).getPackage(ApiConstants.getBasicParams()).map(new Function<ApiResult<Package>, List<Package>>() { // from class: com.ubt.jimu.pack.repository.PackageRepository.3
|
||||
@Override // io.reactivex.functions.Function
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public List<Package> apply(ApiResult<Package> apiResult) throws Exception {
|
||||
return apiResult.getModels();
|
||||
}
|
||||
});
|
||||
return map == null ? create : Observable.zip(map, create, new BiFunction<List<Package>, List<Package>, List<Package>>() { // from class: com.ubt.jimu.pack.repository.PackageRepository.5
|
||||
@Override // io.reactivex.functions.BiFunction
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public List<Package> apply(List<Package> list, List<Package> list2) throws Exception {
|
||||
return PackageRepository.a(list, list2);
|
||||
}
|
||||
}).doAfterNext(new Consumer<List<Package>>() { // from class: com.ubt.jimu.pack.repository.PackageRepository.4
|
||||
@Override // io.reactivex.functions.Consumer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void accept(List<Package> list) throws Exception {
|
||||
PackageDbHandler.saveOrUpdate(list);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Observable<ApiResult<Package>> b() {
|
||||
Map<String, String> basicParams = ApiConstants.getBasicParams();
|
||||
basicParams.put(Constant.SelectRobot.PACKAGE_NAME_KEY, "Astrobot");
|
||||
return ((PackageRobotService) ApiClient.getService(PackageRobotService.class)).getPackage(basicParams);
|
||||
}
|
||||
|
||||
public static List<Package> a(List<Package> list, List<Package> list2) {
|
||||
if (list == null || list.size() == 0) {
|
||||
return list2;
|
||||
}
|
||||
if (list2 != null && list2.size() > 0) {
|
||||
for (Package r0 : list2) {
|
||||
if (r0.getPlayed() >= 1) {
|
||||
Iterator<Package> it = list.iterator();
|
||||
while (true) {
|
||||
if (it.hasNext()) {
|
||||
Package next = it.next();
|
||||
if (next.getId() == r0.getId()) {
|
||||
next.setPlayed(r0.getPlayed());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static Observable<ApiResult<Package>> a() {
|
||||
Map<String, String> basicParams = ApiConstants.getBasicParams();
|
||||
basicParams.put(Constant.SelectRobot.PACKAGE_NAME_KEY, "Unicorn");
|
||||
return ((PackageRobotService) ApiClient.getService(PackageRobotService.class)).getPackage(basicParams);
|
||||
}
|
||||
|
||||
public static Observable<List<Package>> a(Context context, BarcodeFormat barcodeFormat, String str) {
|
||||
List<Package> findByEan;
|
||||
if (!BarcodeFormat.EAN_13.equals(barcodeFormat) && !BarcodeFormat.EAN_8.equals(barcodeFormat)) {
|
||||
if (!BarcodeFormat.UPC_A.equals(barcodeFormat) && !BarcodeFormat.UPC_E.equals(barcodeFormat)) {
|
||||
return null;
|
||||
}
|
||||
findByEan = PackageDbHandler.findByUpc(str);
|
||||
} else {
|
||||
findByEan = PackageDbHandler.findByEan(str);
|
||||
}
|
||||
if (findByEan != null && findByEan.size() > 0) {
|
||||
return Observable.just(findByEan);
|
||||
}
|
||||
Map<String, String> basicParams = ApiConstants.getBasicParams();
|
||||
if (!BarcodeFormat.EAN_13.equals(barcodeFormat) && !BarcodeFormat.EAN_8.equals(barcodeFormat)) {
|
||||
if (!BarcodeFormat.UPC_A.equals(barcodeFormat) && !BarcodeFormat.UPC_E.equals(barcodeFormat)) {
|
||||
return null;
|
||||
}
|
||||
basicParams.put("UPC", str);
|
||||
} else {
|
||||
basicParams.put("EAN", str);
|
||||
}
|
||||
return ((PackageRobotService) ApiClient.getService(PackageRobotService.class)).findPackage(basicParams).map(new Function<ApiResponse<Package>, List<Package>>() { // from class: com.ubt.jimu.pack.repository.PackageRepository.7
|
||||
@Override // io.reactivex.functions.Function
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public List<Package> apply(ApiResponse<Package> apiResponse) throws Exception {
|
||||
if (apiResponse == null || !apiResponse.isStatus()) {
|
||||
return null;
|
||||
}
|
||||
ArrayList arrayList = new ArrayList();
|
||||
arrayList.add(apiResponse.getModels());
|
||||
return arrayList;
|
||||
}
|
||||
}).doAfterNext(new Consumer<List<Package>>() { // from class: com.ubt.jimu.pack.repository.PackageRepository.6
|
||||
@Override // io.reactivex.functions.Consumer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void accept(List<Package> list) throws Exception {
|
||||
PackageDbHandler.saveOrUpdate(list);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
104
sources/com/ubt/jimu/pack/repository/RobotRepository.java
Normal file
104
sources/com/ubt/jimu/pack/repository/RobotRepository.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package com.ubt.jimu.pack.repository;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import com.ubt.jimu.base.db.robot.PartFileInfoDbHandler;
|
||||
import com.ubt.jimu.base.db.robot.RobotDbHandler;
|
||||
import com.ubt.jimu.base.db.robot.RobotPackageDbHandler;
|
||||
import com.ubt.jimu.base.entities.ApiResult;
|
||||
import com.ubt.jimu.base.entities.Constant;
|
||||
import com.ubt.jimu.base.entities.PartFileInfo;
|
||||
import com.ubt.jimu.base.entities.Robot;
|
||||
import com.ubt.jimu.base.entities.RobotPackage;
|
||||
import com.ubt.jimu.base.http.ApiClient;
|
||||
import com.ubt.jimu.base.http.ApiConstants;
|
||||
import com.ubt.jimu.base.http.service.PackageRobotService;
|
||||
import com.ubt.jimu.utils.NetWorkUtil;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.functions.BiFunction;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.functions.Function;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class RobotRepository {
|
||||
public static Observable<List<Robot>> a(Context context, final long j, int i, int i2) {
|
||||
if (!NetWorkUtil.b(context)) {
|
||||
return Observable.create(new ObservableOnSubscribe<List<Robot>>() { // from class: com.ubt.jimu.pack.repository.RobotRepository.1
|
||||
@Override // io.reactivex.ObservableOnSubscribe
|
||||
public void subscribe(ObservableEmitter<List<Robot>> observableEmitter) throws Exception {
|
||||
List<Robot> robotList = RobotDbHandler.getRobotList(j);
|
||||
if (robotList == null || robotList.size() == 0) {
|
||||
observableEmitter.onError(new Throwable(" "));
|
||||
} else {
|
||||
observableEmitter.onNext(robotList);
|
||||
}
|
||||
observableEmitter.onComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
Observable create = Observable.create(new ObservableOnSubscribe<List<Robot>>() { // from class: com.ubt.jimu.pack.repository.RobotRepository.2
|
||||
@Override // io.reactivex.ObservableOnSubscribe
|
||||
public void subscribe(ObservableEmitter<List<Robot>> observableEmitter) throws Exception {
|
||||
List<Robot> robotList = RobotDbHandler.getRobotList(j);
|
||||
if (robotList != null) {
|
||||
Log.i("dbObservable-DbHandler", robotList.toString());
|
||||
observableEmitter.onNext(robotList);
|
||||
} else {
|
||||
observableEmitter.onNext(new ArrayList());
|
||||
}
|
||||
observableEmitter.onComplete();
|
||||
}
|
||||
});
|
||||
HashMap hashMap = new HashMap();
|
||||
hashMap.put(Constant.SelectRobot.PACKAGEID_KEY, String.valueOf(j));
|
||||
hashMap.put("pageNum", String.valueOf(i2));
|
||||
hashMap.put("pageSize", String.valueOf(i));
|
||||
hashMap.putAll(ApiConstants.getBasicParams());
|
||||
return Observable.zip(create, ((PackageRobotService) ApiClient.getService(PackageRobotService.class)).getRobotByPackage(hashMap).map(new Function<ApiResult<Robot>, List<Robot>>() { // from class: com.ubt.jimu.pack.repository.RobotRepository.3
|
||||
@Override // io.reactivex.functions.Function
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public List<Robot> apply(ApiResult<Robot> apiResult) throws Exception {
|
||||
return apiResult.getModels();
|
||||
}
|
||||
}), new BiFunction<List<Robot>, List<Robot>, List<Robot>>() { // from class: com.ubt.jimu.pack.repository.RobotRepository.5
|
||||
@Override // io.reactivex.functions.BiFunction
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public List<Robot> apply(List<Robot> list, List<Robot> list2) throws Exception {
|
||||
Iterator<Robot> it = list2.iterator();
|
||||
while (it.hasNext()) {
|
||||
List<PartFileInfo> componentsFileInfos = it.next().getComponentsFileInfos();
|
||||
if (componentsFileInfos != null && componentsFileInfos.size() != 0) {
|
||||
PartFileInfoDbHandler.insertOrUpdate(componentsFileInfos);
|
||||
}
|
||||
}
|
||||
return RobotRepository.a(list2, list);
|
||||
}
|
||||
}).doAfterNext(new Consumer<List<Robot>>() { // from class: com.ubt.jimu.pack.repository.RobotRepository.4
|
||||
@Override // io.reactivex.functions.Consumer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void accept(List<Robot> list) throws Exception {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
for (Robot robot : list) {
|
||||
RobotPackage robotPackage = new RobotPackage();
|
||||
robotPackage.setId(j + robot.getModelId());
|
||||
robotPackage.setPackageId(j);
|
||||
robotPackage.setRobotId(robot.getModelId());
|
||||
arrayList.add(robotPackage);
|
||||
}
|
||||
Log.i("getRobots", arrayList.toString());
|
||||
RobotPackageDbHandler.saveOrUpdate(arrayList);
|
||||
RobotDbHandler.saveOrUpdate(list);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static List<Robot> a(List<Robot> list, List<Robot> list2) {
|
||||
return (list == null || list.size() == 0) ? list2 : list;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user