opt: post segments

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-11-26 16:28:01 +08:00
parent 4f4f000e98
commit 4df9f55e00

View File

@@ -1044,6 +1044,22 @@ class VideoDetailController extends GetxController
Widget _postPanel(onClose, [bool isChild = true]) => StatefulBuilder( Widget _postPanel(onClose, [bool isChild = true]) => StatefulBuilder(
builder: (context, setState) { builder: (context, setState) {
void updateSegment({
required bool isFirst,
required int index,
required int value,
}) {
if (isFirst) {
list![index].segment.first = value;
} else {
list![index].segment.second = value;
}
if (list![index].category == SegmentType.poi_highlight ||
list![index].actionType == ActionType.full) {
list![index].segment.second = value;
}
}
List<Widget> segmentWidget({ List<Widget> segmentWidget({
required int index, required int index,
required bool isFirst, required bool isFirst,
@@ -1063,13 +1079,11 @@ class VideoDetailController extends GetxController
icon: Icons.my_location, icon: Icons.my_location,
onPressed: () { onPressed: () {
setState(() { setState(() {
if (isFirst) { updateSegment(
list![index].segment.first = isFirst: isFirst,
plPlayerController.positionSeconds.value; index: index,
} else { value: plPlayerController.positionSeconds.value,
list![index].segment.second = );
plPlayerController.positionSeconds.value;
}
}); });
}, },
), ),
@@ -1130,11 +1144,11 @@ class VideoDetailController extends GetxController
if (duration <= if (duration <=
plPlayerController.durationSeconds.value) { plPlayerController.durationSeconds.value) {
setState(() { setState(() {
if (isFirst) { updateSegment(
list![index].segment.first = duration; isFirst: isFirst,
} else { index: index,
list![index].segment.second = duration; value: duration,
} );
}); });
} }
} catch (e) { } catch (e) {
@@ -1191,146 +1205,212 @@ class VideoDetailController extends GetxController
children: [ children: [
...List.generate( ...List.generate(
list!.length, list!.length,
(index) => Container( (index) => Stack(
margin: const EdgeInsets.symmetric( children: [
horizontal: 16, Container(
vertical: 5, margin: const EdgeInsets.symmetric(
), horizontal: 16,
padding: const EdgeInsets.all(12), vertical: 5,
decoration: BoxDecoration( ),
color: Theme.of(context) padding: const EdgeInsets.all(12),
.colorScheme decoration: BoxDecoration(
.onInverseSurface, color: Theme.of(context)
borderRadius: BorderRadius.circular(12), .colorScheme
), .onInverseSurface,
child: Column( borderRadius: BorderRadius.circular(12),
mainAxisSize: MainAxisSize.min, ),
children: [ child: Column(
Row( mainAxisSize: MainAxisSize.min,
children: [ children: [
...segmentWidget( if (list![index].category !=
isFirst: true, SegmentType
index: index, .exclusive_access &&
), list![index].actionType !=
const SizedBox(width: 16), ActionType.full) ...[
...segmentWidget( Row(
isFirst: false, children: [
index: index, ...segmentWidget(
), isFirst: true,
const Spacer(), index: index,
iconButton( ),
context: context, if (list![index].category !=
size: 26, SegmentType
tooltip: '移除', .poi_highlight) ...[
icon: Icons.clear, const SizedBox(width: 16),
onPressed: () { ...segmentWidget(
setState(() { isFirst: false,
list!.removeAt(index); index: index,
}); ),
}, ],
), ],
),
const SizedBox(height: 8),
],
Row(
children: [
const Text('分类: '),
PopupMenuButton(
initialValue:
list![index].category,
onSelected: (item) async {
list![index].category = item;
list![index].actionType =
_segmentType2ActionType(
item)
.first;
switch (item) {
case SegmentType
.poi_highlight:
list![index]
.segment
.second =
list![index]
.segment
.first;
break;
case SegmentType
.exclusive_access:
list![index]
.segment
.first = 0;
list![index]
.segment
.second = 0;
break;
case _:
}
setState(() {});
},
itemBuilder: (context) =>
SegmentType.values
.map((item) =>
PopupMenuItem<
SegmentType>(
value: item,
child: Text(
item.title),
))
.toList(),
child: Row(
mainAxisSize:
MainAxisSize.min,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
list![index]
.category
.title,
style: TextStyle(
fontSize: 14,
color: Theme.of(context)
.colorScheme
.primary,
),
),
SizedBox(
height: MediaQuery
.textScalerOf(
context)
.scale(14),
child: Icon(
Icons
.keyboard_arrow_right,
color: Theme.of(context)
.colorScheme
.primary,
),
),
],
),
),
const SizedBox(width: 16),
const Text('行为类别: '),
PopupMenuButton(
initialValue:
list![index].actionType,
onSelected: (item) async {
list![index].actionType =
item;
if (item == ActionType.full) {
updateSegment(
isFirst: true,
index: index,
value: 0,
);
}
setState(() {});
},
itemBuilder: (context) =>
ActionType.values
.map(
(item) =>
PopupMenuItem<
ActionType>(
enabled: _segmentType2ActionType(
list![index]
.category)
.contains(item),
value: item,
child: Text(
item.title),
),
)
.toList(),
child: Row(
mainAxisSize:
MainAxisSize.min,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
list![index]
.actionType
.title,
style: TextStyle(
fontSize: 14,
color: Theme.of(context)
.colorScheme
.primary,
),
),
SizedBox(
height: MediaQuery
.textScalerOf(
context)
.scale(14),
child: Icon(
Icons
.keyboard_arrow_right,
color: Theme.of(context)
.colorScheme
.primary,
),
)
],
),
),
],
)
], ],
), ),
const SizedBox(height: 8), ),
Row( Positioned(
children: [ top: 10,
const Text('分类: '), right: 21,
PopupMenuButton( child: iconButton(
initialValue: list![index].category, context: context,
onSelected: (item) async { size: 26,
list![index].category = item; tooltip: '移除',
list![index].actionType = icon: Icons.clear,
_segmentType2ActionType(item) onPressed: () {
.first; setState(() {
setState(() {}); list!.removeAt(index);
}, });
itemBuilder: (context) => },
SegmentType.values ),
.map((item) => ),
PopupMenuItem< ],
SegmentType>(
value: item,
child:
Text(item.title),
))
.toList(),
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
list![index].category.title,
style: TextStyle(
fontSize: 14,
color: Theme.of(context)
.colorScheme
.primary,
),
),
Icon(
size: 20,
Icons.keyboard_arrow_right,
color: Theme.of(context)
.colorScheme
.primary,
)
],
),
),
const SizedBox(width: 16),
const Text('行为类别: '),
PopupMenuButton(
initialValue:
list![index].actionType,
onSelected: (item) async {
setState(() {
list![index].actionType = item;
});
},
itemBuilder: (context) => ActionType
.values
.map(
(item) =>
PopupMenuItem<ActionType>(
enabled:
_segmentType2ActionType(
list![index]
.category)
.contains(item),
value: item,
child: Text(item.title),
),
)
.toList(),
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
list![index].actionType.title,
style: TextStyle(
fontSize: 14,
color: Theme.of(context)
.colorScheme
.primary,
),
),
Icon(
size: 20,
Icons.keyboard_arrow_right,
color: Theme.of(context)
.colorScheme
.primary,
)
],
),
),
],
)
],
),
), ),
), ),
SizedBox( SizedBox(