mod: 侧边栏、动态重构,排行改为首页分区,平板、折叠屏、竖屏视频新适配,播放页可隐藏黑边、截图、点踩,弹幕粗细调整,默认关闭后台播放,弹窗接受返回

This commit is contained in:
orz12
2024-05-20 14:46:31 +08:00
parent fd51cddeca
commit 074bf03946
97 changed files with 4105 additions and 2672 deletions

View File

@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
class CacheManage {
CacheManage._internal();
@@ -76,17 +77,16 @@ class CacheManage {
}
// 清除缓存
Future<bool> clearCacheAll() async {
bool cleanStatus = await SmartDialog.show(
useSystem: true,
animationType: SmartAnimationType.centerFade_otherSlide,
builder: (BuildContext context) {
Future<bool> clearCacheAll(BuildContext context) async {
bool cleanStatus = await showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('提示'),
content: const Text('该操作将清除图片及网络请求缓存数据,确认清除?'),
actions: [
TextButton(
onPressed: (() => {SmartDialog.dismiss()}),
onPressed: () => Get.back(),
child: Text(
'取消',
style: TextStyle(color: Theme.of(context).colorScheme.outline),
@@ -94,7 +94,7 @@ class CacheManage {
),
TextButton(
onPressed: () async {
SmartDialog.dismiss();
Get.back();
SmartDialog.showLoading(msg: '正在清除...');
try {
// 清除缓存 图片缓存

View File

@@ -10,15 +10,15 @@ import 'dart:io';
class DownloadUtils {
// 获取存储权限
static Future<bool> requestStoragePer() async {
static Future<bool> requestStoragePer(BuildContext context) async {
await Permission.storage.request();
PermissionStatus status = await Permission.storage.status;
if (status == PermissionStatus.denied ||
status == PermissionStatus.permanentlyDenied) {
SmartDialog.show(
useSystem: true,
animationType: SmartAnimationType.centerFade_otherSlide,
builder: (BuildContext context) {
if (!context.mounted) return false;
await showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('提示'),
content: const Text('存储权限未授权'),
@@ -69,21 +69,22 @@ class DownloadUtils {
}
}
static Future<bool> checkPermissionDependOnSdkInt() async {
static Future<bool> checkPermissionDependOnSdkInt(BuildContext context) async {
if (Platform.isAndroid) {
final androidInfo = await DeviceInfoPlugin().androidInfo;
if (androidInfo.version.sdkInt <= 32) {
return await requestStoragePer();
if (!context.mounted) return false;
return await requestStoragePer(context);
} else {
return await requestPhotoPer();
}
}
return await requestStoragePer();
return await requestStoragePer(context);
}
static Future<bool> downloadImg(String imgUrl,
static Future<bool> downloadImg(BuildContext context, String imgUrl,
{String imgType = 'cover'}) async {
try {
if (!await checkPermissionDependOnSdkInt()) {
if (!await checkPermissionDependOnSdkInt(context)) {
// // return false;
}
SmartDialog.showLoading(msg: '正在下载原图');

View File

@@ -1,18 +1,112 @@
import 'dart:math';
import 'package:flutter/cupertino.dart';
import 'package:flutter/rendering.dart';
import 'storage.dart';
class Grid {
static double maxRowWidth = GStrorage.setting.get(SettingBoxKey.maxRowWidth, defaultValue: 240.0) as double;
static double calculateActualWidth(BuildContext context, double maxCrossAxisExtent, double crossAxisSpacing, {double? screenWidthOffset}) {
double screenWidth = MediaQuery.of(context).size.width;
if (screenWidthOffset != null) {
screenWidth -= screenWidthOffset;
}
int columnCount = ((screenWidth - crossAxisSpacing) / (maxCrossAxisExtent + crossAxisSpacing)).ceil();
if (columnCount < 1){
columnCount = 1;
}
double columnWidth = (screenWidth - crossAxisSpacing) ~/ columnCount - crossAxisSpacing;
return columnWidth;
}
//
// static double calculateActualWidth(BuildContext context, double maxCrossAxisExtent, double crossAxisSpacing, {double? screenWidthOffset}) {
// double screenWidth = MediaQuery.of(context).size.width;
// if (screenWidthOffset != null) {
// screenWidth -= screenWidthOffset;
// }
// if (GStrorage.setting.get(SettingBoxKey.adaptiveNavBar, defaultValue: false) as bool) {
// screenWidth -= 55;
// }
// int columnCount = ((screenWidth - crossAxisSpacing) / (maxCrossAxisExtent + crossAxisSpacing)).ceil();
// if (columnCount < 1){
// columnCount = 1;
// }
// double columnWidth = (screenWidth - crossAxisSpacing) ~/ columnCount - crossAxisSpacing;
// return columnWidth;
// }
}
class SliverGridDelegateWithExtentAndRatio extends SliverGridDelegate {
/// Creates a delegate that makes grid layouts with tiles that have a maximum
/// cross-axis extent.
///
/// The [maxCrossAxisExtent], [mainAxisExtent], [mainAxisSpacing],
/// and [crossAxisSpacing] arguments must not be negative.
/// The [childAspectRatio] argument must be greater than zero.
const SliverGridDelegateWithExtentAndRatio({
required this.maxCrossAxisExtent,
this.mainAxisSpacing = 0.0,
this.crossAxisSpacing = 0.0,
this.childAspectRatio = 1.0,
this.mainAxisExtent = 0.0,
}) : assert(maxCrossAxisExtent > 0),
assert(mainAxisSpacing >= 0),
assert(crossAxisSpacing >= 0),
assert(childAspectRatio > 0);
/// The maximum extent of tiles in the cross axis.
///
/// This delegate will select a cross-axis extent for the tiles that is as
/// large as possible subject to the following conditions:
///
/// - The extent evenly divides the cross-axis extent of the grid.
/// - The extent is at most [maxCrossAxisExtent].
///
/// For example, if the grid is vertical, the grid is 500.0 pixels wide, and
/// [maxCrossAxisExtent] is 150.0, this delegate will create a grid with 4
/// columns that are 125.0 pixels wide.
final double maxCrossAxisExtent;
/// The number of logical pixels between each child along the main axis.
final double mainAxisSpacing;
/// The number of logical pixels between each child along the cross axis.
final double crossAxisSpacing;
/// The ratio of the cross-axis to the main-axis extent of each child.
final double childAspectRatio;
/// The extent of each tile in the main axis. If provided, it would add
/// after [childAspectRatio] is used.
final double mainAxisExtent;
bool _debugAssertIsValid(double crossAxisExtent) {
assert(crossAxisExtent > 0.0);
assert(maxCrossAxisExtent > 0.0);
assert(mainAxisSpacing >= 0.0);
assert(crossAxisSpacing >= 0.0);
assert(childAspectRatio > 0.0);
return true;
}
@override
SliverGridLayout getLayout(SliverConstraints constraints) {
assert(_debugAssertIsValid(constraints.crossAxisExtent));
int crossAxisCount = ((constraints.crossAxisExtent - crossAxisSpacing) / (maxCrossAxisExtent + crossAxisSpacing)).ceil();
// Ensure a minimum count of 1, can be zero and result in an infinite extent
// below when the window size is 0.
crossAxisCount = max(1, crossAxisCount);
final double usableCrossAxisExtent = max(
0.0,
constraints.crossAxisExtent - crossAxisSpacing * (crossAxisCount - 1),
);
final double childCrossAxisExtent = usableCrossAxisExtent / crossAxisCount;
final double childMainAxisExtent = childCrossAxisExtent / childAspectRatio + mainAxisExtent;
return SliverGridRegularTileLayout(
crossAxisCount: crossAxisCount,
mainAxisStride: childMainAxisExtent + mainAxisSpacing,
crossAxisStride: childCrossAxisExtent + crossAxisSpacing,
childMainAxisExtent: childMainAxisExtent,
childCrossAxisExtent: childCrossAxisExtent,
reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection),
);
}
@override
bool shouldRelayout(SliverGridDelegateWithExtentAndRatio oldDelegate) {
return oldDelegate.maxCrossAxisExtent != maxCrossAxisExtent
|| oldDelegate.mainAxisSpacing != mainAxisSpacing
|| oldDelegate.crossAxisSpacing != crossAxisSpacing
|| oldDelegate.childAspectRatio != childAspectRatio
|| oldDelegate.mainAxisExtent != mainAxisExtent;
}
}

View File

@@ -145,6 +145,7 @@ class SettingBoxKey {
/// 其他
autoUpdate = 'autoUpdate',
autoClearCache = 'autoClearCache',
defaultShowComment = 'defaultShowComment',
replySortType = 'replySortType',
defaultDynamicType = 'defaultDynamicType',
enableHotKey = 'enableHotKey',
@@ -156,7 +157,7 @@ class SettingBoxKey {
disableLikeMsg = 'disableLikeMsg',
defaultHomePage = 'defaultHomePage',
// 弹幕相关设置 权重(云屏蔽) 屏蔽类型 显示区域 透明度 字体大小 弹幕时间 描边粗细
// 弹幕相关设置 权重(云屏蔽) 屏蔽类型 显示区域 透明度 字体大小 弹幕时间 描边粗细 字体粗细
danmakuWeight = 'danmakuWeight',
danmakuBlockType = 'danmakuBlockType',
danmakuShowArea = 'danmakuShowArea',
@@ -164,6 +165,8 @@ class SettingBoxKey {
danmakuFontScale = 'danmakuFontScale',
danmakuDuration = 'danmakuDuration',
strokeWidth = 'strokeWidth',
fontWeight = 'fontWeight',
danmakuFilterRule = 'danmakuFilterRule',
// 代理host port
systemProxyHost = 'systemProxyHost',
@@ -177,6 +180,9 @@ class SettingBoxKey {
enableSingleRow = 'enableSingleRow', // 首页单列
displayMode = 'displayMode',
maxRowWidth = 'maxRowWidth', // 首页列最大宽度dp
videoPlayerRemoveSafeArea = 'videoPlayerHideStatusBar',
dynamicsWaterfallFlow = 'dynamicsWaterfallFlow', // 动态瀑布流
upPanelPosition = 'upPanelPosition', // up主面板位置
adaptiveNavBar = 'adaptiveNavBar',
enableMYBar = 'enableMYBar',
hideSearchBar = 'hideSearchBar', // 收起顶栏
@@ -184,8 +190,7 @@ class SettingBoxKey {
tabbarSort = 'tabbarSort', // 首页tabbar
dynamicBadgeMode = 'dynamicBadgeMode',
hiddenSettingUnlocked = 'hiddenSettingUnlocked',
enableGradientBg = 'enableGradientBg',
defaultShowComment = 'defaultShowComment';
enableGradientBg = 'enableGradientBg';
}
class LocalCacheKey {

View File

@@ -351,7 +351,7 @@ class Utils {
child: Text(
"点此查看完整更新即commit内容",
style:
TextStyle(color: Theme.of(context).primaryColor),
TextStyle(color: Theme.of(context).colorScheme.primary),
)),
],
),
@@ -361,7 +361,7 @@ class Utils {
TextButton(
onPressed: () {
setting.put(SettingBoxKey.autoUpdate, false);
SmartDialog.dismiss();
Get.back();
},
child: Text(
'不再提醒',
@@ -370,7 +370,7 @@ class Utils {
),
),
TextButton(
onPressed: () => SmartDialog.dismiss(),
onPressed: () => Get.back(),
child: Text(
'取消',
style: