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

264 lines
9.9 KiB
Dart
Raw Normal View History

2024-05-03 22:35:31 +08:00
import 'package:fluent_ui/fluent_ui.dart';
2024-05-05 14:59:07 +08:00
import 'package:flutter_hooks/flutter_hooks.dart';
2024-05-03 22:35:31 +08:00
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
2024-05-05 14:59:07 +08:00
import 'package:go_router/go_router.dart';
2024-05-03 22:35:31 +08:00
import 'package:hooks_riverpod/hooks_riverpod.dart';
2024-05-05 14:59:07 +08:00
import 'package:re_editor/re_editor.dart';
import 'package:re_highlight/languages/ini.dart';
import 'package:re_highlight/styles/vs2015.dart';
import 'package:starcitizen_doctor/data/app_advanced_localization_data.dart';
2024-05-03 22:35:31 +08:00
import 'package:starcitizen_doctor/ui/home/home_ui_model.dart';
import 'package:starcitizen_doctor/ui/home/localization/advanced_localization_ui_model.dart';
import 'package:starcitizen_doctor/widgets/widgets.dart';
import 'package:super_sliver_list/super_sliver_list.dart';
class AdvancedLocalizationUI extends HookConsumerWidget {
const AdvancedLocalizationUI({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final state = ref.watch(advancedLocalizationUIModelProvider);
2024-05-05 14:59:07 +08:00
final model = ref.read(advancedLocalizationUIModelProvider.notifier);
2024-05-03 22:35:31 +08:00
final homeUIState = ref.watch(homeUIModelProvider);
return makeDefaultPage(
2024-05-05 16:34:38 +08:00
title: S.current.home_localization_advanced_title(
homeUIState.scInstalledPath ?? "-"),
2024-05-03 22:35:31 +08:00
context,
content: state.workingText.isNotEmpty
? Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const ProgressRing(),
const SizedBox(height: 12),
Text(state.workingText),
],
),
)
2024-05-05 14:59:07 +08:00
: Column(
children: [
Row(
children: [
const SizedBox(width: 12),
Expanded(
2024-05-05 16:34:38 +08:00
child: Text(S.current
.home_localization_advanced_msg_version(
state.apiLocalizationData?.versionName ??
"-"))),
Text(S.current.home_localization_advanced_title_msg(
state.serverGlobalIniLines, state.p4kGlobalIniLines)),
2024-05-05 14:59:07 +08:00
const SizedBox(width: 32),
Button(
2024-05-05 16:34:38 +08:00
child: Padding(
padding: const EdgeInsets.only(
2024-05-05 14:59:07 +08:00
left: 12, right: 12, top: 4, bottom: 4),
2024-05-05 16:34:38 +08:00
child: Text(S.current
.home_localization_advanced_action_install),
2024-05-05 14:59:07 +08:00
),
onPressed: () async {
await model.doInstall().unwrap(context: context);
}),
const SizedBox(width: 12),
],
),
Expanded(
child:
_makeBody(context, homeUIState, state, ref, model)),
],
));
2024-05-03 22:35:31 +08:00
}
2024-05-05 14:59:07 +08:00
Widget _makeBody(
BuildContext context,
HomeUIModelState homeUIState,
AdvancedLocalizationUIState state,
WidgetRef ref,
AdvancedLocalizationUIModel model) {
2024-05-03 22:35:31 +08:00
return AlignedGridView.count(
2024-05-05 14:59:07 +08:00
crossAxisCount: 4,
2024-05-03 22:35:31 +08:00
crossAxisSpacing: 12,
mainAxisSpacing: 12,
padding: const EdgeInsets.all(12),
itemBuilder: (BuildContext context, int index) {
final item = state.classMap!.values.elementAt(index);
return Container(
2024-05-05 14:59:07 +08:00
padding: const EdgeInsets.only(top: 6, bottom: 12),
2024-05-03 22:35:31 +08:00
decoration: BoxDecoration(
color: Colors.white.withOpacity(.05),
borderRadius: BorderRadius.circular(4),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2024-05-05 14:59:07 +08:00
IconButton(
onPressed:
item.isWorking ? null : () => _showContent(context, item),
icon: Padding(
padding: const EdgeInsets.only(left: 12, right: 12),
child: Row(
children: [
Expanded(
child: Text(
"${item.className}",
style: const TextStyle(
fontSize: 16, fontWeight: FontWeight.bold),
textAlign: TextAlign.start,
)),
Text(
"${item.valuesMap.length}",
style: TextStyle(
fontSize: 14,
color: Colors.white.withOpacity(.6),
),
),
const SizedBox(width: 6),
Icon(
FluentIcons.chevron_right,
2024-05-03 22:35:31 +08:00
color: Colors.white.withOpacity(.6),
2024-05-05 14:59:07 +08:00
size: 16,
2024-05-03 22:35:31 +08:00
),
2024-05-05 14:59:07 +08:00
],
),
2024-05-03 22:35:31 +08:00
),
),
Container(
margin: const EdgeInsets.only(top: 6, bottom: 12),
width: MediaQuery.of(context).size.width,
height: 1,
color: Colors.white.withOpacity(.1),
),
2024-05-05 14:59:07 +08:00
if (item.isWorking)
Column(
children: [
makeLoading(context),
const SizedBox(height: 6),
2024-05-05 16:34:38 +08:00
Text(
S.current.home_localization_advanced_action_mod_change),
2024-05-05 14:59:07 +08:00
],
)
else ...[
Padding(
2024-05-03 22:35:31 +08:00
padding: const EdgeInsets.only(left: 12, right: 12),
2024-05-05 14:59:07 +08:00
child: Row(
children: [
2024-05-05 16:34:38 +08:00
Expanded(
child: Text(S
.current.home_localization_advanced_action_mode)),
2024-05-05 14:59:07 +08:00
ComboBox(
value: item.mode,
items: [
for (final type
in AppAdvancedLocalizationClassKeysDataMode
.values)
ComboBoxItem(
value: type,
child: Text(state.typeNames[type] ?? "-"),
),
],
onChanged: item.lockMod
? null
: (v) => model.onChangeMod(item,
v as AppAdvancedLocalizationClassKeysDataMode),
2024-05-03 22:35:31 +08:00
),
2024-05-05 14:59:07 +08:00
],
),
2024-05-03 22:35:31 +08:00
),
2024-05-05 14:59:07 +08:00
const SizedBox(height: 6),
SizedBox(
height: 180,
child: SuperListView.builder(
itemCount: item.valuesMap.length,
padding: const EdgeInsets.only(left: 12, right: 12),
itemBuilder: (BuildContext context, int index) {
final itemKey = item.valuesMap.keys.elementAt(index);
return Text(
"${item.valuesMap[itemKey]}",
maxLines: 1,
style: const TextStyle(
fontSize: 12,
overflow: TextOverflow.ellipsis,
),
);
},
),
),
],
2024-05-03 22:35:31 +08:00
],
),
);
},
itemCount: state.classMap?.length ?? 0,
);
}
2024-05-05 14:59:07 +08:00
_showContent(
BuildContext context, AppAdvancedLocalizationClassKeysData item) {
showDialog(
context: context,
builder: (BuildContext context) {
return HookConsumer(
builder: (BuildContext context, WidgetRef ref, Widget? child) {
final textData = useState("");
loadData() async {
final v = StringBuffer("");
for (var element in item.valuesMap.entries) {
v.write("${element.key}=${element.value}\n");
await Future.delayed(Duration.zero);
}
textData.value = v.toString();
}
useEffect(() {
loadData();
return null;
}, const []);
return ContentDialog(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * .8,
),
title: Row(
children: [
IconButton(
icon: const Icon(
FluentIcons.back,
size: 22,
),
onPressed: () => context.pop()),
const SizedBox(
width: 24,
),
2024-05-05 16:34:38 +08:00
Text(S.current.home_localization_advanced_title_preview(
item.className ?? "-")),
2024-05-05 14:59:07 +08:00
],
),
content: textData.value.isEmpty
? makeLoading(context)
: Container(
decoration: BoxDecoration(
color: FluentTheme.of(context).cardColor,
borderRadius: BorderRadius.circular(7),
),
child: CodeEditor(
readOnly: true,
controller:
CodeLineEditingController.fromText(textData.value),
style: CodeEditorStyle(
codeTheme: CodeHighlightTheme(
languages: {
'ini': CodeHighlightThemeMode(mode: langIni)
},
theme: vs2015Theme,
),
),
),
),
);
},
);
},
);
}
2024-05-03 22:35:31 +08:00
}