mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-23 10:36:24 +08:00
tweaks (#1142)
* opt: unused layout * mod: semantics * opt: DanmakuMsg type * opt: avoid cast * opt: unnecessary_lambdas * opt: use isEven * opt: logger * opt: invalid common page * tweak * opt: unify DynController
This commit is contained in:
committed by
GitHub
parent
56ffc2781f
commit
5f8313901b
@@ -78,7 +78,7 @@ class Accounts {
|
||||
}
|
||||
await Future.wait(
|
||||
(accountMode.values.toSet()..retainWhere((i) => !i.activited)).map(
|
||||
(i) => Request.buvidActive(i),
|
||||
Request.buvidActive,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ class AccountManager extends Interceptor {
|
||||
...?previousCookies
|
||||
?.split(';')
|
||||
.where((e) => e.isNotEmpty)
|
||||
.map((c) => Cookie.fromSetCookieValue(c)),
|
||||
.map(Cookie.fromSetCookieValue),
|
||||
...cookies,
|
||||
]);
|
||||
options.headers[HttpHeaders.cookieHeader] = newCookies.isNotEmpty
|
||||
@@ -257,7 +257,7 @@ class AccountManager extends Interceptor {
|
||||
.map((str) => str.split(_setCookieReg))
|
||||
.expand((cookie) => cookie)
|
||||
.where((cookie) => cookie.isNotEmpty)
|
||||
.map((str) => Cookie.fromSetCookieValue(str))
|
||||
.map(Cookie.fromSetCookieValue)
|
||||
.toList();
|
||||
final statusCode = response.statusCode ?? 0;
|
||||
final locations = response.headers[HttpHeaders.locationHeader] ?? [];
|
||||
|
||||
@@ -8,7 +8,7 @@ class BiliCookieJarAdapter extends TypeAdapter<DefaultCookieJar> {
|
||||
|
||||
@override
|
||||
DefaultCookieJar read(BinaryReader reader) =>
|
||||
BiliCookieJar.fromJson(reader.readMap().cast<String, String>());
|
||||
BiliCookieJar.fromJson(reader.readMap());
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, DefaultCookieJar obj) {
|
||||
|
||||
@@ -31,9 +31,7 @@ class PiliScheme {
|
||||
appLinks = AppLinks();
|
||||
|
||||
listener?.cancel();
|
||||
listener = appLinks.uriLinkStream.listen((uri) {
|
||||
routePush(uri);
|
||||
});
|
||||
listener = appLinks.uriLinkStream.listen(routePush);
|
||||
}
|
||||
|
||||
static Future<bool> routePushFromUrl(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:intl/intl.dart' show DateFormat;
|
||||
|
||||
class DateUtil {
|
||||
static final _shortFormat = DateFormat('MM-dd');
|
||||
static final shortFormat = DateFormat('MM-dd');
|
||||
static final longFormat = DateFormat('yyyy-MM-dd');
|
||||
static final _shortFormatD = DateFormat('MM-dd HH:mm');
|
||||
static final longFormatD = DateFormat('yyyy-MM-dd HH:mm');
|
||||
@@ -9,8 +9,8 @@ class DateUtil {
|
||||
|
||||
static String dateFormat(
|
||||
int? time, {
|
||||
DateFormat? shortFormat,
|
||||
DateFormat? longFormat,
|
||||
DateFormat? short,
|
||||
DateFormat? long,
|
||||
}) {
|
||||
if (time == null || time == 0) {
|
||||
return '';
|
||||
@@ -37,8 +37,8 @@ class DateUtil {
|
||||
return '$dayDiff天前';
|
||||
}
|
||||
final DateFormat sdf = now.year == date.year
|
||||
? shortFormat ?? _shortFormat
|
||||
: longFormat ?? DateUtil.longFormat;
|
||||
? short ?? shortFormat
|
||||
: long ?? DateUtil.longFormat;
|
||||
return sdf.format(date);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class DurationUtil {
|
||||
List<int> split = data
|
||||
.split(':')
|
||||
.reversed
|
||||
.map((e) => int.parse(e))
|
||||
.map(int.parse)
|
||||
.toList();
|
||||
int duration = 0;
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
|
||||
@@ -48,6 +48,18 @@ extension IterableExt<T> on Iterable<T>? {
|
||||
bool get isNullOrEmpty => this == null || this!.isEmpty;
|
||||
}
|
||||
|
||||
extension MapExt<K, V> on Map<K, V> {
|
||||
Map<RK, RV> fromCast<RK, RV>() {
|
||||
return Map<RK, RV>.from(this);
|
||||
}
|
||||
}
|
||||
|
||||
extension NonNullListExt<T> on List<T> {
|
||||
List<R> fromCast<R>() {
|
||||
return List<R>.from(this);
|
||||
}
|
||||
}
|
||||
|
||||
extension ListExt<T> on List<T>? {
|
||||
T? getOrNull(int index) {
|
||||
if (isNullOrEmpty) {
|
||||
|
||||
@@ -102,31 +102,30 @@ class Pref {
|
||||
),
|
||||
);
|
||||
|
||||
static List<int>? get tabbarSort =>
|
||||
(_setting.get(SettingBoxKey.tabBarSort) as List?)?.cast<int>();
|
||||
|
||||
static List<Pair<SegmentType, SkipType>> get blockSettings {
|
||||
List<int>? list = (_setting.get(SettingBoxKey.blockSettings) as List?)
|
||||
?.cast<int>();
|
||||
final list = _setting.get(SettingBoxKey.blockSettings) as List?;
|
||||
if (list == null) {
|
||||
return SegmentType.values
|
||||
.map((i) => Pair(first: i, second: SkipType.values[i.index]))
|
||||
.toList();
|
||||
}
|
||||
return SegmentType.values
|
||||
.map(
|
||||
(item) => Pair<SegmentType, SkipType>(
|
||||
first: item,
|
||||
second: SkipType.values[list?[item.index] ?? 1],
|
||||
),
|
||||
(item) =>
|
||||
Pair(first: item, second: SkipType.values[list[item.index]]),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
static List<Color> get blockColor {
|
||||
List<String>? list = (_setting.get(SettingBoxKey.blockColor) as List?)
|
||||
?.cast<String>();
|
||||
final list = _setting.get(SettingBoxKey.blockColor) as List?;
|
||||
if (list == null) {
|
||||
return SegmentType.values.map((i) => i.color).toList();
|
||||
}
|
||||
return SegmentType.values.map(
|
||||
(item) {
|
||||
final e = list?[item.index];
|
||||
final color = e != null && e.isNotEmpty
|
||||
? int.tryParse('FF$e', radix: 16)
|
||||
: null;
|
||||
final String e = list[item.index];
|
||||
final color = e.isNotEmpty ? int.tryParse('FF$e', radix: 16) : null;
|
||||
return color != null ? Color(color) : item.color;
|
||||
},
|
||||
).toList();
|
||||
@@ -692,11 +691,9 @@ class Pref {
|
||||
static bool get enableHA =>
|
||||
_setting.get(SettingBoxKey.enableHA, defaultValue: true);
|
||||
|
||||
static Set<int> get danmakuBlockType =>
|
||||
(_setting.get(SettingBoxKey.danmakuBlockType, defaultValue: <int>[])
|
||||
as Iterable)
|
||||
.cast<int>()
|
||||
.toSet();
|
||||
static Set<int> get danmakuBlockType => Set<int>.from(
|
||||
_setting.get(SettingBoxKey.danmakuBlockType, defaultValue: const <int>{}),
|
||||
);
|
||||
|
||||
static int get danmakuWeight =>
|
||||
_setting.get(SettingBoxKey.danmakuWeight, defaultValue: 0);
|
||||
|
||||
Reference in New Issue
Block a user