Skip to content

Commit

Permalink
fixed annoying bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
clragon committed Apr 13, 2020
1 parent 7a82ae9 commit f38552a
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 80 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.0';
const String appVersion = '1.2.1';
const String defaultEndpoint = 'e926.net';
const String about = 'An app for e621 and e926.';
const String developer = 'binaryfloof';
Expand Down
16 changes: 16 additions & 0 deletions lib/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ class Client {
return await posts(new Tagset.parse(filter), page, limit: 100);
}

Future<Post> post(int postID) async {
try {
String body = await _http
.get(await _host, '/posts/' + postID.toString() + '.json', query: {
'login': await _username,
'api_key': await _apiKey,
}).then((response) => response.body);

Post p = new Post.fromRaw(json.decode(body)['post']);
p.isLoggedIn = await hasLogin();
return p;
} catch (SocketException) {
return null;
}
}

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
2 changes: 1 addition & 1 deletion lib/comment.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// TODO: comments look awful. rework.
// TODO: comments don't work.


import 'dart:async' show Future;
Expand Down
3 changes: 0 additions & 3 deletions lib/input.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// TODO: why do we need this?


import 'package:flutter/services.dart'
show TextInputFormatter, TextEditingValue;

Expand Down
26 changes: 23 additions & 3 deletions lib/pool.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:e1547/post.dart';
import 'package:e1547/posts_page.dart';
import 'package:e1547/tag.dart';
import 'package:flutter/cupertino.dart';
Expand Down Expand Up @@ -79,8 +80,6 @@ class PoolPreview extends StatelessWidget {
renderText: ({String str, String pattern}) {
String display = str;
display = '\n' + ' ' * ('*'.allMatches(display).length - 1) + '•';
// display = display.replaceAll('*', '') + ;
// display = '\t' * display.allMatches('*').length + '* ';
Map<String, String> map = Map<String, String>();
map['display'] = display;
map['value'] = str;
Expand Down Expand Up @@ -113,7 +112,28 @@ class PoolPreview extends StatelessWidget {
),
new MatchText(
type: ParsedType.CUSTOM,
pattern: r'(pool {1,2}#[0-9]{3,6})',
pattern: r'(post #[0-9]{2,7})',
style: new TextStyle(
color: Colors.blue[400],
),
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'),
));
}
}
),
new MatchText(
type: ParsedType.CUSTOM,
pattern: r'(pool #[0-9]{1,5})',
style: new TextStyle(
color: Colors.blue[400],
),
Expand Down
24 changes: 1 addition & 23 deletions lib/pools_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:e1547/main.dart';
import 'package:e1547/pool.dart';
import 'package:e1547/posts_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

import 'client.dart';
import 'input.dart';
Expand Down Expand Up @@ -133,25 +132,6 @@ class _PoolsPageState extends State<PoolsPage> {
return null;
}

StaggeredTile Function(int) _staggeredTileBuilder() {
return (item) {
int i = 0;
for (int p = 0; p < _pages.length; p++) {
List<Pool> page = _pages[p];
i += page.length;
if (item <= i) {
// this might make everything uncomfortably laggy.
// it kinda does but I cant find a solution
// checking for a description of the pool seems impossible.
return const StaggeredTile.fit(1);
}
i += 1;
}

return null;
};
}

@override
Widget build(BuildContext context) {
AppBar appBar() {
Expand Down Expand Up @@ -188,11 +168,9 @@ class _PoolsPageState extends State<PoolsPage> {
),
),
),
StaggeredGridView.countBuilder(
crossAxisCount: 1,
ListView.builder(
itemCount: _itemCount(),
itemBuilder: _itemBuilder,
staggeredTileBuilder: _staggeredTileBuilder(),
physics: new BouncingScrollPhysics(),
),
Visibility(
Expand Down
115 changes: 108 additions & 7 deletions lib/post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class Post {
int id;
int score;
int favorites;

int parent;

String uploader;

Map file;
Expand All @@ -39,11 +42,13 @@ class Post {
String description;

List<int> pools;
List<int> children;
List<String> artist;
List<String> sources;

Map tags;

bool isDeleted;
bool isFavourite;
bool isLoggedIn;

Expand All @@ -54,7 +59,13 @@ class Post {
Post.fromRaw(this.raw) {
id = raw['id'] as int;
favorites = raw['fav_count'] as int;

isFavourite = raw['is_favorited'] as bool;
isDeleted = raw['flags']['deleted'] as bool;

parent = raw["relationships"]['parent_id'] as int ?? -1;
children = [];
children.addAll(raw["relationships"]['children'].cast<int>());

creation = raw['created_at'];

Expand Down Expand Up @@ -180,15 +191,15 @@ class PostSwipe extends StatelessWidget {
}
}

// Preview of a post that appears in lists of posts. Mostly just the image.
// Preview of a post that appears in lists of posts. Just the image.
class PostWidget extends StatelessWidget {
final Post post;

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

@override
Widget build(BuildContext context) {
return new Scaffold(body: new PostWidgetScaffold(post));
return new PostWidgetScaffold(post);
}
}

Expand All @@ -200,8 +211,8 @@ class PostWidgetScaffold extends StatelessWidget {
Function() _download(BuildContext context) {
return () async {
Map<PermissionGroup, PermissionStatus> permissions =
await PermissionHandler()
.requestPermissions([PermissionGroup.storage]);
await PermissionHandler()
.requestPermissions([PermissionGroup.storage]);

if (permissions[PermissionGroup.storage] != PermissionStatus.granted) {
showDialog(
Expand Down Expand Up @@ -394,7 +405,6 @@ class PostWidgetScaffold extends StatelessWidget {
url.launch(post.url(await db.host.value).toString());
break;
}
;
},
),
],
Expand Down Expand Up @@ -602,6 +612,96 @@ class PostWidgetScaffold extends StatelessWidget {
}
}

Widget parentDisplay() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: () {
List<Widget> items = [];
if (post.parent != -1) {
items.addAll([
Padding(
padding: EdgeInsets.only(
right: 4,
left: 4,
top: 2,
bottom: 2,
),
child: Text(
'Parent',
style: TextStyle(
fontSize: 16,
),
),
),
ListTile(
leading: Icon(Icons.supervisor_account),
title: Text(post.parent.toString()),
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'),
));
}
},
),
Divider(),
]);
}
if (post.children.length != 0) {
items.add(
Padding(
padding: EdgeInsets.only(
right: 4,
left: 4,
top: 2,
bottom: 2,
),
child: Text(
'Children',
style: TextStyle(
fontSize: 16,
),
),
),
);
for (int child in post.children) {
items.add(ListTile(
leading: Icon(Icons.supervised_user_circle),
title: Text(child.toString()),
trailing: Icon(Icons.arrow_right),
onTap: () async {
Post p = await client.post(child);
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'),
));
}
},
));
}
items.add(Divider());
}
if (items.length == 0) {
items.add(Container());
}
return items;
}());
}

