mirror of
https://github.com/pd4d10/git-touch.git
synced 2026-05-22 07:11:38 -05:00
feat: show branches count
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/widgets/picker.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class DialogOption<T> {
|
||||
@@ -180,4 +182,50 @@ class ThemeModel with ChangeNotifier {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static Timer _debounce;
|
||||
|
||||
showPicker(BuildContext context, PickerGroupItem<String> groupItem) async {
|
||||
switch (theme) {
|
||||
case AppThemeType.cupertino:
|
||||
await showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return Container(
|
||||
height: 300,
|
||||
child: CupertinoPicker(
|
||||
backgroundColor: CupertinoColors.white,
|
||||
children: groupItem.items.map((v) => Text(v.text)).toList(),
|
||||
itemExtent: 40,
|
||||
scrollController: FixedExtentScrollController(
|
||||
initialItem: groupItem.items
|
||||
.toList()
|
||||
.indexWhere((v) => v.value == groupItem.value)),
|
||||
onSelectedItemChanged: (index) {
|
||||
if (_debounce?.isActive ?? false) _debounce.cancel();
|
||||
_debounce = Timer(const Duration(milliseconds: 500), () {
|
||||
return groupItem
|
||||
.onChange(groupItem.items.toList()[index].value);
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
break;
|
||||
default:
|
||||
final value = await showMenu(
|
||||
context: context,
|
||||
initialValue: groupItem.value,
|
||||
items: groupItem.items
|
||||
.map((item) =>
|
||||
PopupMenuItem(value: item.value, child: Text(item.text)))
|
||||
.toList(),
|
||||
position: RelativeRect.fill,
|
||||
);
|
||||
if (value != null) {
|
||||
groupItem.onChange(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,9 @@ import 'package:primer/primer.dart';
|
||||
class CommitsScreen extends StatelessWidget {
|
||||
final String owner;
|
||||
final String name;
|
||||
final String branch;
|
||||
|
||||
CommitsScreen(this.owner, this.name);
|
||||
CommitsScreen(this.owner, this.name, {this.branch});
|
||||
|
||||
Future<ListPayload> _query(BuildContext context, [String cursor]) async {
|
||||
var params = 'first: 30';
|
||||
|
||||
@@ -24,14 +24,20 @@ import '../widgets/action.dart';
|
||||
class RepoScreen extends StatelessWidget {
|
||||
final String owner;
|
||||
final String name;
|
||||
final String branch;
|
||||
|
||||
static const _languageBarPadding = 10.0;
|
||||
|
||||
RepoScreen(this.owner, this.name);
|
||||
RepoScreen.fromFullName(String fullName)
|
||||
RepoScreen(this.owner, this.name, {this.branch});
|
||||
RepoScreen.fromFullName(String fullName, {this.branch})
|
||||
: owner = fullName.split('/')[0],
|
||||
name = fullName.split('/')[1];
|
||||
|
||||
get _branchQueryChunk =>
|
||||
branch == null ? 'defaultBranchRef' : 'ref(qualifiedName: "$branch")';
|
||||
get _readmeChunk => (branch ?? 'master') + ':README.md';
|
||||
get branchInfoKey => branch == null ? 'defaultBranchRef' : 'ref';
|
||||
|
||||
Future queryRepo(BuildContext context) async {
|
||||
var data = await Provider.of<SettingsModel>(context).query('''
|
||||
{
|
||||
@@ -48,6 +54,9 @@ class RepoScreen extends StatelessWidget {
|
||||
description
|
||||
diskUsage
|
||||
hasIssuesEnabled
|
||||
url
|
||||
viewerHasStarred
|
||||
viewerSubscription
|
||||
watchers {
|
||||
totalCount
|
||||
}
|
||||
@@ -77,8 +86,7 @@ class RepoScreen extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
}
|
||||
url
|
||||
defaultBranchRef {
|
||||
$_branchQueryChunk {
|
||||
name
|
||||
target {
|
||||
... on Commit {
|
||||
@@ -88,9 +96,13 @@ class RepoScreen extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
}
|
||||
viewerHasStarred
|
||||
viewerSubscription
|
||||
object(expression: "master:README.md") {
|
||||
refs(first: 10, refPrefix: "refs/heads/") {
|
||||
totalCount
|
||||
nodes {
|
||||
name
|
||||
}
|
||||
}
|
||||
object(expression: "$_readmeChunk") {
|
||||
... on Blob {
|
||||
text
|
||||
}
|
||||
@@ -222,18 +234,16 @@ class RepoScreen extends StatelessWidget {
|
||||
TableView(
|
||||
hasIcon: true,
|
||||
items: [
|
||||
if (payload['defaultBranchRef'] != null)
|
||||
if (payload[branchInfoKey] != null)
|
||||
TableViewItem(
|
||||
leftIconData: Octicons.code,
|
||||
text: Text('Code'),
|
||||
rightWidget:
|
||||
Text(filesize((payload['diskUsage'] as int) * 1000)),
|
||||
screenBuilder: (_) => ObjectScreen(
|
||||
owner: owner,
|
||||
name: name,
|
||||
branch: payload['defaultBranchRef']
|
||||
['name'], // FIXME: null
|
||||
),
|
||||
owner: owner,
|
||||
name: name,
|
||||
branch: payload[branchInfoKey]['name']),
|
||||
),
|
||||
if (payload['hasIssuesEnabled'] as bool)
|
||||
TableViewItem(
|
||||
@@ -258,14 +268,34 @@ class RepoScreen extends StatelessWidget {
|
||||
TableView(
|
||||
hasIcon: true,
|
||||
items: [
|
||||
if (payload['defaultBranchRef'] != null)
|
||||
if (payload[branchInfoKey] != null)
|
||||
TableViewItem(
|
||||
leftIconData: Octicons.history,
|
||||
text: Text('Commits'),
|
||||
rightWidget: Text(numberFormat.format(
|
||||
payload['defaultBranchRef']['target']['history']
|
||||
['totalCount'])),
|
||||
screenBuilder: (_) => CommitsScreen(owner, name),
|
||||
rightWidget: Text(numberFormat.format(payload[branchInfoKey]
|
||||
['target']['history']['totalCount'])),
|
||||
screenBuilder: (_) =>
|
||||
CommitsScreen(owner, name, branch: branch),
|
||||
),
|
||||
if (payload['refs'] != null)
|
||||
TableViewItem(
|
||||
leftIconData: Octicons.git_branch,
|
||||
text: Text('Branches'),
|
||||
rightWidget: Text(
|
||||
numberFormat.format(payload['refs']['totalCount'])),
|
||||
// onTap: () {
|
||||
// Provider.of<ThemeModel>(context).showPicker(
|
||||
// context,
|
||||
// PickerGroupItem(
|
||||
// items: (payload['refs']['nodes'] as List).map((b) =>
|
||||
// PickerItem(b['name'] as String, text: b['name'])),
|
||||
// onChange: (v) {
|
||||
// // FIXME:
|
||||
// queryRepo(context);
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
),
|
||||
TableViewItem(
|
||||
leftIconData: Octicons.law,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
@@ -27,57 +26,12 @@ class PickerGroupItem<T> {
|
||||
class PickerGroup extends StatelessWidget {
|
||||
final Iterable<PickerGroupItem<String>> items;
|
||||
|
||||
static Timer _debounce;
|
||||
|
||||
PickerGroup({@required this.items});
|
||||
|
||||
showPicker(BuildContext context, PickerGroupItem<String> groupItem) async {
|
||||
switch (Provider.of<ThemeModel>(context).theme) {
|
||||
case AppThemeType.cupertino:
|
||||
await showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return Container(
|
||||
height: 300,
|
||||
child: CupertinoPicker(
|
||||
backgroundColor: CupertinoColors.white,
|
||||
children: groupItem.items.map((v) => Text(v.text)).toList(),
|
||||
itemExtent: 40,
|
||||
scrollController: FixedExtentScrollController(
|
||||
initialItem: groupItem.items
|
||||
.toList()
|
||||
.indexWhere((v) => v.value == groupItem.value)),
|
||||
onSelectedItemChanged: (index) {
|
||||
if (_debounce?.isActive ?? false) _debounce.cancel();
|
||||
_debounce = Timer(const Duration(milliseconds: 500), () {
|
||||
return groupItem
|
||||
.onChange(groupItem.items.toList()[index].value);
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
break;
|
||||
default:
|
||||
final value = await showMenu(
|
||||
context: context,
|
||||
initialValue: groupItem.value,
|
||||
items: groupItem.items
|
||||
.map((item) =>
|
||||
PopupMenuItem(value: item.value, child: Text(item.text)))
|
||||
.toList(),
|
||||
position: RelativeRect.fill,
|
||||
);
|
||||
if (value != null) {
|
||||
groupItem.onChange(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
switch (Provider.of<ThemeModel>(context).theme) {
|
||||
var themeProvider = Provider.of<ThemeModel>(context);
|
||||
switch (themeProvider.theme) {
|
||||
case AppThemeType.cupertino:
|
||||
default:
|
||||
// TODO: Material
|
||||
@@ -87,7 +41,7 @@ class PickerGroup extends StatelessWidget {
|
||||
text: Text(item.title),
|
||||
rightWidget: Text(item.value),
|
||||
onTap: () {
|
||||
showPicker(context, item);
|
||||
themeProvider.showPicker(context, item);
|
||||
},
|
||||
);
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user