mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-30 23:58:13 +08:00
mod: rcmd: show refresh tip
Closes #135 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -194,6 +194,9 @@ class VideoCustomActions {
|
|||||||
SmartDialog.showToast(
|
SmartDialog.showToast(
|
||||||
res['status'] ? "点踩成功" : res['msg'],
|
res['status'] ? "点踩成功" : res['msg'],
|
||||||
);
|
);
|
||||||
|
if (res['status']) {
|
||||||
|
onRemove?.call();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
style: FilledButton.styleFrom(
|
style: FilledButton.styleFrom(
|
||||||
visualDensity: VisualDensity(
|
visualDensity: VisualDensity(
|
||||||
|
|||||||
@@ -4,14 +4,16 @@ import 'package:PiliPlus/pages/common/common_controller.dart';
|
|||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
|
|
||||||
class RcmdController extends CommonController {
|
class RcmdController extends CommonController {
|
||||||
late bool enableSaveLastData;
|
late bool enableSaveLastData = GStorage.setting
|
||||||
|
.get(SettingBoxKey.enableSaveLastData, defaultValue: false);
|
||||||
late String defaultRcmdType = 'app';
|
late String defaultRcmdType = 'app';
|
||||||
|
|
||||||
|
int? lastRefreshAt;
|
||||||
|
late bool savedRcmdTip = GStorage.savedRcmdTip;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
enableSaveLastData = GStorage.setting
|
|
||||||
.get(SettingBoxKey.enableSaveLastData, defaultValue: false);
|
|
||||||
defaultRcmdType = GStorage.setting
|
defaultRcmdType = GStorage.setting
|
||||||
.get(SettingBoxKey.defaultRcmdType, defaultValue: 'app');
|
.get(SettingBoxKey.defaultRcmdType, defaultValue: 'app');
|
||||||
|
|
||||||
@@ -34,12 +36,13 @@ class RcmdController extends CommonController {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List? handleListResponse(List currentList, List dataList) {
|
List? handleListResponse(List currentList, List dataList) {
|
||||||
return currentPage == 0 &&
|
bool shouldSaveLast = enableSaveLastData && currentPage == 0;
|
||||||
enableSaveLastData &&
|
if (shouldSaveLast) {
|
||||||
currentList.isNotEmpty &&
|
int length = currentList.length;
|
||||||
currentList.length < 500
|
shouldSaveLast = shouldSaveLast && length > 0 && length < 500;
|
||||||
? dataList + currentList
|
}
|
||||||
: null;
|
lastRefreshAt = shouldSaveLast && savedRcmdTip ? dataList.length : null;
|
||||||
|
return shouldSaveLast ? dataList + currentList : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -124,21 +124,73 @@ class _RcmdPageState extends State<RcmdPage>
|
|||||||
index == loadingState.response.length - 1) {
|
index == loadingState.response.length - 1) {
|
||||||
_controller.onLoadMore();
|
_controller.onLoadMore();
|
||||||
}
|
}
|
||||||
return loadingState is Success
|
if (widget.tabType == TabType.rcmd) {
|
||||||
? widget.tabType == TabType.rcmd
|
if (loadingState is Success) {
|
||||||
? VideoCardV(
|
RcmdController ctr = _controller as RcmdController;
|
||||||
|
if (ctr.savedRcmdTip) {
|
||||||
|
if (ctr.lastRefreshAt == index) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
_controller.animateToTop();
|
||||||
|
_controller.onRefresh();
|
||||||
|
},
|
||||||
|
child: Card(
|
||||||
|
child: Container(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
|
child: Text(
|
||||||
|
'上次看到这里\n点击刷新',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
color:
|
||||||
|
Theme.of(context).colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
int actualIndex = ctr.lastRefreshAt == null
|
||||||
|
? index
|
||||||
|
: index > ctr.lastRefreshAt!
|
||||||
|
? index - 1
|
||||||
|
: index;
|
||||||
|
return VideoCardV(
|
||||||
|
videoItem: loadingState.response[actualIndex],
|
||||||
|
onRemove: () {
|
||||||
|
if (ctr.lastRefreshAt != null &&
|
||||||
|
actualIndex < ctr.lastRefreshAt!) {
|
||||||
|
ctr.lastRefreshAt = ctr.lastRefreshAt! - 1;
|
||||||
|
}
|
||||||
|
_controller.loadingState.value = LoadingState.success(
|
||||||
|
(loadingState.response as List)..removeAt(actualIndex));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return VideoCardV(
|
||||||
videoItem: loadingState.response[index],
|
videoItem: loadingState.response[index],
|
||||||
onRemove: () {
|
onRemove: () {
|
||||||
_controller.loadingState.value = LoadingState.success(
|
_controller.loadingState.value = LoadingState.success(
|
||||||
(loadingState.response as List)..removeAt(index));
|
(loadingState.response as List)..removeAt(index));
|
||||||
},
|
},
|
||||||
)
|
);
|
||||||
: LiveCardV(
|
}
|
||||||
|
}
|
||||||
|
return const VideoCardVSkeleton();
|
||||||
|
} else {
|
||||||
|
return loadingState is Success
|
||||||
|
? LiveCardV(
|
||||||
liveItem: loadingState.response[index],
|
liveItem: loadingState.response[index],
|
||||||
)
|
)
|
||||||
: const VideoCardVSkeleton();
|
: const VideoCardVSkeleton();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
childCount: loadingState is Success ? loadingState.response.length : 10,
|
childCount: loadingState is Success
|
||||||
|
? widget.tabType == TabType.rcmd &&
|
||||||
|
(_controller as RcmdController).lastRefreshAt != null
|
||||||
|
? loadingState.response.length + 1
|
||||||
|
: loadingState.response.length
|
||||||
|
: 10,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import 'package:PiliPlus/pages/home/controller.dart';
|
|||||||
import 'package:PiliPlus/pages/main/controller.dart';
|
import 'package:PiliPlus/pages/main/controller.dart';
|
||||||
import 'package:PiliPlus/pages/member/new/controller.dart';
|
import 'package:PiliPlus/pages/member/new/controller.dart';
|
||||||
import 'package:PiliPlus/pages/mine/controller.dart';
|
import 'package:PiliPlus/pages/mine/controller.dart';
|
||||||
|
import 'package:PiliPlus/pages/rcmd/controller.dart';
|
||||||
import 'package:PiliPlus/pages/setting/pages/color_select.dart';
|
import 'package:PiliPlus/pages/setting/pages/color_select.dart';
|
||||||
import 'package:PiliPlus/pages/setting/widgets/multi_select_dialog.dart';
|
import 'package:PiliPlus/pages/setting/widgets/multi_select_dialog.dart';
|
||||||
import 'package:PiliPlus/pages/setting/widgets/normal_item.dart';
|
import 'package:PiliPlus/pages/setting/widgets/normal_item.dart';
|
||||||
@@ -1113,12 +1114,33 @@ List<SettingsModel> get recommendSettings => [
|
|||||||
),
|
),
|
||||||
SettingsModel(
|
SettingsModel(
|
||||||
settingsType: SettingsType.sw1tch,
|
settingsType: SettingsType.sw1tch,
|
||||||
title: '首页推荐刷新',
|
title: '保留首页推荐刷新',
|
||||||
subtitle: '下拉刷新时保留上次内容',
|
subtitle: '下拉刷新时保留上次内容',
|
||||||
leading: Icon(Icons.refresh),
|
leading: Icon(Icons.refresh),
|
||||||
setKey: SettingBoxKey.enableSaveLastData,
|
setKey: SettingBoxKey.enableSaveLastData,
|
||||||
defaultVal: false,
|
defaultVal: false,
|
||||||
needReboot: true,
|
onChanged: (value) {
|
||||||
|
try {
|
||||||
|
Get.find<RcmdController>().enableSaveLastData = value;
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('$e');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
SettingsModel(
|
||||||
|
settingsType: SettingsType.sw1tch,
|
||||||
|
title: '显示上次看到位置提示',
|
||||||
|
subtitle: '保留上次推荐时,在上次刷新位置显示提示',
|
||||||
|
leading: Icon(Icons.tips_and_updates_outlined),
|
||||||
|
setKey: SettingBoxKey.savedRcmdTip,
|
||||||
|
defaultVal: true,
|
||||||
|
onChanged: (value) {
|
||||||
|
try {
|
||||||
|
Get.find<RcmdController>().savedRcmdTip = value;
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('$e');
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
SettingsModel(settingsType: SettingsType.divider),
|
SettingsModel(settingsType: SettingsType.divider),
|
||||||
SettingsModel(
|
SettingsModel(
|
||||||
|
|||||||
@@ -318,6 +318,9 @@ class GStorage {
|
|||||||
static bool get horizontalPreview => GStorage.setting
|
static bool get horizontalPreview => GStorage.setting
|
||||||
.get(SettingBoxKey.horizontalPreview, defaultValue: false);
|
.get(SettingBoxKey.horizontalPreview, defaultValue: false);
|
||||||
|
|
||||||
|
static bool get savedRcmdTip =>
|
||||||
|
GStorage.setting.get(SettingBoxKey.savedRcmdTip, defaultValue: true);
|
||||||
|
|
||||||
static List<double> get dynamicDetailRatio => List<double>.from(setting
|
static List<double> get dynamicDetailRatio => List<double>.from(setting
|
||||||
.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]));
|
.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]));
|
||||||
|
|
||||||
@@ -530,6 +533,7 @@ class SettingBoxKey {
|
|||||||
horizontalPreview = 'horizontalPreview',
|
horizontalPreview = 'horizontalPreview',
|
||||||
banWordForReply = 'banWordForReply',
|
banWordForReply = 'banWordForReply',
|
||||||
banWordForZone = 'banWordForZone',
|
banWordForZone = 'banWordForZone',
|
||||||
|
savedRcmdTip = 'savedRcmdTip',
|
||||||
|
|
||||||
// Sponsor Block
|
// Sponsor Block
|
||||||
enableSponsorBlock = 'enableSponsorBlock',
|
enableSponsorBlock = 'enableSponsorBlock',
|
||||||
|
|||||||
Reference in New Issue
Block a user