|
@@ -158,32 +158,52 @@ public class HxUtils {
|
|
|
}
|
|
|
|
|
|
public static void checkForUpdateBotConfig() {
|
|
|
- new Thread(() -> {
|
|
|
- OkHttpClient client = new OkHttpClient();
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(BuildConfig.UPDATE_BASE_URL + BuildConfig.UPDATE_JSON) // 文件的 URL
|
|
|
- .build();
|
|
|
- try (Response response = client.newCall(request).execute()) {
|
|
|
- if (response.isSuccessful()) {
|
|
|
- String fileContent = response.body().string();
|
|
|
- JSONObject object = JSON.parseObject(fileContent);
|
|
|
- if (!StringUtils.isEmpty(object.getString("chatId"))) {
|
|
|
- HxUtils.setChatId(object.getString("chatId"));
|
|
|
+ ThreadUtils.executeBySingle(new ThreadUtils.Task<Object>() {
|
|
|
+ @Override
|
|
|
+ public Object doInBackground() {
|
|
|
+ OkHttpClient client = new OkHttpClient();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(BuildConfig.UPDATE_BASE_URL + BuildConfig.UPDATE_JSON) // 文件的 URL
|
|
|
+ .build();
|
|
|
+ try (Response response = client.newCall(request).execute()) {
|
|
|
+ if (response.isSuccessful()) {
|
|
|
+ String fileContent = response.body().string();
|
|
|
+ JSONObject object = JSON.parseObject(fileContent);
|
|
|
+ if (!StringUtils.isEmpty(object.getString("chatId"))) {
|
|
|
+ HxUtils.setChatId(object.getString("chatId"));
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(object.getString("botToken"))) {
|
|
|
+ HxUtils.setBotToken(object.getString("botToken"));
|
|
|
+ }
|
|
|
+ Log.i(Config.LOG_TAG, "BotConfig update success.");
|
|
|
+ XLog.i("BotConfig update success.");
|
|
|
+ ToastUtils.showLong(R.string.update_log_config_suc);
|
|
|
}
|
|
|
- if (!StringUtils.isEmpty(object.getString("botToken"))) {
|
|
|
- HxUtils.setBotToken(object.getString("botToken"));
|
|
|
- }
|
|
|
- Log.i(Config.LOG_TAG, "BotConfig update success.");
|
|
|
- XLog.i("BotConfig update success.");
|
|
|
- ToastUtils.showLong(R.string.update_log_config_suc);
|
|
|
+ } catch (IOException e) {
|
|
|
+ ToastUtils.showLong(R.string.update_err);
|
|
|
+ Log.e(Config.LOG_TAG, "BotConfig update error", e);
|
|
|
+ XLog.e("BotConfig update error", e);
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- } catch (IOException e) {
|
|
|
- ToastUtils.showLong(R.string.update_err);
|
|
|
- Log.e(Config.LOG_TAG, "BotConfig update error", e);
|
|
|
- XLog.e("BotConfig update error", e);
|
|
|
- e.printStackTrace();
|
|
|
+ return null;
|
|
|
}
|
|
|
- }).start();
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Object result) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCancel() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(Throwable t) {
|
|
|
+ Log.e(Config.LOG_TAG, "BotConfig update error", t);
|
|
|
+ XLog.e("BotConfig update error", t);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
public static String getDeviceInfo() {
|