view.dart 10 KB

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