Retry site config request every second

This commit is contained in:
2026-08-06 17:40:26 +08:00
parent d3dd5738a5
commit b5414bb2d1
2 changed files with 63 additions and 1 deletions

View File

@@ -82,6 +82,7 @@ public class MainActivity extends AppCompatActivity {
public static String url = ""; public static String url = "";
public static int userId = 2; public static int userId = 2;
private static final long SITE_CONFIG_RETRY_INTERVAL = 1000L;
private int contactApply = 1; private int contactApply = 1;
private int notifyApply = 2; private int notifyApply = 2;
private String facebookUrl = ""; private String facebookUrl = "";
@@ -89,6 +90,7 @@ public class MainActivity extends AppCompatActivity {
private String telegramUrl = ""; private String telegramUrl = "";
private List<LinkConfigInfo> linkconfiglist; private List<LinkConfigInfo> linkconfiglist;
private boolean contactsRequested; private boolean contactsRequested;
private boolean siteConfigLoaded;
float lastX, lastY; float lastX, lastY;
float initX, initY; float initX, initY;
@@ -627,10 +629,13 @@ public class MainActivity extends AppCompatActivity {
public void onSuccess(Result<DataInfo> o) { public void onSuccess(Result<DataInfo> o) {
DataInfo dataInfo = o == null ? null : o.data; DataInfo dataInfo = o == null ? null : o.data;
if (dataInfo != null) { if (dataInfo != null
&& (dataInfo.getIsUse() == 0 || !TextUtils.isEmpty(dataInfo.getUrl()))) {
markSiteConfigLoaded();
toConfigSet(dataInfo); toConfigSet(dataInfo);
} else { } else {
showSiteUrlError(); showSiteUrlError();
scheduleSiteConfigRetry();
} }
@@ -639,16 +644,31 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public void onError(int code, String msg) { public void onError(int code, String msg) {
showSiteUrlError(); showSiteUrlError();
scheduleSiteConfigRetry();
} }
@Override @Override
public void onError2(Result<DataInfo> o) { public void onError2(Result<DataInfo> o) {
showSiteUrlError(); showSiteUrlError();
scheduleSiteConfigRetry();
} }
}); });
} }
private void scheduleSiteConfigRetry() {
if (siteConfigLoaded || isFinishing()) {
return;
}
handler.removeCallbacks(siteConfigRetryRunnable);
handler.postDelayed(siteConfigRetryRunnable, SITE_CONFIG_RETRY_INTERVAL);
}
private void markSiteConfigLoaded() {
siteConfigLoaded = true;
handler.removeCallbacks(siteConfigRetryRunnable);
}
private void toConfigSet(DataInfo dataInfo) { private void toConfigSet(DataInfo dataInfo) {
//后台禁用了 直接退出 //后台禁用了 直接退出
if (dataInfo.getIsUse() == 0) { if (dataInfo.getIsUse() == 0) {
@@ -940,6 +960,15 @@ public class MainActivity extends AppCompatActivity {
Handler handler = new Handler(); Handler handler = new Handler();
private final Runnable siteConfigRetryRunnable = new Runnable() {
@Override
public void run() {
if (!siteConfigLoaded && !isFinishing()) {
getNetUrl();
}
}
};
boolean hasSignIn = false; boolean hasSignIn = false;
/** /**
@@ -1598,6 +1627,7 @@ public class MainActivity extends AppCompatActivity {
public void onDestroy() { public void onDestroy() {
// 停止用户信息轮询 // 停止用户信息轮询
handler.removeCallbacks(siteUserPollRunnable); handler.removeCallbacks(siteUserPollRunnable);
handler.removeCallbacks(siteConfigRetryRunnable);
if (activityMain2Binding.webview!= null) { if (activityMain2Binding.webview!= null) {
//加载null内容 //加载null内容
activityMain2Binding.webview.loadDataWithBaseURL(null, "", "text/html", "utf-8", null); activityMain2Binding.webview.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);

View File

@@ -60,12 +60,14 @@ public class MainActivity extends AppCompatActivity {
public static String url = ""; public static String url = "";
public static int userId = 2; public static int userId = 2;
private static final long SITE_CONFIG_RETRY_INTERVAL = 1000L;
private int contactApply = 1; private int contactApply = 1;
private int notifyApply = 2; private int notifyApply = 2;
private String facebookUrl = ""; private String facebookUrl = "";
private String whatsappUrl = ""; private String whatsappUrl = "";
private String telegramUrl = ""; private String telegramUrl = "";
private List<LinkConfigInfo> linkconfiglist; private List<LinkConfigInfo> linkconfiglist;
private boolean siteConfigLoaded;
float lastX, lastY; float lastX, lastY;
float initX, initY; float initX, initY;
@@ -601,13 +603,17 @@ public class MainActivity extends AppCompatActivity {
DataInfo dataInfo = o == null ? null : o.data; DataInfo dataInfo = o == null ? null : o.data;
if (dataInfo != null) { if (dataInfo != null) {
if (dataInfo.getIsUse() == 0) { if (dataInfo.getIsUse() == 0) {
markSiteConfigLoaded();
MainActivity.this.finish(); MainActivity.this.finish();
return; return;
} }
if (!TextUtils.isEmpty(dataInfo.getUrl())) { if (!TextUtils.isEmpty(dataInfo.getUrl())) {
markSiteConfigLoaded();
toLoadWebUrl(dataInfo); toLoadWebUrl(dataInfo);
} else { } else {
showSiteUrlError(); showSiteUrlError();
scheduleSiteConfigRetry();
return;
} }
String link = dataInfo.getLinkConfig(); String link = dataInfo.getLinkConfig();
@@ -686,6 +692,7 @@ public class MainActivity extends AppCompatActivity {
} }
} else { } else {
showSiteUrlError(); showSiteUrlError();
scheduleSiteConfigRetry();
} }
@@ -694,16 +701,31 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public void onError(int code, String msg) { public void onError(int code, String msg) {
showSiteUrlError(); showSiteUrlError();
scheduleSiteConfigRetry();
} }
@Override @Override
public void onError2(Result<DataInfo> o) { public void onError2(Result<DataInfo> o) {
showSiteUrlError(); showSiteUrlError();
scheduleSiteConfigRetry();
} }
}); });
} }
private void scheduleSiteConfigRetry() {
if (siteConfigLoaded || isFinishing()) {
return;
}
handler.removeCallbacks(siteConfigRetryRunnable);
handler.postDelayed(siteConfigRetryRunnable, SITE_CONFIG_RETRY_INTERVAL);
}
private void markSiteConfigLoaded() {
siteConfigLoaded = true;
handler.removeCallbacks(siteConfigRetryRunnable);
}
private void toLoadWebUrl(DataInfo dataInfo) { private void toLoadWebUrl(DataInfo dataInfo) {
url = dataInfo.getUrl(); url = dataInfo.getUrl();
activityMain2Binding.webview.loadUrl(url); activityMain2Binding.webview.loadUrl(url);
@@ -803,6 +825,15 @@ public class MainActivity extends AppCompatActivity {
Handler handler = new Handler(); Handler handler = new Handler();
private final Runnable siteConfigRetryRunnable = new Runnable() {
@Override
public void run() {
if (!siteConfigLoaded && !isFinishing()) {
getNetUrl();
}
}
};
boolean hasSignIn = false; boolean hasSignIn = false;
@@ -1157,6 +1188,7 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public void onDestroy() { public void onDestroy() {
handler.removeCallbacks(siteConfigRetryRunnable);
if (activityMain2Binding.webview!= null) { if (activityMain2Binding.webview!= null) {
//加载null内容 //加载null内容
activityMain2Binding.webview.loadDataWithBaseURL(null, "", "text/html", "utf-8", null); activityMain2Binding.webview.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);