You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
5.4 KiB
110 lines
5.4 KiB
package com.project.survey.util;
|
|
|
|
import android.graphics.Color;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.appcompat.app.AlertDialog;
|
|
import androidx.core.content.ContextCompat;
|
|
import androidx.fragment.app.FragmentActivity;
|
|
import androidx.lifecycle.Lifecycle;
|
|
import androidx.lifecycle.LifecycleEventObserver;
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
|
|
import com.bingce.event.CountDownEvent;
|
|
import com.bingce.utils.ActivityProviderUtils;
|
|
import com.bingce.utils.ColorUtil;
|
|
import com.bingce.utils.IProvider;
|
|
import com.bingce.utils.SdkUtils;
|
|
import com.bingce.utils.VipManager;
|
|
import com.daimajia.numberprogressbar.NumberProgressBar;
|
|
import com.project.survey.R;
|
|
import com.project.survey.ui.base.BaseSurveyNewActivity;
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
import blankj.utilcode.util.Utils;
|
|
|
|
public class CountDownUtils extends ActivityProviderUtils {
|
|
public interface ICountDownSwitcher {
|
|
//是否启动倒计时
|
|
boolean isVipCountDownOpen();
|
|
}
|
|
|
|
private final ICountDownSwitcher mSwitcher;
|
|
|
|
public CountDownUtils(IProvider<FragmentActivity> activityIProvider) {
|
|
this(activityIProvider, () -> true);
|
|
}
|
|
|
|
public CountDownUtils(IProvider<FragmentActivity> activityIProvider, ICountDownSwitcher switcher) {
|
|
super(activityIProvider);
|
|
activity().getLifecycle().addObserver(new LifecycleEventObserver() {
|
|
@Override
|
|
public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) {
|
|
switch (event) {
|
|
case ON_CREATE:
|
|
EventBus.getDefault().register(CountDownUtils.this);
|
|
break;
|
|
case ON_DESTROY:
|
|
EventBus.getDefault().unregister(CountDownUtils.this);
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
mSwitcher = switcher;
|
|
}
|
|
|
|
public void refresh(CountDownEvent event) {
|
|
if (mSwitcher != null && !mSwitcher.isVipCountDownOpen()) return;
|
|
Log.d("CountDownUtils", "vipinfo refresh:" + "needRefresh:" + event.isNeedRefresh());
|
|
if (activity() instanceof BaseSurveyNewActivity) {
|
|
NumberProgressBar cutDownProgressBar = ((BaseSurveyNewActivity) activity()).baseSurveyActivityUtils.activityBaseSurveyBinding.cutDownProgressbar;
|
|
if (!SdkUtils.isRegCodeValidate() && SdkUtils.isVipValidate()) {
|
|
cutDownProgressBar.setVisibility(View.VISIBLE);
|
|
int maxProgress = (int) (SdkUtils.availableTimeMax() / 60 / 1000L);
|
|
cutDownProgressBar.setMax(maxProgress);
|
|
int progress = Math.max((int) (SdkUtils.availableTime() / 60 / 1000L), 0);//可用时间可能小于0
|
|
cutDownProgressBar.setProgress(progress);
|
|
if (progress < 60) {
|
|
cutDownProgressBar.setPrefix(getString(R.string.remaining_offline_time) + progress + getString(R.string.minute) + " ");
|
|
} else {
|
|
cutDownProgressBar.setPrefix(getString(R.string.remaining_offline_time) + progress / 60 + getString(R.string.hour) + progress % 60 + getString(R.string.minute) + " ");
|
|
}
|
|
if (event.isNeedRefresh()) {
|
|
// VipManager.getInstance().surveyorSdkRefresh(activity(), ((App) Utils.getApp()).registerCodeV2, null);
|
|
}
|
|
if (progress == 240 || progress == 180 || progress == 120 || progress == 60 || (progress > 0 && progress < 60 && progress % 10 == 0)) {
|
|
new AlertDialog.Builder(/*this*/activity())
|
|
.setTitle(R.string.warning)
|
|
.setMessage(getString(R.string.remaining_offline_time) + progress + getString(R.string.minute) + "," + getString(R.string.the_network_reboot_software_can_reset_the_remaining_time_offline))
|
|
.setPositiveButton(R.string.i_know, null)
|
|
.show();
|
|
}
|
|
if (progress > 240) {//离线时间大于4小时,主题色显示
|
|
cutDownProgressBar.setProgressTextColor(ColorUtil.getColorPrimary(/*this*/activity()));
|
|
cutDownProgressBar.setReachedBarColor(ColorUtil.getColorPrimary(/*this*/activity()));
|
|
cutDownProgressBar.setUnreachedBarColor(ColorUtil.getColorPrimary(/*this*/activity()));
|
|
} else if (progress > 120) {//离线时间2-5小时间显示橙色警告
|
|
cutDownProgressBar.setProgressTextColor(ContextCompat.getColor(/*this*/activity(), R.color.md_orange_800));
|
|
cutDownProgressBar.setReachedBarColor(ContextCompat.getColor(/*this*/activity(), R.color.md_orange_800));
|
|
cutDownProgressBar.setUnreachedBarColor(ContextCompat.getColor(/*this*/activity(), R.color.md_orange_800));
|
|
} else {//离线时间小于2小时红色警告
|
|
cutDownProgressBar.setProgressTextColor(Color.RED);
|
|
cutDownProgressBar.setReachedBarColor(Color.RED);
|
|
cutDownProgressBar.setUnreachedBarColor(Color.RED);
|
|
}
|
|
} else {
|
|
cutDownProgressBar.setVisibility(View.GONE);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
public void onMessageEvent(CountDownEvent event) {
|
|
refresh(event);
|
|
}
|
|
}
|
|
|