Skip to content

Commit

Permalink
auto read
Browse files Browse the repository at this point in the history
  • Loading branch information
honjow committed Oct 31, 2022
1 parent a0500cf commit 62530e4
Show file tree
Hide file tree
Showing 23 changed files with 1,636 additions and 995 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ jobs:
if: matrix.os == 'macos-latest'
run: xcodebuild -resolvePackageDependencies -workspace ios/Runner.xcworkspace -scheme Runner -configuration Release

- name: replace isar
if: matrix.target == 'windows'
shell: bash
run: |
sed -i "s#isar: ^3.0.2'#isar: 3.0.0-dev.8#g" pubspec.yaml
git stash
- name: Flutter pub get
run: |
git config --global core.longpaths true
Expand Down
5 changes: 5 additions & 0 deletions lib/common/provider/settings_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ class SettingsNotifier extends StateNotifier<Settings> {
state = state.copyWith(volumeKeyTurnPage: value);
hiveHelper.setSettings(state);
}

void setAutoReadInterval(double value) {
state = state.copyWith(autoReadInterval: value);
hiveHelper.setSettings(state);
}
}

final settingsProvider =
Expand Down
5 changes: 4 additions & 1 deletion lib/component/models/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Settings with _$Settings {
@Default(true) bool hideBottomNavigationOnScroll,
@Default(true) bool useGalleryTint,
@Default(false) bool volumeKeyTurnPage,
@Default(2.0) double autoReadInterval,
}) = _Settings;

const Settings._();
Expand All @@ -35,5 +36,7 @@ class Settings with _$Settings {

@JsonKey(ignore: true)
bool get readModelPageView =>
readModel == ReadModel.leftToRight || readModel == ReadModel.rightToLeft;
readModel == ReadModel.leftToRight ||
readModel == ReadModel.rightToLeft ||
readModel == ReadModel.vertical;
}
37 changes: 30 additions & 7 deletions lib/component/models/settings.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mixin _$Settings {
bool get hideBottomNavigationOnScroll => throw _privateConstructorUsedError;
bool get useGalleryTint => throw _privateConstructorUsedError;
bool get volumeKeyTurnPage => throw _privateConstructorUsedError;
double get autoReadInterval => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
Expand Down Expand Up @@ -64,7 +65,8 @@ abstract class $SettingsCopyWith<$Res> {
bool supportDynamicColors,
bool hideBottomNavigationOnScroll,
bool useGalleryTint,
bool volumeKeyTurnPage});
bool volumeKeyTurnPage,
double autoReadInterval});
}

/// @nodoc
Expand Down Expand Up @@ -96,6 +98,7 @@ class _$SettingsCopyWithImpl<$Res, $Val extends Settings>
Object? hideBottomNavigationOnScroll = null,
Object? useGalleryTint = null,
Object? volumeKeyTurnPage = null,
Object? autoReadInterval = null,
}) {
return _then(_value.copyWith(
isCoverBlur: null == isCoverBlur
Expand Down Expand Up @@ -162,6 +165,10 @@ class _$SettingsCopyWithImpl<$Res, $Val extends Settings>
? _value.volumeKeyTurnPage
: volumeKeyTurnPage // ignore: cast_nullable_to_non_nullable
as bool,
autoReadInterval: null == autoReadInterval
? _value.autoReadInterval
: autoReadInterval // ignore: cast_nullable_to_non_nullable
as double,
) as $Val);
}
}
Expand Down Expand Up @@ -189,7 +196,8 @@ abstract class _$$_SettingsCopyWith<$Res> implements $SettingsCopyWith<$Res> {
bool supportDynamicColors,
bool hideBottomNavigationOnScroll,
bool useGalleryTint,
bool volumeKeyTurnPage});
bool volumeKeyTurnPage,
double autoReadInterval});
}

