Skip to content

Commit

Permalink
added tag wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
clragon committed Apr 14, 2020
1 parent 06145ce commit ffc1aff
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 91 deletions.
10 changes: 10 additions & 0 deletions lib/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ class Client {
}
}

Future<Map> wiki(String search) async {
String body = await _http.get(await _host, 'wiki_pages.json', query: {
'search[title]': search,
'login': await _username,
'api_key': await _apiKey,
}).then((response) => response.body);

return json.decode(body)[0];
}

Future<List<Comment>> comments(int postId, int page) async {
// THIS DOES NOT WORK YET; API BROKEN.
String body = await _http.get(await _host, '/comments.json', query: {
Expand Down
24 changes: 21 additions & 3 deletions lib/pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PoolPreview extends StatelessWidget {
),
renderText: ({String str, String pattern}) {
String display = str;
display = display.replaceAll(RegExp(r'h[1-6]\.'), '');
display = display.replaceAll(RegExp(r'h[1-6]\. ?'), '');
Map<String, String> map = Map<String, String>();
map['display'] = display;
map['value'] = str;
Expand Down Expand Up @@ -127,7 +127,7 @@ class PoolPreview extends StatelessWidget {
}),
new MatchText(
type: ParsedType.CUSTOM,
pattern: r'(\[\[[\S]*\]\])|({{[\S]*}})',
pattern: r'(\[\[.*?\]\])|({{.*?}})',
style: new TextStyle(
color: Colors.blue[400],
),
Expand All @@ -137,9 +137,14 @@ class PoolPreview extends StatelessWidget {
display = display.replaceAll('}}', '');
display = display.replaceAll('[[', '');
display = display.replaceAll(']]', '');
String value = display;
if(display.contains('|')) {
value = display.split('|')[0];
display = display.split('|')[1];
}
Map<String, String> map = Map<String, String>();
map['display'] = display;
map['value'] = display;
map['value'] = value;
return map;
},
onTap: (url) {
Expand Down Expand Up @@ -175,6 +180,19 @@ class PoolPreview extends StatelessWidget {
return new PoolPage(p);
}));
}),
new MatchText(
type: ParsedType.CUSTOM,
pattern: r'(thumb #[0-9]{2,8})',
style: new TextStyle(
color: Colors.blue[400],
),
renderText: ({String str, String pattern}) {
Map<String, String> map = Map<String, String>();
map['display'] = '';
map['value'] = '';
return map;
},
),
new MatchText(
type: ParsedType.CUSTOM,
pattern:
Expand Down
250 changes: 162 additions & 88 deletions lib/post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,94 +214,93 @@ class PostWidgetScaffold extends StatelessWidget {
const PostWidgetScaffold(this.post, {Key key}) : super(key: key);

void _download(BuildContext context) async {
Map<PermissionGroup, PermissionStatus> permissions =
await PermissionHandler()
.requestPermissions([PermissionGroup.storage]);

if (permissions[PermissionGroup.storage] != PermissionStatus.granted) {
showDialog(
context: context,
builder: (context) {
return new AlertDialog(
content: const Text(
'You need to grant write permission in order to download files.'),
actions: [
new RaisedButton(
child: const Text('TRY AGAIN'),
onPressed: () {
Navigator.of(context).pop();
_download(context); // recursively re-execute
},
),
],
);
});
return;
}
Map<PermissionGroup, PermissionStatus> permissions =
await PermissionHandler().requestPermissions([PermissionGroup.storage]);

String filename =
'${post.artist.join(', ')} - ${post.id}.${post.file['ext']}';
String filepath =
'${Platform.environment['EXTERNAL_STORAGE']}/Download/$filename';
if (permissions[PermissionGroup.storage] != PermissionStatus.granted) {
showDialog(
context: context,
builder: (context) {
return new AlertDialog(
content: const Text(
'You need to grant write permission in order to download files.'),
actions: [
new RaisedButton(
child: const Text('TRY AGAIN'),
onPressed: () {
Navigator.of(context).pop();
_download(context); // recursively re-execute
},
),
],
);
});
return;
}

Future<File> download() async {
File file = new File(filepath);
if (file.existsSync()) {
return file;
}
String filename =
'${post.artist.join(', ')} - ${post.id}.${post.file['ext']}';
String filepath =
'${Platform.environment['EXTERNAL_STORAGE']}/Download/$filename';

DefaultCacheManager cm = DefaultCacheManager();
return (await cm.getSingleFile(post.file['url'])).copySync(filepath);
Future<File> download() async {
File file = new File(filepath);
if (file.existsSync()) {
return file;
}

showDialog(
context: context,
builder: (context) {
return new FutureBuilder(
future: download(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return new AlertDialog(
title: const Text('Error'),
content: new Text(snapshot.error.toString()),
actions: [
new RaisedButton(
child: const Text('OK'),
onPressed: () => Navigator.pop(context),
),
],
);
}

bool done = snapshot.connectionState == ConnectionState.done &&
snapshot.hasData;
DefaultCacheManager cm = DefaultCacheManager();
return (await cm.getSingleFile(post.file['url'])).copySync(filepath);
}

showDialog(
context: context,
builder: (context) {
return new FutureBuilder(
future: download(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return new AlertDialog(
title: const Text('Download'),
content: new Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
new Padding(
padding: const EdgeInsets.only(bottom: 20.0),
child: done
? const Icon(Icons.done)
: const CircularProgressIndicator(),
),
new Text(filename, softWrap: true),
],
),
title: const Text('Error'),
content: new Text(snapshot.error.toString()),
actions: [
new RaisedButton(
child: const Text('OK'),
onPressed: () => Navigator.pop(context),
),
],
);
},
);
},
);
}

bool done = snapshot.connectionState == ConnectionState.done &&
snapshot.hasData;

return new AlertDialog(
title: const Text('Download'),
content: new Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
new Padding(
padding: const EdgeInsets.only(bottom: 20.0),
child: done
? const Icon(Icons.done)
: const CircularProgressIndicator(),
),
new Text(filename, softWrap: true),
],
),
actions: [
new RaisedButton(
child: const Text('OK'),
onPressed: () => Navigator.pop(context),
),
],
);
},
);
},
);
}

