view.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 Padding(
  166. padding: EdgeInsets.only(bottom: 8.w),
  167. child: GestureDetector(
  168. onLongPressStart: (details) {
  169. if (!accountRepository.isLogin.value) {
  170. return;
  171. }
  172. showTalkPopup(details.globalPosition, Alignment.bottomRight,
  173. onRename: () {
  174. showRenameTalkDialog(talkBean);
  175. }, onDelete: () {
  176. showDeleteTalkDialog(talkBean);
  177. });
  178. },
  179. onTap: () {
  180. TalkPage.start(talkBean);
  181. },
  182. child: Container(
  183. decoration: BoxDecoration(
  184. color: Colors.white,
  185. borderRadius: BorderRadius.circular(8.w),
  186. ),
  187. padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 14.w),
  188. child: Row(
  189. crossAxisAlignment: CrossAxisAlignment.start,
  190. children: [
  191. Image(
  192. image: (talkBean.status.value == TalkStatus.analysing ||
  193. talkBean.status.value == TalkStatus.waitAnalysis)
  194. ? Assets.images.iconTalkAnalysis.provider()
  195. : Assets.images.iconFilesFile.provider(),
  196. width: 28.w,
  197. height: 32.w),
  198. Expanded(
  199. child: Padding(
  200. padding: EdgeInsets.symmetric(horizontal: 8.w),
  201. child: Column(
  202. crossAxisAlignment: CrossAxisAlignment.start,
  203. children: [
  204. Text(talkBean.title.value.orEmpty,
  205. maxLines: 1,
  206. overflow: TextOverflow.ellipsis,
  207. style: TextStyle(
  208. fontSize: 14.sp,
  209. color: ColorName.primaryTextColor,
  210. fontWeight: FontWeight.bold)),
  211. Text(talkBean.summary.value.orEmpty,
  212. maxLines: 2,
  213. overflow: TextOverflow.ellipsis,
  214. style: TextStyle(
  215. fontSize: 12.sp,
  216. color: talkBean.status.value ==
  217. TalkStatus.analysisFail
  218. ? "#F5574E".toColor()
  219. : ColorName.secondaryTextColor)),
  220. Container(
  221. margin: EdgeInsets.only(top: 6.w),
  222. child: Row(
  223. crossAxisAlignment: CrossAxisAlignment.center,
  224. children: [
  225. Text(talkBean.duration.toFormattedDuration(),
  226. style: TextStyle(
  227. fontSize: 12.sp,
  228. color: ColorName.tertiaryTextColor)),
  229. Text(" | ",
  230. style: TextStyle(
  231. fontSize: 12.sp,
  232. color: ColorName.tertiaryTextColor,
  233. fontWeight: FontWeight.bold)),
  234. Text(talkBean.createTime.orEmpty,
  235. style: TextStyle(
  236. fontSize: 12.sp,
  237. color: ColorName.tertiaryTextColor)),
  238. ],
  239. ),
  240. )
  241. ],
  242. ),
  243. )),
  244. ],
  245. ),
  246. ),
  247. ));
  248. });
  249. }
  250. void showRenameTalkDialog(TalkBean item) {
  251. reNameDialog(StringName.talkRenameTitle.tr, item.title.value,
  252. hintTxt: StringName.talkRenameTitleHint.tr,
  253. maxLength: 15, returnBuilder: (newName) {
  254. controller.requestName(newName, item);
  255. });
  256. }
  257. void showDeleteTalkDialog(TalkBean item) {
  258. talkDeleteDialog(item.id, item.title.value, returnBuilder: () {
  259. controller.requestDelete(item);
  260. });
  261. }
  262. }