/// @nodoc
Expand Down Expand Up @@ -219,6 +227,7 @@ class __$$_SettingsCopyWithImpl<$Res>
Object? hideBottomNavigationOnScroll = null,
Object? useGalleryTint = null,
Object? volumeKeyTurnPage = null,
Object? autoReadInterval = null,
}) {
return _then(_$_Settings(
isCoverBlur: null == isCoverBlur
Expand Down Expand Up @@ -285,6 +294,10 @@ class __$$_SettingsCopyWithImpl<$Res>
? _value.volumeKeyTurnPage
: volumeKeyTurnPage // ignore: cast_nullable_to_non_nullable
as bool,
autoReadInterval: null == autoReadInterval
? _value.autoReadInterval
: autoReadInterval // ignore: cast_nullable_to_non_nullable
as double,
));
}
}
Expand All @@ -308,7 +321,8 @@ class _$_Settings extends _Settings {
this.supportDynamicColors = false,
this.hideBottomNavigationOnScroll = true,
this.useGalleryTint = true,
this.volumeKeyTurnPage = false})
this.volumeKeyTurnPage = false,
this.autoReadInterval = 2.0})
: super._();

factory _$_Settings.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -362,10 +376,13 @@ class _$_Settings extends _Settings {
@override
@JsonKey()
final bool volumeKeyTurnPage;
@override
@JsonKey()
final double autoReadInterval;

@override
String toString() {
return 'Settings(isCoverBlur: $isCoverBlur, isTagTranslate: $isTagTranslate, dynamicColor: $dynamicColor, searchSort: $searchSort, showTags: $showTags, tagLayoutOnItem: $tagLayoutOnItem, themeMode: $themeMode, fullScreenReader: $fullScreenReader, readModel: $readModel, listModel: $listModel, localeCode: $localeCode, themeColorLabel: $themeColorLabel, supportDynamicColors: $supportDynamicColors, hideBottomNavigationOnScroll: $hideBottomNavigationOnScroll, useGalleryTint: $useGalleryTint, volumeKeyTurnPage: $volumeKeyTurnPage)';
return 'Settings(isCoverBlur: $isCoverBlur, isTagTranslate: $isTagTranslate, dynamicColor: $dynamicColor, searchSort: $searchSort, showTags: $showTags, tagLayoutOnItem: $tagLayoutOnItem, themeMode: $themeMode, fullScreenReader: $fullScreenReader, readModel: $readModel, listModel: $listModel, localeCode: $localeCode, themeColorLabel: $themeColorLabel, supportDynamicColors: $supportDynamicColors, hideBottomNavigationOnScroll: $hideBottomNavigationOnScroll, useGalleryTint: $useGalleryTint, volumeKeyTurnPage: $volumeKeyTurnPage, autoReadInterval: $autoReadInterval)';
}

@override
Expand Down Expand Up @@ -406,7 +423,9 @@ class _$_Settings extends _Settings {
(identical(other.useGalleryTint, useGalleryTint) ||
other.useGalleryTint == useGalleryTint) &&
(identical(other.volumeKeyTurnPage, volumeKeyTurnPage) ||
other.volumeKeyTurnPage == volumeKeyTurnPage));
other.volumeKeyTurnPage == volumeKeyTurnPage) &&
(identical(other.autoReadInterval, autoReadInterval) ||
other.autoReadInterval == autoReadInterval));
}

@JsonKey(ignore: true)
Expand All @@ -428,7 +447,8 @@ class _$_Settings extends _Settings {
supportDynamicColors,
hideBottomNavigationOnScroll,
useGalleryTint,
volumeKeyTurnPage);
volumeKeyTurnPage,
autoReadInterval);

@JsonKey(ignore: true)
@override
Expand Down Expand Up @@ -461,7 +481,8 @@ abstract class _Settings extends Settings {
final bool supportDynamicColors,
final bool hideBottomNavigationOnScroll,
final bool useGalleryTint,
final bool volumeKeyTurnPage}) = _$_Settings;
final bool volumeKeyTurnPage,
final double autoReadInterval}) = _$_Settings;
const _Settings._() : super._();