static String formatBytes(int bytes, int decimals) {
Expand Down Expand Up @@ -357,9 +356,25 @@ class PostWidgetScaffold extends StatelessWidget {
));
}
if (post.file['ext'] == 'swf' || post.file['ext'] == 'webm') {
return placeholder(const Text(
'Webm support under development. \nTap to open in browser.',
textAlign: TextAlign.center,
return placeholder(Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.all(8),
child: const Text(
'Webm support under development',
textAlign: TextAlign.center,
),
),
InkWell(
child: Card(
child: Padding(
padding: EdgeInsets.all(8), child: Text('Browse'))),
onTap: () async =>
url.launch(post.url(await db.host.value).toString()),
)
],
));
}
return CachedNetworkImage(
Expand Down Expand Up @@ -409,16 +424,18 @@ class PostWidgetScaffold extends StatelessWidget {
child: Text('Share'),
),
),
PopupMenuItem(
value: 'download',
child: Padding(
padding: EdgeInsets.all(4),
child: Text(
'Download',
maxLines: 1,
),
),
),
post.file['url'] != null
? PopupMenuItem(
value: 'download',
child: Padding(
padding: EdgeInsets.all(4),
child: Text(
'Download',
maxLines: 1,
),
),
)
: null,
PopupMenuItem(
//
value: 'browser',
Expand Down Expand Up @@ -453,7 +470,9 @@ class PostWidgetScaffold extends StatelessWidget {
}

return new GestureDetector(
onTap: _onTapImage(context, post),
onTap: post.file['url'] != null && post.file['ext'] != 'webm'
? _onTapImage(context, post)
: null,
child: overlayImageWidget(),
);
}
Expand Down Expand Up @@ -782,6 +801,61 @@ class PostWidgetScaffold extends StatelessWidget {
return new SearchPage(
Tagset.parse(tag));
})),
onLongPress: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(tag),
content: new ConstrainedBox(
child: FutureBuilder(
builder: (context, snapshot) {
if (snapshot.hasData) {
return SingleChildScrollView(
scrollDirection:
Axis.vertical,
child: PoolPreview
.dTextField(
context,
snapshot.data[
'body']),
physics:
BouncingScrollPhysics(),
);
} else {
return Row(
mainAxisAlignment:
MainAxisAlignment
.center,
children: <Widget>[
Padding(
padding:
EdgeInsets
.all(16),
child: Container(
height: 26,
width: 26,
child:
CircularProgressIndicator(),
))
],
);
}
},
future: client.wiki(tag),
),
constraints: new BoxConstraints(
maxHeight: 400.0,
)),
actions: [
FlatButton(
child: Text('OK'),
onPressed: () =>
Navigator.of(context).pop(),
),
],
),
);
},
child: Card(
child: Padding(
padding: EdgeInsets.all(4),
Expand Down

0 comments on commit ffc1aff

Please sign in to comment.