diff --git a/android/app/build.gradle b/android/app/build.gradle index 609b5cb..01311d8 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -50,7 +50,7 @@ android { // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. // minSdkVersion flutter.minSdkVersion - minSdkVersion 24 + minSdkVersion 19 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/lib/applovin_max/applovin_manage.dart b/lib/applovin_max/applovin_manage.dart new file mode 100644 index 0000000..f21a495 --- /dev/null +++ b/lib/applovin_max/applovin_manage.dart @@ -0,0 +1,134 @@ +// Author: fengshengxiong +// Date: 2024/5/20 +// Description: 广告管理 + +import 'dart:async'; +import 'dart:math'; + +import 'package:applovin_max/applovin_max.dart'; +import 'package:flutter/material.dart'; +import 'package:now_wallpaper/common/utils/log_print.dart'; + +class ApplovinManage { + ApplovinManage._(); + + static final ApplovinManage _instance = ApplovinManage._(); + + factory ApplovinManage() => _instance; + + /// sdkKey + final String applovinKey = 'nEo4OHOhAZuAK9-IARuNaUfW-yDLBayq9FIGZs0L9XMNTByuDV6dsvMEIGnEAkQu-KR8D42QdKRlbniP910xnK'; + + /// 广告单元Id + final String adUnitId1 = 'edc4bd530e79af75'; + final String adUnitId2 = '3f38d70ff5e85f92'; + final String adUnitId3 = '8a0fc2feeba310bc'; + + /// 是否已初始化 + bool isInitialized = false; + + /// 是否是启动屏幕 + bool isSplashScreen = true; + + /// 重试计数 + final _maxExponentialRetryCount = 6; + var _interstitialRetryAttempt = 0; + + /// 倒计时30秒,3个广告单元不重复展示 + // Timer? _timer; + // int _timeCount = 30; + + /// 初始化 + Future initApplovin() async { + MaxConfiguration? configuration = await AppLovinMAX.initialize(applovinKey); + if (configuration != null) { + isInitialized = true; + } + } + + /// 初始化插页广告 + void initializeInterstitialAds({VoidCallback? onAdLoadedCallback}) { + if (isInitialized) { + AppLovinMAX.setInterstitialListener(InterstitialListener( + onAdLoadedCallback: (ad) { + LogPrint.d('插页广告加载成功:${ad.adUnitId}'); + if (ad.adUnitId == adUnitId1 && isSplashScreen) { + isSplashScreen = false; + onAdLoadedCallback!; + showAdIfReady(adUnitId1); + // AppLovinMAX.showInterstitial(adUnitId1); + AppLovinMAX.loadInterstitial(adUnitId1); + } + _interstitialRetryAttempt = 0; + }, + onAdLoadFailedCallback: (adUnitId, error) { + LogPrint.d('插页广告加载失败adUnitId:$adUnitId,code:${error.code},message:${error.message}'); + if (adUnitId == adUnitId1 && isSplashScreen) { + isSplashScreen = false; + } + // Applovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds). + _interstitialRetryAttempt = _interstitialRetryAttempt + 1; + if (_interstitialRetryAttempt > _maxExponentialRetryCount) return; + int retryDelay = pow(2, min(_maxExponentialRetryCount, _interstitialRetryAttempt)).toInt(); + + Future.delayed(Duration(milliseconds: retryDelay * 1000), () { + AppLovinMAX.loadInterstitial(adUnitId); + }); + }, + onAdDisplayedCallback: (ad) { + LogPrint.d('插页广告显示成功:${ad.adUnitId}'); + // _startTimer(); + }, + onAdDisplayFailedCallback: (ad, error) { + LogPrint.d('插页广告显示失败adUnitId:${ad.adUnitId},code:${error.code},message:${error.message}'); + }, + onAdClickedCallback: (ad) {}, + onAdHiddenCallback: (ad) { + LogPrint.d('插页广告隐藏:${ad.adUnitId}'); + AppLovinMAX.loadInterstitial(ad.adUnitId); + }, + )); + + AppLovinMAX.loadInterstitial(adUnitId1); + AppLovinMAX.loadInterstitial(adUnitId2); + AppLovinMAX.loadInterstitial(adUnitId3); + } + } + + /// 显示插页广告,如果准备好 + Future showAdIfReady(String adUnitId) async { + if (!isInitialized) { + return; + } + + bool isReady = (await AppLovinMAX.isInterstitialReady(adUnitId))!; + if (isReady) { + // if (_timeCount == 30) { + // AppLovinMAX.showInterstitial(adUnitId); + // } + AppLovinMAX.showInterstitial(adUnitId); + } else { + AppLovinMAX.loadInterstitial(adUnitId); + } + } + + // /// 开始定时器 + // void _startTimer() { + // _timer = Timer.periodic(const Duration(seconds: 1), (Timer t) { + // if (_timeCount > 0) { + // _timeCount--; + // LogPrint.d('广告间隔倒计时$_timeCount秒'); + // } else { + // _stopTimer(); + // LogPrint.d('广告间隔计时停止'); + // } + // }); + // } + // + // /// 停止定时器 + // void _stopTimer() { + // _timer?.cancel(); + // _timer = null; + // _timeCount = 30; + // } +} \ No newline at end of file diff --git a/lib/common/components/navigation_bar/base_appbar.dart b/lib/common/components/navigation_bar/base_appbar.dart index 3270fc8..38fdda0 100644 --- a/lib/common/components/navigation_bar/base_appbar.dart +++ b/lib/common/components/navigation_bar/base_appbar.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:now_wallpaper/applovin_max/applovin_manage.dart'; import 'package:now_wallpaper/generated/assets.dart'; import 'package:now_wallpaper/res/themes/app_colors.dart'; @@ -15,12 +16,14 @@ class BaseAppBar extends StatelessWidget implements PreferredSizeWidget { this.backgroundColor, this.backWidget, this.titleStyle, + this.onBackTap, }); final Color? backgroundColor; final Widget? backWidget; final String title; final TextStyle? titleStyle; + final Function()? onBackTap; @override Widget build(BuildContext context) { @@ -35,7 +38,10 @@ class BaseAppBar extends StatelessWidget implements PreferredSizeWidget { child: Material( color: Colors.transparent, child: InkWell( - onTap: Get.back, + onTap: onBackTap ?? () async { + await ApplovinManage().showAdIfReady(ApplovinManage().adUnitId3); + Get.back(); + }, child: Padding( padding: const EdgeInsets.all(10).w, child: Image.asset( diff --git a/lib/common/plugin/set_wallpaper.dart b/lib/common/plugin/set_wallpaper.dart index eec32f3..ab5b9a6 100644 --- a/lib/common/plugin/set_wallpaper.dart +++ b/lib/common/plugin/set_wallpaper.dart @@ -3,6 +3,7 @@ // Description: 设置壁纸插件 import 'package:flutter/services.dart'; +import 'package:now_wallpaper/common/utils/log_print.dart'; class SetWallpaper { static const MethodChannel _channel = MethodChannel('set_wallpaper'); @@ -13,10 +14,10 @@ class SetWallpaper { "path": path, "wallpaperType": wallpaperType // 0 for home screen, 1 for lock screen, 2 for both }); - print(result); + LogPrint.d(result); return result; } on PlatformException catch (e) { - print('Failed to set wallpaper: ${e.message}.'); + LogPrint.e('Failed to set wallpaper: ${e.message}.'); return 'Failed to set wallpaper: ${e.message}.'; } } diff --git a/lib/main.dart b/lib/main.dart index da66c6f..2db84fe 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,9 +1,11 @@ import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:now_wallpaper/applovin_max/applovin_manage.dart'; import 'package:now_wallpaper/common/components/easy_loading.dart'; import 'package:now_wallpaper/common/storage/hive_storage.dart'; import 'package:now_wallpaper/res/themes/app_themes.dart'; @@ -11,6 +13,17 @@ import 'package:now_wallpaper/res/values/strings.dart'; import 'package:now_wallpaper/routes/app_pages.dart'; void main() async { + WidgetsFlutterBinding.ensureInitialized(); + + // 竖屏 + SystemChrome.setPreferredOrientations([ + DeviceOrientation.portraitUp, + DeviceOrientation.portraitDown, + ]); + + // 初始化广告sdk + await ApplovinManage().initApplovin(); + // 初始化Hive await initHive(); @@ -46,7 +59,7 @@ class MyApp extends StatelessWidget { darkTheme: darkTheme, themeMode: ThemeMode.dark, getPages: AppPages.routes, - initialRoute: AppPages.root, + initialRoute: AppPages.splashScreen, builder: (context, widget) { widget = easyLoading(context, widget); return MediaQuery( diff --git a/lib/modules/catalog/catalog_controller.dart b/lib/modules/catalog/catalog_controller.dart index ed493a7..b2de48d 100644 --- a/lib/modules/catalog/catalog_controller.dart +++ b/lib/modules/catalog/catalog_controller.dart @@ -1,7 +1,7 @@ import 'package:get/get.dart'; import 'package:now_wallpaper/common/components/view_state_widget.dart'; import 'package:now_wallpaper/models/wallpaper_model.dart'; -import 'package:now_wallpaper/modules/root/root_controller.dart'; +import 'package:now_wallpaper/modules/home/home_controller.dart'; import 'package:now_wallpaper/routes/app_pages.dart'; class CatalogController extends GetxController { @@ -16,7 +16,7 @@ class CatalogController extends GetxController { } void getData() { - wallpaperModelList = RootController.to.wallpaperModelList; + wallpaperModelList = HomeController.to.wallpaperModelList; viewState = wallpaperModelList.isNotEmpty ? ViewState.normal : ViewState.empty; refresh(); } @@ -32,8 +32,8 @@ class CatalogController extends GetxController { } void onTapSingleCls(WallpaperModel wallpaperModel) { - // 进入单个分类页面 - Get.toNamed(AppPages.singleCls, arguments: wallpaperModel); + // 进入分类详情页面 + Get.toNamed(AppPages.clsDet, arguments: wallpaperModel); } /// 点击壁纸 diff --git a/lib/modules/cls_det/cls_det_binding.dart b/lib/modules/cls_det/cls_det_binding.dart new file mode 100644 index 0000000..0b944ec --- /dev/null +++ b/lib/modules/cls_det/cls_det_binding.dart @@ -0,0 +1,9 @@ +import 'package:get/get.dart'; +import 'package:now_wallpaper/modules/cls_det/cls_det_controller.dart'; + +class ClsDetBinding extends Bindings { + @override + void dependencies() { + Get.lazyPut(() => ClsDetController()); + } +} diff --git a/lib/modules/single_cls/single_cls_controller.dart b/lib/modules/cls_det/cls_det_controller.dart similarity index 92% rename from lib/modules/single_cls/single_cls_controller.dart rename to lib/modules/cls_det/cls_det_controller.dart index b50d420..c51ac2a 100644 --- a/lib/modules/single_cls/single_cls_controller.dart +++ b/lib/modules/cls_det/cls_det_controller.dart @@ -2,7 +2,7 @@ import 'package:get/get.dart'; import 'package:now_wallpaper/models/wallpaper_model.dart'; import 'package:now_wallpaper/routes/app_pages.dart'; -class SingleClsController extends GetxController { +class ClsDetController extends GetxController { late final List wallpaperDataList; late final String clsName; diff --git a/lib/modules/single_cls/single_cls_view.dart b/lib/modules/cls_det/cls_det_view.dart similarity index 87% rename from lib/modules/single_cls/single_cls_view.dart rename to lib/modules/cls_det/cls_det_view.dart index 275f2b2..4c799d5 100644 --- a/lib/modules/single_cls/single_cls_view.dart +++ b/lib/modules/cls_det/cls_det_view.dart @@ -5,10 +5,10 @@ import 'package:get/get.dart'; import 'package:now_wallpaper/common/components/image_network_widget.dart'; import 'package:now_wallpaper/common/components/navigation_bar/base_appbar.dart'; import 'package:now_wallpaper/models/wallpaper_model.dart'; -import 'package:now_wallpaper/modules/single_cls/single_cls_controller.dart'; +import 'package:now_wallpaper/modules/cls_det/cls_det_controller.dart'; -class SingleClsView extends GetView { - const SingleClsView({super.key}); +class ClsDetView extends GetView { + const ClsDetView({super.key}); @override Widget build(BuildContext context) { diff --git a/lib/modules/discover/discover_controller.dart b/lib/modules/discover/discover_controller.dart index d3142be..c057f93 100644 --- a/lib/modules/discover/discover_controller.dart +++ b/lib/modules/discover/discover_controller.dart @@ -3,7 +3,7 @@ import 'package:get/get.dart'; import 'package:now_wallpaper/common/components/view_state_widget.dart'; import 'package:now_wallpaper/common/utils/obj_util.dart'; import 'package:now_wallpaper/models/wallpaper_model.dart'; -import 'package:now_wallpaper/modules/root/root_controller.dart'; +import 'package:now_wallpaper/modules/home/home_controller.dart'; import 'package:now_wallpaper/routes/app_pages.dart'; class DiscoverController extends GetxController { @@ -28,15 +28,15 @@ class DiscoverController extends GetxController { } void getData() { - todayNewestData = RootController.to.getRandomCls(); + todayNewestData = HomeController.to.getRandomCls(); if (todayNewestData != null && todayNewestData!.data != null && todayNewestData!.data!.length >= 3) { clsName = ObjUtil.getStr(todayNewestData!.name); var flatList = todayNewestData!.data!.map((e) => e).toList(); // 随机打乱此列表中的元素,再取前3个元素 todayNewestList = (flatList..shuffle()).take(3).toList(); } - viewState = RootController.to.viewState; - allWallpaper = RootController.to.wallpaperModelList.expand((element) => element.data ?? []).toList(); + viewState = HomeController.to.viewState; + allWallpaper = HomeController.to.wallpaperModelList.expand((element) => element.data ?? []).toList(); _getDataToShow(); } @@ -64,8 +64,8 @@ class DiscoverController extends GetxController { /// 点击今日最新 void onTapTodayNewest() { - // 进入单个分类页面 - Get.toNamed(AppPages.singleCls, arguments: todayNewestData); + // 进入分类详情页面 + Get.toNamed(AppPages.clsDet, arguments: todayNewestData); } /// 点击壁纸 diff --git a/lib/modules/favorite/favorite_controller.dart b/lib/modules/favorite/favorite_controller.dart index 0026db5..94a3546 100644 --- a/lib/modules/favorite/favorite_controller.dart +++ b/lib/modules/favorite/favorite_controller.dart @@ -3,7 +3,7 @@ import 'package:now_wallpaper/common/components/dialog/remind_dialog.dart'; import 'package:now_wallpaper/common/components/view_state_widget.dart'; import 'package:now_wallpaper/common/storage/favorite_data.dart'; import 'package:now_wallpaper/models/wallpaper_model.dart'; -import 'package:now_wallpaper/modules/root/root_controller.dart'; +import 'package:now_wallpaper/modules/home/home_controller.dart'; import 'package:now_wallpaper/routes/app_pages.dart'; class FavoriteController extends GetxController { @@ -33,7 +33,7 @@ class FavoriteController extends GetxController { /// 获取今日最热门壁纸 void getTodayHottestList() { // 从分类中随机取3张壁纸 - todayHottestData = RootController.to.getRandomCls(); + todayHottestData = HomeController.to.getRandomCls(); if (todayHottestData != null && todayHottestData!.data != null && todayHottestData!.data!.length >= 3) { var flatList = todayHottestData!.data!.map((e) => e).toList(); todayHottestList = (flatList..shuffle()).take(3).toList(); @@ -81,7 +81,7 @@ class FavoriteController extends GetxController { } void onTapViewMore() { - // 进入单个分类页面 - Get.toNamed(AppPages.singleCls, arguments: todayHottestData); + // 进入分类详情页面 + Get.toNamed(AppPages.clsDet, arguments: todayHottestData); } } diff --git a/lib/modules/home/home_binding.dart b/lib/modules/home/home_binding.dart new file mode 100644 index 0000000..7fbb9b8 --- /dev/null +++ b/lib/modules/home/home_binding.dart @@ -0,0 +1,9 @@ +import 'package:get/get.dart'; +import 'package:now_wallpaper/modules/home/home_controller.dart'; + +class HomeBinding extends Bindings { + @override + void dependencies() { + Get.lazyPut(() => HomeController()); + } +} diff --git a/lib/modules/root/root_controller.dart b/lib/modules/home/home_controller.dart similarity index 80% rename from lib/modules/root/root_controller.dart rename to lib/modules/home/home_controller.dart index 7c078b8..01ec0e6 100644 --- a/lib/modules/root/root_controller.dart +++ b/lib/modules/home/home_controller.dart @@ -1,8 +1,10 @@ import 'dart:convert'; import 'dart:math'; + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; +import 'package:now_wallpaper/applovin_max/applovin_manage.dart'; import 'package:now_wallpaper/common/components/view_state_widget.dart'; import 'package:now_wallpaper/generated/assets.dart'; import 'package:now_wallpaper/models/wallpaper_model.dart'; @@ -14,8 +16,8 @@ import 'package:now_wallpaper/modules/favorite/favorite_controller.dart'; import 'package:now_wallpaper/modules/favorite/favorite_view.dart'; import 'package:now_wallpaper/routes/app_pages.dart'; -class RootController extends GetxController { - static RootController get to => Get.find(); +class HomeController extends GetxController with WidgetsBindingObserver { + static HomeController get to => Get.find(); final pages = [ PageItem('Discover', [Assets.imagesDiscoverUnchecked, Assets.imagesDiscoverSelected], const DiscoverView()), PageItem('Favorite', [Assets.imagesFavoriteUnchecked, Assets.imagesFavoriteSelected], const FavoriteView()), @@ -29,6 +31,7 @@ class RootController extends GetxController { @override void onInit() { super.onInit(); + WidgetsBinding.instance.addObserver(this); pageController = PageController(initialPage: currentIndex.value); } @@ -40,18 +43,34 @@ class RootController extends GetxController { @override void onClose() { + WidgetsBinding.instance.removeObserver(this); pageController.dispose(); super.onClose(); } + @override + Future didChangeAppLifecycleState(AppLifecycleState state) async { + switch (state) { + case AppLifecycleState.resumed: + await ApplovinManage().showAdIfReady(ApplovinManage().adUnitId1); + break; + case AppLifecycleState.inactive: + case AppLifecycleState.hidden: + case AppLifecycleState.paused: + case AppLifecycleState.detached: + break; + } + } + /// PageView页面改变回调 void onPageChanged(int index) { currentIndex.value = index; } /// 点击BottomNavigationBar - void onTapNavigationBar(int index) { + void onTapNavigationBar(int index) async { pageController.jumpToPage(index); + await ApplovinManage().showAdIfReady(ApplovinManage().adUnitId1); } /// 点击设置 diff --git a/lib/modules/root/root_view.dart b/lib/modules/home/home_view.dart similarity index 92% rename from lib/modules/root/root_view.dart rename to lib/modules/home/home_view.dart index 3caa974..5803960 100644 --- a/lib/modules/root/root_view.dart +++ b/lib/modules/home/home_view.dart @@ -3,10 +3,10 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:now_wallpaper/common/components/keep_alive_wrapper.dart'; import 'package:now_wallpaper/common/components/navigation_bar/title_bar_widget.dart'; -import 'package:now_wallpaper/modules/root/root_controller.dart'; +import 'package:now_wallpaper/modules/home/home_controller.dart'; -class RootView extends GetView { - const RootView({super.key}); +class HomeView extends GetView { + const HomeView({super.key}); @override Widget build(BuildContext context) { diff --git a/lib/modules/root/root_binding.dart b/lib/modules/root/root_binding.dart deleted file mode 100644 index a446eec..0000000 --- a/lib/modules/root/root_binding.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:get/get.dart'; -import 'package:now_wallpaper/modules/root/root_controller.dart'; - -class RootBinding extends Bindings { - @override - void dependencies() { - Get.lazyPut(() => RootController()); - } -} diff --git a/lib/modules/single_cls/single_cls_binding.dart b/lib/modules/single_cls/single_cls_binding.dart deleted file mode 100644 index b8be398..0000000 --- a/lib/modules/single_cls/single_cls_binding.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:get/get.dart'; - -import 'single_cls_controller.dart'; - -class SingleClsBinding extends Bindings { - @override - void dependencies() { - Get.lazyPut(() => SingleClsController()); - } -} diff --git a/lib/modules/splash_screen/splash_screen_binding.dart b/lib/modules/splash_screen/splash_screen_binding.dart new file mode 100644 index 0000000..952799a --- /dev/null +++ b/lib/modules/splash_screen/splash_screen_binding.dart @@ -0,0 +1,10 @@ +import 'package:get/get.dart'; + +import 'splash_screen_controller.dart'; + +class SplashScreenBinding extends Bindings { + @override + void dependencies() { + Get.lazyPut(() => SplashScreenController()); + } +} diff --git a/lib/modules/splash_screen/splash_screen_controller.dart b/lib/modules/splash_screen/splash_screen_controller.dart new file mode 100644 index 0000000..fb89722 --- /dev/null +++ b/lib/modules/splash_screen/splash_screen_controller.dart @@ -0,0 +1,48 @@ +import 'dart:async'; + +import 'package:get/get.dart'; +import 'package:now_wallpaper/applovin_max/applovin_manage.dart'; +import 'package:now_wallpaper/routes/app_pages.dart'; + +class SplashScreenController extends GetxController { + Timer? _timer; + int _timeCount = 15; + + @override + void onInit() { + super.onInit(); + ApplovinManage().initializeInterstitialAds( + onAdLoadedCallback: _openHomePage, + ); + _startTimer(); + } + + @override + void onClose() { + _stopTimer(); + super.onClose(); + } + + /// 开始定时器 + void _startTimer() { + _timer = Timer.periodic(const Duration(seconds: 1), (Timer t) { + if (_timeCount <= 0) { + _openHomePage(); + return; + } + _timeCount--; + }); + } + + /// 停止定时器 + void _stopTimer() { + _timer?.cancel(); + _timer = null; + } + + /// 打开首页 + void _openHomePage() { + _stopTimer(); + Get.offAndToNamed(AppPages.home); + } +} diff --git a/lib/modules/splash_screen/splash_screen_view.dart b/lib/modules/splash_screen/splash_screen_view.dart new file mode 100644 index 0000000..58a22e2 --- /dev/null +++ b/lib/modules/splash_screen/splash_screen_view.dart @@ -0,0 +1,75 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; +import 'package:now_wallpaper/generated/assets.dart'; +import 'package:now_wallpaper/modules/splash_screen/splash_screen_controller.dart'; +import 'package:now_wallpaper/res/values/strings.dart'; + +class SplashScreenView extends GetView { + const SplashScreenView({super.key}); + + @override + Widget build(BuildContext context) { + Get.find(); + return Scaffold( + body: Stack( + children: [ + _buildIconName(), + _buildProgress(), + ], + ), + ); + } + + Widget _buildIconName() { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Image.asset( + Assets.iconIconApp, + width: 96.w, + height: 96.w, + ), + SizedBox(height: 20.h), + Text( + appName, + style: TextStyle( + color: Colors.white, + fontSize: 22.sp, + fontWeight: FontWeight.w600, + ), + ), + ], + ), + ); + } + + Widget _buildProgress() { + return Container( + alignment: Alignment.center, + margin: const EdgeInsets.only(bottom: 60).h, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + SizedBox( + width: 0.5.sw, + child: LinearProgressIndicator( + backgroundColor: Colors.white, + valueColor: const AlwaysStoppedAnimation(Colors.grey), + borderRadius: BorderRadius.circular(8).r, + ), + ), + SizedBox(height: 14.h), + Text( + 'Resource Loading...', + style: TextStyle( + color: Colors.white, + fontSize: 12.sp, + ), + ), + ], + ), + ); + } +} diff --git a/lib/modules/wallpaper_det/wallpaper_det_controller.dart b/lib/modules/wallpaper_det/wallpaper_det_controller.dart index 61cbf22..569406a 100644 --- a/lib/modules/wallpaper_det/wallpaper_det_controller.dart +++ b/lib/modules/wallpaper_det/wallpaper_det_controller.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:get/get.dart'; import 'package:image_gallery_saver/image_gallery_saver.dart'; +import 'package:now_wallpaper/applovin_max/applovin_manage.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:now_wallpaper/common/components/dialog/bottomsheet_dialog.dart'; import 'package:now_wallpaper/common/components/easy_loading.dart'; @@ -97,6 +98,7 @@ class WallpaperDetController extends GetxController { /// 设置壁纸 void onTapSetWallpaper() async { + await ApplovinManage().showAdIfReady(ApplovinManage().adUnitId2); BottomSheetDialog.show((location) async { if (showBlur.value) { await _captureScreenshot(); @@ -152,4 +154,10 @@ class WallpaperDetController extends GetxController { } dismiss(); } + + /// 显示广告 + Future showAd() async { + await ApplovinManage().showAdIfReady(ApplovinManage().adUnitId3); + Get.back(); + } } diff --git a/lib/modules/wallpaper_det/wallpaper_det_view.dart b/lib/modules/wallpaper_det/wallpaper_det_view.dart index 0d93da7..3a68e8d 100644 --- a/lib/modules/wallpaper_det/wallpaper_det_view.dart +++ b/lib/modules/wallpaper_det/wallpaper_det_view.dart @@ -39,7 +39,7 @@ class WallpaperDetView extends GetView { /// 返回按钮 Widget _buildBackWidget() { return GestureDetector( - onTap: Get.back, + onTap: controller.showAd, child: Padding( padding: const EdgeInsets.only(left: 10).w, child: ClipOval( diff --git a/lib/res/themes/app_themes.dart b/lib/res/themes/app_themes.dart index 4159997..c945c62 100644 --- a/lib/res/themes/app_themes.dart +++ b/lib/res/themes/app_themes.dart @@ -8,7 +8,7 @@ import 'package:now_wallpaper/res/themes/app_colors.dart'; import 'package:now_wallpaper/res/themes/app_sizes.dart'; /// 深色主题 -ThemeData darkTheme = ThemeData.dark(useMaterial3: false).copyWith( +ThemeData darkTheme = ThemeData.dark(useMaterial3: true).copyWith( colorScheme: ColorScheme.fromSeed(seedColor: seedColor, primary: Colors.white), scaffoldBackgroundColor: seedColor, bottomNavigationBarTheme: BottomNavigationBarThemeData( diff --git a/lib/routes/app_pages.dart b/lib/routes/app_pages.dart index ddf2caf..450bea4 100644 --- a/lib/routes/app_pages.dart +++ b/lib/routes/app_pages.dart @@ -5,12 +5,14 @@ import 'package:get/get.dart'; import 'package:now_wallpaper/modules/about/about_binding.dart'; import 'package:now_wallpaper/modules/about/about_view.dart'; -import 'package:now_wallpaper/modules/root/root_binding.dart'; -import 'package:now_wallpaper/modules/root/root_view.dart'; +import 'package:now_wallpaper/modules/cls_det/cls_det_binding.dart'; +import 'package:now_wallpaper/modules/cls_det/cls_det_view.dart'; +import 'package:now_wallpaper/modules/home/home_binding.dart'; +import 'package:now_wallpaper/modules/home/home_view.dart'; import 'package:now_wallpaper/modules/settings/settings_binding.dart'; import 'package:now_wallpaper/modules/settings/settings_view.dart'; -import 'package:now_wallpaper/modules/single_cls/single_cls_binding.dart'; -import 'package:now_wallpaper/modules/single_cls/single_cls_view.dart'; +import 'package:now_wallpaper/modules/splash_screen/splash_screen_binding.dart'; +import 'package:now_wallpaper/modules/splash_screen/splash_screen_view.dart'; import 'package:now_wallpaper/modules/wallpaper_det/wallpaper_det_binding.dart'; import 'package:now_wallpaper/modules/wallpaper_det/wallpaper_det_view.dart'; import 'package:now_wallpaper/modules/web_page/web_page_binding.dart'; @@ -19,24 +21,37 @@ import 'package:now_wallpaper/modules/web_page/web_page_view.dart'; class AppPages { AppPages._(); - /// 根路由 - static const root = '/'; + /// 启动页面 + static const splashScreen = '/splash_screen'; + + /// 首页 + static const home = '/home'; + /// 壁纸详情 static const wallpaperDet = '/wallpaper_det'; - /// 单个分类 - static const singleCls = '/single_cls'; + + /// 分类详情 + static const clsDet = '/cls_det'; + /// 设置 static const settings = '/settings'; + /// 关于 static const about = '/about'; + /// WebView页面 static const webPage = '/web_page'; static final routes = [ GetPage( - name: root, - page: () => const RootView(), - binding: RootBinding(), + name: splashScreen, + page: () => const SplashScreenView(), + binding: SplashScreenBinding(), + ), + GetPage( + name: home, + page: () => const HomeView(), + binding: HomeBinding(), ), GetPage( name: wallpaperDet, @@ -44,9 +59,9 @@ class AppPages { binding: WallpaperDetBinding(), ), GetPage( - name: singleCls, - page: () => const SingleClsView(), - binding: SingleClsBinding(), + name: clsDet, + page: () => const ClsDetView(), + binding: ClsDetBinding(), ), GetPage( name: settings, diff --git a/pubspec.yaml b/pubspec.yaml index aa56c14..585f0a6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+1 +version: 1.0.1+2 environment: sdk: '>=3.3.4 <4.0.0' @@ -92,6 +92,9 @@ dependencies: # 分享 share_plus: ^9.0.0 + # AppLovin + applovin_max: ^3.10.0 + flutter_launcher_icons: android: "launcher_icon" ios: true