view.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import 'package:electronic_assistant/base/base_page.dart';
  2. import 'package:electronic_assistant/data/bean/talks.dart';
  3. import 'package:electronic_assistant/dialog/alert_dialog.dart';
  4. import 'package:electronic_assistant/module/files/controller.dart';
  5. import 'package:electronic_assistant/module/talk/view.dart';
  6. import 'package:electronic_assistant/resource/colors.gen.dart';
  7. import 'package:electronic_assistant/resource/string.gen.dart';
  8. import 'package:electronic_assistant/router/app_pages.dart';
  9. import 'package:electronic_assistant/utils/expand.dart';
  10. import 'package:flutter/material.dart';
  11. import 'package:flutter_screenutil/flutter_screenutil.dart';
  12. import 'package:get/get.dart';
  13. import 'package:pull_to_refresh/pull_to_refresh.dart';
  14. import '../../data/repositories/account_repository.dart';
  15. import '../../dialog/rename_dialog.dart';
  16. import '../../dialog/talk_delete_dialog.dart';
  17. import '../../popup/talk_popup.dart';
  18. import '../../resource/assets.gen.dart';
  19. class FilesPage extends BasePage<FilesController> {
  20. const FilesPage({super.key});
  21. @override
  22. bool immersive() {
  23. return true;
  24. }
  25. @override
  26. Widget buildBody(BuildContext context) {
  27. return Scaffold(
  28. backgroundColor: const Color.fromRGBO(246, 245, 248, 1),
  29. appBar: AppBar(
  30. title: Text(StringName.talkAll.tr),
  31. backgroundColor: const Color.fromRGBO(246, 245, 248, 1),
  32. scrolledUnderElevation: 0,
  33. // actions: [
  34. // IconButton(
  35. // onPressed: () {},
  36. // icon: ImageIcon(Assets.images.iconFilesNewDir.provider()),
  37. // ),
  38. // IconButton(
  39. // onPressed: () {},
  40. // icon: ImageIcon(Assets.images.iconMore.provider()),
  41. // ),
  42. // ],
  43. ),
  44. body: Column(
  45. children: [
  46. // Column(
  47. // children: [
  48. // GestureDetector(
  49. // onTap: () {
  50. // Get.toNamed(RoutePath.fileSearch);
  51. // },
  52. // child: Container(
  53. // margin: EdgeInsets.symmetric(horizontal: 12.w),
  54. // padding:
  55. // EdgeInsets.symmetric(horizontal: 10.w, vertical: 8.w),
  56. // height: 36.w,
  57. // decoration: BoxDecoration(
  58. // color: Colors.white,
  59. // borderRadius: BorderRadius.circular(8.w),
  60. // ),
  61. // child: TextField(
  62. // maxLines: 1,
  63. // textAlignVertical: TextAlignVertical.center,
  64. // textInputAction: TextInputAction.search,
  65. // decoration: InputDecoration(
  66. // hintText: '搜索所有文件标题 / 内容',
  67. // border: InputBorder.none,
  68. // icon: ImageIcon(Assets.images.iconSearch.provider()),
  69. // iconColor: const Color.fromRGBO(95, 95, 97, 1),
  70. // enabled: false),
  71. // style: TextStyle(fontSize: 14.sp),
  72. // ),
  73. // ),
  74. // ),
  75. // ],
  76. // ),
  77. Expanded(
  78. child: Padding(
  79. // padding: EdgeInsets.only(top: 16.w, left: 12.w, right: 12.w),
  80. padding: EdgeInsets.only(left: 12.w, right: 12.w),
  81. child: SmartRefresher(
  82. enablePullUp: true,
  83. enablePullDown: true,
  84. controller: controller.refreshController,
  85. onRefresh: controller.onRefreshData,
  86. onLoading: controller.onLoadMoreTalkData,
  87. child: CustomScrollView(
  88. slivers: [
  89. // SliverAnimatedGrid(
  90. // itemBuilder: _buildDirItem,
  91. // gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  92. // crossAxisCount: 2,
  93. // crossAxisSpacing: 8.w,
  94. // mainAxisSpacing: 8.w,
  95. // childAspectRatio: 164 / 65,
  96. // ),
  97. // initialItemCount: 10,
  98. // ),
  99. // SliverToBoxAdapter(
  100. // child: Padding(
  101. // padding: EdgeInsets.only(top: 20.w, bottom: 12.w),
  102. // child: Text(StringName.talkAll.tr,
  103. // style: TextStyle(
  104. // fontSize: 14.sp,
  105. // color: ColorName.secondaryTextColor,
  106. // fontWeight: FontWeight.bold))),
  107. // ),
  108. Obx(() {
  109. return SliverList.builder(
  110. itemBuilder: _buildFileItem,
  111. itemCount: controller.talkList.length);
  112. }),
  113. ],
  114. ),
  115. ),
  116. ))
  117. ],
  118. ),
  119. );
  120. }
  121. Widget _buildDirItem(
  122. BuildContext context, int index, Animation<double> animation) {
  123. return Container(
  124. decoration: BoxDecoration(
  125. color: Colors.white,
  126. borderRadius: BorderRadius.circular(8.w),
  127. ),
  128. padding: EdgeInsets.only(left: 8.w),
  129. child: Row(
  130. crossAxisAlignment: CrossAxisAlignment.center,
  131. children: [
  132. Image(
  133. image: Assets.images.iconFilesDir.provider(),
  134. width: 32.w,
  135. height: 32.w),
  136. Expanded(
  137. child: Padding(
  138. padding: EdgeInsets.symmetric(horizontal: 8.w),
  139. child: Column(
  140. mainAxisAlignment: MainAxisAlignment.center,
  141. crossAxisAlignment: CrossAxisAlignment.start,
  142. children: [
  143. Text('文件夹',
  144. maxLines: 1,
  145. overflow: TextOverflow.ellipsis,
  146. style: TextStyle(
  147. fontSize: 14.sp,
  148. color: ColorName.primaryTextColor,
  149. fontWeight: FontWeight.bold)),
  150. Text('2021-09-09 12:00:00',
  151. maxLines: 1,
  152. overflow: TextOverflow.ellipsis,
  153. style: TextStyle(
  154. fontSize: 12.sp, color: ColorName.secondaryTextColor)),
  155. ],
  156. ),
  157. ))
  158. ],
  159. ),
  160. );
  161. }
  162. Widget _buildFileItem(BuildContext context, int index) {
  163. TalkBean talkBean = controller.talkList[index];
  164. return Obx(() {
  165. return buildFileTalkItem(talkBean, onTap: () {
  166. TalkPage.start(talkBean);
  167. }, onLongPressStart: (details) {
  168. if (!accountRepository.isLogin.value) {
  169. return;
  170. }
  171. showTalkPopup(details.globalPosition, Alignment.bottomRight,
  172. onRename: () {
  173. showRenameTalkDialog(talkBean);
  174. }, onDelete: () {
  175. showDeleteTalkDialog(talkBean);
  176. });
  177. });
  178. });
  179. }
  180. void showRenameTalkDialog(TalkBean item) {
  181. reNameDialog(StringName.talkRenameTitle.tr, item.title.value,
  182. hintTxt: StringName.talkRenameTitleHint.tr,
  183. maxLength: 15, returnBuilder: (newName) {
  184. controller.requestName(newName, item);
  185. });
  186. }
  187. void showDeleteTalkDialog(TalkBean item) {
  188. talkDeleteDialog(item.id, item.title.value, returnBuilder: () {
  189. controller.requestDelete(item);
  190. });
  191. }
  192. }
  193. Widget buildFileTalkItem(TalkBean talkBean,
  194. {GestureTapCallback? onTap,
  195. GestureLongPressStartCallback? onLongPressStart}) {
  196. return Padding(
  197. padding: EdgeInsets.only(bottom: 8.w),
  198. child: GestureDetector(
  199. onLongPressStart: onLongPressStart,
  200. onTap: onTap,
  201. child: Container(
  202. decoration: BoxDecoration(
  203. color: Colors.white,
  204. borderRadius: BorderRadius.circular(8.w),
  205. ),
  206. padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 14.w),
  207. child: Row(
  208. crossAxisAlignment: CrossAxisAlignment.start,
  209. children: [
  210. Image(
  211. image: (talkBean.status.value == TalkStatus.analysing ||
  212. talkBean.status.value == TalkStatus.waitAnalysis)
  213. ? Assets.images.iconTalkAnalysis.provider()
  214. : Assets.images.iconFilesFile.provider(),
  215. width: 28.w,
  216. height: 32.w),
  217. Expanded(
  218. child: Padding(
  219. padding: EdgeInsets.symmetric(horizontal: 8.w),
  220. child: Column(
  221. crossAxisAlignment: CrossAxisAlignment.start,
  222. children: [
  223. Text(talkBean.title.value.orEmpty,
  224. maxLines: 1,
  225. overflow: TextOverflow.ellipsis,
  226. style: TextStyle(
  227. fontSize: 14.sp,
  228. color: ColorName.primaryTextColor,
  229. fontWeight: FontWeight.bold)),
  230. Text(talkBean.summary.value.orEmpty,
  231. maxLines: 2,
  232. overflow: TextOverflow.ellipsis,
  233. style: TextStyle(
  234. fontSize: 12.sp,
  235. color:
  236. talkBean.status.value == TalkStatus.analysisFail
  237. ? "#F5574E".toColor()
  238. : ColorName.secondaryTextColor)),
  239. Container(
  240. margin: EdgeInsets.only(top: 6.w),
  241. child: Row(
  242. crossAxisAlignment: CrossAxisAlignment.center,
  243. children: [
  244. Text(talkBean.duration.toFormattedDuration(),
  245. style: TextStyle(
  246. fontSize: 12.sp,
  247. color: ColorName.tertiaryTextColor)),
  248. Text(" | ",
  249. style: TextStyle(
  250. fontSize: 12.sp,
  251. color: ColorName.tertiaryTextColor,
  252. fontWeight: FontWeight.bold)),
  253. Text(talkBean.createTime.orEmpty,
  254. style: TextStyle(
  255. fontSize: 12.sp,
  256. color: ColorName.tertiaryTextColor)),
  257. ],
  258. ),
  259. )
  260. ],
  261. ),
  262. )),
  263. ],
  264. ),
  265. ),
  266. ));
  267. }