Skip to content

Commit

Permalink
fix locale update
Browse files Browse the repository at this point in the history
3003h committed Nov 12, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 067fa07 commit 1df7637
Showing 10 changed files with 81 additions and 114 deletions.
6 changes: 2 additions & 4 deletions lib/common/service/locale_service.dart
Original file line number Diff line number Diff line change
@@ -2,18 +2,16 @@ import 'dart:ui';

import 'package:fehviewer/common/global.dart';
import 'package:fehviewer/models/index.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

import 'base_service.dart';

class LocaleService extends ProfileService {
RxString localCode = window.locale.toString().obs;
RxString localCode = PlatformDispatcher.instance.locale.toString().obs;

Locale? get locale {
final String localeSt = localCode.value;
if (localeSt.isEmpty || localeSt == '_' || !localeSt.contains('_')) {
// return window.locale;
return null;
}
final List<String> t = localeSt.split('_');
@@ -22,7 +20,7 @@ class LocaleService extends ProfileService {

bool get isLanguageCodeZh =>
locale?.languageCode.startsWith('zh') ??
window.locale.languageCode.startsWith('zh');
PlatformDispatcher.instance.locale.languageCode.startsWith('zh');

@override
void onInit() {
2 changes: 1 addition & 1 deletion lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
@@ -495,7 +495,7 @@ class MessageLookup extends MessageLookupByLibrary {
"uc_archiver_desc": MessageLookupByLibrary.simpleMessage(
"The default behavior for the Archiver is to confirm the cost and selection for original or resampled archive, then present a link that can be clicked or copied elsewhere. You can change this behavior here."),
"uc_archiver_set":
MessageLookupByLibrary.simpleMessage("rchiver Settings"),
MessageLookupByLibrary.simpleMessage("Archiver Settings"),
"uc_artist": MessageLookupByLibrary.simpleMessage("artist"),
"uc_auto": MessageLookupByLibrary.simpleMessage("Auto"),
"uc_character": MessageLookupByLibrary.simpleMessage("character"),
4 changes: 2 additions & 2 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
@@ -201,7 +201,7 @@
"uc_img_cussize_desc": "While the site will automatically scale down images to fit your screen width, you can also manually restrict the maximum display size of an image. Like the automatic scaling, this does not resample the image, as the resizing is done browser-side. (0 = no limit)",
"uc_name_display": "Gallery Name Display",
"uc_name_display_desc": "Many galleries have both an English/Romanized title and a title in Japanese script. Which gallery name would you like as default?",
"uc_archiver_set": "rchiver Settings",
"uc_archiver_set": "Archiver Settings",
"uc_archiver_desc": "The default behavior for the Archiver is to confirm the cost and selection for original or resampled archive, then present a link that can be clicked or copied elsewhere. You can change this behavior here.",
"uc_front_page": "Front Page",
"uc_front_page_dis_mode": "Front Page Display mode",
25 changes: 11 additions & 14 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -231,20 +231,17 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
// localeResolutionCallback: (_, Iterable<Locale> supportedLocales) {
// final Locale _locale = window.locale;
// logger.t(
// 'system Locale \n${_locale.languageCode} ${_locale.scriptCode} ${_locale.countryCode}');
// // logger.d('${_locale} ${supportedLocales}');
// if (locale != null) {
// // logger.d('sel $locale');
// //如果已经选定语言,则不跟随系统
// return locale;
// } else {
// logger.t('语言跟随系统语言 $_locale');
// return null;
// }
// },

localeResolutionCallback: (_, Iterable<Locale> supportedLocales) {
final Locale _locale = PlatformDispatcher.instance.locale;

return localeService.locale ??
supportedLocales.firstWhere(
(Locale locale) =>
locale.languageCode == _locale.languageCode,
orElse: () => supportedLocales.first,
);
},
);
});
}
42 changes: 2 additions & 40 deletions lib/pages/setting/eh_mysettings_items.dart
Original file line number Diff line number Diff line change
@@ -335,18 +335,6 @@ Widget _buildOriginalImages(
'1': L10n.of(context).uc_oi_1,
};

// return Obx(
// () {
// return TextSwitchItem(
// L10n.of(context).uc_ori_image,
// hideDivider: true,
// value: _controller.ehSetting.originalImages == '1',
// onChanged: (val) => _controller.ehSetting =
// _controller.ehSetting.copyWith(originalImages: val ? '1' : '0'),
// );
// },
// );

return EhCupertinoListTile(
title: Text(L10n.of(context).uc_ori_image),
trailing: Obx(() {
@@ -367,18 +355,6 @@ Widget _buildMPVAlwaysUse(
'1': L10n.of(context).uc_qb_1,
};

// return Obx(
// () {
// return TextSwitchItem(
// L10n.of(context).uc_mpv_always,
// key: UniqueKey(),
// value: _controller.ehSetting.alwaysUseMpv == '1',
// onChanged: (val) => _controller.ehSetting =
// _controller.ehSetting.copyWith(alwaysUseMpv: val ? '1' : '0'),
// );
// },
// );

return EhCupertinoListTile(
title: Text(L10n.of(context).uc_mpv_always),
trailing: Obx(() {
@@ -427,18 +403,6 @@ Widget _buildMPVThumbPane(
'1': L10n.of(context).uc_mt_1,
};

// return Obx(
// () {
// return TextSwitchItem(
// L10n.of(context).uc_mpv_thumb_pane,
// key: UniqueKey(),
// value: _controller.ehSetting.mpvThumbnailPane == '0',
// onChanged: (val) => _controller.ehSetting =
// _controller.ehSetting.copyWith(mpvThumbnailPane: val ? '0' : '1'),
// );
// },
// );

return EhCupertinoListTile(
title: Text(L10n.of(context).uc_mpv_thumb_pane),
trailing: Obx(() {
@@ -467,9 +431,8 @@ Widget _buildRatingsItem(

Widget _buildTagFilteringThreshold(BuildContext context) {
return Obx(() {
return TextInputItem(
return CupertinoTextInputListTile(
title: L10n.of(context).uc_tag_ft,
hideDivider: true,
initValue: _controller.ehSetting.tagFilteringThreshold ?? '',
onChanged: (val) => _controller.ehSetting =
_controller.ehSetting.copyWith(tagFilteringThreshold: val),
@@ -479,9 +442,8 @@ Widget _buildTagFilteringThreshold(BuildContext context) {

Widget _buildTagWatchingThreshold(BuildContext context) {
return Obx(() {
return TextInputItem(
return CupertinoTextInputListTile(
title: L10n.of(context).uc_tag_wt,
hideDivider: true,
initValue: _controller.ehSetting.tagWatchingThreshold ?? '',
onChanged: (val) => _controller.ehSetting =
_controller.ehSetting.copyWith(tagWatchingThreshold: val),
10 changes: 6 additions & 4 deletions lib/pages/setting/eh_mysettings_page.dart
Original file line number Diff line number Diff line change
@@ -324,12 +324,14 @@ class _ListViewEhMySettingsState extends State<ListViewEhMySettings> {

return CustomScrollView(
slivers: [
EhCupertinoSliverRefreshControl(
onRefresh: controller.reloadData,
SliverSafeArea(
bottom: false,
sliver: EhCupertinoSliverRefreshControl(
onRefresh: controller.reloadData,
),
),
SliverSafeArea(
left: false,
right: false,
top: false,
sliver: FutureBuilder<EhSettings?>(
future: future,
initialData: controller.ehSetting,
1 change: 1 addition & 0 deletions lib/pages/setting/log_page.dart
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ class LogListView extends GetView<LogService> {

final logfiles = controller.logFiles;
return SliverCupertinoListSection.insetGrouped(
key: ValueKey(logfiles.length),
itemCount: logfiles.length,
itemBuilder: (context, index) {
final _file = logfiles[index];
99 changes: 55 additions & 44 deletions lib/pages/setting/log_view_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:fehviewer/common/controller/log_controller.dart';
import 'package:fehviewer/common/service/theme_service.dart';
import 'package:fehviewer/const/const.dart';
import 'package:fehviewer/utils/logger.dart';
import 'package:fehviewer/fehviewer.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/scheduler.dart';
import 'package:get/get.dart';
import 'package:share_plus/share_plus.dart';

@@ -28,53 +28,66 @@ class _LogViewPageState extends State<LogViewPage> {
void initState() {
super.initState();

SchedulerBinding.instance.addPostFrameCallback((_) {
// build完成后的回调
logger.t('to end');
_scrollController.animateTo(
_scrollController.position.maxScrollExtent, //滚动到底部
duration: const Duration(milliseconds: 500),
curve: Curves.easeOut,
);
});
// SchedulerBinding.instance.addPostFrameCallback((_) {
// _scrollToBottom();
// });
}

void _scrollToBottom() {
_scrollController.animateTo(
_scrollController.position.maxScrollExtent, //滚动到底部
duration: const Duration(milliseconds: 500),
curve: Curves.easeOut,
);
}

Future<String> _getLog() async {
final logFile = logService.logFiles[widget.index];
if (!logFile.existsSync()) {
Get.back();
}

final Uint8List _logByte = logFile.readAsBytesSync();
final _log = const Utf8Decoder(allowMalformed: true).convert(_logByte);

// final lines = await readLastNLines(logFile.path, 1000);
// final _log = lines.join('\n');

return _log;
}

@override
Widget build(BuildContext context) {
final _logByte = logService.logFiles[widget.index].readAsBytesSync();
final _log = const Utf8Decoder(allowMalformed: true).convert(_logByte);
final logFile = logService.logFiles[widget.index];

Widget scrollView = SingleChildScrollView(
controller: _scrollController,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(
child: Text(
_log,
softWrap: false,
style: const TextStyle(
fontSize: 12,
height: 1.1,
fontFamilyFallback: EHConst.monoFontFamilyFallback,
),
).paddingAll(8),
),
),
);
child: FutureBuilder<String>(
future: _getLog(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CupertinoActivityIndicator();
}

// scrollView = CustomScrollView(
// controller: _scrollController,
// slivers: [
// SliverList(
// delegate: SliverChildBuilderDelegate(
// (BuildContext context, int index) {
// return Text('index:$index');
// },
// childCount: 100,
// ),
// ),
// ],
// );
final _log = snapshot.data ?? '';
_scrollToBottom();

return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(
child: Text(
_log,
softWrap: false,
style: const TextStyle(
fontSize: 12,
height: 1.1,
fontFamilyFallback: EHConst.monoFontFamilyFallback,
),
).paddingAll(8),
),
);
}),
);

if (GetPlatform.isMobile) {
scrollView = CupertinoScrollbar(
@@ -100,11 +113,9 @@ class _LogViewPageState extends State<LogViewPage> {
size: 26,
),
onPressed: () {
Share.shareXFiles(
[XFile(logService.logFiles[widget.index].path)]);
Share.shareXFiles([XFile(logFile.path)]);
},
),
// transitionBetweenRoutes: false,
),
child: SafeArea(
bottom: false,
4 changes: 0 additions & 4 deletions lib/pages/tab/view/setting_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'package:fehviewer/common/service/ehsetting_service.dart';
import 'package:fehviewer/fehviewer.dart';
import 'package:fehviewer/generated/l10n.dart';
import 'package:fehviewer/pages/item/user_item.dart';
import 'package:fehviewer/pages/tab/controller/setting_controller.dart';
import 'package:fehviewer/widget/cupertino/sliver_list_section.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

@@ -43,8 +41,6 @@ class SettingTab extends GetView<SettingViewController> {
),
SliverSafeArea(
top: false,
left: false,
right: false,
sliver: SliverCupertinoListSection.insetGrouped(
itemCount: controller.itemCount,
itemBuilder: (context, index) {

0 comments on commit 1df7637

Please sign in to comment.