app/lib/ui/home/localization/localization_dialog_ui.dart

458 lines
16 KiB
Dart
Raw Normal View History

import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
2024-05-03 14:39:46 +08:00
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:flutter_tilt/flutter_tilt.dart';
2024-05-03 22:35:31 +08:00
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:starcitizen_doctor/data/sc_localization_data.dart';
import 'package:starcitizen_doctor/widgets/widgets.dart';
2024-05-05 20:58:58 +08:00
import 'localization_form_file_dialog_ui.dart';
import 'localization_ui_model.dart';
class LocalizationDialogUI extends HookConsumerWidget {
const LocalizationDialogUI({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final state = ref.watch(localizationUIModelProvider);
final model = ref.read(localizationUIModelProvider.notifier);
2024-05-03 14:39:46 +08:00
// final curInstallInfo = state.apiLocalizationData?[state.patchStatus?.value];
useEffect(() {
addPostFrameCallback(() {
2024-09-04 20:50:23 +08:00
// model.checkUserCfg(context);
});
return null;
}, []);
return ContentDialog(
title: makeTitle(context, model, state),
2024-09-04 20:50:23 +08:00
constraints: const BoxConstraints(maxWidth: 1080, minHeight: 920),
content: Padding(
padding: const EdgeInsets.only(left: 12, right: 12, top: 12),
child: SingleChildScrollView(
child: Column(
children: [
makeListContainer(
2024-03-15 00:01:06 +08:00
S.current.localization_info_community_translation,
[
if (state.apiLocalizationData == null)
makeLoading(context)
else if (state.apiLocalizationData!.isEmpty)
Center(
child: Text(
2024-03-15 00:01:06 +08:00
S.current.localization_info_no_translation_available,
style: TextStyle(
fontSize: 13,
color: Colors.white.withOpacity(.8)),
),
)
else
for (final item in state.apiLocalizationData!.entries)
makeRemoteList(context, model, item, state),
],
2024-05-03 14:39:46 +08:00
context,
gridViewMode: true),
2024-05-03 22:35:31 +08:00
makeToolsListContainer(context, model, state),
],
),
),
),
);
}
Widget makeRemoteList(BuildContext context, LocalizationUIModel model,
MapEntry<String, ScLocalizationData> item, LocalizationUIState state) {
final isWorking = state.workingVersion.isNotEmpty;
final isMineWorking = state.workingVersion == item.key;
final isInstalled = state.patchStatus?.value == item.key;
2024-05-03 14:39:46 +08:00
final isItemEnabled = ((item.value.enable ?? false));
final tapDisabled =
isInstalled || isWorking || !isItemEnabled || isMineWorking;
return Tilt(
shadowConfig: const ShadowConfig(maxIntensity: .3),
borderRadius: BorderRadius.circular(7),
disable: tapDisabled,
child: GestureDetector(
onTap:
tapDisabled ? null : () => doInsTall(context, model, item, state),
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white.withOpacity(tapDisabled ? .03 : .05),
borderRadius: BorderRadius.circular(7),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2024-05-03 14:39:46 +08:00
Row(
children: [
2024-05-03 14:39:46 +08:00
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"${item.value.info}",
style: const TextStyle(fontSize: 19),
),
const SizedBox(height: 4),
Text(
S.current.localization_info_version_number(
item.value.versionName ?? ""),
style: TextStyle(color: Colors.white.withOpacity(.6)),
),
const SizedBox(height: 4),
Text(
S.current.localization_info_channel(
item.value.gameChannel ?? ""),
style: TextStyle(color: Colors.white.withOpacity(.6)),
),
const SizedBox(height: 4),
Text(
S.current.localization_info_update_time(
item.value.updateAt ?? ""),
style: TextStyle(color: Colors.white.withOpacity(.6)),
),
],
),
),
2024-05-03 14:39:46 +08:00
if (isMineWorking)
const Padding(
padding: EdgeInsets.only(right: 12),
child: ProgressRing(),
)
else ...[
Icon(
isInstalled
? FluentIcons.check_mark
: isItemEnabled
? FluentIcons.download
: FluentIcons.disable_updates,
color: Colors.white.withOpacity(.8),
size: 18,
),
const SizedBox(width: 6),
Text(
isInstalled
? S.current.localization_info_installed
: (isItemEnabled
? S.current.localization_action_install
: S.current.localization_info_unavailable),
style: TextStyle(
color: Colors.white.withOpacity(.8),
),
),
const SizedBox(width: 6),
if ((!isInstalled) && isItemEnabled)
Icon(
FluentIcons.chevron_right,
size: 14,
color: Colors.white.withOpacity(.6),
)
]
],
),
2024-05-03 14:39:46 +08:00
if (item.value.note != null) ...[
const SizedBox(height: 6),
Text(
"${item.value.note}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white.withOpacity(.4),
fontSize: 13,
),
),
],
],
),
2024-05-03 14:39:46 +08:00
),
),
);
}
Widget makeListContainer(
String title, List<Widget> children, BuildContext context,
2024-05-03 14:39:46 +08:00
{List<Widget> actions = const [],
bool gridViewMode = false,
int gridViewCrossAxisCount = 2}) {
return Padding(
padding: const EdgeInsets.only(bottom: 12),
child: AnimatedSize(
duration: const Duration(milliseconds: 130),
child: Container(
decoration: BoxDecoration(
color: FluentTheme.of(context).cardColor,
borderRadius: BorderRadius.circular(7)),
child: Padding(
padding:
const EdgeInsets.only(top: 12, bottom: 12, left: 24, right: 24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
title,
style: const TextStyle(fontSize: 22),
),
const Spacer(),
if (actions.isNotEmpty) ...actions,
],
),
const SizedBox(
height: 6,
),
Container(
color: Colors.white.withOpacity(.1),
height: 1,
),
const SizedBox(height: 12),
2024-05-03 14:39:46 +08:00
if (gridViewMode)
AlignedGridView.count(
crossAxisCount: gridViewCrossAxisCount,
crossAxisSpacing: 12,
mainAxisSpacing: 12,
itemBuilder: (BuildContext context, int index) {
return children[index];
},
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: children.length,
)
else
...children
],
),
),
),
),
);
}
Widget makeTitle(BuildContext context, LocalizationUIModel model,
LocalizationUIState state) {
return Row(
children: [
IconButton(
icon: const Icon(
FluentIcons.back,
size: 22,
),
onPressed: model.onBack(context)),
const SizedBox(width: 12),
2024-03-15 00:01:06 +08:00
Text(S.current.home_action_localization_management),
const SizedBox(width: 24),
2024-09-04 20:50:23 +08:00
// Text(
// "${model.getScInstallPath()}",
// style: const TextStyle(fontSize: 13),
// ),
const Spacer(),
SizedBox(
height: 36,
child: Row(
children: [
2024-09-04 20:50:23 +08:00
Text(
S.current.localization_info_channel(""),
style: const TextStyle(fontSize: 16),
),
const SizedBox(width: 12),
ComboBox<String>(
value: state.selectedChannel,
items: [
for (final channel in ["LIVE", "PTU"])
ComboBoxItem(
value: channel,
child: Text(channel),
)
],
onChanged: state.workingVersion.isNotEmpty
? null
: (v) {
if (v == null) return;
model.selectChannel(v);
},
),
const SizedBox(width: 24),
2024-03-15 00:01:06 +08:00
Text(
S.current.localization_info_language,
style: const TextStyle(fontSize: 16),
),
2024-03-17 16:54:09 +08:00
const SizedBox(width: 12),
ComboBox<String>(
value: state.selectedLanguage,
items: [
for (final lang
in LocalizationUIModel.languageSupport.entries)
ComboBoxItem(
value: lang.key,
child: Text(lang.value),
)
],
onChanged: state.workingVersion.isNotEmpty
? null
: (v) {
if (v == null) return;
model.selectLang(v);
},
)
],
),
),
const SizedBox(width: 12),
Button(
onPressed: model.doRefresh(),
child: const Padding(
padding: EdgeInsets.all(6),
child: Icon(FluentIcons.refresh),
)),
],
);
}
2024-05-03 14:39:46 +08:00
doInsTall(
BuildContext context,
LocalizationUIModel model,
MapEntry<String, ScLocalizationData> item,
LocalizationUIState state) async {
final userOK = await showConfirmDialogs(
context,
"${item.value.info}",
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
S.current.localization_info_version_number(
item.value.versionName ?? ""),
style: TextStyle(color: Colors.white.withOpacity(.6)),
),
const SizedBox(height: 4),
Text(
S.current
.localization_info_channel(item.value.gameChannel ?? ""),
style: TextStyle(color: Colors.white.withOpacity(.6)),
),
const SizedBox(height: 4),
Text(
S.current
.localization_info_update_time(item.value.updateAt ?? ""),
style: TextStyle(color: Colors.white.withOpacity(.6)),
),
],
),
const SizedBox(height: 12),
Container(
decoration: BoxDecoration(
color: FluentTheme.of(context).cardColor,
borderRadius: BorderRadius.circular(7)),
padding: const EdgeInsets.all(12),
child: Row(
children: [
Expanded(
child: Text(
2024-05-05 16:34:38 +08:00
item.value.note ?? S.current.home_localization_msg_no_note,
2024-05-03 14:39:46 +08:00
style: const TextStyle(fontSize: 15),
),
),
],
),
),
],
),
confirm: S.current.localization_action_install,
cancel: S.current.home_action_cancel,
2024-09-04 20:50:23 +08:00
constraints: const BoxConstraints(maxWidth: 720),
2024-05-03 14:39:46 +08:00
);
if (userOK) {
if (!context.mounted) return;
model.doRemoteInstall(context, item.value)?.call();
}
}
2024-05-03 22:35:31 +08:00
Widget makeToolsListContainer(BuildContext context, LocalizationUIModel model,
LocalizationUIState state) {
2024-05-03 14:39:46 +08:00
final toolsMenu = {
"launcher_mod": (
const Icon(FluentIcons.c_plus_plus, size: 24),
2024-05-05 16:34:38 +08:00
(S.current.home_localization_action_rsi_launcher_localization),
2024-05-03 14:39:46 +08:00
),
"advanced": (
const Icon(FluentIcons.queue_advanced, size: 24),
2024-05-05 16:34:38 +08:00
(S.current.home_localization_action_advanced),
2024-05-03 14:39:46 +08:00
),
"custom_files": (
const Icon(FluentIcons.custom_activity, size: 24),
2024-05-05 16:34:38 +08:00
(S.current.home_localization_action_install_customize),
2024-05-03 14:39:46 +08:00
),
};
2024-05-03 22:35:31 +08:00
final enableTap = state.workingVersion.isEmpty;
2024-05-03 14:39:46 +08:00
return makeListContainer(
2024-05-05 16:34:38 +08:00
S.current.home_localization_title_localization_tools,
2024-05-03 14:39:46 +08:00
[
for (final item in toolsMenu.entries)
Tilt(
2024-05-03 22:35:31 +08:00
disable: !enableTap,
2024-05-03 14:39:46 +08:00
shadowConfig: const ShadowConfig(maxIntensity: .3),
borderRadius: BorderRadius.circular(7),
child: GestureDetector(
2024-05-03 22:35:31 +08:00
onTap: enableTap
? () async {
switch (item.key) {
case "launcher_mod":
2024-09-04 17:18:13 +08:00
// ToolsUIModel.rsiEnhance(context);
2024-05-03 22:35:31 +08:00
break;
case "advanced":
context.push("/index/advanced_localization");
break;
2024-05-05 20:58:58 +08:00
case "custom_files":
final sb = await showDialog(
context: context,
builder: (BuildContext context) =>
const LocalizationFromFileDialogUI(),
);
if (sb is StringBuffer) {
await model.installFormString(
sb, S.current.localization_info_custom_files);
}
break;
2024-05-03 22:35:31 +08:00
}
}
: null,
2024-05-03 14:39:46 +08:00
child: Container(
decoration: BoxDecoration(
color: FluentTheme.of(context).cardColor,
borderRadius: BorderRadius.circular(7),
),
padding: const EdgeInsets.all(12),
child: Row(
children: [
item.value.$1,
const SizedBox(width: 12),
Text(item.value.$2),
const SizedBox(width: 12),
const Spacer(),
Icon(
FluentIcons.chevron_right,
size: 14,
color: Colors.white.withOpacity(.6),
)
],
),
),
),
),
],
context,
gridViewMode: true,
2024-05-05 16:34:38 +08:00
gridViewCrossAxisCount: 3);
2024-05-03 14:39:46 +08:00
}
}