Skip to content

Commit

Permalink
add color settings in mobile novel reader
Browse files Browse the repository at this point in the history
  • Loading branch information
appdevelpo committed Feb 10, 2024
1 parent 6575ec0 commit bb4be5f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 6 deletions.
5 changes: 4 additions & 1 deletion assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@
"tts-lang": "TTS Language",
"tts-volume": "TTS Volume",
"tts-pitch": "TTS Pitch",
"text-color": "Text Color"
"text-color": "Text Color",
"heighlight-color": "Highlight Color",
"heighlight-text-color": "Highlight Text Color",
"leading": "Leading"
},
"bugreport": {
"auto-remove-subtitle": "delete in ~ days",
Expand Down
11 changes: 10 additions & 1 deletion lib/controllers/watch/novel_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class NovelController extends ReaderController<ExtensionFikushonWatch> {
late final RxList<String> subtitles =
List.generate(playList.length, (index) => "").obs;
final Rx<Color> textColor = Colors.white.obs;
final Rx<Color> heighLightColor = Colors.blue.obs;
final Rx<Color> heighLightTextColor = Colors.white.obs;
final RxInt currentLine = 0.obs;
final RxDouble leading = 20.0.obs;
initTts() {
ttsVolume.value = MiruStorage.getSetting(SettingKey.ttsVolume);
ttsRate.value = MiruStorage.getSetting(SettingKey.ttsRate);
Expand All @@ -60,6 +64,7 @@ class NovelController extends ReaderController<ExtensionFikushonWatch> {
WakelockPlus.toggle(
enable: MiruStorage.getSetting(SettingKey.enableWakelock));
ttsLangValue.value = MiruStorage.getSetting(SettingKey.ttsLanguage);
leading.value = MiruStorage.getSetting(SettingKey.leading);
ttsLang.value = await flutterTts.getLanguages;
debugPrint(ttsLang.toString());
itemPositionsListener.itemPositions.addListener(() {
Expand Down Expand Up @@ -122,10 +127,14 @@ class NovelController extends ReaderController<ExtensionFikushonWatch> {
}
final readingProgress = items[index.value][i];
debugPrint("current reading: $readingProgress , progress: $i");
animeScrollTo(localToGloabalProgress(i) - 1);
animeScrollTo((localToGloabalProgress(i) - 2) > 0
? localToGloabalProgress(i) - 2
: 0);
currentLine.value = i;
await flutterTts.speak(items[index.value][i]);
}
enableAutoScroll.value = false;
currentLine.value = -1;
});
ever(currentGlobalProgress, (callback) {
if (updateSlider.value) {
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/miru_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ class MiruStorage {
await _initSetting(SettingKey.autoScrollOffset, 20.0);
await _initSetting(
SettingKey.ttsLanguage, Platform.localeName.split('_')[0]);
await _initSetting(SettingKey.ttsPitch, 0.3);
await _initSetting(SettingKey.ttsPitch, 1.0);
await _initSetting(SettingKey.ttsRate, 0.3);
await _initSetting(SettingKey.ttsVolume, 0.5);
await _initSetting(SettingKey.leading, 20.0);
}

static _initSetting(String key, dynamic value) async {
Expand Down Expand Up @@ -207,4 +208,5 @@ class SettingKey {
static String ttsPitch = "TTSPitch";
static String ttsRate = "TTSRate";
static String ttsVolume = "TTSVolume";
static String leading = "Leading";
}
9 changes: 7 additions & 2 deletions lib/views/pages/watch/reader/novel/novel_reader_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class _NovelReaderContentState extends State<NovelReaderContent> {
Widget _textContent(int index, double fontSize) {
final content = _c.items.expand((element) => element).toList();
return Obx(() => Padding(
padding: const EdgeInsets.only(bottom: 20),
padding: EdgeInsets.only(bottom: _c.leading.value),
child: SelectableText.rich(
onTap: () {
_c.setControllPanel.value = !_c.setControllPanel.value;
Expand All @@ -197,9 +197,14 @@ class _NovelReaderContentState extends State<NovelReaderContent> {
TextSpan(
text: content[index],
style: TextStyle(
color: _c.textColor.value,
color: index == _c.currentLine.value
? _c.heighLightTextColor.value
: _c.textColor.value,
fontSize: fontSize,
fontWeight: FontWeight.w400,
backgroundColor: index == _c.currentLine.value
? _c.heighLightColor.value
: null,
height: 2,
textBaseline: TextBaseline.ideographic,
fontFamily: 'Microsoft Yahei',
Expand Down
66 changes: 65 additions & 1 deletion lib/views/pages/watch/reader/novel/novel_reader_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,23 @@ class _NovelReaderSettingsState extends State<NovelReaderSettings> {
divisions: 24,
min: 12,
max: 24,
))
)),
const SizedBox(height: 16),
Text("novel-settings.leading".i18n),
const SizedBox(height: 5),
SizedBox(
width: double.infinity,
child: Slider(
value: _c.leading.value,
onChanged: (value) {
_c.leading.value = value;
},
label: _c.leading.value.toString(),
divisions: 40,
min: 0,
max: 40,
),
),
],
)),
),
Expand Down Expand Up @@ -255,6 +271,54 @@ class _NovelReaderSettingsState extends State<NovelReaderSettings> {
selected: ColorUtils.baseColors[index] ==
_c.textColor.value)),
),
const SizedBox(height: 16),
Text("novel-settings.heighlight-color".i18n),
const SizedBox(height: 5),
Wrap(
spacing: 5,
children: List<Widget>.generate(
ColorUtils.baseColors.length,
(index) => ChoiceChip(
onSelected: (val) {
if (val) {
_c.heighLightColor.value =
ColorUtils.baseColors[index];
}
},
label: Container(
width: 20,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: ColorUtils.baseColors[index],
),
),
selected: ColorUtils.baseColors[index] ==
_c.heighLightColor.value)),
),
const SizedBox(height: 16),
Text("novel-settings.heighlight-text-color".i18n),
const SizedBox(height: 5),
Wrap(
spacing: 5,
children: List<Widget>.generate(
ColorUtils.baseColors.length,
(index) => ChoiceChip(
onSelected: (val) {
if (val) {
_c.heighLightTextColor.value =
ColorUtils.baseColors[index];
}
},
label: Container(
width: 20,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: ColorUtils.baseColors[index],
),
),
selected: ColorUtils.baseColors[index] ==
_c.heighLightTextColor.value)),
),
],
)),
)
Expand Down

0 comments on commit bb4be5f

Please sign in to comment.