mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-29 12:38:34 +00:00
tweaks (#1821)
* opt: _onTapUp * opt: set contains * opt: elementAtOrNull
This commit is contained in:
committed by
GitHub
parent
37fa165f59
commit
7260a387f9
@@ -17,7 +17,9 @@
|
||||
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/foundation.dart' show listEquals, kDebugMode;
|
||||
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart' show listEquals;
|
||||
import 'package:flutter/gestures.dart' show TapGestureRecognizer;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart' show BoxHitTestEntry;
|
||||
@@ -223,6 +225,8 @@ class RenderViewPointProgressBar
|
||||
final canvas = context.canvas;
|
||||
final paint = Paint()..style = PaintingStyle.fill;
|
||||
|
||||
assert(segments.isSortedBy((i) => i.end));
|
||||
|
||||
canvas.drawRect(
|
||||
Rect.fromLTRB(0, 0, size.width, _barHeight),
|
||||
paint..color = Colors.grey[600]!.withValues(alpha: 0.45),
|
||||
@@ -305,19 +309,16 @@ class RenderViewPointProgressBar
|
||||
}
|
||||
}
|
||||
|
||||
@pragma('vm:notify-debugger-on-exception')
|
||||
void _onTapUp(TapUpDetails details) {
|
||||
try {
|
||||
final seg = details.localPosition.dx / size.width;
|
||||
final item = _segments
|
||||
.where((item) => item.end >= seg)
|
||||
.reduce((a, b) => a.end < b.end ? a : b);
|
||||
final item = _segments[_segments.lowerBoundByKey((i) => i.end, seg)];
|
||||
if (item.from case final from?) {
|
||||
_onSeek?.call(Duration(seconds: from));
|
||||
}
|
||||
// if (kDebugMode) debugPrint('${item.title},,${item.from}');
|
||||
} catch (e) {
|
||||
if (kDebugMode) rethrow;
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import 'package:PiliPlus/models_new/dynamic/dyn_topic_pub_search/data.dart';
|
||||
import 'package:PiliPlus/models_new/pgc/pgc_info_model/result.dart';
|
||||
import 'package:PiliPlus/models_new/search/search_rcmd/data.dart';
|
||||
import 'package:PiliPlus/models_new/search/search_trending/data.dart';
|
||||
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
||||
import 'package:PiliPlus/utils/request_utils.dart';
|
||||
import 'package:PiliPlus/utils/wbi_sign.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
@@ -183,7 +182,8 @@ abstract final class SearchHttp {
|
||||
if (res.data['code'] == 0) {
|
||||
if (res.data['data'] case List list) {
|
||||
return part != null
|
||||
? (list.getOrNull(part - 1)?['cid'] ?? list.firstOrNull?['cid'])
|
||||
? (list.elementAtOrNull(part - 1)?['cid'] ??
|
||||
list.firstOrNull?['cid'])
|
||||
: list.firstOrNull?['cid'];
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -10,7 +10,6 @@ import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/pages/dynamics_tab/controller.dart';
|
||||
import 'package:PiliPlus/services/account_service.dart';
|
||||
import 'package:PiliPlus/utils/accounts.dart';
|
||||
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/scroll_controller_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/string_ext.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
@@ -33,7 +32,7 @@ class DynamicsController extends GetxController
|
||||
LoadingState<FollowUpModel>.loading().obs;
|
||||
late int _upPage = 1;
|
||||
late bool _upEnd = false;
|
||||
List<UpItem>? _cacheUpList;
|
||||
Set<UpItem>? _cacheUpList;
|
||||
late final _showAllUp = Pref.dynamicsShowAllFollowedUp;
|
||||
late bool showLiveUp = Pref.expandDynLivePanel;
|
||||
|
||||
@@ -150,7 +149,7 @@ class DynamicsController extends GetxController
|
||||
final first = res.first;
|
||||
if (first case final Success<FollowUpModel> i) {
|
||||
final data = i.response;
|
||||
final second = res.getOrNull(1);
|
||||
final second = res.elementAtOrNull(1);
|
||||
if (second case final Success<FollowData> j) {
|
||||
final data1 = j.response;
|
||||
final list1 = data1.list;
|
||||
@@ -161,8 +160,7 @@ class DynamicsController extends GetxController
|
||||
}
|
||||
|
||||
final list = data.upList;
|
||||
_cacheUpList = List<UpItem>.from(list);
|
||||
list.addAll(list1..removeWhere(list.contains));
|
||||
list.addAll(list1..removeWhere((_cacheUpList = list.toSet()).contains));
|
||||
}
|
||||
if (!_showAllUp) {
|
||||
if (data.hasMore == false || data.offset.isNullOrEmpty) {
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_detail/media.dart';
|
||||
import 'package:PiliPlus/pages/fav_detail/controller.dart';
|
||||
import 'package:PiliPlus/pages/fav_detail/widget/fav_video_card.dart';
|
||||
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -84,7 +83,7 @@ class _FavSortPageState extends State<FavSortPage> {
|
||||
}
|
||||
|
||||
final oldItem = sortList[oldIndex];
|
||||
final newItem = sortList.getOrNull(
|
||||
final newItem = sortList.elementAtOrNull(
|
||||
oldIndex > newIndex ? newIndex - 1 : newIndex,
|
||||
);
|
||||
sort.add(
|
||||
|
||||
@@ -15,7 +15,6 @@ import 'package:PiliPlus/utils/accounts.dart';
|
||||
import 'package:PiliPlus/utils/app_sign.dart';
|
||||
import 'package:PiliPlus/utils/date_utils.dart';
|
||||
import 'package:PiliPlus/utils/extension/file_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/theme_ext.dart';
|
||||
import 'package:PiliPlus/utils/page_utils.dart';
|
||||
import 'package:PiliPlus/utils/platform_utils.dart';
|
||||
@@ -483,7 +482,7 @@ class _EditProfilePageState extends State<EditProfilePage> {
|
||||
if (pickedFile != null && mounted) {
|
||||
String? mimeType = lookupMimeType(
|
||||
pickedFile.path,
|
||||
)?.split('/').getOrNull(1);
|
||||
)?.split('/').elementAtOrNull(1);
|
||||
if (mimeType == 'gif') {
|
||||
SmartDialog.showToast('不能选GIF');
|
||||
return;
|
||||
|
||||
@@ -9,7 +9,6 @@ import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart'
|
||||
import 'package:PiliPlus/models/common/badge_type.dart';
|
||||
import 'package:PiliPlus/pages/whisper_secondary/view.dart';
|
||||
import 'package:PiliPlus/utils/date_utils.dart';
|
||||
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/num_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/theme_ext.dart';
|
||||
import 'package:PiliPlus/utils/page_utils.dart';
|
||||
@@ -190,7 +189,7 @@ class WhisperSessionItem extends StatelessWidget {
|
||||
leading: Builder(
|
||||
builder: (context) {
|
||||
final pendant = item.sessionInfo.avatar.fallbackLayers.layers
|
||||
.getOrNull(1)
|
||||
.elementAtOrNull(1)
|
||||
?.resource;
|
||||
final official = item
|
||||
.sessionInfo
|
||||
|
||||
@@ -16,7 +16,6 @@ import 'package:PiliPlus/pages/whisper_detail/controller.dart';
|
||||
import 'package:PiliPlus/pages/whisper_detail/widget/chat_item.dart';
|
||||
import 'package:PiliPlus/pages/whisper_link_setting/view.dart';
|
||||
import 'package:PiliPlus/utils/extension/file_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/num_ext.dart';
|
||||
import 'package:PiliPlus/utils/extension/widget_ext.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
@@ -360,7 +359,9 @@ class _WhisperDetailPageState
|
||||
);
|
||||
if (result case Success(:final response)) {
|
||||
final mimeType =
|
||||
lookupMimeType(path)?.split('/').getOrNull(1) ??
|
||||
lookupMimeType(
|
||||
path,
|
||||
)?.split('/').elementAtOrNull(1) ??
|
||||
'jpg';
|
||||
final picMsg = {
|
||||
'url': response.imageUrl,
|
||||
|
||||
@@ -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