2022-09-20 20:00:03 +02:00
|
|
|
import 'package:antd_mobile/antd_mobile.dart';
|
2019-09-04 16:59:33 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:flutter/widgets.dart';
|
2022-09-13 17:52:35 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/S.dart';
|
2020-01-27 07:43:10 +01:00
|
|
|
import 'package:git_touch/models/auth.dart';
|
|
|
|
import 'package:git_touch/models/code.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-09-25 11:06:36 +02:00
|
|
|
import 'package:git_touch/scaffolds/single.dart';
|
2021-02-27 10:41:57 +01:00
|
|
|
import 'package:git_touch/utils/locale.dart';
|
2019-09-04 16:59:33 +02:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2020-01-24 16:11:43 +01:00
|
|
|
import 'package:git_touch/widgets/action_button.dart';
|
2019-09-11 13:59:47 +02:00
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
2022-09-20 20:00:03 +02:00
|
|
|
import 'package:go_router/go_router.dart';
|
2020-01-27 07:43:10 +01: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';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2020-01-13 14:07:28 +01:00
|
|
|
import 'package:tuple/tuple.dart';
|
2019-12-13 06:13:45 +01:00
|
|
|
|
2020-10-06 08:31:07 +02:00
|
|
|
class SettingsScreen extends StatelessWidget {
|
2019-02-08 12:34:07 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-01-13 14:07:28 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
2020-01-27 07:43:10 +01:00
|
|
|
final auth = Provider.of<AuthModel>(context);
|
|
|
|
final code = Provider.of<CodeModel>(context);
|
2019-09-25 11:06:36 +02:00
|
|
|
return SingleScaffold(
|
2021-05-16 09:16:35 +02:00
|
|
|
title: AppBarTitle(AppLocalizations.of(context)!.settings),
|
2019-09-25 11:06:36 +02:00
|
|
|
body: Column(
|
2019-09-25 08:24:20 +02:00
|
|
|
children: <Widget>[
|
2019-10-02 10:09:54 +02:00
|
|
|
CommonStyle.verticalGap,
|
2022-09-22 17:37:06 +02:00
|
|
|
AntList(
|
2022-09-25 19:32:51 +02:00
|
|
|
mode: AntListMode.card,
|
|
|
|
header: Text(AppLocalizations.of(context)!.system),
|
|
|
|
children: [
|
|
|
|
if (auth.activeAccount!.platform == PlatformType.github) ...[
|
2022-09-22 17:37:06 +02:00
|
|
|
AntListItem(
|
2022-09-25 19:32:51 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.githubStatus),
|
2022-09-22 17:37:06 +02:00
|
|
|
onClick: () {
|
2022-09-25 19:32:51 +02:00
|
|
|
launchStringUrl('https://www.githubstatus.com/');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
AntListItem(
|
|
|
|
child: const Text('Meta'),
|
|
|
|
onClick: () {
|
|
|
|
context.push('/settings/github-meta');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
AntListItem(
|
|
|
|
onClick: () {
|
|
|
|
launchStringUrl(
|
|
|
|
'https://github.com/settings/connections/applications/$clientId');
|
2022-09-13 19:19:52 +02:00
|
|
|
},
|
2022-09-22 17:37:06 +02:00
|
|
|
extra: Text(auth.activeAccount!.login),
|
2022-09-25 19:32:51 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.reviewPermissions),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
if (auth.activeAccount!.platform == PlatformType.gitlab)
|
|
|
|
AntListItem(
|
|
|
|
onClick: () {
|
|
|
|
launchStringUrl('${auth.activeAccount!.domain}/help');
|
|
|
|
},
|
|
|
|
extra: FutureBuilder<String>(
|
|
|
|
future:
|
|
|
|
auth.fetchGitlab('/version').then((v) => v['version']),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return Text(snapshot.data ?? '');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
child: Text(AppLocalizations.of(context)!.gitlabStatus),
|
2021-06-14 05:28:12 +02:00
|
|
|
),
|
2022-09-25 19:32:51 +02:00
|
|
|
if (auth.activeAccount!.platform == PlatformType.gitea)
|
2022-09-22 17:37:06 +02:00
|
|
|
AntListItem(
|
2022-09-25 19:32:51 +02:00
|
|
|
prefix: const Icon(Octicons.info),
|
2022-09-22 17:37:06 +02:00
|
|
|
onClick: () {
|
2022-09-25 19:32:51 +02:00
|
|
|
context.push('/gitea/status');
|
2021-06-17 05:02:41 +02:00
|
|
|
},
|
2022-09-25 19:32:51 +02:00
|
|
|
extra: FutureBuilder<String>(
|
|
|
|
future:
|
|
|
|
auth.fetchGitea('/version').then((v) => v['version']),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return Text(snapshot.data ?? '');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
child: Text(AppLocalizations.of(context)!.giteaStatus),
|
|
|
|
),
|
|
|
|
AntListItem(
|
|
|
|
onClick: () {
|
|
|
|
context.push('/login');
|
|
|
|
},
|
|
|
|
extra: Text(auth.activeAccount!.login),
|
|
|
|
child: Text(AppLocalizations.of(context)!.switchAccounts),
|
|
|
|
),
|
|
|
|
AntListItem(
|
|
|
|
extra: Text(theme.locale == null
|
|
|
|
? AppLocalizations.of(context)!.followSystem
|
|
|
|
: localeNameMap[theme.locale!] ?? theme.locale!),
|
|
|
|
onClick: () {
|
|
|
|
// TODO: too many options, better use a new page
|
|
|
|
theme.showActions(context, [
|
|
|
|
for (final key in [
|
|
|
|
null,
|
|
|
|
...AppLocalizations.supportedLocales
|
|
|
|
.map((l) => l.toString())
|
|
|
|
.where((key) => localeNameMap[key] != null)
|
|
|
|
])
|
|
|
|
ActionItem(
|
|
|
|
text: key == null
|
|
|
|
? AppLocalizations.of(context)!.followSystem
|
|
|
|
: localeNameMap[key],
|
|
|
|
onTap: (_) async {
|
|
|
|
final res = await theme.showConfirm(
|
|
|
|
context,
|
|
|
|
const Text(
|
|
|
|
'The app will reload to make the language setting take effect'),
|
|
|
|
);
|
|
|
|
if (res == true && theme.locale != key) {
|
|
|
|
await theme.setLocale(key);
|
|
|
|
auth.reloadApp();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
child: Text(AppLocalizations.of(context)!.appLanguage),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2019-10-02 10:09:54 +02:00
|
|
|
CommonStyle.verticalGap,
|
2022-09-20 20:00:03 +02:00
|
|
|
AntList(
|
2022-09-25 19:32:51 +02:00
|
|
|
mode: AntListMode.card,
|
2022-09-13 19:19:52 +02:00
|
|
|
header: Text(AppLocalizations.of(context)!.theme),
|
2022-09-22 17:37:06 +02:00
|
|
|
children: [
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
2022-09-13 19:19:52 +02:00
|
|
|
extra: Text(theme.brighnessValue == AppBrightnessType.light
|
|
|
|
? AppLocalizations.of(context)!.light
|
|
|
|
: theme.brighnessValue == AppBrightnessType.dark
|
|
|
|
? AppLocalizations.of(context)!.dark
|
|
|
|
: AppLocalizations.of(context)!.followSystem),
|
|
|
|
onClick: () {
|
2021-06-18 20:06:09 +02:00
|
|
|
theme.showActions(context, [
|
|
|
|
for (var t in [
|
|
|
|
Tuple2(AppLocalizations.of(context)!.followSystem,
|
|
|
|
AppBrightnessType.followSystem),
|
|
|
|
Tuple2(AppLocalizations.of(context)!.light,
|
|
|
|
AppBrightnessType.light),
|
|
|
|
Tuple2(AppLocalizations.of(context)!.dark,
|
|
|
|
AppBrightnessType.dark),
|
|
|
|
])
|
|
|
|
ActionItem(
|
|
|
|
text: t.item1,
|
|
|
|
onTap: (_) {
|
2022-09-06 18:28:12 +02:00
|
|
|
if (theme.brighnessValue != t.item2) {
|
2021-06-18 20:06:09 +02:00
|
|
|
theme.setBrightness(t.item2);
|
2022-09-06 18:28:12 +02:00
|
|
|
}
|
2021-06-18 20:06:09 +02:00
|
|
|
},
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
},
|
2022-09-22 17:37:06 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.brightness),
|
2021-06-18 20:06:09 +02:00
|
|
|
),
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
|
|
|
onClick: () {
|
|
|
|
context.push('/choose-code-theme');
|
|
|
|
},
|
2022-09-13 19:19:52 +02:00
|
|
|
extra: Text('${code.fontFamily}, ${code.fontSize}pt'),
|
2022-09-22 17:37:06 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.codeTheme),
|
2021-06-18 20:06:09 +02:00
|
|
|
),
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
2022-09-13 19:19:52 +02:00
|
|
|
extra: Text(theme.markdown == AppMarkdownType.flutter
|
2021-06-18 20:06:09 +02:00
|
|
|
? AppLocalizations.of(context)!.flutter
|
|
|
|
: AppLocalizations.of(context)!.webview),
|
2022-09-13 19:19:52 +02:00
|
|
|
onClick: () {
|
2021-06-18 20:06:09 +02:00
|
|
|
theme.showActions(context, [
|
|
|
|
for (var t in [
|
|
|
|
Tuple2(AppLocalizations.of(context)!.flutter,
|
|
|
|
AppMarkdownType.flutter),
|
|
|
|
Tuple2(AppLocalizations.of(context)!.webview,
|
|
|
|
AppMarkdownType.webview),
|
|
|
|
])
|
|
|
|
ActionItem(
|
|
|
|
text: t.item1,
|
|
|
|
onTap: (_) {
|
|
|
|
if (theme.markdown != t.item2) {
|
|
|
|
theme.setMarkdown(t.item2);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
},
|
2022-09-22 17:37:06 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.markdownRenderEngine),
|
2021-06-18 20:06:09 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-01-27 07:43:10 +01:00
|
|
|
CommonStyle.verticalGap,
|
2022-09-20 20:00:03 +02:00
|
|
|
AntList(
|
2022-09-25 19:32:51 +02:00
|
|
|
mode: AntListMode.card,
|
2022-09-13 19:19:52 +02:00
|
|
|
header: Text(AppLocalizations.of(context)!.feedback),
|
2022-09-22 17:37:06 +02:00
|
|
|
children: [
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
2022-09-13 19:19:52 +02:00
|
|
|
extra: const Text('git-touch/git-touch'),
|
2022-09-20 20:00:03 +02:00
|
|
|
onClick: () {
|
|
|
|
const suffix = 'git-touch/git-touch/issues/new';
|
|
|
|
if (auth.activeAccount!.platform == PlatformType.github) {
|
|
|
|
context.push('/github/$suffix');
|
|
|
|
} else {
|
|
|
|
launchStringUrl('https://github.com/$suffix');
|
|
|
|
}
|
|
|
|
},
|
2022-09-22 17:37:06 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.submitAnIssue),
|
2021-06-18 20:06:09 +02:00
|
|
|
),
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
2022-09-13 19:19:52 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.rateThisApp),
|
|
|
|
onClick: () {
|
2021-06-18 20:06:09 +02:00
|
|
|
LaunchReview.launch(
|
|
|
|
androidAppId: 'io.github.pd4d10.gittouch',
|
|
|
|
iOSAppId: '1452042346',
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
2022-09-13 19:19:52 +02:00
|
|
|
extra: const Text('pd4d10@gmail.com'),
|
2022-09-20 20:00:03 +02:00
|
|
|
arrow: null,
|
|
|
|
onClick: () {
|
|
|
|
launchStringUrl('mailto:pd4d10@gmail.com');
|
|
|
|
},
|
2022-09-22 17:37:06 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.email),
|
2021-06-18 20:06:09 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-01-27 07:43:10 +01:00
|
|
|
CommonStyle.verticalGap,
|
2022-09-20 20:00:03 +02:00
|
|
|
AntList(
|
2022-09-25 19:32:51 +02:00
|
|
|
mode: AntListMode.card,
|
2022-09-13 19:19:52 +02:00
|
|
|
header: Text(AppLocalizations.of(context)!.about),
|
2022-09-22 17:37:06 +02:00
|
|
|
children: [
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
|
|
|
extra: FutureBuilder<String>(
|
|
|
|
future:
|
|
|
|
PackageInfo.fromPlatform().then((info) => info.version),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return Text(snapshot.data ?? '');
|
|
|
|
},
|
|
|
|
),
|
2022-09-22 17:37:06 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.version),
|
2022-09-20 20:00:03 +02:00
|
|
|
),
|
|
|
|
AntListItem(
|
2022-09-13 19:19:52 +02:00
|
|
|
extra: const Text('git-touch/git-touch'),
|
2022-09-20 20:00:03 +02:00
|
|
|
onClick: () {
|
|
|
|
const suffix = 'git-touch/git-touch';
|
|
|
|
if (auth.activeAccount!.platform == PlatformType.github) {
|
|
|
|
context.push('/github/$suffix');
|
|
|
|
} else {
|
|
|
|
launchStringUrl('https://github.com/$suffix');
|
|
|
|
}
|
|
|
|
},
|
2022-09-22 17:37:06 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.sourceCode),
|
2021-06-18 20:06:09 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2019-09-25 08:24:20 +02:00
|
|
|
],
|
|
|
|
),
|
2019-02-08 12:34:07 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|