mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: session secondary
Closes #837 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import 'package:PiliPlus/grpc/bilibili/main/community/reply/v1.pb.dart'
|
||||
show MainListReply, ReplyInfo;
|
||||
import 'package:PiliPlus/grpc/reply.dart';
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/reply.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/models/dynamics/article_content_model.dart'
|
||||
@@ -172,7 +172,7 @@ class ArticleController extends ReplyController<MainListReply> {
|
||||
|
||||
@override
|
||||
Future<LoadingState<MainListReply>> customGetData() {
|
||||
return ReplyHttp.mainList(
|
||||
return ReplyGrpc.mainList(
|
||||
type: commentType,
|
||||
oid: commentId,
|
||||
mode: mode.value,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:PiliPlus/grpc/bilibili/community/service/dm/v1.pb.dart';
|
||||
import 'package:PiliPlus/http/danmaku.dart';
|
||||
import 'package:PiliPlus/grpc/dm.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/controller.dart';
|
||||
|
||||
class PlDanmakuController {
|
||||
@@ -31,7 +31,7 @@ class PlDanmakuController {
|
||||
return;
|
||||
}
|
||||
requestedSeg.add(segmentIndex);
|
||||
final result = await DanmakuHttp.queryDanmaku(
|
||||
final result = await DmGrpc.dmSegMobile(
|
||||
cid: cid,
|
||||
segmentIndex: segmentIndex + 1,
|
||||
);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:PiliPlus/grpc/bilibili/main/community/reply/v1.pb.dart'
|
||||
show MainListReply, ReplyInfo;
|
||||
import 'package:PiliPlus/grpc/reply.dart';
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/reply.dart';
|
||||
import 'package:PiliPlus/models/common/reply/reply_type.dart';
|
||||
import 'package:PiliPlus/models/dynamics/result.dart';
|
||||
import 'package:PiliPlus/pages/common/reply_controller.dart';
|
||||
@@ -54,7 +54,7 @@ class DynamicDetailController extends ReplyController<MainListReply> {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<MainListReply>> customGetData() => ReplyHttp.mainList(
|
||||
Future<LoadingState<MainListReply>> customGetData() => ReplyGrpc.mainList(
|
||||
type: type,
|
||||
oid: oid,
|
||||
mode: mode.value,
|
||||
|
||||
@@ -35,23 +35,20 @@ class _DynTopicPageState extends State<DynTopicPage> {
|
||||
Obx(() {
|
||||
if (_controller.topicSortByConf.value?.allSortBy?.isNotEmpty ==
|
||||
true) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 16),
|
||||
child: PopupMenuButton(
|
||||
initialValue: _controller.sortBy,
|
||||
itemBuilder: (context) {
|
||||
return _controller.topicSortByConf.value!.allSortBy!
|
||||
.map<PopupMenuItem>((e) {
|
||||
return PopupMenuItem(
|
||||
value: e.sortBy,
|
||||
child: Text(e.sortName!),
|
||||
onTap: () {
|
||||
_controller.onSort(e.sortBy!);
|
||||
},
|
||||
);
|
||||
}).toList();
|
||||
},
|
||||
),
|
||||
return PopupMenuButton(
|
||||
initialValue: _controller.sortBy,
|
||||
itemBuilder: (context) {
|
||||
return _controller.topicSortByConf.value!.allSortBy!
|
||||
.map<PopupMenuItem>((e) {
|
||||
return PopupMenuItem(
|
||||
value: e.sortBy,
|
||||
child: Text(e.sortName!),
|
||||
onTap: () {
|
||||
_controller.onSort(e.sortBy!);
|
||||
},
|
||||
);
|
||||
}).toList();
|
||||
},
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:PiliPlus/grpc/grpc_repo.dart';
|
||||
import 'package:PiliPlus/grpc/dyn.dart';
|
||||
import 'package:PiliPlus/http/api.dart';
|
||||
import 'package:PiliPlus/http/init.dart';
|
||||
import 'package:PiliPlus/models/common/dynamic/dynamic_badge_mode.dart';
|
||||
@@ -175,7 +175,7 @@ class MainController extends GetxController {
|
||||
if (!isLogin.value || dynIndex == -1) {
|
||||
return;
|
||||
}
|
||||
GrpcRepo.dynRed().then((res) {
|
||||
DynGrpc.dynRed().then((res) {
|
||||
if (res['status']) {
|
||||
setCount(res['data']);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:PiliPlus/grpc/bilibili/main/community/reply/v1.pb.dart'
|
||||
show MainListReply, ReplyInfo;
|
||||
import 'package:PiliPlus/grpc/reply.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/reply.dart';
|
||||
import 'package:PiliPlus/pages/common/reply_controller.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -41,7 +41,7 @@ class VideoReplyController extends ReplyController<MainListReply>
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<MainListReply>> customGetData() => ReplyHttp.mainList(
|
||||
Future<LoadingState<MainListReply>> customGetData() => ReplyGrpc.mainList(
|
||||
oid: aid,
|
||||
mode: mode.value,
|
||||
cursorNext: cursorNext,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:PiliPlus/grpc/bilibili/main/community/reply/v1.pb.dart'
|
||||
show ReplyInfo, DetailListReply, Mode;
|
||||
import 'package:PiliPlus/grpc/reply.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/reply.dart';
|
||||
import 'package:PiliPlus/models/common/reply/reply_type.dart';
|
||||
import 'package:PiliPlus/pages/common/reply_controller.dart';
|
||||
import 'package:PiliPlus/utils/id_utils.dart';
|
||||
@@ -107,7 +107,7 @@ class VideoReplyReplyController extends ReplyController
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => isDialogue
|
||||
? ReplyHttp.dialogList(
|
||||
? ReplyGrpc.dialogList(
|
||||
type: replyType.index,
|
||||
oid: oid,
|
||||
root: rpid,
|
||||
@@ -115,7 +115,7 @@ class VideoReplyReplyController extends ReplyController
|
||||
offset: paginationReply?.nextOffset,
|
||||
antiGoodsReply: antiGoodsReply,
|
||||
)
|
||||
: ReplyHttp.detailList(
|
||||
: ReplyGrpc.detailList(
|
||||
type: replyType.index,
|
||||
oid: oid,
|
||||
root: rpid,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart'
|
||||
show SessionMainReply, Session, Offset, SessionPageType;
|
||||
import 'package:PiliPlus/grpc/grpc_repo.dart';
|
||||
show Offset, Session, SessionId, SessionMainReply, SessionPageType;
|
||||
import 'package:PiliPlus/grpc/im.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/msg.dart';
|
||||
import 'package:PiliPlus/models/msg/msgfeed_unread.dart';
|
||||
@@ -74,7 +74,7 @@ class WhisperController
|
||||
|
||||
@override
|
||||
Future<LoadingState<SessionMainReply>> customGetData() =>
|
||||
MsgHttp.sessionMain(offset: offset);
|
||||
ImGrpc.sessionMain(offset: offset);
|
||||
|
||||
@override
|
||||
Future<void> onRefresh() {
|
||||
@@ -94,13 +94,13 @@ class WhisperController
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> onSetTop(int index, bool isTop, int? talkerId) async {
|
||||
var res = await MsgHttp.setTop(
|
||||
talkerId: talkerId,
|
||||
opType: isTop ? 1 : 0,
|
||||
);
|
||||
Future<void> onSetTop(int index, bool isTop, SessionId sessionId) async {
|
||||
var res = isTop
|
||||
? await ImGrpc.unpinSession(sessionId: sessionId)
|
||||
: await ImGrpc.pinSession(sessionId: sessionId);
|
||||
|
||||
if (res['status']) {
|
||||
List<Session> list = (loadingState.value as Success).response;
|
||||
List<Session> list = loadingState.value.data!;
|
||||
list[index].isPinned = isTop ? false : true;
|
||||
if (!isTop) {
|
||||
list.insert(0, list.removeAt(index));
|
||||
@@ -121,7 +121,7 @@ class WhisperController
|
||||
}
|
||||
|
||||
Future<void> onClearUnread() async {
|
||||
final res = await GrpcRepo.clearUnread(
|
||||
final res = await ImGrpc.clearUnread(
|
||||
pageType: SessionPageType.SESSION_PAGE_TYPE_HOME);
|
||||
if (res['status']) {
|
||||
if (loadingState.value is Success) {
|
||||
|
||||
@@ -50,7 +50,13 @@ class _WhisperPageState extends State<WhisperPage> {
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
_buildTopItems,
|
||||
Obx(() => _buildBody(_whisperController.loadingState.value)),
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 100,
|
||||
),
|
||||
sliver:
|
||||
Obx(() => _buildBody(_whisperController.loadingState.value)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -66,31 +72,26 @@ class _WhisperPageState extends State<WhisperPage> {
|
||||
},
|
||||
),
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 100,
|
||||
),
|
||||
sliver: SliverList.separated(
|
||||
itemCount: loadingState.response!.length,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_whisperController.onLoadMore();
|
||||
}
|
||||
return WhisperSessionItem(
|
||||
item: loadingState.response![index],
|
||||
onSetTop: (isTop, talkerId) =>
|
||||
_whisperController.onSetTop(index, isTop, talkerId),
|
||||
onRemove: (talkerId) =>
|
||||
_whisperController.onRemove(index, talkerId),
|
||||
onTap: () => _whisperController.onTap(index),
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
indent: 72,
|
||||
endIndent: 20,
|
||||
height: 1,
|
||||
color: Colors.grey.withOpacity(0.1),
|
||||
),
|
||||
? SliverList.separated(
|
||||
itemCount: loadingState.response!.length,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_whisperController.onLoadMore();
|
||||
}
|
||||
return WhisperSessionItem(
|
||||
item: loadingState.response![index],
|
||||
onSetTop: (isTop, id) =>
|
||||
_whisperController.onSetTop(index, isTop, id),
|
||||
onRemove: (talkerId) =>
|
||||
_whisperController.onRemove(index, talkerId),
|
||||
onTap: () => _whisperController.onTap(index),
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
indent: 72,
|
||||
endIndent: 20,
|
||||
height: 1,
|
||||
color: Colors.grey.withOpacity(0.1),
|
||||
),
|
||||
)
|
||||
: HttpError(
|
||||
|
||||
@@ -3,11 +3,13 @@ import 'dart:convert';
|
||||
import 'package:PiliPlus/common/widgets/badge.dart';
|
||||
import 'package:PiliPlus/common/widgets/pendant_avatar.dart';
|
||||
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart'
|
||||
show Session, UnreadStyle;
|
||||
show Session, SessionId, SessionPageType, SessionType, UnreadStyle;
|
||||
import 'package:PiliPlus/models/common/badge_type.dart';
|
||||
import 'package:PiliPlus/pages/whisper_secondary/view.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class WhisperSessionItem extends StatelessWidget {
|
||||
@@ -20,7 +22,7 @@ class WhisperSessionItem extends StatelessWidget {
|
||||
});
|
||||
|
||||
final Session item;
|
||||
final Function(bool isTop, int? talkerId) onSetTop;
|
||||
final Function(bool isTop, SessionId id) onSetTop;
|
||||
final ValueChanged<int?> onRemove;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@@ -49,27 +51,25 @@ class WhisperSessionItem extends StatelessWidget {
|
||||
dense: true,
|
||||
onTap: () {
|
||||
Get.back();
|
||||
onSetTop(
|
||||
item.isPinned,
|
||||
item.id.privateId.talkerUid.toInt(),
|
||||
);
|
||||
onSetTop(item.isPinned, item.id);
|
||||
},
|
||||
title: Text(
|
||||
item.isPinned ? '移除置顶' : '置顶',
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
dense: true,
|
||||
onTap: () {
|
||||
Get.back();
|
||||
onRemove(item.id.privateId.talkerUid.toInt());
|
||||
},
|
||||
title: const Text(
|
||||
'删除',
|
||||
style: TextStyle(fontSize: 14),
|
||||
if (item.id.privateId.hasTalkerUid())
|
||||
ListTile(
|
||||
dense: true,
|
||||
onTap: () {
|
||||
Get.back();
|
||||
onRemove(item.id.privateId.talkerUid.toInt());
|
||||
},
|
||||
title: const Text(
|
||||
'删除',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -78,17 +78,54 @@ class WhisperSessionItem extends StatelessWidget {
|
||||
},
|
||||
onTap: () {
|
||||
onTap();
|
||||
Get.toNamed(
|
||||
'/whisperDetail',
|
||||
parameters: {
|
||||
'talkerId': item.id.privateId.talkerUid.toString(),
|
||||
'name': item.sessionInfo.sessionName,
|
||||
'face': item.sessionInfo.avatar.fallbackLayers.layers.first.resource
|
||||
.resImage.imageSrc.remote.url,
|
||||
if (item.sessionInfo.avatar.hasMid())
|
||||
'mid': item.sessionInfo.avatar.mid.toString(),
|
||||
},
|
||||
);
|
||||
if (item.id.privateId.hasTalkerUid()) {
|
||||
Get.toNamed(
|
||||
'/whisperDetail',
|
||||
parameters: {
|
||||
'talkerId': item.id.privateId.talkerUid.toString(),
|
||||
'name': item.sessionInfo.sessionName,
|
||||
'face': item.sessionInfo.avatar.fallbackLayers.layers.first
|
||||
.resource.resImage.imageSrc.remote.url,
|
||||
if (item.sessionInfo.avatar.hasMid())
|
||||
'mid': item.sessionInfo.avatar.mid.toString(),
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.id.foldId.hasType()) {
|
||||
SessionPageType? sessionPageType = switch (item.id.foldId.type) {
|
||||
SessionType.SESSION_TYPE_UNKNOWN =>
|
||||
SessionPageType.SESSION_PAGE_TYPE_UNKNOWN,
|
||||
SessionType.SESSION_TYPE_GROUP =>
|
||||
SessionPageType.SESSION_PAGE_TYPE_GROUP,
|
||||
SessionType.SESSION_TYPE_GROUP_FOLD =>
|
||||
SessionPageType.SESSION_PAGE_TYPE_GROUP,
|
||||
SessionType.SESSION_TYPE_UNFOLLOWED =>
|
||||
SessionPageType.SESSION_PAGE_TYPE_UNFOLLOWED,
|
||||
SessionType.SESSION_TYPE_STRANGER =>
|
||||
SessionPageType.SESSION_PAGE_TYPE_STRANGER,
|
||||
SessionType.SESSION_TYPE_DUSTBIN =>
|
||||
SessionPageType.SESSION_PAGE_TYPE_DUSTBIN,
|
||||
SessionType.SESSION_TYPE_CUSTOMER_FOLD =>
|
||||
SessionPageType.SESSION_PAGE_TYPE_CUSTOMER,
|
||||
SessionType.SESSION_TYPE_AI_FOLD =>
|
||||
SessionPageType.SESSION_PAGE_TYPE_AI,
|
||||
SessionType.SESSION_TYPE_CUSTOMER_ACCOUNT =>
|
||||
SessionPageType.SESSION_PAGE_TYPE_CUSTOMER,
|
||||
_ => null,
|
||||
};
|
||||
if (sessionPageType != null) {
|
||||
Get.to(
|
||||
WhisperSecPage(
|
||||
name: item.sessionInfo.sessionName,
|
||||
sessionPageType: sessionPageType,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
SmartDialog.showToast(item.id.foldId.type.name);
|
||||
}
|
||||
}
|
||||
},
|
||||
leading: Builder(
|
||||
builder: (context) {
|
||||
|
||||
114
lib/pages/whisper_secondary/controller.dart
Normal file
114
lib/pages/whisper_secondary/controller.dart
Normal file
@@ -0,0 +1,114 @@
|
||||
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart'
|
||||
show Offset, Session, SessionId, SessionPageType, SessionSecondaryReply;
|
||||
import 'package:PiliPlus/grpc/im.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/msg.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:protobuf/protobuf.dart' show PbMap;
|
||||
|
||||
class WhisperSecController
|
||||
extends CommonListController<SessionSecondaryReply, Session> {
|
||||
WhisperSecController({
|
||||
required this.sessionPageType,
|
||||
});
|
||||
|
||||
PbMap<int, Offset>? offset;
|
||||
final SessionPageType sessionPageType;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
queryData();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onRefresh() {
|
||||
offset = null;
|
||||
return super.onRefresh();
|
||||
}
|
||||
|
||||
@override
|
||||
List<Session>? getDataList(SessionSecondaryReply response) {
|
||||
if (response.paginationParams.hasMore == false) {
|
||||
isEnd = true;
|
||||
}
|
||||
return response.sessions;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<SessionSecondaryReply>> customGetData() =>
|
||||
ImGrpc.sessionSecondary(
|
||||
offset: offset,
|
||||
pageType: sessionPageType,
|
||||
);
|
||||
|
||||
Future<void> onRemove(int index, int? talkerId) async {
|
||||
var res = await MsgHttp.removeMsg(talkerId);
|
||||
if (res['status']) {
|
||||
loadingState
|
||||
..value.data!.removeAt(index)
|
||||
..refresh();
|
||||
SmartDialog.showToast('删除成功');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> onSetTop(int index, bool isTop, SessionId sessionId) async {
|
||||
var res = isTop
|
||||
? await ImGrpc.unpinSession(sessionId: sessionId)
|
||||
: await ImGrpc.pinSession(sessionId: sessionId);
|
||||
|
||||
if (res['status']) {
|
||||
List<Session> list = loadingState.value.data!;
|
||||
list[index].isPinned = isTop ? false : true;
|
||||
if (!isTop) {
|
||||
list.insert(0, list.removeAt(index));
|
||||
}
|
||||
loadingState.refresh();
|
||||
SmartDialog.showToast('${isTop ? '移除' : ''}置顶成功');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
void onTap(int index) {
|
||||
Session item = loadingState.value.data![index];
|
||||
if (item.hasUnread()) {
|
||||
item.clearUnread();
|
||||
loadingState.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> onClearUnread() async {
|
||||
final res = await ImGrpc.clearUnread(
|
||||
pageType: SessionPageType.SESSION_PAGE_TYPE_UNFOLLOWED);
|
||||
if (res['status']) {
|
||||
if (loadingState.value is Success) {
|
||||
List<Session>? list = loadingState.value.data;
|
||||
if (list?.isNotEmpty == true) {
|
||||
for (var item in list!) {
|
||||
if (item.hasUnread()) {
|
||||
item.clearUnread();
|
||||
}
|
||||
}
|
||||
loadingState.refresh();
|
||||
}
|
||||
}
|
||||
SmartDialog.showToast('已标记为已读');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> onDeleteList() async {
|
||||
var res = await ImGrpc.deleteSessionList(
|
||||
pageType: SessionPageType.SESSION_PAGE_TYPE_UNFOLLOWED);
|
||||
if (res['status']) {
|
||||
loadingState.value = LoadingState.success(null);
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
139
lib/pages/whisper_secondary/view.dart
Normal file
139
lib/pages/whisper_secondary/view.dart
Normal file
@@ -0,0 +1,139 @@
|
||||
import 'package:PiliPlus/common/skeleton/whisper_item.dart';
|
||||
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/grpc/bilibili/app/im/v1.pb.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/pages/whisper/widgets/item.dart';
|
||||
import 'package:PiliPlus/pages/whisper_secondary/controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class WhisperSecPage extends StatefulWidget {
|
||||
const WhisperSecPage({
|
||||
super.key,
|
||||
required this.name,
|
||||
required this.sessionPageType,
|
||||
});
|
||||
|
||||
final String name;
|
||||
final SessionPageType sessionPageType;
|
||||
|
||||
@override
|
||||
State<WhisperSecPage> createState() => _WhisperSecPageState();
|
||||
}
|
||||
|
||||
class _WhisperSecPageState extends State<WhisperSecPage> {
|
||||
late final WhisperSecController _controller = Get.put(
|
||||
WhisperSecController(sessionPageType: widget.sessionPageType),
|
||||
tag: widget.sessionPageType.name,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(widget.name),
|
||||
actions: [
|
||||
PopupMenuButton(
|
||||
itemBuilder: (context) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
onTap: () {
|
||||
showConfirmDialog(
|
||||
context: context,
|
||||
title: '一键已读',
|
||||
content: '是否清除全部新消息提醒?',
|
||||
onConfirm: _controller.onClearUnread,
|
||||
);
|
||||
},
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(
|
||||
size: 17,
|
||||
Icons.cleaning_services,
|
||||
),
|
||||
Text(' 一键已读'),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () {
|
||||
showConfirmDialog(
|
||||
context: context,
|
||||
title: '清空列表',
|
||||
content: '清空后所有消息将被删除,无法恢复',
|
||||
onConfirm: _controller.onDeleteList,
|
||||
);
|
||||
},
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(
|
||||
size: 19,
|
||||
Icons.delete_forever_outlined,
|
||||
),
|
||||
Text(' 清空列表'),
|
||||
],
|
||||
),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: refreshIndicator(
|
||||
onRefresh: _controller.onRefresh,
|
||||
child: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 80),
|
||||
sliver: Obx(() => _buildBody(_controller.loadingState.value)),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState<List<Session>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverList.builder(
|
||||
itemCount: 12,
|
||||
itemBuilder: (context, index) {
|
||||
return const WhisperItemSkeleton();
|
||||
},
|
||||
),
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverList.separated(
|
||||
itemCount: loadingState.response!.length,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_controller.onLoadMore();
|
||||
}
|
||||
return WhisperSessionItem(
|
||||
item: loadingState.response![index],
|
||||
onSetTop: (isTop, talkerId) =>
|
||||
_controller.onSetTop(index, isTop, talkerId),
|
||||
onRemove: (talkerId) => _controller.onRemove(index, talkerId),
|
||||
onTap: () => _controller.onTap(index),
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
indent: 72,
|
||||
endIndent: 20,
|
||||
height: 1,
|
||||
color: Colors.grey.withOpacity(0.1),
|
||||
),
|
||||
)
|
||||
: HttpError(
|
||||
onReload: _controller.onReload,
|
||||
),
|
||||
Error() => HttpError(
|
||||
errMsg: loadingState.errMsg,
|
||||
onReload: _controller.onReload,
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user