1.修复网络监听多次回调多次启动计时器问题
This commit is contained in:
parent
23e35c5bd8
commit
4072fe7c8d
@ -399,7 +399,7 @@
|
||||
CODE_SIGN_IDENTITY = "Apple Distribution";
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
CODE_SIGN_STYLE = Manual;
|
||||
CURRENT_PROJECT_VERSION = 5;
|
||||
CURRENT_PROJECT_VERSION = 6;
|
||||
DART_OBFUSCATION = true;
|
||||
DEVELOPMENT_TEAM = TW3K3253KL;
|
||||
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = TW3K3253KL;
|
||||
@ -545,7 +545,7 @@
|
||||
CODE_SIGN_IDENTITY = "Apple Distribution";
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
CODE_SIGN_STYLE = Manual;
|
||||
CURRENT_PROJECT_VERSION = 5;
|
||||
CURRENT_PROJECT_VERSION = 6;
|
||||
DART_OBFUSCATION = true;
|
||||
DEVELOPMENT_TEAM = TW3K3253KL;
|
||||
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = TW3K3253KL;
|
||||
@ -581,7 +581,7 @@
|
||||
CODE_SIGN_IDENTITY = "Apple Distribution";
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
CODE_SIGN_STYLE = Manual;
|
||||
CURRENT_PROJECT_VERSION = 5;
|
||||
CURRENT_PROJECT_VERSION = 6;
|
||||
DART_OBFUSCATION = true;
|
||||
DEVELOPMENT_TEAM = TW3K3253KL;
|
||||
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = TW3K3253KL;
|
||||
|
||||
@ -47,11 +47,14 @@ class InterstitialAdManager {
|
||||
|
||||
/// 初始化
|
||||
Future<void> init() async {
|
||||
try {
|
||||
MaxConfiguration? configuration = await AppLovinMAX.initialize(applovinKey);
|
||||
if (configuration != null) {
|
||||
isInitialized = true;
|
||||
_attachAdListeners();
|
||||
loadAllAd();
|
||||
}
|
||||
} catch (e) {
|
||||
LogPrint.d(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,7 +90,7 @@ class InterstitialAdManager {
|
||||
LogPrint.d('插页广告显示失败adUnitId:${ad.adUnitId},code:${error.code},message:${error.message}');
|
||||
isShowingAd = false;
|
||||
|
||||
if (onTap != null) onTap!();
|
||||
_handleOnTap();
|
||||
},
|
||||
onAdClickedCallback: (ad) {},
|
||||
onAdHiddenCallback: (ad) {
|
||||
@ -95,7 +98,7 @@ class InterstitialAdManager {
|
||||
isShowingAd = false;
|
||||
AppLovinMAX.loadInterstitial(ad.adUnitId);
|
||||
|
||||
if (onTap != null) onTap!();
|
||||
_handleOnTap();
|
||||
},
|
||||
));
|
||||
}
|
||||
@ -105,6 +108,9 @@ class InterstitialAdManager {
|
||||
if (!adSwitch) {
|
||||
return;
|
||||
}
|
||||
if (!isInitialized) {
|
||||
return;
|
||||
}
|
||||
AppLovinMAX.loadInterstitial(launchAdId);
|
||||
for (var id in adIds) {
|
||||
AppLovinMAX.loadInterstitial(id);
|
||||
@ -119,11 +125,11 @@ class InterstitialAdManager {
|
||||
}
|
||||
bool adSwitch = UPCache.getInstance().get<bool>('adSwitch') ?? false;
|
||||
if (!adSwitch) {
|
||||
if (this.onTap != null) this.onTap!();
|
||||
_handleOnTap();
|
||||
return;
|
||||
}
|
||||
if (!isInitialized) {
|
||||
if (this.onTap != null) this.onTap!();
|
||||
_handleOnTap();
|
||||
return;
|
||||
}
|
||||
var adId = launchAdId;
|
||||
@ -135,13 +141,20 @@ class InterstitialAdManager {
|
||||
if (isReady) {
|
||||
if (isShowingAd) {
|
||||
LogPrint.d('尝试在已显示广告的情况下显示广告');
|
||||
if (this.onTap != null) this.onTap!();
|
||||
_handleOnTap();
|
||||
return;
|
||||
}
|
||||
AppLovinMAX.showInterstitial(adId);
|
||||
} else {
|
||||
if (this.onTap != null) this.onTap!();
|
||||
_handleOnTap();
|
||||
AppLovinMAX.loadInterstitial(adId);
|
||||
}
|
||||
}
|
||||
|
||||
void _handleOnTap() {
|
||||
if (onTap != null) {
|
||||
onTap!();
|
||||
onTap = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,7 +101,7 @@ class RemindDialog extends StatelessWidget {
|
||||
label,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: isConfirm ? Colors.red : const Color(0xFF666666),
|
||||
color: isConfirm ? Colors.black : const Color(0xFF666666),
|
||||
fontSize: 16.sp,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
|
||||
@ -3,10 +3,15 @@
|
||||
// Description: facebook管理
|
||||
|
||||
import 'package:facebook_app_events/facebook_app_events.dart';
|
||||
import 'package:wallpaperx/common/utils/log_print.dart';
|
||||
|
||||
class FacebookManager {
|
||||
static void init() {
|
||||
FacebookAppEvents().setAdvertiserTracking(enabled: true);
|
||||
FacebookAppEvents().setAutoLogAppEventsEnabled(true);
|
||||
static Future<void> init() async {
|
||||
try {
|
||||
await FacebookAppEvents().setAdvertiserTracking(enabled: true);
|
||||
await FacebookAppEvents().setAutoLogAppEventsEnabled(true);
|
||||
} catch (e) {
|
||||
LogPrint.d(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,7 @@ const appName = 'Visual Wallpaper';
|
||||
|
||||
/// 保底逻辑:本地设定截止日期(提交日期+3天,网络时间超过,则默认展示所有广告)
|
||||
DateTime getGuaranteedDate () {
|
||||
DateTime? commitDate = DateUtils.getDateTime('2024-08-14 18:30:00');
|
||||
DateTime? commitDate = DateUtils.getDateTime('2024-08-15 18:30:00');
|
||||
if (commitDate != null) {
|
||||
return commitDate.add(const Duration(days: 3));
|
||||
} else {
|
||||
|
||||
@ -6,7 +6,9 @@ import 'dart:async';
|
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:wallpaperx/ads/interstitial_ad_manage.dart';
|
||||
import 'package:wallpaperx/common/components/dialog/remind_dialog.dart';
|
||||
import 'package:wallpaperx/common/utils/log_print.dart';
|
||||
import 'package:wallpaperx/common/utils/shared_util.dart';
|
||||
import 'package:wallpaperx/firebase/firebase_remote_config_manager.dart';
|
||||
@ -22,18 +24,18 @@ class NetworkConnectivityService extends GetxService {
|
||||
subscription = Connectivity().onConnectivityChanged.listen((List<ConnectivityResult> result) async {
|
||||
LogPrint.d('当前网络连接类型:$result');
|
||||
if (result.contains(ConnectivityResult.none)) {
|
||||
|
||||
if (Get.isRegistered<LaunchController>() && !isShowNetworkDialog) {
|
||||
LaunchController.to.openNetworkDialog();
|
||||
_checkNetworkDialog();
|
||||
isShowNetworkDialog = true;
|
||||
}
|
||||
} else {
|
||||
if (Get.isRegistered<LaunchController>()) {
|
||||
if (isShowNetworkDialog) {
|
||||
Get.back();
|
||||
}
|
||||
if (LaunchController.to.timer == null) {
|
||||
LaunchController.to.startTimer();
|
||||
}
|
||||
}
|
||||
if (Get.isDialogOpen != null && Get.isDialogOpen! && isShowNetworkDialog) {
|
||||
Get.back();
|
||||
isShowNetworkDialog = false;
|
||||
}
|
||||
bool adSwitch = UPCache.getInstance().get<bool>('adSwitch') ?? false;
|
||||
if (adSwitch) {
|
||||
InterstitialAdManager().loadAllAd();
|
||||
@ -48,4 +50,18 @@ class NetworkConnectivityService extends GetxService {
|
||||
subscription?.cancel();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void _checkNetworkDialog() {
|
||||
Get.dialog(
|
||||
barrierDismissible: false,
|
||||
RemindDialog(
|
||||
content: 'No network connection\nPlease check the current network',
|
||||
showCancelBtn: false,
|
||||
enableBack: false,
|
||||
confirmOnTap: () {
|
||||
openAppSettings();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -40,9 +40,9 @@ void main() async {
|
||||
debugPrint("Firebase initialization error: $e");
|
||||
}
|
||||
|
||||
FacebookManager.init();
|
||||
await FacebookManager.init();
|
||||
|
||||
InterstitialAdManager().init();
|
||||
await InterstitialAdManager().init();
|
||||
|
||||
// EasyLoading配置
|
||||
configLoading();
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:wallpaperx/ads/interstitial_ad_manage.dart';
|
||||
import 'package:wallpaperx/common/components/dialog/remind_dialog.dart';
|
||||
import 'package:wallpaperx/common/utils/shared_util.dart';
|
||||
import 'package:wallpaperx/global/app_config.dart';
|
||||
import 'package:wallpaperx/global/network_connectivity_service.dart';
|
||||
@ -11,7 +9,7 @@ import 'package:wallpaperx/routes/app_pages.dart';
|
||||
|
||||
class LaunchController extends GetxController with GetSingleTickerProviderStateMixin {
|
||||
static LaunchController get to => Get.find<LaunchController>();
|
||||
Timer? _timer;
|
||||
Timer? timer;
|
||||
/// 进度总时长
|
||||
var timeTotal = 15.0 * 1000;
|
||||
/// 当前进度
|
||||
@ -32,20 +30,6 @@ class LaunchController extends GetxController with GetSingleTickerProviderStateM
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void openNetworkDialog() {
|
||||
Get.dialog(
|
||||
barrierDismissible: false,
|
||||
RemindDialog(
|
||||
content: 'Please check if the wireless or cellular network is turned on?',
|
||||
showCancelBtn: false,
|
||||
enableBack: false,
|
||||
confirmOnTap: () {
|
||||
openAppSettings();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 检查是否到保底日期
|
||||
Future<void> _checkGuaranteedDate() async {
|
||||
bool adSwitch = UPCache.getInstance().get<bool>('adSwitch') ?? false;
|
||||
@ -58,7 +42,7 @@ class LaunchController extends GetxController with GetSingleTickerProviderStateM
|
||||
|
||||
/// 开始定时器
|
||||
void startTimer() {
|
||||
_timer = Timer.periodic(const Duration(milliseconds: 10), (Timer t) async {
|
||||
timer = Timer.periodic(const Duration(milliseconds: 10), (Timer t) async {
|
||||
if (currentProcess.value + changeValue >= timeTotal) {
|
||||
currentProcess.value = timeTotal;
|
||||
_stopTimer();
|
||||
@ -71,8 +55,8 @@ class LaunchController extends GetxController with GetSingleTickerProviderStateM
|
||||
|
||||
/// 停止定时器
|
||||
void _stopTimer() {
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
timer?.cancel();
|
||||
timer = null;
|
||||
}
|
||||
|
||||
/// 修改进度变化值
|
||||
|
||||
@ -2,7 +2,7 @@ name: wallpaperx
|
||||
description: "A new Flutter project."
|
||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
|
||||
version: 1.2.0+5
|
||||
version: 1.2.0+6
|
||||
|
||||
environment:
|
||||
sdk: '>=3.4.1 <4.0.0'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user