11import 'package:fluro/fluro.dart' ;
22import 'package:flutter/material.dart' ;
3+ import 'package:flutter_picgo/components/loading.dart' ;
4+ import 'package:flutter_picgo/components/manage_item.dart' ;
35import 'package:flutter_picgo/model/github_content.dart' ;
46import 'package:flutter_picgo/routers/application.dart' ;
57import 'package:flutter_picgo/routers/routers.dart' ;
@@ -8,6 +10,7 @@ import 'package:flutter_picgo/views/manage_page/github_page/github_repo_page_pre
810import 'package:path/path.dart' as pathlib;
911import 'package:flutter/services.dart' ;
1012import 'package:toast/toast.dart' ;
13+ import 'package:url_launcher/url_launcher.dart' ;
1114
1215class GithubRepoPage extends StatefulWidget {
1316 final String path;
@@ -129,33 +132,51 @@ class _GithubRepoPageState extends BaseLoadingPageState<GithubRepoPage>
129132 return ListView .builder (
130133 itemCount: contents.length,
131134 itemBuilder: (context, index) {
132- return Container (
133- decoration: BoxDecoration (
134- border: Border (
135- bottom: BorderSide (width: 0.5 , color: Colors .grey[400 ])),
136- ),
137- child: ListTile (
138- title: Text (contents[index].name,
139- textWidthBasis: TextWidthBasis .longestLine,
140- maxLines: 1 ,
141- overflow: TextOverflow .ellipsis),
142- leading: Icon (contents[index].type == GithubContentType .FILE
143- ? IconData (0xe654 , fontFamily: 'iconfont' )
144- : IconData (0xe63f , fontFamily: 'iconfont' )),
145- onTap: () {
146- if (contents[index].type == GithubContentType .DIR ) {
147- var prePathParam = pathlib
148- .joinAll ([_prePath ?? '' , _path == '/' ? '' : _path]);
149- Application .router.navigateTo (context,
150- '${Routes .settingPbGitubRepo }?path=${Uri .encodeComponent (contents [index ].name )}&prePath=${Uri .encodeComponent (prePathParam )}' ,
151- transition: TransitionType .cupertino);
152- } else {
153- Clipboard .setData (
154- ClipboardData (text: contents[index].downloadUrl));
155- Toast .show ('已获取下载链接到剪切板' , context);
156- }
157- },
158- ),
135+ return ManageItem (
136+ Key ('$index ' ),
137+ contents[index].downloadUrl,
138+ contents[index].name,
139+ '${contents [index ].size }k' ,
140+ contents[index].type,
141+ onTap: () {
142+ if (contents[index].type == FileContentType .DIR ) {
143+ var prePathParam = pathlib
144+ .joinAll ([_prePath ?? '' , _path == '/' ? '' : _path]);
145+ Application .router.navigateTo (context,
146+ '${Routes .settingPbGitubRepo }?path=${Uri .encodeComponent (contents [index ].name )}&prePath=${Uri .encodeComponent (prePathParam )}' ,
147+ transition: TransitionType .cupertino);
148+ } else {
149+ launch (contents[index].downloadUrl);
150+ }
151+ },
152+ confirmDismiss: (direction) async {
153+ if (contents[index].type == FileContentType .DIR ) {
154+ Toast .show ('暂不支持删除文件夹' , context);
155+ return false ;
156+ }
157+ bool result = await showDialog (
158+ context: context,
159+ builder: (BuildContext context) {
160+ return AlertDialog (
161+ title: Text ('确定删除吗' ),
162+ content: Text ('删除后无法恢复' ),
163+ actions: < Widget > [
164+ FlatButton (
165+ child: Text ('确定' ),
166+ onPressed: () {
167+ Navigator .pop (context, true );
168+ }),
169+ ],
170+ );
171+ });
172+ if (! (result ?? false )) {
173+ return false ;
174+ }
175+
176+ var del = await _presenter.doDeleteContents (
177+ _path, _prePath, contents[index].name, contents[index].sha);
178+ return del;
179+ },
159180 );
160181 });
161182 }
0 commit comments