|
|
|
@ -15,6 +15,8 @@ import androidx.annotation.Nullable;
@@ -15,6 +15,8 @@ import androidx.annotation.Nullable;
|
|
|
|
|
import androidx.core.app.ActivityCompat; |
|
|
|
|
import androidx.core.content.ContextCompat; |
|
|
|
|
|
|
|
|
|
import com.google.gson.JsonParser; |
|
|
|
|
|
|
|
|
|
import java.io.FileNotFoundException; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.io.OutputStream; |
|
|
|
@ -188,6 +190,11 @@ public class SettingFragment extends BaseFragment {
@@ -188,6 +190,11 @@ public class SettingFragment extends BaseFragment {
|
|
|
|
|
InputStream inputStream = getContext().getContentResolver().openInputStream(uri); |
|
|
|
|
|
|
|
|
|
String readStr = IoUtil.read(inputStream, StandardCharsets.UTF_8); |
|
|
|
|
if (!GsonUtil.isJson(readStr)) { |
|
|
|
|
XLog.d("非json: {}", readStr); |
|
|
|
|
Toasts.shortShow(getContext(), "文件内容非JSON格式"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> list = GsonUtil.toBean(readStr, List.class); |
|
|
|
|
if (CollUtil.isEmpty(list)) { |
|
|
|
@ -213,6 +220,16 @@ public class SettingFragment extends BaseFragment {
@@ -213,6 +220,16 @@ public class SettingFragment extends BaseFragment {
|
|
|
|
|
private void restoreProjectRecord(List<ProjectRecord> projectRecordList) { |
|
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(projectRecordList)) { |
|
|
|
|
|
|
|
|
|
insertProject(projectRecordList); |
|
|
|
|
|
|
|
|
|
insertRecord(projectRecordList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void insertRecord(List<ProjectRecord> projectRecordList) { |
|
|
|
|
for (ProjectRecord projectRecord : projectRecordList) { |
|
|
|
|
|
|
|
|
|
List<Record> recordList = projectRecord.getRecordList(); |
|
|
|
@ -224,51 +241,59 @@ public class SettingFragment extends BaseFragment {
@@ -224,51 +241,59 @@ public class SettingFragment extends BaseFragment {
|
|
|
|
|
.subscribe(new CompletableObserver() { |
|
|
|
|
@Override |
|
|
|
|
public void onSubscribe(Disposable d) { |
|
|
|
|
XLog.d("restore onSubscribe"); |
|
|
|
|
XLog.d("restore insertRecord onSubscribe"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onComplete() { |
|
|
|
|
XLog.d("restore onComplete"); |
|
|
|
|
XLog.d("restore insertRecord onComplete"); |
|
|
|
|
BizGlobal.buildCache(); |
|
|
|
|
Toasts.shortShow(getContext(), "恢复打卡记录成功"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onError(Throwable e) { |
|
|
|
|
XLog.d("restore onError: {}", e.getMessage(), e); |
|
|
|
|
XLog.d("restore insertRecord onError: {}", e.getMessage(), e); |
|
|
|
|
Toasts.shortShow(getContext(),"恢复打卡记录出错: {}", e.getMessage()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 插入project
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void insertProject(List<ProjectRecord> projectRecordList) { |
|
|
|
|
List<Project> projectList = projectRecordList.stream().map(item -> { |
|
|
|
|
Project project = new Project(); |
|
|
|
|
BeanUtil.copyProperties(projectRecord, project); |
|
|
|
|
Completable completable = DBManager.INSTANCE.projectDao().insertAll(project); |
|
|
|
|
BeanUtil.copyProperties(item, project); |
|
|
|
|
return project; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
// 插入project
|
|
|
|
|
Completable completable = DBManager.INSTANCE.projectDao().insertAll(projectList); |
|
|
|
|
completable.subscribeOn(Schedulers.io()) |
|
|
|
|
.observeOn(AndroidSchedulers.mainThread()) |
|
|
|
|
.subscribe(new CompletableObserver() { |
|
|
|
|
@Override |
|
|
|
|
public void onSubscribe(Disposable d) { |
|
|
|
|
|
|
|
|
|
XLog.d("restore insertProject onComplete"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onComplete() { |
|
|
|
|
XLog.d("restore insertProject onComplete"); |
|
|
|
|
BizGlobal.buildCache(); |
|
|
|
|
Toasts.shortShow(getContext(), "恢复打卡项成功"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onError(Throwable e) { |
|
|
|
|
|
|
|
|
|
XLog.d("restore insertProject onError: {}", e.getMessage(), e); |
|
|
|
|
Toasts.shortShow(getContext(),"恢复打卡项出错: {}", e.getMessage()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void backupResult(@NonNull Intent data) { |
|
|
|
|
Uri fileUri = data.getData(); |
|
|
|
|
|
|
|
|
|