From 4e2808fab72c2971c1bafaacb8d0a9dd73272904 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sun, 27 Aug 2023 18:12:15 +0800 Subject: [PATCH] feat: appscheme --- android/app/src/main/AndroidManifest.xml | 176 ++++++++++++++++++++++- ios/Podfile.lock | 6 + ios/Runner/Info.plist | 161 +++++++++++++-------- lib/main.dart | 2 + lib/pages/liveRoom/controller.dart | 4 +- lib/pages/liveRoom/view.dart | 86 +++++------ lib/utils/app_scheme.dart | 106 ++++++++++++++ pubspec.lock | 8 ++ pubspec.yaml | 2 + 9 files changed, 448 insertions(+), 103 deletions(-) create mode 100644 lib/utils/app_scheme.dart diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 94db6539..55667534 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -20,7 +20,22 @@ "android.support.customtabs.action.CustomTabsService" /> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -56,7 +229,6 @@ android:value="2" /> - diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 5100bf76..183d026e 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1,4 +1,6 @@ PODS: + - appscheme (1.0.4): + - Flutter - connectivity_plus (0.0.1): - Flutter - ReachabilitySwift @@ -45,6 +47,7 @@ PODS: - Flutter DEPENDENCIES: + - appscheme (from `.symlinks/plugins/appscheme/ios`) - connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`) - device_info_plus (from `.symlinks/plugins/device_info_plus/ios`) - Flutter (from `Flutter`) @@ -71,6 +74,8 @@ SPEC REPOS: - ReachabilitySwift EXTERNAL SOURCES: + appscheme: + :path: ".symlinks/plugins/appscheme/ios" connectivity_plus: :path: ".symlinks/plugins/connectivity_plus/ios" device_info_plus: @@ -111,6 +116,7 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/webview_flutter_wkwebview/ios" SPEC CHECKSUMS: + appscheme: b1c3f8862331cb20430cf9e0e4af85dbc1572ad8 connectivity_plus: 07c49e96d7fc92bc9920617b83238c4d178b446a device_info_plus: 7545d84d8d1b896cb16a4ff98c19f07ec4b298ea Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 863a8ef8..57e29a51 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -1,62 +1,107 @@ - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleDisplayName - PiliPala - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - pilipala - CFBundlePackageType - APPL - CFBundleShortVersionString - $(FLUTTER_BUILD_NAME) - CFBundleSignature - ???? - CFBundleVersion - $(FLUTTER_BUILD_NUMBER) - LSRequiresIPhoneOS - - UILaunchStoryboardName - LaunchScreen - UIMainStoryboardFile - Main - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UISupportedInterfaceOrientations~ipad - - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UIViewControllerBasedStatusBarAppearance - - CADisableMinimumFrameDurationOnPhone - - UIApplicationSupportsIndirectInputEvents - - NSPhotoLibraryAddUsageDescription - 请允许APP保存图片到相册 - NSCameraUsageDescription - App需要您的同意,才能访问相册 - NSAppleMusicUsageDescription - App需要您的同意,才能访问媒体资料库 - LSApplicationQueriesSchemes - - https - http - - + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + PiliPala + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + PiliPala + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + + NSPhotoLibraryAddUsageDescription + 请允许APP保存图片到相册 + NSCameraUsageDescription + App需要您的同意,才能访问相册 + NSAppleMusicUsageDescription + App需要您的同意,才能访问媒体资料库 + LSApplicationQueriesSchemes + + https + http + + + CFBundleURLTypes + + + CFBundleURLName + + CFBundleURLSchemes + + http + https + + CFBundleURLTypes + + + CFBundleURLName + + CFBundleURLSchemes + + m.bilibili.com + bilibili.com + www.bilibili.com + bangumi.bilibili.com + bilibili.cn + www.bilibili.cn + bangumi.bilibili.cn + bilibili.tv + www.bilibili.tv + bangumi.bilibili.tv + miniapp.bilibili.com + live.bilibili.com + + + + + + + + CFBundleURLName + bilibili + CFBundleURLSchemes + + bilibili + + + + diff --git a/lib/main.dart b/lib/main.dart index 5c5b511e..5040edca 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -13,6 +13,7 @@ import 'package:pilipala/pages/search/index.dart'; import 'package:pilipala/pages/video/detail/index.dart'; import 'package:pilipala/router/app_pages.dart'; import 'package:pilipala/pages/main/view.dart'; +import 'package:pilipala/utils/app_scheme.dart'; import 'package:pilipala/utils/data.dart'; import 'package:pilipala/utils/storage.dart'; import 'package:media_kit/media_kit.dart'; // Provides [Player], [Media], [Playlist] etc. @@ -35,6 +36,7 @@ void main() async { await Request.setCookie(); Data.init(); GStrorage.lazyInit(); + PiliSchame.init(); }); } diff --git a/lib/pages/liveRoom/controller.dart b/lib/pages/liveRoom/controller.dart index 18b39756..2f489fec 100644 --- a/lib/pages/liveRoom/controller.dart +++ b/lib/pages/liveRoom/controller.dart @@ -29,10 +29,10 @@ class LiveRoomController extends GetxController { if (Get.arguments != null) { liveItem = Get.arguments['liveItem']; heroTag = Get.arguments['heroTag'] ?? ''; - if (liveItem.pic != null && liveItem.pic != '') { + if (liveItem != null && liveItem.pic != null && liveItem.pic != '') { cover = liveItem.pic; } - if (liveItem.cover != null && liveItem.cover != '') { + if (liveItem != null && liveItem.cover != null && liveItem.cover != '') { cover = liveItem.cover; } } diff --git a/lib/pages/liveRoom/view.dart b/lib/pages/liveRoom/view.dart index 0c650126..fa881cb8 100644 --- a/lib/pages/liveRoom/view.dart +++ b/lib/pages/liveRoom/view.dart @@ -48,32 +48,35 @@ class _LiveRoomPageState extends State { appBar: AppBar( centerTitle: false, titleSpacing: 0, - title: Row( - children: [ - NetworkImgLayer( - width: 34, - height: 34, - type: 'avatar', - src: _liveRoomController.liveItem.face, - ), - const SizedBox(width: 10), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - _liveRoomController.liveItem.uname, - style: const TextStyle(fontSize: 14), - ), - const SizedBox(height: 1), - if (_liveRoomController.liveItem.watchedShow != null) - Text( - _liveRoomController.liveItem.watchedShow['text_large'] ?? - '', - style: const TextStyle(fontSize: 12)), - ], - ), - ], - ), + title: _liveRoomController.liveItem != null + ? Row( + children: [ + NetworkImgLayer( + width: 34, + height: 34, + type: 'avatar', + src: _liveRoomController.liveItem.face, + ), + const SizedBox(width: 10), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + _liveRoomController.liveItem.uname, + style: const TextStyle(fontSize: 14), + ), + const SizedBox(height: 1), + if (_liveRoomController.liveItem.watchedShow != null) + Text( + _liveRoomController + .liveItem.watchedShow['text_large'] ?? + '', + style: const TextStyle(fontSize: 12)), + ], + ), + ], + ) + : const SizedBox(), // actions: [ // SizedBox( // height: 34, @@ -94,21 +97,22 @@ class _LiveRoomPageState extends State { ? PLVideoPlayer(controller: plPlayerController!) : const SizedBox(), ), - if (_liveRoomController.liveItem.cover != null) - Visibility( - visible: isShowCover, - child: Positioned( - top: 0, - left: 0, - right: 0, - child: NetworkImgLayer( - type: 'emote', - src: _liveRoomController.liveItem.cover, - width: Get.size.width, - height: videoHeight, - ), - ), - ), + // if (_liveRoomController.liveItem != null && + // _liveRoomController.liveItem.cover != null) + // Visibility( + // visible: isShowCover, + // child: Positioned( + // top: 0, + // left: 0, + // right: 0, + // child: NetworkImgLayer( + // type: 'emote', + // src: _liveRoomController.liveItem.cover, + // width: Get.size.width, + // height: videoHeight, + // ), + // ), + // ), ], ), ), diff --git a/lib/utils/app_scheme.dart b/lib/utils/app_scheme.dart new file mode 100644 index 00000000..3736b5b5 --- /dev/null +++ b/lib/utils/app_scheme.dart @@ -0,0 +1,106 @@ +import 'package:appscheme/appscheme.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; +import 'package:get/get.dart'; +import 'package:pilipala/http/search.dart'; +import 'package:pilipala/models/common/search_type.dart'; + +import 'id_utils.dart'; +import 'utils.dart'; + +class PiliSchame { + static AppScheme appScheme = AppSchemeImpl.getInstance() as AppScheme; + static void init() async { + /// + SchemeEntity? value = await appScheme.getInitScheme(); + if (value != null) { + _routePush(value); + } + + /// + appScheme.getLatestScheme().then((value) { + if (value != null) {} + }); + + /// 注册从外部打开的Scheme监听信息 # + appScheme.registerSchemeListener().listen((event) { + if (event != null) { + _routePush(event); + } + }); + } + + /// 路由跳转 + static void _routePush(value) async { + String scheme = value.scheme; + String host = value.host; + String path = value.path; + + if (scheme == 'bilibili') { + // bilibili://root + if (host == 'root') { + Navigator.popUntil(Get.context!, (route) => route.isFirst); + } + + // bilibili://space/{uid} + else if (host == 'space') { + var mid = path.split('/').last; + Get.toNamed( + '/member?mid=$mid', + arguments: {'face': null}, + ); + } + + // bilibili://video/{aid} + else if (host == 'video') { + var pathQuery = path.split('/').last; + int aid = int.parse(pathQuery); + String bvid = IdUtils.av2bv(aid); + int cid = await SearchHttp.ab2c(bvid: bvid); + String heroTag = Utils.makeHeroTag(aid); + Get.toNamed('/video?bvid=$bvid&cid=$cid', arguments: { + 'pic': null, + 'heroTag': heroTag, + }); + } + + // bilibili://live/{roomid} + else if (host == 'live') { + var roomId = path.split('/').last; + Get.toNamed('/liveRoom?roomid=$roomId', + arguments: {'liveItem': null, 'heroTag': roomId.toString()}); + } + + // bilibili://bangumi/season/${ssid} + else if (host == 'bangumi') { + if (path.startsWith('/season')) { + SmartDialog.showLoading(msg: '获取中...'); + try { + var seasonId = path.split('/').last; + var result = await SearchHttp.bangumiInfo( + seasonId: int.parse(seasonId), epId: null); + if (result['status']) { + var bangumiDetail = result['data']; + int cid = bangumiDetail.episodes!.first.cid; + String bvid = IdUtils.av2bv(bangumiDetail.episodes!.first.aid); + String heroTag = Utils.makeHeroTag(cid); + var epId = bangumiDetail.episodes!.first.id; + SmartDialog.dismiss().then( + (e) => Get.toNamed( + '/video?bvid=$bvid&cid=$cid&epId=$epId', + arguments: { + 'pic': bangumiDetail.cover, + 'heroTag': heroTag, + 'videoType': SearchType.media_bangumi, + }, + ), + ); + } + } catch (e) { + SmartDialog.showToast('失败:${e.toString()}'); + } + } + } + } + } +} diff --git a/pubspec.lock b/pubspec.lock index f1643599..396a1635 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -25,6 +25,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.7" + appscheme: + dependency: "direct main" + description: + name: appscheme + sha256: b885b65219f3839ebafc937024a1bc5ce5a75b0e458fd249ef15e80e81235b6f + url: "https://pub.dev" + source: hosted + version: "1.0.8" archive: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 222c9d67..fa49cbe1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -105,6 +105,8 @@ dependencies: easy_debounce: ^2.0.3 # 高帧率 flutter_displaymode: ^0.6.0 + # scheme跳转 + appscheme: ^1.0.8 dev_dependencies: flutter_test: