Rewrite backup and restore - part 5

pull/586/head
FongMi 12 months ago
parent bf6b7e1ee9
commit 3b1033aec5
  1. 10
      app/src/main/java/com/fongmi/android/tv/bean/Backup.java
  2. 8
      app/src/main/java/com/fongmi/android/tv/db/AppDatabase.java

@ -33,11 +33,11 @@ public class Backup {
public void restore() {
AppDatabase.get().clearAllTables();
for (History item : getHistory()) item.save();
for (Config item : getConfig()) item.save();
for (Site item : getSite()) item.save();
for (Live item : getLive()) item.save();
for (Keep item : getKeep()) item.save();
AppDatabase.get().getKeepDao().insertOrUpdate(getKeep());
AppDatabase.get().getLiveDao().insertOrUpdate(getLive());
AppDatabase.get().getSiteDao().insertOrUpdate(getSite());
AppDatabase.get().getConfigDao().insertOrUpdate(getConfig());
AppDatabase.get().getHistoryDao().insertOrUpdate(getHistory());
}
public static Backup objectFrom(String json) {

@ -64,14 +64,14 @@ public abstract class AppDatabase extends RoomDatabase {
public static void restore(File file, com.fongmi.android.tv.impl.Callback callback) {
App.execute(() -> {
File cache = Path.cache("restore");
FileUtil.gzipDecompress(file, cache);
Backup backup = Backup.objectFrom(Path.read(cache));
File restore = Path.cache("restore");
FileUtil.gzipDecompress(file, restore);
Backup backup = Backup.objectFrom(Path.read(restore));
if (backup.getConfig().isEmpty()) {
App.post(callback::error);
} else {
backup.restore();
Path.clear(cache);
Path.clear(restore);
App.post(callback::success);
}
});

Loading…
Cancel
Save