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