mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-26 21:35:49 +08:00
tweaks (#1821)
* opt: _onTapUp * opt: set contains * opt: elementAtOrNull
This commit is contained in:
committed by
GitHub
parent
37fa165f59
commit
7260a387f9
@@ -1,5 +1,4 @@
|
||||
import 'package:PiliPlus/models/common/account_type.dart';
|
||||
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
class AccountTypeAdapter extends TypeAdapter<AccountType> {
|
||||
@@ -8,7 +7,7 @@ class AccountTypeAdapter extends TypeAdapter<AccountType> {
|
||||
|
||||
@override
|
||||
AccountType read(BinaryReader reader) =>
|
||||
AccountType.values.getOrNull(reader.readByte()) ?? AccountType.main;
|
||||
AccountType.values.elementAtOrNull(reader.readByte()) ?? AccountType.main;
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, AccountType obj) {
|
||||
|
||||
@@ -14,7 +14,6 @@ import 'package:PiliPlus/pages/live/view.dart';
|
||||
import 'package:PiliPlus/pages/rank/view.dart';
|
||||
import 'package:PiliPlus/pages/subscription_detail/view.dart';
|
||||
import 'package:PiliPlus/pages/video/reply_reply/view.dart';
|
||||
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
import 'package:PiliPlus/utils/page_utils.dart';
|
||||
import 'package:PiliPlus/utils/request_utils.dart';
|
||||
@@ -579,7 +578,7 @@ abstract final class PiliScheme {
|
||||
}
|
||||
final first = pathSegments.first;
|
||||
final String? area = const ['mobile', 'h5', 'v'].contains(first)
|
||||
? pathSegments.getOrNull(1)
|
||||
? pathSegments.elementAtOrNull(1)
|
||||
: first;
|
||||
// if (kDebugMode) debugPrint('area: $area');
|
||||
switch (area) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
||||
import 'package:PiliPlus/utils/platform_utils.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
@@ -55,7 +54,7 @@ abstract final class CacheManager {
|
||||
value = value / 1024;
|
||||
}
|
||||
String size = value.toStringAsFixed(2);
|
||||
return size + (unitArr.getOrNull(index) ?? '');
|
||||
return size + (unitArr.elementAtOrNull(index) ?? '');
|
||||
}
|
||||
|
||||
// 清除 Library/Caches 目录及文件缓存
|
||||
|
||||
@@ -24,13 +24,6 @@ extension IterableExt<T> on Iterable<T> {
|
||||
}
|
||||
|
||||
extension ListExt<T> on List<T> {
|
||||
T? getOrNull(int index) {
|
||||
if (index < 0 || index >= length) {
|
||||
return null;
|
||||
}
|
||||
return this[index];
|
||||
}
|
||||
|
||||
bool removeFirstWhere(bool Function(T) test) {
|
||||
final index = indexWhere(test);
|
||||
if (index != -1) {
|
||||
@@ -50,4 +43,27 @@ extension ListExt<T> on List<T> {
|
||||
) {
|
||||
return where(test).reduceOrNull(combine) ?? reduce(combine);
|
||||
}
|
||||
|
||||
/// from [algorithms.lowerBoundBy].
|
||||
int lowerBoundByKey<K extends Comparable<K>>(
|
||||
K Function(T element) keyOf,
|
||||
K key, [
|
||||
int start = 0,
|
||||
int? end,
|
||||
]) {
|
||||
end = RangeError.checkValidRange(start, end, length);
|
||||
var min = start;
|
||||
var max = end;
|
||||
while (min < max) {
|
||||
var mid = min + ((max - min) >> 1);
|
||||
var element = this[mid];
|
||||
var comp = keyOf(element).compareTo(key);
|
||||
if (comp < 0) {
|
||||
min = mid + 1;
|
||||
} else {
|
||||
max = mid;
|
||||
}
|
||||
}
|
||||
return min;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,7 +461,7 @@ abstract final class Pref {
|
||||
SuperResolutionType? superResolutionType;
|
||||
final index = _setting.get(SettingBoxKey.superResolutionType);
|
||||
if (index != null) {
|
||||
superResolutionType = SuperResolutionType.values.getOrNull(index);
|
||||
superResolutionType = SuperResolutionType.values.elementAtOrNull(index);
|
||||
}
|
||||
return superResolutionType ?? SuperResolutionType.disable;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user