Widget tagDisplay() {
return Column(
mainAxisSize: MainAxisSize.min,
Expand Down Expand Up @@ -772,6 +872,7 @@ class PostWidgetScaffold extends StatelessWidget {
artistDisplay(),
descriptionDisplay(),
likeDisplay(),
parentDisplay(),
poolDisplay(),
tagDisplay(),
fileInfoDisplay(),
Expand Down Expand Up @@ -805,7 +906,7 @@ class PostWidgetScaffold extends StatelessWidget {

Widget floatingActionButton() {
return new FloatingActionButton(
heroTag: 'postButton',
heroTag: null,
backgroundColor: Theme.of(context).cardColor,
child: Padding(
padding: EdgeInsets.only(left: 2),
Expand Down Expand Up @@ -846,7 +947,7 @@ class PostWidgetScaffold extends StatelessWidget {
],
physics: BouncingScrollPhysics(),
),
floatingActionButton: floatingActionButton(),
floatingActionButton: post.isLoggedIn ? floatingActionButton() : null,
);
}

Expand Down
8 changes: 3 additions & 5 deletions lib/posts_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import 'package:flutter/material.dart';
import 'package:flutter/painting.dart' show EdgeInsets;
import 'package:flutter/services.dart' show Clipboard, ClipboardData;
import 'package:flutter/widgets.dart';

import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'
show StaggeredGridView, StaggeredTile;
import 'package:meta/meta.dart' show required;

import 'client.dart' show client;
import 'input.dart' show LowercaseTextInputFormatter;
import 'main.dart' show NavigationDrawer;
import 'persistence.dart' show db;
import 'post.dart';
import 'range_dialog.dart' show RangeDialog;
import 'tag.dart' show Tagset;
import 'main.dart' show NavigationDrawer;

class HomePage extends StatelessWidget {
@override
Expand Down Expand Up @@ -277,8 +276,7 @@ class _PostsPageState extends State<PostsPage> {
onPressed: () => Navigator.pop(context),
),
actions: [
widget.pool == null ?
new Container() :
widget.pool != null && widget.pool.description != '' ?
IconButton(
icon: Icon(Icons.info_outline),
tooltip: 'Info',
Expand All @@ -297,7 +295,7 @@ class _PostsPageState extends State<PostsPage> {
),
);
},
),
) : new Container(),
new IconButton(
icon: const Icon(Icons.refresh),
tooltip: 'Refresh',
Expand Down
2 changes: 0 additions & 2 deletions lib/range_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: do we really need this?

import 'dart:math' as math show max, min;

import 'package:flutter/material.dart';
Expand Down
Loading

0 comments on commit f38552a

Please sign in to comment.