新增模拟未登录推荐,独立推荐设置,新增accesskey风控警告,统一推荐逻辑
This commit is contained in:
@ -1,9 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/http/member.dart';
|
||||
import 'package:pilipala/models/common/dynamics_type.dart';
|
||||
import 'package:pilipala/models/common/rcmd_type.dart';
|
||||
import 'package:pilipala/models/common/reply_sort_type.dart';
|
||||
import 'package:pilipala/pages/setting/widgets/select_dialog.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
@ -20,23 +18,16 @@ class ExtraSetting extends StatefulWidget {
|
||||
class _ExtraSettingState extends State<ExtraSetting> {
|
||||
Box setting = GStrorage.setting;
|
||||
static Box localCache = GStrorage.localCache;
|
||||
late dynamic defaultRcmdType;
|
||||
late dynamic defaultReplySort;
|
||||
late dynamic defaultDynamicType;
|
||||
late dynamic enableSystemProxy;
|
||||
late String defaultSystemProxyHost;
|
||||
late String defaultSystemProxyPort;
|
||||
Box userInfoCache = GStrorage.userInfo;
|
||||
var userInfo;
|
||||
bool userLogin = false;
|
||||
var accessKeyInfo;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 首页默认推荐类型
|
||||
defaultRcmdType =
|
||||
setting.get(SettingBoxKey.defaultRcmdType, defaultValue: 'web');
|
||||
// 默认优先显示最新评论
|
||||
defaultReplySort =
|
||||
setting.get(SettingBoxKey.replySortType, defaultValue: 0);
|
||||
@ -49,9 +40,6 @@ class _ExtraSettingState extends State<ExtraSetting> {
|
||||
localCache.get(LocalCacheKey.systemProxyHost, defaultValue: '');
|
||||
defaultSystemProxyPort =
|
||||
localCache.get(LocalCacheKey.systemProxyPort, defaultValue: '');
|
||||
userInfo = userInfoCache.get('userInfoCache');
|
||||
userLogin = userInfo != null;
|
||||
accessKeyInfo = localCache.get(LocalCacheKey.accessKey, defaultValue: null);
|
||||
}
|
||||
|
||||
// 设置代理
|
||||
@ -159,12 +147,6 @@ class _ExtraSettingState extends State<ExtraSetting> {
|
||||
setKey: SettingBoxKey.enableSearchWord,
|
||||
defaultVal: true,
|
||||
),
|
||||
const SetSwitchItem(
|
||||
title: '推荐动态',
|
||||
subTitle: '是否在推荐内容中展示动态',
|
||||
setKey: SettingBoxKey.enableRcmdDynamic,
|
||||
defaultVal: true,
|
||||
),
|
||||
const SetSwitchItem(
|
||||
title: '快速收藏',
|
||||
subTitle: '点按收藏至默认,长按选择文件夹',
|
||||
@ -177,50 +159,6 @@ class _ExtraSettingState extends State<ExtraSetting> {
|
||||
setKey: SettingBoxKey.enableWordRe,
|
||||
defaultVal: false,
|
||||
),
|
||||
const SetSwitchItem(
|
||||
title: '首页推荐刷新',
|
||||
subTitle: '下拉刷新时保留上次内容',
|
||||
setKey: SettingBoxKey.enableSaveLastData,
|
||||
defaultVal: false,
|
||||
),
|
||||
ListTile(
|
||||
dense: false,
|
||||
title: Text('首页推荐类型', style: titleStyle),
|
||||
subtitle: Text(
|
||||
'当前使用「$defaultRcmdType端」推荐',
|
||||
style: subTitleStyle,
|
||||
),
|
||||
onTap: () async {
|
||||
String? result = await showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return SelectDialog<String>(
|
||||
title: '推荐类型',
|
||||
value: defaultRcmdType,
|
||||
values: RcmdType.values.map((e) {
|
||||
return {'title': e.labels, 'value': e.values};
|
||||
}).toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
if (result != null) {
|
||||
if (result == 'app') {
|
||||
// app端推荐需要access_key
|
||||
if (accessKeyInfo == null) {
|
||||
if (!userLogin) {
|
||||
SmartDialog.showToast('请先登录');
|
||||
return;
|
||||
}
|
||||
await MemberHttp.cookieToKey();
|
||||
}
|
||||
}
|
||||
defaultRcmdType = result;
|
||||
setting.put(SettingBoxKey.defaultRcmdType, result);
|
||||
SmartDialog.showToast('下次启动时生效');
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
),
|
||||
const SetSwitchItem(
|
||||
title: '启用ai总结',
|
||||
subTitle: '视频详情页开启ai总结',
|
||||
|
137
lib/pages/setting/recommend_setting.dart
Normal file
137
lib/pages/setting/recommend_setting.dart
Normal file
@ -0,0 +1,137 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/http/member.dart';
|
||||
import 'package:pilipala/models/common/rcmd_type.dart';
|
||||
import 'package:pilipala/pages/setting/widgets/select_dialog.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
|
||||
import 'widgets/switch_item.dart';
|
||||
|
||||
class RecommendSetting extends StatefulWidget {
|
||||
const RecommendSetting({super.key});
|
||||
|
||||
@override
|
||||
State<RecommendSetting> createState() => _RecommendSettingState();
|
||||
}
|
||||
|
||||
class _RecommendSettingState extends State<RecommendSetting> {
|
||||
Box setting = GStrorage.setting;
|
||||
static Box localCache = GStrorage.localCache;
|
||||
late dynamic defaultRcmdType;
|
||||
Box userInfoCache = GStrorage.userInfo;
|
||||
late dynamic userInfo;
|
||||
bool userLogin = false;
|
||||
late dynamic accessKeyInfo;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 首页默认推荐类型
|
||||
defaultRcmdType =
|
||||
setting.get(SettingBoxKey.defaultRcmdType, defaultValue: 'web');
|
||||
userInfo = userInfoCache.get('userInfoCache');
|
||||
userLogin = userInfo != null;
|
||||
accessKeyInfo = localCache.get(LocalCacheKey.accessKey, defaultValue: null);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
TextStyle titleStyle = Theme.of(context).textTheme.titleMedium!;
|
||||
TextStyle subTitleStyle = Theme.of(context)
|
||||
.textTheme
|
||||
.labelMedium!
|
||||
.copyWith(color: Theme.of(context).colorScheme.outline);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: false,
|
||||
titleSpacing: 0,
|
||||
title: Text(
|
||||
'推荐设置',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
const SetSwitchItem(
|
||||
title: '推荐动态',
|
||||
subTitle: '是否在推荐内容中展示动态',
|
||||
setKey: SettingBoxKey.enableRcmdDynamic,
|
||||
defaultVal: true,
|
||||
),
|
||||
const SetSwitchItem(
|
||||
title: '首页推荐刷新',
|
||||
subTitle: '下拉刷新时保留上次内容',
|
||||
setKey: SettingBoxKey.enableSaveLastData,
|
||||
defaultVal: false,
|
||||
),
|
||||
ListTile(
|
||||
dense: false,
|
||||
title: Text('首页推荐类型', style: titleStyle),
|
||||
subtitle: Text(
|
||||
'当前使用「$defaultRcmdType端」推荐',
|
||||
style: subTitleStyle,
|
||||
),
|
||||
onTap: () async {
|
||||
String? result = await showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return SelectDialog<String>(
|
||||
title: '推荐类型',
|
||||
value: defaultRcmdType,
|
||||
values: RcmdType.values.map((e) {
|
||||
return {'title': e.labels, 'value': e.values};
|
||||
}).toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
if (result != null) {
|
||||
if (result == 'app') {
|
||||
// app端推荐需要access_key
|
||||
if (accessKeyInfo == null) {
|
||||
if (!userLogin) {
|
||||
SmartDialog.showToast('请先登录');
|
||||
return;
|
||||
}
|
||||
// 显示一个确认框,告知用户可能会导致账号被风控
|
||||
SmartDialog.show(
|
||||
animationType: SmartAnimationType.centerFade_otherSlide,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text('提示'),
|
||||
content: const Text(
|
||||
'使用app端推荐需获取access_key,有小概率触发风控导致账号退出(在官方app重新登录即可解除),是否继续?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
result = null;
|
||||
SmartDialog.dismiss();
|
||||
},
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
SmartDialog.dismiss();
|
||||
await MemberHttp.cookieToKey();
|
||||
},
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (result != null) {
|
||||
defaultRcmdType = result;
|
||||
setting.put(SettingBoxKey.defaultRcmdType, result);
|
||||
SmartDialog.showToast('下次启动时生效');
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -24,6 +24,11 @@ class SettingPage extends StatelessWidget {
|
||||
dense: false,
|
||||
title: const Text('隐私设置'),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () => Get.toNamed('/recommendSetting'),
|
||||
dense: false,
|
||||
title: const Text('推荐设置'),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () => Get.toNamed('/playSetting'),
|
||||
dense: false,
|
||||
|
Reference in New Issue
Block a user