[app] Temporarily fix #169

This commit is contained in:
LoveSy 2021-02-23 08:43:08 +08:00
parent a556880228
commit ceb70aea3b
1 changed files with 24 additions and 16 deletions

View File

@ -25,6 +25,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -86,22 +87,29 @@ public class RepoLoader {
@Override @Override
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException { public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
ResponseBody body = response.body(); try {
if (body != null) { ResponseBody body = response.body();
String bodyString = body.string(); if (body != null) {
Gson gson = new Gson(); String bodyString = body.string();
Map<String, OnlineModule> modules = new HashMap<>(); Gson gson = new Gson();
OnlineModule[] repoModules = gson.fromJson(bodyString, OnlineModule[].class); Map<String, OnlineModule> modules = new HashMap<>();
Arrays.stream(repoModules).forEach(onlineModule -> modules.put(onlineModule.getName(), onlineModule)); OnlineModule[] repoModules = gson.fromJson(bodyString, OnlineModule[].class);
onlineModules = modules; Arrays.stream(repoModules).forEach(onlineModule -> modules.put(onlineModule.getName(), onlineModule));
Files.write(repoFile, bodyString.getBytes(StandardCharsets.UTF_8)); onlineModules = modules;
} Files.write(repoFile, bodyString.getBytes(StandardCharsets.UTF_8));
for (Listener listener : listeners) { }
listener.repoLoaded(); for (Listener listener : listeners) {
} listener.repoLoaded();
synchronized (this) { }
isLoading = false; synchronized (this) {
repoLoaded = true; isLoading = false;
repoLoaded = true;
}
} catch (Throwable e) {
if (e instanceof IOException)
throw e;
else
throw new IOException(e.getMessage(), e.getCause());
} }
} }
}); });