2022-09-24 20:46:37 +02:00
|
|
|
import 'package:antd_mobile/antd_mobile.dart';
|
2020-01-14 11:13:07 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2022-09-11 19:54:07 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/S.dart';
|
2022-10-07 18:55:47 +02:00
|
|
|
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
2020-01-14 11:13:07 +01:00
|
|
|
import 'package:git_touch/models/auth.dart';
|
|
|
|
import 'package:git_touch/models/notification.dart';
|
|
|
|
import 'package:git_touch/models/theme.dart';
|
2020-02-02 10:30:48 +01:00
|
|
|
import 'package:git_touch/screens/bb_explore.dart';
|
2020-02-02 10:47:05 +01:00
|
|
|
import 'package:git_touch/screens/bb_teams.dart';
|
2020-02-02 09:40:12 +01:00
|
|
|
import 'package:git_touch/screens/bb_user.dart';
|
2022-09-11 19:54:07 +02:00
|
|
|
import 'package:git_touch/screens/ge_search.dart';
|
2020-10-17 11:35:08 +02:00
|
|
|
import 'package:git_touch/screens/ge_user.dart';
|
2022-09-11 19:54:07 +02:00
|
|
|
import 'package:git_touch/screens/gh_news.dart';
|
|
|
|
import 'package:git_touch/screens/gh_notification.dart';
|
|
|
|
import 'package:git_touch/screens/gh_search.dart';
|
|
|
|
import 'package:git_touch/screens/gh_trending.dart';
|
|
|
|
import 'package:git_touch/screens/gh_user.dart';
|
|
|
|
import 'package:git_touch/screens/gl_explore.dart';
|
|
|
|
import 'package:git_touch/screens/gl_groups.dart';
|
2020-05-09 07:37:36 +02:00
|
|
|
import 'package:git_touch/screens/gl_search.dart';
|
2022-09-11 19:54:07 +02:00
|
|
|
import 'package:git_touch/screens/gl_user.dart';
|
2021-01-23 15:08:05 +01:00
|
|
|
import 'package:git_touch/screens/go_search.dart';
|
|
|
|
import 'package:git_touch/screens/go_user.dart';
|
2020-02-07 15:20:06 +01:00
|
|
|
import 'package:git_touch/screens/gt_orgs.dart';
|
|
|
|
import 'package:git_touch/screens/gt_user.dart';
|
2020-01-14 11:27:43 +01:00
|
|
|
import 'package:git_touch/screens/login.dart';
|
2020-01-14 11:13:07 +01:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2022-09-11 19:54:07 +02:00
|
|
|
import 'package:github/github.dart';
|
2021-06-14 10:00:27 +02:00
|
|
|
import 'package:launch_review/launch_review.dart';
|
2022-06-26 09:08:39 +02:00
|
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
2020-01-14 11:13:07 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2021-06-14 10:00:27 +02:00
|
|
|
import 'package:pub_semver/pub_semver.dart';
|
|
|
|
import 'package:universal_io/io.dart';
|
2020-01-14 11:13:07 +01:00
|
|
|
|
|
|
|
class Home extends StatefulWidget {
|
|
|
|
@override
|
2022-10-03 19:05:29 +02:00
|
|
|
State<Home> createState() => _HomeState();
|
2020-01-14 11:13:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class _HomeState extends State<Home> {
|
2020-04-16 05:29:26 +02:00
|
|
|
// Created 5 different variables instead of a list as list doesn't work
|
|
|
|
final GlobalKey<NavigatorState> tab1 = GlobalKey<NavigatorState>();
|
|
|
|
final GlobalKey<NavigatorState> tab2 = GlobalKey<NavigatorState>();
|
|
|
|
final GlobalKey<NavigatorState> tab3 = GlobalKey<NavigatorState>();
|
|
|
|
final GlobalKey<NavigatorState> tab4 = GlobalKey<NavigatorState>();
|
|
|
|
final GlobalKey<NavigatorState> tab5 = GlobalKey<NavigatorState>();
|
2020-01-14 11:13:07 +01:00
|
|
|
|
2021-06-14 10:00:27 +02:00
|
|
|
@override
|
|
|
|
initState() {
|
|
|
|
super.initState();
|
2022-09-06 18:32:56 +02:00
|
|
|
Future.delayed(const Duration(seconds: 5), () async {
|
2021-06-14 10:00:27 +02:00
|
|
|
final latest = await GitHub()
|
|
|
|
.repositories
|
|
|
|
.getLatestRelease(RepositorySlug.full('git-touch/git-touch'));
|
|
|
|
final current =
|
|
|
|
await PackageInfo.fromPlatform().then((value) => value.version);
|
|
|
|
if (Version.parse(latest.tagName!.substring(1))
|
|
|
|
.compareTo(Version.parse(current)) ==
|
|
|
|
1) {
|
|
|
|
final res = await context.read<ThemeModel>().showConfirm(context,
|
2022-09-06 18:32:56 +02:00
|
|
|
const Text('New version released. Would you like to download it?'));
|
2021-06-14 10:00:27 +02:00
|
|
|
if (res == true) {
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
// go to app store
|
|
|
|
LaunchReview.launch(writeReview: false);
|
|
|
|
} else {
|
2022-09-22 19:50:45 +02:00
|
|
|
context.pushUrl(latest.htmlUrl!);
|
2021-06-14 10:00:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-14 11:13:07 +01:00
|
|
|
_buildScreen(int index) {
|
2021-02-14 06:01:09 +01:00
|
|
|
// print(Localizations.localeOf(context).toString());
|
2020-02-07 15:26:37 +01:00
|
|
|
// return GlProjectScreen(32221);
|
2021-01-17 15:08:32 +01:00
|
|
|
// return GhIssuesScreen('flutter', 'flutter', isPullRequest: true);
|
|
|
|
// return GhIssueScreen('reactjs', 'rfcs', 29);
|
|
|
|
// return GhIssueScreen('reactjs', 'rfcs', 68);
|
2020-01-14 11:13:07 +01:00
|
|
|
// return Image.asset('images/spinner.webp', width: 32, height: 32);
|
2020-10-06 16:26:03 +02:00
|
|
|
// return GhRepoScreen('shreyas1599', 'test');
|
2020-01-14 11:13:07 +01:00
|
|
|
final auth = Provider.of<AuthModel>(context);
|
2021-05-16 09:16:35 +02:00
|
|
|
switch (auth.activeAccount!.platform) {
|
2020-01-14 11:13:07 +01:00
|
|
|
case PlatformType.github:
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
2020-02-07 07:17:05 +01:00
|
|
|
return GhNewsScreen();
|
2020-01-14 11:13:07 +01:00
|
|
|
case 1:
|
2020-02-07 07:17:05 +01:00
|
|
|
return GhNotificationScreen();
|
2020-01-14 11:13:07 +01:00
|
|
|
case 2:
|
2020-02-07 07:17:05 +01:00
|
|
|
return GhTrendingScreen();
|
2020-01-14 11:13:07 +01:00
|
|
|
case 3:
|
2020-02-07 07:17:05 +01:00
|
|
|
return GhSearchScreen();
|
2020-01-14 11:13:07 +01:00
|
|
|
case 4:
|
2022-09-24 07:22:07 +02:00
|
|
|
return const GhViewerScreen();
|
2020-01-14 11:13:07 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PlatformType.gitlab:
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
2020-02-07 15:26:37 +01:00
|
|
|
return GlExploreScreen();
|
2020-01-14 11:13:07 +01:00
|
|
|
case 1:
|
2020-02-07 15:26:37 +01:00
|
|
|
return GlGroupsScreenn();
|
2020-02-01 03:32:29 +01:00
|
|
|
case 2:
|
2020-05-09 07:37:36 +02:00
|
|
|
return GlSearchScreen();
|
|
|
|
case 3:
|
2022-09-06 18:32:56 +02:00
|
|
|
return const GlUserScreen(null);
|
2020-01-14 11:13:07 +01:00
|
|
|
}
|
|
|
|
break;
|
2020-02-02 09:40:12 +01:00
|
|
|
case PlatformType.bitbucket:
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
2020-02-02 10:47:05 +01:00
|
|
|
return BbExploreScreen();
|
2020-02-02 09:40:12 +01:00
|
|
|
case 1:
|
2020-02-02 10:47:05 +01:00
|
|
|
return BbTeamsScreen();
|
|
|
|
case 2:
|
2022-09-06 18:32:56 +02:00
|
|
|
return const BbUserScreen(null);
|
2020-02-02 09:40:12 +01:00
|
|
|
}
|
|
|
|
break;
|
2020-01-29 10:33:54 +01:00
|
|
|
case PlatformType.gitea:
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
2022-09-06 18:32:56 +02:00
|
|
|
return const GtOrgsScreen();
|
2020-01-29 10:33:54 +01:00
|
|
|
case 1:
|
2021-05-16 09:16:35 +02:00
|
|
|
return GtUserScreen(auth.activeAccount!.login, isViewer: true);
|
2020-01-29 10:33:54 +01:00
|
|
|
}
|
|
|
|
break;
|
2020-10-17 11:35:08 +02:00
|
|
|
case PlatformType.gitee:
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
2020-11-01 17:32:47 +01:00
|
|
|
return GeSearchScreen();
|
2020-10-17 11:35:08 +02:00
|
|
|
case 1:
|
2021-05-16 09:16:35 +02:00
|
|
|
return GeUserScreen(auth.activeAccount!.login, isViewer: true);
|
2020-10-17 11:35:08 +02:00
|
|
|
}
|
|
|
|
break;
|
2021-01-23 15:08:05 +01:00
|
|
|
case PlatformType.gogs:
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
return GoSearchScreen();
|
|
|
|
case 1:
|
2021-05-16 09:16:35 +02:00
|
|
|
return GoUserScreen(auth.activeAccount!.login, isViewer: true);
|
2021-01-23 15:08:05 +01:00
|
|
|
}
|
2020-01-14 11:13:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-01 16:30:19 +01:00
|
|
|
Widget _buildNotificationIcon(BuildContext context, IconData iconData) {
|
2022-09-24 07:41:46 +02:00
|
|
|
final count = Provider.of<NotificationModel>(context).count;
|
2020-01-14 11:13:07 +01:00
|
|
|
if (count == 0) {
|
|
|
|
return Icon(iconData);
|
|
|
|
}
|
|
|
|
|
|
|
|
// String text = count > 99 ? '99+' : count.toString();
|
|
|
|
return Stack(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(iconData),
|
|
|
|
Positioned(
|
2022-09-17 16:35:45 +02:00
|
|
|
right: -2,
|
|
|
|
top: -2,
|
2022-09-24 20:46:37 +02:00
|
|
|
child: Icon(Octicons.dot_fill,
|
|
|
|
color: AntTheme.of(context).colorPrimary, size: 14),
|
2022-09-17 16:35:45 +02:00
|
|
|
)
|
2020-01-14 11:13:07 +01:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-16 05:29:26 +02:00
|
|
|
GlobalKey<NavigatorState> getNavigatorKey(int index) {
|
2020-04-16 05:36:48 +02:00
|
|
|
switch (index) {
|
2020-04-16 05:29:26 +02:00
|
|
|
case 0:
|
|
|
|
return tab1;
|
|
|
|
case 1:
|
|
|
|
return tab2;
|
2020-04-16 05:36:48 +02:00
|
|
|
case 2:
|
2020-04-16 05:29:26 +02:00
|
|
|
return tab3;
|
2020-04-16 05:36:48 +02:00
|
|
|
case 3:
|
2020-04-16 05:29:26 +02:00
|
|
|
return tab4;
|
2020-04-16 05:36:48 +02:00
|
|
|
case 4:
|
2020-04-16 05:29:26 +02:00
|
|
|
return tab5;
|
|
|
|
}
|
|
|
|
return tab1;
|
|
|
|
}
|
|
|
|
|
2021-02-01 16:30:19 +01:00
|
|
|
List<BottomNavigationBarItem> _buildNavigationItems(String platform) {
|
|
|
|
final search = BottomNavigationBarItem(
|
2022-09-06 18:32:56 +02:00
|
|
|
icon: const Icon(Ionicons.search_outline),
|
|
|
|
activeIcon: const Icon(Ionicons.search),
|
2021-05-16 09:16:35 +02:00
|
|
|
label: AppLocalizations.of(context)!.search,
|
2021-02-01 16:30:19 +01:00
|
|
|
);
|
|
|
|
final group = BottomNavigationBarItem(
|
2022-09-06 18:32:56 +02:00
|
|
|
icon: const Icon(Ionicons.people_outline),
|
|
|
|
activeIcon: const Icon(Ionicons.people),
|
2021-05-16 09:16:35 +02:00
|
|
|
label: AppLocalizations.of(context)!.organizations,
|
2021-02-01 16:30:19 +01:00
|
|
|
);
|
|
|
|
final me = BottomNavigationBarItem(
|
2022-09-06 18:32:56 +02:00
|
|
|
icon: const Icon(Ionicons.person_outline),
|
|
|
|
activeIcon: const Icon(Ionicons.person),
|
2021-05-16 09:16:35 +02:00
|
|
|
label: AppLocalizations.of(context)!.me,
|
2021-02-01 16:30:19 +01:00
|
|
|
);
|
|
|
|
final explore = BottomNavigationBarItem(
|
2022-09-06 18:32:56 +02:00
|
|
|
icon: const Icon(Ionicons.compass_outline),
|
|
|
|
activeIcon: const Icon(Ionicons.compass),
|
2021-05-16 09:16:35 +02:00
|
|
|
label: AppLocalizations.of(context)!.explore,
|
2021-02-01 16:30:19 +01:00
|
|
|
);
|
2020-10-06 15:33:10 +02:00
|
|
|
|
2021-02-01 16:30:19 +01:00
|
|
|
switch (platform) {
|
2020-10-06 15:33:10 +02:00
|
|
|
case PlatformType.github:
|
2021-02-01 16:30:19 +01:00
|
|
|
return [
|
|
|
|
BottomNavigationBarItem(
|
2022-09-06 18:32:56 +02:00
|
|
|
icon: const Icon(Ionicons.newspaper_outline),
|
|
|
|
activeIcon: const Icon(Ionicons.newspaper),
|
2021-05-16 09:16:35 +02:00
|
|
|
label: AppLocalizations.of(context)!.news,
|
2021-02-01 16:30:19 +01:00
|
|
|
),
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon:
|
|
|
|
_buildNotificationIcon(context, Ionicons.notifications_outline),
|
|
|
|
activeIcon: _buildNotificationIcon(context, Ionicons.notifications),
|
2021-05-16 09:16:35 +02:00
|
|
|
label: AppLocalizations.of(context)!.notification,
|
2021-02-01 16:30:19 +01:00
|
|
|
),
|
|
|
|
BottomNavigationBarItem(
|
2022-09-06 18:32:56 +02:00
|
|
|
icon: const Icon(Ionicons.flame_outline),
|
|
|
|
activeIcon: const Icon(Ionicons.flame),
|
2021-05-16 09:16:35 +02:00
|
|
|
label: AppLocalizations.of(context)!.trending,
|
2021-02-01 16:30:19 +01:00
|
|
|
),
|
|
|
|
search,
|
|
|
|
me,
|
2020-10-06 15:33:10 +02:00
|
|
|
];
|
|
|
|
case PlatformType.gitlab:
|
2021-02-01 16:30:19 +01:00
|
|
|
return [explore, group, search, me];
|
2020-10-06 15:33:10 +02:00
|
|
|
case PlatformType.bitbucket:
|
2021-02-01 16:30:19 +01:00
|
|
|
return [explore, group, me];
|
2020-10-06 15:33:10 +02:00
|
|
|
case PlatformType.gitea:
|
2021-02-01 16:30:19 +01:00
|
|
|
return [group, me];
|
2020-10-17 11:35:08 +02:00
|
|
|
case PlatformType.gitee:
|
2021-01-23 15:08:05 +01:00
|
|
|
case PlatformType.gogs:
|
2021-02-01 16:30:19 +01:00
|
|
|
return [search, me];
|
|
|
|
default:
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final auth = Provider.of<AuthModel>(context);
|
|
|
|
|
|
|
|
if (auth.activeAccount == null) {
|
|
|
|
return LoginScreen();
|
2020-10-06 15:33:10 +02:00
|
|
|
}
|
|
|
|
|
2021-05-16 09:16:35 +02:00
|
|
|
final navigationItems = _buildNavigationItems(auth.activeAccount!.platform);
|
2021-02-01 16:30:19 +01:00
|
|
|
|
2022-09-17 14:35:45 +02:00
|
|
|
return WillPopScope(
|
|
|
|
onWillPop: () async {
|
|
|
|
return !(await getNavigatorKey(auth.activeTab)
|
|
|
|
.currentState
|
|
|
|
?.maybePop())!;
|
|
|
|
},
|
|
|
|
child: CupertinoTabScaffold(
|
|
|
|
tabBuilder: (context, index) {
|
|
|
|
return CupertinoTabView(
|
|
|
|
navigatorKey: getNavigatorKey(index),
|
|
|
|
builder: (context) {
|
|
|
|
return _buildScreen(index);
|
2020-05-01 12:05:49 +02:00
|
|
|
},
|
2022-09-17 14:35:45 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
tabBar: CupertinoTabBar(
|
|
|
|
items: navigationItems,
|
|
|
|
currentIndex: auth.activeTab,
|
|
|
|
onTap: (index) {
|
|
|
|
if (auth.activeTab == index) {
|
|
|
|
getNavigatorKey(index)
|
|
|
|
.currentState
|
|
|
|
?.popUntil((route) => route.isFirst);
|
|
|
|
} else {
|
2020-05-01 12:05:49 +02:00
|
|
|
auth.setActiveTab(index);
|
2022-09-17 14:35:45 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2020-01-14 11:13:07 +01:00
|
|
|
}
|
|
|
|
}
|