Skip to content

Commit

Permalink
reworked following page
Browse files Browse the repository at this point in the history
  • Loading branch information
clragon committed Jul 26, 2020
1 parent a18ccef commit 1f029ce
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 127 deletions.
9 changes: 3 additions & 6 deletions lib/about_page.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import 'dart:convert';

import 'package:e1547/appinfo.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

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

import 'package:e1547/appInfo.dart';
import 'package:e1547/http.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart' as url;

class AboutPage extends StatelessWidget {
@override
Expand Down
File renamed without changes.
38 changes: 18 additions & 20 deletions lib/blacklist_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';

import 'client.dart';
import 'interface.dart';
import 'persistence.dart' show db;
Expand Down Expand Up @@ -32,14 +33,20 @@ class _BlacklistPageState extends State<BlacklistPage> {
return () async {
setFocusToEnd(_tagController);
if (_isSearching) {
if (_tagController.text.trim() != '') {
if (_editing != null) {
if (_editing != null) {
if (_tagController.text.trim().isNotEmpty) {
_blacklist[_editing] = _tagController.text;
} else {
_blacklist.add(_tagController.text);
_blacklist.removeAt(_editing);
}
db.blacklist.value = Future.value(_blacklist);
_bottomSheetController?.close();
} else {
if (_tagController.text.trim().isNotEmpty) {
_blacklist.add(_tagController.text);
db.blacklist.value = Future.value(_blacklist);
_bottomSheetController?.close();
}
}
} else {
if (edit != null) {
Expand Down Expand Up @@ -205,34 +212,25 @@ class _BlacklistPageState extends State<BlacklistPage> {
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
PopupMenuItem(
value: 'delete',
child: Padding(
padding: EdgeInsets.all(4),
child: Text('Delete'),
),
value: 'edit',
child: popMenuListTile('Edit', Icons.edit),
),
PopupMenuItem(
value: 'edit',
child: Padding(
padding: EdgeInsets.all(4),
child: Text(
'Edit',
maxLines: 1,
),
),
)
value: 'delete',
child: popMenuListTile('Delete', Icons.delete),
),
],
onSelected: (value) async {
switch (value) {
case 'edit':
_addTags(context, edit: index)();
break;
case 'delete':
setState(() {
_blacklist.removeAt(index);
db.blacklist.value = Future.value(_blacklist);
});
break;
case 'edit':
_addTags(context, edit: index)();
break;
}
},
),
Expand Down
3 changes: 1 addition & 2 deletions lib/client.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import 'dart:async' show Future;
import 'dart:convert' show json;

import 'package:e1547/pool.dart';

import 'package:e1547/comment.dart' show Comment;
import 'package:e1547/http.dart';
import 'package:e1547/persistence.dart' show db;
import 'package:e1547/pool.dart';
import 'package:e1547/post.dart' show Post;
import 'package:e1547/tag.dart';

Expand Down
4 changes: 2 additions & 2 deletions lib/comment.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:async' show Future;
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'package:e1547/client.dart' show client;
import 'package:e1547/interface.dart';
import 'package:e1547/post.dart' show Post;
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class Comment {
Map raw;
Expand Down
122 changes: 94 additions & 28 deletions lib/follow_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class _FollowingPageState extends State<FollowingPage> {
db.follows.addListener(() async {
List<String> follows = await db.follows.value;
setState(() => _follows = follows);
_refresh = true;
});
db.follows.value.then((a) async => setState(() => _follows = a));
}
Expand All @@ -49,8 +50,12 @@ class _FollowingPageState extends State<FollowingPage> {
children: () {
return [
InkWell(
onTap: () => wikiDialog(
context, _follows[index], actions: true),
onTap: () => Navigator.of(context).push(
MaterialPageRoute<Null>(
builder: (context) {
return SearchPage(
tags: Tagset.parse(_follows[index]));
})),
onLongPress: () => wikiDialog(
context, _follows[index],
actions: true),
Expand All @@ -66,33 +71,49 @@ class _FollowingPageState extends State<FollowingPage> {
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
icon: Icon(Icons.search),
onPressed: () async {
if (_follows[index].startsWith('pool:')) {
Pool p = await client.pool(
int.parse(_follows[index].split(':')[1]));
Navigator.of(context).push(
MaterialPageRoute<Null>(builder: (context) {
return PoolPage(p);
}));
} else {
Navigator.of(context).push(
MaterialPageRoute<Null>(builder: (context) {
return SearchPage(
tags: Tagset.parse(_follows[index]));
}));
PopupMenuButton<String>(
icon: Icon(
Icons.more_vert,
color: Theme.of(context).iconTheme.color,
),
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
PopupMenuItem(
value: 'search',
child: popMenuListTile('Search', Icons.search),
),
PopupMenuItem(
value: 'delete',
child: popMenuListTile('Delete', Icons.delete),
),
],
onSelected: (value) async {
switch (value) {
case 'search':
if (_follows[index].startsWith('pool:')) {
Pool p = await client.pool(
int.parse(_follows[index].split(':')[1]));
Navigator.of(context).push(
MaterialPageRoute<Null>(
builder: (context) {
return PoolPage(p);
}));
} else {
Navigator.of(context).push(
MaterialPageRoute<Null>(
builder: (context) {
return SearchPage(
tags: Tagset.parse(_follows[index]));
}));
}
break;
case 'delete':
db.follows.value =
Future.value(_follows..removeAt(index));
break;
}
},
),
IconButton(
icon: Icon(Icons.delete),
onPressed: () {
db.follows.value =
Future.value(_follows..removeAt(index));
_refresh = true;
},
),
],
),
],
Expand All @@ -119,7 +140,6 @@ class _FollowingPageState extends State<FollowingPage> {
setFocusToEnd(_tagController);
if (isSearching.value) {
if (_tagController.text.trim() != '') {
_refresh = true;
db.follows.value =
Future.value(_follows..add(_tagController.text.trim()));
_bottomSheetController?.close();
Expand Down Expand Up @@ -149,7 +169,7 @@ class _FollowingPageState extends State<FollowingPage> {
border: UnderlineInputBorder()),
),
onSuggestionSelected: (suggestion) {
_tagController.text = suggestion.toLowerCase();
_tagController.text = suggestion['name'];
},
itemBuilder: (BuildContext context, itemData) {
return ListTile(
Expand Down Expand Up @@ -177,6 +197,42 @@ class _FollowingPageState extends State<FollowingPage> {
);
}

Widget editor() {
TextEditingController controller = TextEditingController();
controller.text = _follows.join('\n');
return AlertDialog(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Following'),
],
),
content: TextField(
controller: controller,
keyboardType: TextInputType.multiline,
inputFormatters: [BlacklistingTextInputFormatter(' ')],
maxLines: null,
),
actions: <Widget>[
FlatButton(
child: Text('CANCEL'),
onPressed: () {
Navigator.of(context).pop();
},
),
FlatButton(
child: Text('OK'),
onPressed: () {
setState(() {
db.follows.value = Future.value(controller.text.split('\n'));
});
Navigator.of(context).pop();
},
),
],
);
}

return WillPopScope(
onWillPop: () async {
if (_refresh) {
Expand All @@ -198,6 +254,16 @@ class _FollowingPageState extends State<FollowingPage> {
Navigator.pop(context);
}
}),
actions: <Widget>[
IconButton(
icon: Icon(Icons.edit),
onPressed: () async {
showDialog(
context: context,
builder: (context) => editor(),
);
}),
],
),
body: body(),
floatingActionButton: Builder(
Expand Down
6 changes: 3 additions & 3 deletions lib/http.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:async' show Future;
import 'package:e1547/appinfo.dart' as appInfo;

import 'package:e1547/appInfo.dart';
import 'package:http/http.dart' as http;

String userAgent =
'${appInfo.appName}/${appInfo.appVersion} (${appInfo.developer})';
String userAgent = '$appName/$appVersion ($developer)';

class HttpHelper {
Map<String, String> headers = {'User-Agent': userAgent};
Expand Down
19 changes: 16 additions & 3 deletions lib/interface.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'dart:math' as math show max, min;

import 'package:e1547/client.dart';
import 'package:e1547/persistence.dart';
import 'package:e1547/pool.dart';
import 'package:e1547/post.dart';
Expand All @@ -7,10 +10,8 @@ import 'package:expandable/expandable.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart' as url;
import 'package:e1547/client.dart';
import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
import 'dart:math' as math show max, min;
import 'package:url_launcher/url_launcher.dart' as url;

void wikiDialog(BuildContext context, String tag, {actions = false}) {
Widget body() {
Expand Down Expand Up @@ -1241,6 +1242,18 @@ class _TextEditorState extends State<TextEditor> with TickerProviderStateMixin {
}
}

Widget popMenuListTile(String title, IconData icon) {
return Row(
children: <Widget>[
Icon(icon, size: 20),
Padding(
padding: EdgeInsets.only(left: 16, right: 16, top: 4, bottom: 4),
child: Text(title),
),
],
);
}

class RangeDialog extends StatefulWidget {
RangeDialog({this.title, this.value, this.max, this.min, this.division});

Expand Down
7 changes: 4 additions & 3 deletions lib/login_page.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'dart:async' show Future, Timer;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show Clipboard;
import 'package:url_launcher/url_launcher.dart' as url;

import 'package:e1547/client.dart' show client;
import 'package:e1547/main.dart';
import 'package:e1547/persistence.dart' show db;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show Clipboard;
import 'package:url_launcher/url_launcher.dart' as url;

class LoginPage extends StatelessWidget {
@override
Expand Down
15 changes: 7 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import 'package:e1547/about_page.dart';
import 'package:e1547/appInfo.dart';
import 'package:e1547/blacklist_page.dart';
import 'package:e1547/interface.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:e1547/client.dart';
import 'package:e1547/follow_page.dart';
import 'package:e1547/interface.dart';
import 'package:e1547/login_page.dart';
import 'package:e1547/persistence.dart';
import 'package:e1547/pools_page.dart';
import 'package:e1547/posts_page.dart';
import 'package:e1547/appinfo.dart' as appInfo;
import 'package:e1547/settings_page.dart';
import 'package:flutter/material.dart';
import 'package:e1547/appinfo.dart';
import 'package:flutter/services.dart';

ValueNotifier<ThemeData> _theme = ValueNotifier(themeMap['dark']);

Expand All @@ -32,7 +31,7 @@ class Main extends StatelessWidget {
builder: (context, value, child) {
setUIColors(value);
return MaterialApp(
title: appInfo.appName,
title: appName,
theme: value,
routes: <String, WidgetBuilder>{
'/': (context) => () {
Expand Down
Loading

0 comments on commit 1f029ce

Please sign in to comment.