增加启动超时时间为10s

pull/21/head
fengyuecanzhu 3 years ago
parent 9f1d062889
commit 41078c2c46
  1. 34
      app/src/main/java/xyz/fycz/myreader/ui/activity/SplashActivity.java
  2. 2
      app/version_code.properties

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
@ -53,7 +54,8 @@ public class SplashActivity extends BaseActivity<ActivitySplashBinding> {
private boolean hasStart = false; private boolean hasStart = false;
private boolean startToAd = false; private boolean startToAd = false;
private static final String INTENT_TO_AD = "startToAd"; private static final String INTENT_TO_AD = "startToAd";
private int timeOut = 10;
private Handler handler = new Handler();
//创建子线程 //创建子线程
private Runnable start = () -> { private Runnable start = () -> {
@ -71,23 +73,7 @@ public class SplashActivity extends BaseActivity<ActivitySplashBinding> {
} }
}; };
private Thread countTime = new Thread() { private Runnable adTimeOutRunnable = () -> adTimeout(--timeOut);
@Override
public void run() {
App.runOnUiThread(() -> binding.tvSkip.setVisibility(View.VISIBLE));
for (int i = 0; i < 5; i++) {
int time = 5 - i;
App.runOnUiThread(() -> binding.tvSkip.setText(getString(R.string.skip_ad, time)));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
WAIT_INTERVAL = 0;
startNormal();
}
};
public static void start(Context context) { public static void start(Context context) {
Intent intent = new Intent(context, SplashActivity.class); Intent intent = new Intent(context, SplashActivity.class);
@ -233,11 +219,11 @@ public class SplashActivity extends BaseActivity<ActivitySplashBinding> {
// 展示成功 // 展示成功
@Override @Override
public void show() { public void show() {
handler.removeCallbacks(adTimeOutRunnable);
SharedPreUtils.getInstance(true).putLong("splashAdTime", System.currentTimeMillis()); SharedPreUtils.getInstance(true).putLong("splashAdTime", System.currentTimeMillis());
Log.d(TAG, "广告展示成功"); Log.d(TAG, "广告展示成功");
AdUtils.adRecord("splash", "adShow"); AdUtils.adRecord("splash", "adShow");
countTodayAd(); countTodayAd();
//countTime.start();
} }
// 广告被点击 // 广告被点击
@ -265,6 +251,7 @@ public class SplashActivity extends BaseActivity<ActivitySplashBinding> {
startNormal(); startNormal();
} }
}); });
adTimeout(timeOut);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
WAIT_INTERVAL = 1500; WAIT_INTERVAL = 1500;
@ -374,4 +361,13 @@ public class SplashActivity extends BaseActivity<ActivitySplashBinding> {
todayAdCount++; todayAdCount++;
SharedPreUtils.getInstance().putString("splashAdCount", today + ":" + todayAdCount); SharedPreUtils.getInstance().putString("splashAdCount", today + ":" + todayAdCount);
} }
private void adTimeout(int time) {
if (time == 0) {
WAIT_INTERVAL = 0;
startNormal();
} else {
handler.postDelayed(adTimeOutRunnable, 1000);
}
}
} }

@ -1,3 +1,3 @@
#Fri Jun 18 21:45:31 CST 2021 #Fri Jun 18 21:45:31 CST 2021
VERSION_CODE=240 VERSION_CODE=241
NEED_CREATE_RELEASE=true NEED_CREATE_RELEASE=true

Loading…
Cancel
Save