1.修复网络监听多次回调多次启动计时器问题

This commit is contained in:
Fson 2024-08-15 17:56:23 +08:00
parent 23e35c5bd8
commit 4072fe7c8d
9 changed files with 68 additions and 50 deletions

View File

@ -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;

View File

@ -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;
}
}
}

View File

@ -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,
),

View File

@ -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());
}
}
}

View File

@ -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 {

View File

@ -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();
},
),
);
}
}

View File

@ -40,9 +40,9 @@ void main() async {
debugPrint("Firebase initialization error: $e");
}
FacebookManager.init();
await FacebookManager.init();
InterstitialAdManager().init();
await InterstitialAdManager().init();
// EasyLoading配置
configLoading();

View File

@ -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;
}
///

View File

@ -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'