Skip to content

Commit

Permalink
fixed several bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
clragon committed Apr 10, 2020
1 parent a0a0b68 commit 4c547cc
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 88 deletions.
66 changes: 66 additions & 0 deletions lib/about_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:e1547/appinfo.dart';
import 'package:flutter/material.dart';

import 'package:url_launcher/url_launcher.dart' as url;

class AboutPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
AppBar appBarWidget() {
return new AppBar(
title: new Text('About'),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => Navigator.pop(context),
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.update),
onPressed: () async => url.launch(github),
),
],
);
}

Widget body() {
return new Row(children: [
new Flexible(
child: new Center(
child: new Padding(
padding: EdgeInsets.only(bottom: 100),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const CircleAvatar(
backgroundImage: const AssetImage('assets/icon/paw.png'),
radius: 44.0,
),
new Padding(
padding: EdgeInsets.only(top: 24, bottom: 12),
child: const Text(
appName,
style: const TextStyle(
fontSize: 22,
),
),
),
const Text(
appVersion,
style: const TextStyle(
fontSize: 16,
),
),
],
),
)),
),
]);
}

return new Scaffold(
appBar: appBarWidget(),
body: body(),
);
}
}
5 changes: 3 additions & 2 deletions lib/appinfo.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const String appName = 'e1547';
const String appVersion = '1.1.0';
const String appVersion = '1.1.1';
const String defaultEndpoint = 'e926.net';
const String about = 'An app for e621 and e926.';
const String developer = 'binaryfloof';
const String developer = 'binaryfloof';
const String github = 'https://github.com/clragon/e1547/releases';
2 changes: 2 additions & 0 deletions lib/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ class Client {

List<Post> posts = [];
bool loggedIn = await this.isLoggedIn();
bool showWebm = await db.showWebm.value;
for (Map rp in json.decode(body)['posts']) {
Post p = new Post.fromRaw(rp);
p.isLoggedIn = loggedIn;
if (p.file['url'] == null || p.file['ext'] == 'swf') { continue; }
if (!showWebm && p.file['ext'] == 'webm') { continue; }
posts.add(p);
}

Expand Down
65 changes: 37 additions & 28 deletions lib/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class LoginPage extends StatelessWidget {
new _InstructionStep(
1, _buttonLink('Login via web browser', '/session/new')),
new _InstructionStep(2, _buttonLink('Enable API Access', '/users/home')),
const _InstructionStep(3, const Text('Copy and paste your API key')),
const _InstructionStep(
3,
const Padding(
padding: EdgeInsets.all(16),
child: const Text('Copy and paste your API key'))),
new _LoginFormFields(),
];

Expand Down Expand Up @@ -221,21 +225,24 @@ class _LoginFormFieldsState extends State<_LoginFormFields> {

Widget saveAndTestWidget() {
return new Padding(
padding: const EdgeInsets.only(top: 20.0),
padding: const EdgeInsets.only(top: 26.0),
child: new RaisedButton(
child: const Text('SAVE & TEST'),
child: const Text('LOGIN'),
onPressed: _saveAndTest(context),
),
);
}

return new Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
usernameWidget(),
apiKeyWidget(),
saveAndTestWidget(),
],
return new Padding(
padding: EdgeInsets.all(16),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
usernameWidget(),
apiKeyWidget(),
saveAndTestWidget(),
],
),
);
}
}
Expand Down Expand Up @@ -272,10 +279,16 @@ class _LoginProgressDialogState extends State<_LoginProgressDialog> {
return new Dialog(
child: new Container(
padding: const EdgeInsets.all(20.0),
child:
new Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
const CircularProgressIndicator(),
new Text('Logging in as ${widget.username}'),
child: new Row(children: [
new Container(
height: 28,
width: 28,
child: const CircularProgressIndicator(),
),
new Padding(
padding: EdgeInsets.only(left: 16),
child: new Text('Logging in as ${widget.username}'),
)
]),
));
}
Expand All @@ -290,31 +303,27 @@ class _InstructionStep extends StatelessWidget {

@override
Widget build(BuildContext context) {
Widget leadingCircleWidget() {
Widget stepNumber() {
return new Container(
decoration: const ShapeDecoration(
color: Colors.white,
shape: const CircleBorder(),
),
width: 64.0,
height: 64.0,
width: 36.0,
height: 36.0,
alignment: Alignment.center,
child: new Text(
_stepNumber.toString(),
textAlign: TextAlign.center,
style: const TextStyle(color: Colors.black, fontSize: 48.0),
style: const TextStyle(fontSize: 26.0),
),
);
}

return new Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child:
new Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
leadingCircleWidget(),
new Expanded(child: new Container()),
_content,
new Expanded(child: new Container()),
child: new Row(children: [
stepNumber(),
new Padding(
padding: EdgeInsets.only(left: 16),
child: _content,
),
]),
);
}
Expand Down
81 changes: 51 additions & 30 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:e1547/about_page.dart';
import 'package:e1547/persistence.dart';
import 'package:e1547/pools_page.dart';
import 'package:e1547/settings_page.dart';
import 'package:flutter/services.dart';
import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
import 'client.dart';
import 'login_page.dart';
import 'posts_page.dart';
import 'appinfo.dart' as appInfo;
Expand All @@ -24,11 +26,6 @@ class Main extends StatelessWidget {
FlutterStatusbarcolor.setStatusBarWhiteForeground(
theme.brightness == Brightness.dark);

SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);

return MaterialApp(
title: appInfo.appName,
theme: theme,
Expand All @@ -39,6 +36,7 @@ class Main extends StatelessWidget {
'/pools': (context) => new PoolsPage(),
'/login': (context) => new LoginPage(),
'/settings': (context) => new SettingsPage(),
'/about': (context) => new AboutPage(),
},
);
}
Expand Down Expand Up @@ -66,20 +64,42 @@ class NavigationDrawer extends StatelessWidget {
if (snapshot.connectionState == ConnectionState.done &&
!snapshot.hasError &&
snapshot.hasData) {
return new Row(
children: <Widget>[
new Expanded(
child: new Text(
snapshot.data,
style: new TextStyle(fontSize: 16.0),
overflow: TextOverflow.ellipsis,
)),
],
);
if (snapshot.data != null) {
return new Row(
children: <Widget>[
new Expanded(
child: new Text(
snapshot.data,
style: new TextStyle(fontSize: 16.0),
overflow: TextOverflow.ellipsis,
)),
new IconButton(
icon: new Icon(Icons.exit_to_app),
onPressed: () {
db.username.value = new Future.value(null);
db.apiKey.value = new Future.value(null);

String msg = 'Forgot login details';

Scaffold.of(context).showSnackBar(new SnackBar(
duration: const Duration(seconds: 5),
content: new Text(msg),
));
_drawerSelection = _DrawerSelection.home;
Navigator.of(context)
.pushNamedAndRemoveUntil('/', (Route<dynamic> route) => false);
}
)
],
);
}
}
return new RaisedButton(
child: const Text('LOGIN'),
onPressed: () => Navigator.popAndPushNamed(context, '/login'),
return new Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: new RaisedButton(
child: const Text('LOGIN'),
onPressed: () => Navigator.popAndPushNamed(context, '/login'),
),
);
},
);
Expand All @@ -101,7 +121,7 @@ class NavigationDrawer extends StatelessWidget {
radius: 36.0,
),
new Expanded(child: Padding(
padding: EdgeInsets.all(16),
padding: EdgeInsets.all(20),
child: userInfoWidget(),
),
),
Expand Down Expand Up @@ -135,10 +155,14 @@ class NavigationDrawer extends StatelessWidget {
selected: _drawerSelection == _DrawerSelection.favorites,
leading: const Icon(Icons.favorite),
title: const Text('Favorites'),
onTap: () {
_drawerSelection = _DrawerSelection.favorites;
Navigator.of(context).pushNamedAndRemoveUntil(
'/fav', (Route<dynamic> route) => false);
onTap: () async {
if (await client.isLoggedIn()) {
_drawerSelection = _DrawerSelection.favorites;
Navigator.of(context).pushNamedAndRemoveUntil(
'/fav', (Route<dynamic> route) => false);
} else {
Navigator.popAndPushNamed(context, '/login');
}
}),
Divider(),
new ListTile(
Expand All @@ -157,13 +181,10 @@ class NavigationDrawer extends StatelessWidget {
title: const Text('Settings'),
onTap: () => Navigator.popAndPushNamed(context, '/settings'),
),
// TODO: get rid of this garbage and make own about screen.
const AboutListTile(
child: const Text('About'),
icon: const Icon(Icons.help),
applicationName: appInfo.appName,
applicationVersion: appInfo.appVersion,
applicationLegalese: appInfo.about,
new ListTile(
leading: const Icon(Icons.info),
title: const Text('About'),
onTap: () => Navigator.popAndPushNamed(context, '/about'),
),
]),
);
Expand Down
10 changes: 4 additions & 6 deletions lib/persistence.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: this seems awfully outdated. Remove or rewrite?

