mirror of
https://github.com/git-touch/git-touch
synced 2025-03-26 08:00:05 +01:00
refactor: action items
This commit is contained in:
parent
b93d8313f9
commit
9c4cd73814
@ -3,7 +3,6 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:git_touch/models/auth.dart';
|
import 'package:git_touch/models/auth.dart';
|
||||||
import 'package:primer/primer.dart';
|
import 'package:primer/primer.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:share/share.dart';
|
|
||||||
import '../utils/utils.dart';
|
import '../utils/utils.dart';
|
||||||
import '../scaffolds/long_list.dart';
|
import '../scaffolds/long_list.dart';
|
||||||
import '../widgets/timeline_item.dart';
|
import '../widgets/timeline_item.dart';
|
||||||
@ -343,19 +342,11 @@ mutation {
|
|||||||
trailingBuilder: (payload) {
|
trailingBuilder: (payload) {
|
||||||
return ActionButton(
|
return ActionButton(
|
||||||
title: (isPullRequest ? 'Pull Request' : 'Issue') + ' Actions',
|
title: (isPullRequest ? 'Pull Request' : 'Issue') + ' Actions',
|
||||||
actions: [
|
items: [
|
||||||
MyAction(
|
if (payload != null) ...[
|
||||||
text: 'Share',
|
ActionItem.share(payload['url']),
|
||||||
onPress: () {
|
ActionItem.launch(payload['url']),
|
||||||
Share.share(payload['url']);
|
],
|
||||||
},
|
|
||||||
),
|
|
||||||
MyAction(
|
|
||||||
text: 'Open in Browser',
|
|
||||||
onPress: () {
|
|
||||||
launchUrl(payload['url']);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -8,7 +8,6 @@ import 'package:git_touch/widgets/entry_item.dart';
|
|||||||
import 'package:git_touch/widgets/repository_item.dart';
|
import 'package:git_touch/widgets/repository_item.dart';
|
||||||
import 'package:git_touch/widgets/table_view.dart';
|
import 'package:git_touch/widgets/table_view.dart';
|
||||||
import 'package:git_touch/widgets/user_item.dart';
|
import 'package:git_touch/widgets/user_item.dart';
|
||||||
import 'package:share/share.dart';
|
|
||||||
import 'package:git_touch/models/auth.dart';
|
import 'package:git_touch/models/auth.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../widgets/action.dart';
|
import '../widgets/action.dart';
|
||||||
@ -93,23 +92,11 @@ class OrganizationScreen extends StatelessWidget {
|
|||||||
trailingBuilder: (payload) {
|
trailingBuilder: (payload) {
|
||||||
return ActionButton(
|
return ActionButton(
|
||||||
title: 'Organization Actions',
|
title: 'Organization Actions',
|
||||||
actions: [
|
items: [
|
||||||
MyAction(
|
if (payload != null) ...[
|
||||||
text: 'Share',
|
ActionItem.share(payload['url']),
|
||||||
onPress: () {
|
ActionItem.launch(payload['url']),
|
||||||
if (payload != null) {
|
],
|
||||||
Share.share(payload['url']);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
MyAction(
|
|
||||||
text: 'Open in Browser',
|
|
||||||
onPress: () {
|
|
||||||
if (payload != null) {
|
|
||||||
launchUrl(payload['url']);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -13,7 +13,6 @@ import 'package:provider/provider.dart';
|
|||||||
import 'package:git_touch/models/theme.dart';
|
import 'package:git_touch/models/theme.dart';
|
||||||
import 'package:git_touch/screens/commits.dart';
|
import 'package:git_touch/screens/commits.dart';
|
||||||
import 'package:git_touch/screens/object.dart';
|
import 'package:git_touch/screens/object.dart';
|
||||||
import 'package:share/share.dart';
|
|
||||||
import 'package:git_touch/widgets/repository_item.dart';
|
import 'package:git_touch/widgets/repository_item.dart';
|
||||||
import '../widgets/entry_item.dart';
|
import '../widgets/entry_item.dart';
|
||||||
import '../screens/issues.dart';
|
import '../screens/issues.dart';
|
||||||
@ -149,8 +148,8 @@ class RepositoryScreen extends StatelessWidget {
|
|||||||
trailingBuilder: (data) {
|
trailingBuilder: (data) {
|
||||||
return ActionButton(
|
return ActionButton(
|
||||||
title: 'Repository Actions',
|
title: 'Repository Actions',
|
||||||
actions: [
|
items: [
|
||||||
MyAction(
|
ActionItem(
|
||||||
text: '@$owner',
|
text: '@$owner',
|
||||||
onPress: () {
|
onPress: () {
|
||||||
if (data == null) return;
|
if (data == null) return;
|
||||||
@ -169,7 +168,7 @@ class RepositoryScreen extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (data != null) ...[
|
if (data != null) ...[
|
||||||
MyAction(
|
ActionItem(
|
||||||
text: data[0]['viewerHasStarred'] ? 'Unstar' : 'Star',
|
text: data[0]['viewerHasStarred'] ? 'Unstar' : 'Star',
|
||||||
onPress: () async {
|
onPress: () async {
|
||||||
if (data[0]['viewerHasStarred']) {
|
if (data[0]['viewerHasStarred']) {
|
||||||
@ -183,7 +182,7 @@ class RepositoryScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
MyAction(
|
ActionItem(
|
||||||
text: data[0]['viewerSubscription'] == 'SUBSCRIBED'
|
text: data[0]['viewerSubscription'] == 'SUBSCRIBED'
|
||||||
? 'Unwatch'
|
? 'Unwatch'
|
||||||
: 'Watch',
|
: 'Watch',
|
||||||
@ -200,22 +199,10 @@ class RepositoryScreen extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
MyAction(
|
if (data != null) ...[
|
||||||
text: 'Share',
|
ActionItem.share(data[0]['url']),
|
||||||
onPress: () {
|
ActionItem.launch(data[0]['url']),
|
||||||
if (data != null) {
|
],
|
||||||
Share.share(data[0]['url']);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
MyAction(
|
|
||||||
text: 'Open in Browser',
|
|
||||||
onPress: () {
|
|
||||||
if (data != null) {
|
|
||||||
launchUrl(data[0]['url']);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -9,7 +9,6 @@ import 'package:git_touch/widgets/table_view.dart';
|
|||||||
import 'package:git_touch/widgets/text_contains_organization.dart';
|
import 'package:git_touch/widgets/text_contains_organization.dart';
|
||||||
import 'package:git_touch/widgets/user_item.dart';
|
import 'package:git_touch/widgets/user_item.dart';
|
||||||
import 'package:primer/primer.dart';
|
import 'package:primer/primer.dart';
|
||||||
import 'package:share/share.dart';
|
|
||||||
import 'package:github_contributions/github_contributions.dart';
|
import 'package:github_contributions/github_contributions.dart';
|
||||||
import 'package:git_touch/models/auth.dart';
|
import 'package:git_touch/models/auth.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@ -161,9 +160,9 @@ class UserScreen extends StatelessWidget {
|
|||||||
} else {
|
} else {
|
||||||
return ActionButton(
|
return ActionButton(
|
||||||
title: 'User Actions',
|
title: 'User Actions',
|
||||||
actions: [
|
items: [
|
||||||
if (data != null && data[0]['viewerCanFollow'])
|
if (data != null && data[0]['viewerCanFollow'])
|
||||||
MyAction(
|
ActionItem(
|
||||||
text: data[0]['viewerIsFollowing'] ? 'Unfollow' : 'Follow',
|
text: data[0]['viewerIsFollowing'] ? 'Unfollow' : 'Follow',
|
||||||
onPress: () async {
|
onPress: () async {
|
||||||
if (data[0]['viewerIsFollowing']) {
|
if (data[0]['viewerIsFollowing']) {
|
||||||
@ -177,22 +176,10 @@ class UserScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
MyAction(
|
if (data != null) ...[
|
||||||
text: 'Share',
|
ActionItem.share(data[0]['url']),
|
||||||
onPress: () {
|
ActionItem.launch(data[0]['url']),
|
||||||
if (data[0] != null) {
|
],
|
||||||
Share.share(data[0]['url']);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
MyAction(
|
|
||||||
text: 'Open in Browser',
|
|
||||||
onPress: () {
|
|
||||||
if (data[0] != null) {
|
|
||||||
launchUrl(data[0]['url']);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,39 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:git_touch/utils/utils.dart';
|
||||||
import 'package:git_touch/widgets/action_entry.dart';
|
import 'package:git_touch/widgets/action_entry.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:git_touch/models/theme.dart';
|
import 'package:git_touch/models/theme.dart';
|
||||||
|
import 'package:share/share.dart';
|
||||||
|
|
||||||
class MyAction {
|
class ActionItem {
|
||||||
String text;
|
String text;
|
||||||
Function onPress;
|
void Function() onPress;
|
||||||
|
|
||||||
MyAction({@required this.text, @required this.onPress});
|
ActionItem({@required this.text, @required this.onPress});
|
||||||
|
ActionItem.share(String url)
|
||||||
|
: text = 'Share',
|
||||||
|
onPress = (() {
|
||||||
|
Share.share(url);
|
||||||
|
});
|
||||||
|
ActionItem.launch(String url)
|
||||||
|
: text = 'Open in Browser',
|
||||||
|
onPress = (() {
|
||||||
|
launchUrl(url);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class ActionButton extends StatelessWidget {
|
class ActionButton extends StatelessWidget {
|
||||||
final String title;
|
final String title;
|
||||||
final List<MyAction> actions;
|
final List<ActionItem> items;
|
||||||
final IconData iconData;
|
final IconData iconData;
|
||||||
|
|
||||||
ActionButton({
|
ActionButton({
|
||||||
@required this.title,
|
@required this.title,
|
||||||
@required this.actions,
|
@required this.items,
|
||||||
this.iconData = Icons.more_vert,
|
this.iconData = Icons.more_vert,
|
||||||
});
|
});
|
||||||
|
|
||||||
void _onSelected(int value) {
|
|
||||||
if (value != null) {
|
|
||||||
actions[value].onPress();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
switch (Provider.of<ThemeModel>(context).theme) {
|
switch (Provider.of<ThemeModel>(context).theme) {
|
||||||
@ -36,12 +42,12 @@ class ActionButton extends StatelessWidget {
|
|||||||
return ActionEntry(
|
return ActionEntry(
|
||||||
iconData: iconData,
|
iconData: iconData,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
int value = await showCupertinoModalPopup<int>(
|
var value = await showCupertinoModalPopup<int>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return CupertinoActionSheet(
|
return CupertinoActionSheet(
|
||||||
title: Text(title),
|
title: Text(title),
|
||||||
actions: actions.asMap().entries.map((entry) {
|
actions: items.asMap().entries.map((entry) {
|
||||||
return CupertinoActionSheetAction(
|
return CupertinoActionSheetAction(
|
||||||
child: Text(entry.value.text),
|
child: Text(entry.value.text),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -60,7 +66,9 @@ class ActionButton extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
_onSelected(value);
|
if (value != null) {
|
||||||
|
items[value].onPress();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user