mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 11:08:03 +08:00
* tweak * opt: show bar * opt: crc32 * opt: appsign * opt: Get * opt: compress only if large * opt: wbi * tweak Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> --------- Signed-off-by: My-Responsitories <107370289+My-Responsitories@users.noreply.github.com> Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
83 lines
2.3 KiB
Dart
83 lines
2.3 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:PiliPlus/http/danmaku_block.dart';
|
|
import 'package:PiliPlus/models/common/dm_block_type.dart';
|
|
import 'package:PiliPlus/models/user/danmaku_block.dart';
|
|
import 'package:archive/archive.dart' show getCrc32;
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
class DanmakuBlockController extends GetxController
|
|
with GetSingleTickerProviderStateMixin {
|
|
late final List<RxList<SimpleRule>> rules = List.generate(
|
|
DmBlockType.values.length,
|
|
(_) => <SimpleRule>[].obs,
|
|
);
|
|
|
|
late TabController tabController;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
queryDanmakuFilter();
|
|
tabController = TabController(length: 3, vsync: this);
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
tabController.dispose();
|
|
super.onClose();
|
|
}
|
|
|
|
Future<void> queryDanmakuFilter() async {
|
|
SmartDialog.showLoading(msg: '正在同步弹幕屏蔽规则……');
|
|
final result = await DanmakuFilterHttp.danmakuFilter();
|
|
SmartDialog.dismiss();
|
|
if (result.isSuccess) {
|
|
final data = result.data;
|
|
rules[0].addAll(data.rule);
|
|
rules[1].addAll(data.rule1);
|
|
rules[2].addAll(data.rule2);
|
|
if (data.toast != null) {
|
|
SmartDialog.showToast(data.toast!);
|
|
}
|
|
} else {
|
|
result.toast();
|
|
}
|
|
}
|
|
|
|
Future<void> danmakuFilterDel(int tabIndex, int itemIndex, int id) async {
|
|
SmartDialog.showLoading(msg: '正在删除弹幕屏蔽规则……');
|
|
final result = await DanmakuFilterHttp.danmakuFilterDel(ids: id);
|
|
SmartDialog.dismiss();
|
|
if (result.isSuccess) {
|
|
rules[tabIndex].removeAt(itemIndex);
|
|
SmartDialog.showToast('删除成功');
|
|
} else {
|
|
result.toast();
|
|
}
|
|
}
|
|
|
|
Future<void> danmakuFilterAdd({
|
|
required String filter,
|
|
required int type,
|
|
}) async {
|
|
if (type == 2) {
|
|
filter = getCrc32(ascii.encode(filter), 0).toRadixString(16);
|
|
}
|
|
SmartDialog.showLoading(msg: '正在添加弹幕屏蔽规则……');
|
|
final result = await DanmakuFilterHttp.danmakuFilterAdd(
|
|
filter: filter,
|
|
type: type,
|
|
);
|
|
SmartDialog.dismiss();
|
|
if (result.isSuccess) {
|
|
rules[type].add(result.data);
|
|
SmartDialog.showToast('添加成功');
|
|
} else {
|
|
result.toast();
|
|
}
|
|
}
|
|
}
|