import 'dart:async' show Future;

import 'package:flutter/foundation.dart' show ValueNotifier;
Expand All @@ -16,18 +14,15 @@ final Persistence db = new Persistence();

class Persistence {
ValueNotifier<Future<String>> host;
ValueNotifier<Future<Tagset>> tags;
ValueNotifier<Future<Tagset>> homeTags;
ValueNotifier<Future<String>> username;
ValueNotifier<Future<String>> apiKey;
ValueNotifier<Future<bool>> showWebm;

Persistence() {
host = _makeNotifier((p) => p.getString('host') ?? appInfo.defaultEndpoint);
host.addListener(_saveString('host', host));

tags = _makeNotifier((p) => new Tagset.parse(p.getString('tags') ?? ''));
tags.addListener(_saveString('tags', tags));

homeTags = _makeNotifier((p) => new Tagset.parse(p.getString('homeTags') ?? ''));
homeTags.addListener(_saveString('homeTags', homeTags));

Expand All @@ -36,6 +31,9 @@ class Persistence {

apiKey = _makeNotifier((p) => p.getString('apiKey'));
apiKey.addListener(_saveString('apiKey', apiKey));

showWebm = _makeNotifier((p) => p.getBool('showWebm'));
showWebm.addListener(_saveBool('showWebm', showWebm));
}

final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
Expand Down
5 changes: 2 additions & 3 deletions lib/post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,15 @@ class PostPreview extends StatelessWidget {
),
);

// TODO: maybe remove this?
Widget specialOverlayIcon;
if (post.file['ext'] == 'gif') {
if (post.file['ext'] == 'gif' || post.file['ext'] == 'webm') {
specialOverlayIcon = new Positioned(
top: 4,
right: 4,
child: new Container(
padding: EdgeInsets.zero,
color: Colors.black38,
child: const Icon(Icons.gif),
child: const Icon(Icons.play_arrow),
));
}

Expand Down
Loading

0 comments on commit 4c547cc

Please sign in to comment.