Skip to content

Commit

Permalink
polished post page
Browse files Browse the repository at this point in the history
  • Loading branch information
clragon committed Apr 14, 2020
1 parent f38552a commit b0ddf2a
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 96 deletions.
2 changes: 1 addition & 1 deletion lib/appinfo.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const String appName = 'e1547';
const String appVersion = '1.2.1';
const String appVersion = '1.2.2';
const String defaultEndpoint = 'e926.net';
const String about = 'An app for e621 and e926.';
const String developer = 'binaryfloof';
Expand Down
4 changes: 2 additions & 2 deletions lib/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:url_launcher/url_launcher.dart' as url;

import 'client.dart' show client;
import 'input.dart' show LowercaseTextInputFormatter;
import 'main.dart';
import 'persistence.dart' show db;

class LoginPage extends StatelessWidget {
Expand Down Expand Up @@ -132,8 +133,7 @@ class _LoginFormFieldsState extends State<_LoginFormFields> {
);

if (ok) {
Navigator.of(context).pushNamedAndRemoveUntil(
'/', (Route<dynamic> route) => false);
refreshPage(context);
} else {
_authDidJustFail = true;
form.validate();
Expand Down
13 changes: 13 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ enum _DrawerSelection {

_DrawerSelection _drawerSelection = _DrawerSelection.home;


void refreshPage(BuildContext context) {
Map<_DrawerSelection, String> routes = {
_DrawerSelection.home: '/',
_DrawerSelection.hot: '/hot',
_DrawerSelection.favorites: '/fav',
_DrawerSelection.pools: '/pools',
};

Navigator.of(context).pushNamedAndRemoveUntil(
routes[_drawerSelection], (Route<dynamic> route) => false);
}

class NavigationDrawer extends StatelessWidget {
const NavigationDrawer();

Expand Down
79 changes: 55 additions & 24 deletions lib/pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@ class Pool {
String description;
List<int> postIDs = [];
String creator;
String creation;
String updated;
bool active;

Pool.fromRaw(this.raw) {
id = raw['id'];
name = raw['name'];
description = raw['description'];
postIDs.addAll(raw['post_ids'].cast<int>());
creator = raw['creator_name'];
active = raw['is_active'] as bool;
creation = raw['created_at'];
updated = raw['updated_at'];
}

Uri url(String host) =>
new Uri(scheme: 'https', host: host, path: '/pools/$id');
}

class PoolPreview extends StatelessWidget {
Expand All @@ -36,7 +45,8 @@ class PoolPreview extends StatelessWidget {
this.onPressed,
}) : super(key: key);

static Widget dTextField(BuildContext context, String msg, {bool darkText = false}) {
static Widget dTextField(BuildContext context, String msg,
{bool darkText = false}) {
return new ParsedText(
text: msg,
style: new TextStyle(
Expand Down Expand Up @@ -72,20 +82,49 @@ class PoolPreview extends StatelessWidget {
map['display'] = display;
map['value'] = str;
return map;
}
),
}),
new MatchText(
type: ParsedType.CUSTOM,
pattern: r'\[i\].*\[/i\]',
style: TextStyle(
fontStyle: FontStyle.italic,
),
renderText: ({String str, String pattern}) {
String display = str;
display = display.replaceAll('[i]', '');
display = display.replaceAll('[/i]', '');
Map<String, String> map = Map<String, String>();
map['display'] = display;
map['value'] = str;
return map;
}),
new MatchText(
type: ParsedType.CUSTOM,
pattern: r'\[s\].*\[/s\]',
style: TextStyle(
fontStyle: FontStyle.italic,
),
renderText: ({String str, String pattern}) {
String display = str;
display = display.replaceAll('[i]', '');
display = display.replaceAll('[/i]', '');
Map<String, String> map = Map<String, String>();
map['display'] = display;
map['value'] = str;
return map;
}),
new MatchText(
type: ParsedType.CUSTOM,
pattern: r'(^|\n)\*+',
renderText: ({String str, String pattern}) {
String display = str;
display = '\n' + ' ' * ('*'.allMatches(display).length - 1) + '•';
display =
'\n' + ' ' * ('*'.allMatches(display).length - 1) + '•';
Map<String, String> map = Map<String, String>();
map['display'] = display;
map['value'] = str;
return map;
}
),
}),
new MatchText(
type: ParsedType.CUSTOM,
pattern: r'(\[\[[\S]*\]\])|({{[\S]*}})',
Expand Down Expand Up @@ -118,19 +157,11 @@ class PoolPreview extends StatelessWidget {
),
onTap: (url) async {
Post p = await client.post(int.parse(url.split('#')[1]));
if (!p.isDeleted) {
Navigator.of(context)
.push(new MaterialPageRoute<Null>(builder: (context) {
return new PostWidget(p);
}));
} else {
Scaffold.of(context).showSnackBar(new SnackBar(
duration: const Duration(seconds: 1),
content: new Text('Post has been deleted'),
));
}
}
),
Navigator.of(context)
.push(new MaterialPageRoute<Null>(builder: (context) {
return new PostWidget(p);
}));
}),
new MatchText(
type: ParsedType.CUSTOM,
pattern: r'(pool #[0-9]{1,5})',
Expand All @@ -143,11 +174,11 @@ class PoolPreview extends StatelessWidget {
.push(new MaterialPageRoute<Null>(builder: (context) {
return new PoolPage(p);
}));
}
),
}),
new MatchText(
type: ParsedType.CUSTOM,
pattern: r'(".+":)*https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)',
pattern:
r'(".+":)*https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*[^\s]+)',
style: new TextStyle(
color: Colors.blue[400],
),
Expand All @@ -161,8 +192,8 @@ class PoolPreview extends StatelessWidget {
display = str.replaceAll('https://', '');
value = str;
}
if (display[display.length -1] == '/') {
display = display.substring(0, display.length -1);
if (display[display.length - 1] == '/') {
display = display.substring(0, display.length - 1);
}
Map<String, String> map = Map<String, String>();
map['display'] = display;
Expand Down
119 changes: 75 additions & 44 deletions lib/post.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async' show Future;
import 'dart:collection';
import 'dart:io' show File, Platform;
import 'dart:math';

Expand All @@ -20,6 +21,7 @@ import 'package:url_launcher/url_launcher.dart' as url;
import 'client.dart' show client;
import 'persistence.dart' show db;
import 'package:icon_shadow/icon_shadow.dart';
import 'package:share/share.dart';

class Post {
Map raw;
Expand Down Expand Up @@ -74,7 +76,10 @@ class Post {
hasComments = (raw['comment_count'] as int == 0);

pools = [];
pools.addAll(raw['pools'].cast<int>());
// somehow, there are sometimes duplicates in there
// not my fault, the json just is like that
// we remove them with this convenient LinkedHashSet
pools.addAll(LinkedHashSet<int>.from(raw['pools'].cast<int>()).toList());

sources = [];
sources.addAll(raw['sources'].cast<String>());
Expand Down Expand Up @@ -208,8 +213,7 @@ class PostWidgetScaffold extends StatelessWidget {

const PostWidgetScaffold(this.post, {Key key}) : super(key: key);

Function() _download(BuildContext context) {
return () async {
void _download(BuildContext context) async {
Map<PermissionGroup, PermissionStatus> permissions =
await PermissionHandler()
.requestPermissions([PermissionGroup.storage]);
Expand All @@ -226,7 +230,7 @@ class PostWidgetScaffold extends StatelessWidget {
child: const Text('TRY AGAIN'),
onPressed: () {
Navigator.of(context).pop();
_download(context)(); // recursively re-execute
_download(context); // recursively re-execute
},
),
],
Expand Down Expand Up @@ -260,6 +264,12 @@ class PostWidgetScaffold extends StatelessWidget {
return new AlertDialog(
title: const Text('Error'),
content: new Text(snapshot.error.toString()),
actions: [
new RaisedButton(
child: const Text('OK'),
onPressed: () => Navigator.pop(context),
),
],
);
}

Expand Down Expand Up @@ -292,7 +302,6 @@ class PostWidgetScaffold extends StatelessWidget {
);
},
);
};
}

static String formatBytes(int bytes, int decimals) {
Expand All @@ -307,34 +316,65 @@ class PostWidgetScaffold extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget postContentsWidget() {
Widget placeholder(Widget child) {
return Container(
height: 400,
child: Center(
child: child,
),
);
}

Widget overlayImageWidget() {
Widget imageWidget() {
return post.file['ext'] == 'swf' || post.file['ext'] == 'webm'
? new Container(
height: 400,
child: Center(
child: const Text(
'Webm support under development. \nTap to open in browser.',
textAlign: TextAlign.center,
)))
: new CachedNetworkImage(
imageUrl: post.sample['url'],
placeholder: (context, url) => Container(
height: 400,
child: Center(
child: Container(
height: 26,
width: 26,
child: const CircularProgressIndicator(),
),
)),
errorWidget: (context, url, error) =>
const Icon(Icons.error_outline),
);
return () {
if (post.isDeleted) {
return placeholder(const Text(
'Post was deleted',
textAlign: TextAlign.center,
));
}
if (post.file['url'] == null) {
return placeholder(Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.all(8),
child: const Text(
'Image unavailable in safe mode',
textAlign: TextAlign.center,
),
),
InkWell(
child: Card(
child: Padding(
padding: EdgeInsets.all(8),
child: Text('Settings'))),
onTap: () => Navigator.pushNamed(context, '/settings'),
)
],
));
}
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 CachedNetworkImage(
imageUrl: post.sample['url'],
placeholder: (context, url) => placeholder(Container(
height: 26,
width: 26,
child: const CircularProgressIndicator(),
)),
errorWidget: (context, url, error) =>
const Icon(Icons.error_outline),
);
}();
}

// return new Center(child: imageWidget());

return Stack(
children: <Widget>[
Center(child: imageWidget()),
Expand Down Expand Up @@ -362,7 +402,6 @@ class PostWidgetScaffold extends StatelessWidget {
),
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
/*
PopupMenuItem(
value: 'share',
child: Padding(
Expand All @@ -380,14 +419,13 @@ class PostWidgetScaffold extends StatelessWidget {
),
),
),
*/
PopupMenuItem(
//
value: 'browser',
child: Padding(
padding: EdgeInsets.all(4),
child: Text(
'Browser',
'Browse',
maxLines: 1,
),
),
Expand All @@ -396,7 +434,7 @@ class PostWidgetScaffold extends StatelessWidget {
onSelected: (value) async {
switch (value) {
case 'share':
// not implemented
Share.share(post.url(await db.host.value).toString());
break;
case 'download':
_download(context);
Expand Down Expand Up @@ -639,17 +677,10 @@ class PostWidgetScaffold extends StatelessWidget {
trailing: Icon(Icons.arrow_right),
onTap: () async {
Post p = await client.post(post.parent);
if (!p.isDeleted) {
Navigator.of(context).push(
new MaterialPageRoute<Null>(builder: (context) {
return new PostWidget(p);
}));
} else {
Scaffold.of(context).showSnackBar(new SnackBar(
duration: const Duration(seconds: 1),
content: new Text('Post has been deleted'),
));
}
Navigator.of(context)
.push(new MaterialPageRoute<Null>(builder: (context) {
return new PostWidget(p);
}));
},
),
Divider(),
Expand Down
Loading

0 comments on commit b0ddf2a

Please sign in to comment.