feat: appscheme

This commit is contained in:
guozhigq
2023-08-27 18:12:15 +08:00
parent a1900c7362
commit 4e2808fab7
9 changed files with 448 additions and 103 deletions

View File

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

View File

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

View File

@ -48,32 +48,35 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
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<LiveRoomPage> {
? 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,
// ),
// ),
// ),
],
),
),

106
lib/utils/app_scheme.dart Normal file
View File

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