1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-18 19:22:54 +01:00

refactor: url action items

This commit is contained in:
Rongjian Zhang 2020-01-27 13:41:17 +08:00
parent e97befd412
commit 4ea5a03431
5 changed files with 19 additions and 22 deletions

View File

@ -41,8 +41,7 @@ class GitlabProjectScreen extends StatelessWidget {
return ActionButton( return ActionButton(
title: 'Project Actions', title: 'Project Actions',
items: [ items: [
ActionItem.share(data.webUrl), ...ActionItem.getUrlActions(data.webUrl),
ActionItem.launch(data.webUrl),
], ],
); );
}, },

View File

@ -401,8 +401,7 @@ mutation {
}); });
}, },
), ),
ActionItem.share(payload['url']), ...ActionItem.getUrlActions(payload['url'] as String),
ActionItem.launch(payload['url']),
], ],
], ],
); );

View File

@ -130,8 +130,7 @@ class RepositoryScreen extends StatelessWidget {
text: 'Releases(${repo.releases.totalCount})', text: 'Releases(${repo.releases.totalCount})',
url: 'https://github.com/$owner/$name/releases', url: 'https://github.com/$owner/$name/releases',
), ),
ActionItem.share(repo.url), ...ActionItem.getUrlActions(repo.url),
ActionItem.launch(repo.url),
], ],
); );
}, },

View File

@ -402,20 +402,14 @@ class UserScreen extends StatelessWidget {
final user = payload as GhUserUser; final user = payload as GhUserUser;
return ActionButton( return ActionButton(
title: 'User Actions', title: 'User Actions',
items: [ items: [...ActionItem.getUrlActions(user.url)],
ActionItem.share(user.url),
ActionItem.launch(user.url),
],
); );
case 'Organization': case 'Organization':
final organization = payload as GhUserOrganization; final organization = payload as GhUserOrganization;
return ActionButton( return ActionButton(
title: 'Organization Actions', title: 'Organization Actions',
items: [ items: [
if (payload != null) ...[ ...ActionItem.getUrlActions(organization.url),
ActionItem.share(organization.url),
ActionItem.launch(organization.url),
],
], ],
); );
default: default:

View File

@ -18,16 +18,22 @@ class ActionItem {
this.iconData, this.iconData,
}); });
ActionItem.share(String url) static List<ActionItem> getUrlActions(String url) {
: text = 'Share', return [
onTap = ((_) { ActionItem(
text: 'Share',
onTap: (_) {
Share.share(url); Share.share(url);
}); },
ActionItem.launch(String url) ),
: text = 'Open in Browser', ActionItem(
onTap = ((_) { text: 'Open in Browser',
onTap: (_) {
launchUrl(url); launchUrl(url);
}); },
),
];
}
} }
class ActionButton extends StatelessWidget { class ActionButton extends StatelessWidget {