factory _Settings.fromJson(Map<String, dynamic> json) = _$_Settings.fromJson;
Expand Down Expand Up @@ -499,6 +520,8 @@ abstract class _Settings extends Settings {
@override
bool get volumeKeyTurnPage;
@override
double get autoReadInterval;
@override
@JsonKey(ignore: true)
_$$_SettingsCopyWith<_$_Settings> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
2 changes: 2 additions & 0 deletions lib/component/models/settings.g.dart

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

2 changes: 2 additions & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class MessageLookup extends MessageLookupByLibrary {
"app_title": MessageLookupByLibrary.simpleMessage("Eros-N"),
"appearance": MessageLookupByLibrary.simpleMessage("Appearance"),
"auto": MessageLookupByLibrary.simpleMessage("Auto"),
"auto_read_interval":
MessageLookupByLibrary.simpleMessage("Auto read interval"),
"cancel": MessageLookupByLibrary.simpleMessage("Cancel"),
"clear_history": MessageLookupByLibrary.simpleMessage("Clear History"),
"clear_history_tip": MessageLookupByLibrary.simpleMessage(
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_zh_CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MessageLookup extends MessageLookupByLibrary {
"app_title": MessageLookupByLibrary.simpleMessage("Eros-N"),
"appearance": MessageLookupByLibrary.simpleMessage("外观"),
"auto": MessageLookupByLibrary.simpleMessage("自动"),
"auto_read_interval": MessageLookupByLibrary.simpleMessage("自动阅读间隔"),
"cancel": MessageLookupByLibrary.simpleMessage("取消"),
"clear_history": MessageLookupByLibrary.simpleMessage("清除历史"),
"clear_history_tip":
Expand Down
10 changes: 10 additions & 0 deletions lib/generated/l10n.dart

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

3 changes: 2 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,6 @@
"comment_length_error": "Comment must be longer than 10 characters",
"open_supported_links": "Open supported links",
"open_supported_links_tip": "Starting with Android 12, apps can only be used as web link handling apps if they are approved. Otherwise it will be processed using the default browser. You can manually approve it here",
"volume_key_turn_page": "Volume key to turn page"
"volume_key_turn_page": "Volume key to turn page",
"auto_read_interval": "Auto read interval"
}
3 changes: 2 additions & 1 deletion lib/l10n/intl_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,6 @@
"comment_length_error": "评论内容需要超过10个字符",
"open_supported_links": "打开支持的链接",
"open_supported_links_tip": "从 Android 12 开始, 应用只有在获得许可的情况下,才能作为网络链接的处理应用。否则会使用默认浏览器处理。您可以在此手动许可",
"volume_key_turn_page": "音量键翻页"
"volume_key_turn_page": "音量键翻页",
"auto_read_interval": "自动阅读间隔"
}
1 change: 1 addition & 0 deletions lib/pages/nav/front/front_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class _FrontPageState extends ConsumerState<FrontPage>
child: SizedBox(height: 0),
),
toolbarHeight: 0,
elevation: 0,
),
SliverSafeArea(
top: false,
Expand Down
41 changes: 40 additions & 1 deletion lib/pages/read/read_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class ReadNotifier extends StateNotifier<ReadState> {
ReadNotifier(super.state, this.ref)
: preloadPageController = PreloadPageController(
initialPage:
ref.read(galleryProvider(currentGalleryGid)).currentPageIndex);
ref.read(galleryProvider(currentGalleryGid)).currentPageIndex,
keepPage: true);
final Ref ref;

final PreloadPageController preloadPageController;
Expand Down Expand Up @@ -236,6 +237,44 @@ class ReadNotifier extends StateNotifier<ReadState> {
logger.d('closeVolumeKeydownListen');
_volumeKeyDownSubscription?.cancel();
}

Timer? _autoReadTimer;

void toggleAutoRead() {
if (state.autoRead) {
stopAutoRead();
} else {
startAutoRead();
}
}

void stopAutoRead() {
state = state.copyWith(autoRead: false);
_autoReadTimer?.cancel();
_autoReadTimer = null;
}

void startAutoRead() {
state = state.copyWith(autoRead: true);
_autoReadTimer?.cancel();
_autoReadTimer = null;

final autoReadInterval =
ref.read(settingsProvider.select((s) => s.autoReadInterval));
final autoReadDuration =
Duration(milliseconds: (autoReadInterval * 1000).round());

_autoReadTimer = Timer.periodic(
autoReadDuration,
(timer) async {
if (state.autoRead) {
toNext();
} else {
timer.cancel();
}
},
);
}
}

final readProvider =
Expand Down
1 change: 1 addition & 0 deletions lib/pages/read/read_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ReadState with _$ReadState {
@Default(false) bool showThumbList,
@Default(0.0) double paddingTop,
@Default(0.0) double paddingBottom,
@Default(false) bool autoRead,
}) = _ReadState;

const ReadState._();
Expand Down
Loading

0 comments on commit 62530e4

Please sign in to comment.