mirror of
https://github.com/git-touch/git-touch
synced 2025-01-31 08:04:51 +01:00
feat(bb): explore screen
This commit is contained in:
parent
830bceaa36
commit
6d35703554
@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/notification.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/screens/bb_explore.dart';
|
||||
import 'package:git_touch/screens/bb_user.dart';
|
||||
import 'package:git_touch/screens/gitea_orgs.dart';
|
||||
import 'package:git_touch/screens/gitea_user.dart';
|
||||
@ -64,7 +65,7 @@ class _HomeState extends State<Home> {
|
||||
case PlatformType.bitbucket:
|
||||
switch (index) {
|
||||
case 0:
|
||||
return BbUserScreen(null);
|
||||
return BbExplore();
|
||||
case 1:
|
||||
return BbUserScreen(null);
|
||||
}
|
||||
|
@ -40,6 +40,19 @@ class DataWithPage<T> {
|
||||
});
|
||||
}
|
||||
|
||||
class BbPagePayload<T> {
|
||||
T data;
|
||||
String cursor;
|
||||
bool hasMore;
|
||||
int total;
|
||||
BbPagePayload({
|
||||
@required this.data,
|
||||
@required this.cursor,
|
||||
@required this.hasMore,
|
||||
this.total,
|
||||
});
|
||||
}
|
||||
|
||||
class AuthModel with ChangeNotifier {
|
||||
static const _apiPrefix = 'https://api.github.com';
|
||||
|
||||
@ -248,7 +261,7 @@ class AuthModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
Future fetchBb(String p) async {
|
||||
if (!p.startsWith('/api')) p = '/api/2.0$p';
|
||||
if (p.startsWith('/') && !p.startsWith('/api')) p = '/api/2.0$p';
|
||||
final input = Uri.parse(p);
|
||||
final uri = Uri.parse(activeAccount.domain).replace(
|
||||
userInfo: '${activeAccount.login}:${activeAccount.appPassword}',
|
||||
@ -260,11 +273,11 @@ class AuthModel with ChangeNotifier {
|
||||
return info;
|
||||
}
|
||||
|
||||
Future<DataWithPage<List>> fetchBbWithPage(String p) async {
|
||||
Future<BbPagePayload<List>> fetchBbWithPage(String p) async {
|
||||
final res = await fetchBb(p);
|
||||
final v = BbPagination.fromJson(res);
|
||||
return DataWithPage(
|
||||
cursor: v.page,
|
||||
return BbPagePayload(
|
||||
cursor: v.next,
|
||||
total: v.size,
|
||||
data: v.values,
|
||||
hasMore: v.next != null,
|
||||
|
35
lib/screens/bb_explore.dart
Normal file
35
lib/screens/bb_explore.dart
Normal file
@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/bitbucket.dart';
|
||||
import 'package:git_touch/scaffolds/list_stateful.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:git_touch/widgets/repository_item.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class BbExplore extends StatelessWidget {
|
||||
Future<ListPayload<BbRepo, String>> _query(BuildContext context,
|
||||
[String nextUrl]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth.fetchBbWithPage(
|
||||
nextUrl ?? '/repositories?role=member&sort=-updated_on');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
hasMore: res.hasMore,
|
||||
items: <BbRepo>[
|
||||
for (var v in res.data) BbRepo.fromJson(v),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListStatefulScaffold<BbRepo, String>(
|
||||
title: AppBarTitle('Explore'),
|
||||
onRefresh: () => _query(context),
|
||||
onLoadMore: (page) => _query(context, page),
|
||||
itemBuilder: (v) {
|
||||
return RepositoryItem.bb(payload: v);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -9,7 +9,6 @@ import 'package:git_touch/widgets/user_header.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
|
||||
class BbUserScreen extends StatelessWidget {
|
||||
final String login;
|
||||
@ -30,7 +29,7 @@ class BbUserScreen extends StatelessWidget {
|
||||
return Tuple2(
|
||||
BbUser.fromJson(res[0]),
|
||||
[
|
||||
for (var v in (res[1] as DataWithPage<List>).data)
|
||||
for (var v in (res[1] as BbPagePayload<List>).data)
|
||||
BbRepo.fromJson(v)
|
||||
],
|
||||
);
|
||||
@ -56,18 +55,7 @@ class BbUserScreen extends StatelessWidget {
|
||||
CommonStyle.border,
|
||||
Column(
|
||||
children: <Widget>[
|
||||
for (var v in repos)
|
||||
RepositoryItem(
|
||||
owner: v.owner.displayName,
|
||||
name: v.name,
|
||||
url: '/bitbucket/${v.fullName}',
|
||||
avatarUrl: v.avatarUrl,
|
||||
avatarLink: '/bitbucket/${v.owner.displayName}',
|
||||
note: 'Updated ${timeago.format(v.updatedOn)}',
|
||||
description: v.description,
|
||||
forkCount: 0,
|
||||
starCount: 0,
|
||||
)
|
||||
for (var v in repos) RepositoryItem.bb(payload: v)
|
||||
],
|
||||
)
|
||||
],
|
||||
|
@ -1,11 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_touch/models/bitbucket.dart';
|
||||
import 'package:git_touch/models/gitlab.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/widgets/avatar.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../utils/utils.dart';
|
||||
import 'link.dart';
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
|
||||
class RepositoryItem extends StatelessWidget {
|
||||
final String owner;
|
||||
@ -36,6 +38,21 @@ class RepositoryItem extends StatelessWidget {
|
||||
@required this.avatarLink,
|
||||
});
|
||||
|
||||
RepositoryItem.bb({
|
||||
@required BbRepo payload,
|
||||
this.primaryLanguageName,
|
||||
this.primaryLanguageColor,
|
||||
}) : owner = payload.owner.displayName,
|
||||
name = payload.name,
|
||||
url = '/bitbucket/${payload.fullName}',
|
||||
avatarUrl = payload.avatarUrl,
|
||||
avatarLink = '/bitbucket/${payload.owner.displayName}',
|
||||
note = 'Updated ${timeago.format(payload.updatedOn)}',
|
||||
description = payload.description,
|
||||
forkCount = 0,
|
||||
starCount = 0,
|
||||
iconData = payload.isPrivate ? Octicons.lock : null;
|
||||
|
||||
RepositoryItem.gl({
|
||||
@required GitlabProject payload,
|
||||
this.primaryLanguageName,
|
||||
|
Loading…
x
Reference in New Issue
Block a user