mod: 新增推荐过滤器,回退model转换修改,移除不必要的futureBuilder
This commit is contained in:
52
lib/utils/recommend_filter.dart
Normal file
52
lib/utils/recommend_filter.dart
Normal file
@ -0,0 +1,52 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'storage.dart';
|
||||
|
||||
class RecommendFilter {
|
||||
// static late int filterUnfollowedRatio;
|
||||
static late int minDurationForRcmd;
|
||||
static late int minLikeRatioForRecommend;
|
||||
static late bool exemptFilterForFollowed;
|
||||
static late bool applyFilterToRelatedVideos;
|
||||
RecommendFilter() {
|
||||
update();
|
||||
}
|
||||
|
||||
static void update() {
|
||||
var setting = GStrorage.setting;
|
||||
// filterUnfollowedRatio =
|
||||
// setting.get(SettingBoxKey.filterUnfollowedRatio, defaultValue: 0);
|
||||
minDurationForRcmd =
|
||||
setting.get(SettingBoxKey.minDurationForRcmd, defaultValue: 0);
|
||||
minLikeRatioForRecommend =
|
||||
setting.get(SettingBoxKey.minLikeRatioForRecommend, defaultValue: 0);
|
||||
exemptFilterForFollowed =
|
||||
setting.get(SettingBoxKey.exemptFilterForFollowed, defaultValue: true);
|
||||
applyFilterToRelatedVideos = setting
|
||||
.get(SettingBoxKey.applyFilterToRelatedVideos, defaultValue: true);
|
||||
}
|
||||
|
||||
static bool filter(dynamic videoItem, {bool relatedVideos = false}) {
|
||||
if (relatedVideos && !applyFilterToRelatedVideos) {
|
||||
return false;
|
||||
}
|
||||
//由于相关视频中没有已关注标签,只能视为非关注视频
|
||||
if (!relatedVideos &&
|
||||
videoItem.isFollowed == 1 &&
|
||||
exemptFilterForFollowed) {
|
||||
return false;
|
||||
}
|
||||
if (videoItem.duration > 0 && videoItem.duration < minDurationForRcmd) {
|
||||
return true;
|
||||
}
|
||||
if (videoItem.stat.view is int &&
|
||||
videoItem.stat.view > -1 &&
|
||||
videoItem.stat.like is int &&
|
||||
videoItem.stat.like > -1 &&
|
||||
videoItem.stat.like * 100 <
|
||||
minLikeRatioForRecommend * videoItem.stat.view) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -124,6 +124,11 @@ class SettingBoxKey {
|
||||
enableRcmdDynamic = 'enableRcmdDynamic',
|
||||
defaultRcmdType = 'defaultRcmdType',
|
||||
enableSaveLastData = 'enableSaveLastData',
|
||||
minDurationForRcmd = 'minDurationForRcmd',
|
||||
minLikeRatioForRecommend = 'minLikeRatioForRecommend',
|
||||
exemptFilterForFollowed = 'exemptFilterForFollowed',
|
||||
//filterUnfollowedRatio = 'filterUnfollowedRatio',
|
||||
applyFilterToRelatedVideos = 'applyFilterToRelatedVideos',
|
||||
|
||||
/// 其他
|
||||
autoUpdate = 'autoUpdate',
|
||||
|
@ -9,7 +9,6 @@ import 'package:crypto/crypto.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get_utils/get_utils.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
@ -28,10 +27,16 @@ class Utils {
|
||||
return tempPath;
|
||||
}
|
||||
|
||||
static String numFormat(int number) {
|
||||
static String numFormat(dynamic number) {
|
||||
if (number == null){
|
||||
return '0';
|
||||
}
|
||||
if (number is String) {
|
||||
return number;
|
||||
}
|
||||
final String res = (number / 10000).toString();
|
||||
if (int.parse(res.split('.')[0]) >= 1) {
|
||||
return '${(number / 10000).toPrecision(1)}万';
|
||||
return '${(number / 10000).toStringAsFixed(1)}万';
|
||||
} else {
|
||||
return number.toString();
|
||||
}
|
||||
|
Reference in New Issue
Block a user