Skip to content

Commit

Permalink
Merge pull request #93 from venera-app/dev
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
wgh136 authored Dec 12, 2024
2 parents 488299b + bda2c6c commit 586874d
Show file tree
Hide file tree
Showing 55 changed files with 1,547 additions and 806 deletions.
14 changes: 12 additions & 2 deletions assets/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,12 @@
"New version available": "有新版本可用",
"A new version is available. Do you want to update now?" : "有新版本可用。您要现在更新吗?",
"No new version available": "没有新版本可用",
"Export as pdf": "导出为pdf"
"Export as pdf": "导出为pdf",
"Export as epub": "导出为epub",
"Aggregated Search": "聚合搜索",
"No search results found": "未找到搜索结果",
"Added @c comics to download queue." : "已添加 @c 本漫画到下载队列",
"Download started": "下载已开始"
},
"zh_TW": {
"Home": "首頁",
Expand Down Expand Up @@ -495,6 +500,11 @@
"New version available": "有新版本可用",
"A new version is available. Do you want to update now?" : "有新版本可用。您要現在更新嗎?",
"No new version available": "沒有新版本可用",
"Export as pdf": "匯出為pdf"
"Export as pdf": "匯出為pdf",
"Export as epub": "匯出為epub",
"Aggregated Search": "聚合搜索",
"No search results found": "未找到搜索結果",
"Added @c comics to download queue." : "已添加 @c 本漫畫到下載隊列",
"Download started": "下載已開始"
}
}
35 changes: 23 additions & 12 deletions lib/components/appbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class _AppbarState extends State<Appbar> {
var content = Container(
decoration: BoxDecoration(
color: widget.backgroundColor ??
context.colorScheme.surface.withOpacity(0.72),
context.colorScheme.surface.toOpacity(0.72),
),
height: _kAppBarHeight + context.padding.top,
child: Row(
Expand Down Expand Up @@ -189,20 +189,19 @@ class _MySliverAppBarDelegate extends SliverPersistentHeaderDelegate {
leading ??
(Navigator.of(context).canPop()
? Tooltip(
message: "Back".tl,
child: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () => Navigator.maybePop(context),
),
)
message: "Back".tl,
child: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () => Navigator.maybePop(context),
),
)
: const SizedBox()),
const SizedBox(
width: 16,
),
Expanded(
child: DefaultTextStyle(
style:
DefaultTextStyle.of(context).style.copyWith(fontSize: 20),
style: DefaultTextStyle.of(context).style.copyWith(fontSize: 20),
maxLines: 1,
overflow: TextOverflow.ellipsis,
child: title,
Expand All @@ -215,12 +214,12 @@ class _MySliverAppBarDelegate extends SliverPersistentHeaderDelegate {
],
).paddingTop(topPadding);

if(style == AppbarStyle.blur) {
if (style == AppbarStyle.blur) {
return SizedBox.expand(
child: BlurEffect(
blur: 15,
child: Material(
color: context.colorScheme.surface.withOpacity(0.72),
color: context.colorScheme.surface.toOpacity(0.72),
elevation: 0,
borderRadius: BorderRadius.circular(radius),
child: body,
Expand Down Expand Up @@ -298,12 +297,21 @@ class _FilledTabBarState extends State<FilledTabBar> {
super.dispose();
}

PageStorageBucket get bucket => PageStorage.of(context);

@override
void didChangeDependencies() {
_controller = widget.controller ?? DefaultTabController.of(context);
_controller.animation!.addListener(onTabChanged);
initPainter();
super.didChangeDependencies();
var prevIndex = bucket.readState(context) as int?;
if (prevIndex != null &&
prevIndex != _controller.index &&
prevIndex >= 0 &&
prevIndex < widget.tabs.length) {
_controller.index = prevIndex;
}
_controller.animation!.addListener(onTabChanged);
}

@override
Expand Down Expand Up @@ -347,6 +355,7 @@ class _FilledTabBarState extends State<FilledTabBar> {
controller: scrollController,
builder: (context, controller, physics) {
return SingleChildScrollView(
key: const PageStorageKey('scroll'),
scrollDirection: Axis.horizontal,
padding: EdgeInsets.zero,
controller: controller,
Expand Down Expand Up @@ -387,6 +396,7 @@ class _FilledTabBarState extends State<FilledTabBar> {
}
updateScrollOffset(i);
previousIndex = i;
bucket.writeState(context, i);
}

void updateScrollOffset(int i) {
Expand Down Expand Up @@ -724,6 +734,7 @@ class _SliverSearchBarDelegate extends SliverPersistentHeaderDelegate {
icon: const Icon(Icons.clear),
onPressed: () {
editingController.clear();
onChanged?.call("");
},
);
},
Expand Down
10 changes: 5 additions & 5 deletions lib/components/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class _ButtonState extends State<Button> {
boxShadow: (isHover && !isLoading && (widget.type == ButtonType.filled || widget.type == ButtonType.normal))
? [
BoxShadow(
color: Colors.black.withOpacity(0.1),
color: Colors.black.toOpacity(0.1),
blurRadius: 2,
offset: const Offset(0, 1),
)
Expand Down Expand Up @@ -248,21 +248,21 @@ class _ButtonState extends State<Button> {
if (widget.type == ButtonType.filled) {
var color = widget.color ?? context.colorScheme.primary;
if (isHover) {
return color.withOpacity(0.9);
return color.toOpacity(0.9);
} else {
return color;
}
}
if (widget.type == ButtonType.normal) {
var color = widget.color ?? context.colorScheme.surfaceContainer;
if (isHover) {
return color.withOpacity(0.9);
return color.toOpacity(0.9);
} else {
return color;
}
}
if (isHover) {
return context.colorScheme.outline.withOpacity(0.2);
return context.colorScheme.outline.toOpacity(0.2);
}
return Colors.transparent;
}
Expand Down Expand Up @@ -345,7 +345,7 @@ class _IconButtonState extends State<_IconButton> {
? Theme.of(context)
.colorScheme
.outlineVariant
.withOpacity(0.4)
.toOpacity(0.4)
: null,
borderRadius: BorderRadius.circular((iconSize + 12) / 2),
),
Expand Down
72 changes: 63 additions & 9 deletions lib/components/comic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ComicTile extends StatelessWidget {
var renderBox = context.findRenderObject() as RenderBox;
var size = renderBox.size;
var location = renderBox.localToGlobal(
Offset(size.width / 2, size.height / 2),
Offset((size.width - 242) / 2, size.height / 2),
);
showMenu(location, context);
}
Expand Down Expand Up @@ -144,7 +144,7 @@ class ComicTile extends StatelessWidget {
if (history != null)
Container(
height: 24,
color: Colors.blue.withOpacity(0.9),
color: Colors.blue.toOpacity(0.9),
constraints: const BoxConstraints(minWidth: 24),
padding: const EdgeInsets.symmetric(horizontal: 4),
child: CustomPaint(
Expand Down Expand Up @@ -293,7 +293,7 @@ class ComicTile extends StatelessWidget {
Radius.circular(10.0),
),
child: Container(
color: Colors.black.withOpacity(0.5),
color: Colors.black.toOpacity(0.5),
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 6, 8, 6),
Expand Down Expand Up @@ -475,7 +475,7 @@ class _ComicDescription extends StatelessWidget {
subtitle,
style: TextStyle(
fontSize: 10.0,
color: context.colorScheme.onSurface.withOpacity(0.7)),
color: context.colorScheme.onSurface.toOpacity(0.7)),
maxLines: 1,
softWrap: true,
overflow: TextOverflow.ellipsis,
Expand Down Expand Up @@ -780,7 +780,7 @@ class _SliverGridComics extends StatelessWidget {
duration: const Duration(milliseconds: 150),
decoration: BoxDecoration(
color: isSelected
? Theme.of(context).colorScheme.secondaryContainer.withOpacity(0.72)
? Theme.of(context).colorScheme.secondaryContainer.toOpacity(0.72)
: null,
borderRadius: BorderRadius.circular(12),
),
Expand Down Expand Up @@ -832,6 +832,7 @@ class ComicList extends StatefulWidget {
this.errorLeading,
this.menuBuilder,
this.controller,
this.refreshHandlerCallback,
});

final Future<Res<List<Comic>>> Function(int page)? loadPage;
Expand All @@ -848,6 +849,8 @@ class ComicList extends StatefulWidget {

final ScrollController? controller;

final void Function(VoidCallback c)? refreshHandlerCallback;

@override
State<ComicList> createState() => ComicListState();
}
Expand All @@ -865,6 +868,51 @@ class ComicListState extends State<ComicList> {

String? _nextUrl;

Map<String, dynamic> get state => {
'maxPage': _maxPage,
'data': _data,
'page': _page,
'error': _error,
'loading': _loading,
'nextUrl': _nextUrl,
};

void restoreState(Map<String, dynamic>? state) {
if (state == null) {
return;
}
_maxPage = state['maxPage'];
_data.clear();
_data.addAll(state['data']);
_page = state['page'];
_error = state['error'];
_loading.clear();
_loading.addAll(state['loading']);
_nextUrl = state['nextUrl'];
}

void storeState() {
PageStorage.of(context).writeState(context, state);
}

void refresh() {
_data.clear();
_page = 1;
_maxPage = null;
_error = null;
_nextUrl = null;
_loading.clear();
storeState();
setState(() {});
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
restoreState(PageStorage.of(context).readState(context));
widget.refreshHandlerCallback?.call(refresh);
}

void remove(Comic c) {
if (_data[_page] == null || !_data[_page]!.remove(c)) {
for (var page in _data.values) {
Expand Down Expand Up @@ -1012,15 +1060,20 @@ class ComicListState extends State<ComicList> {
while (_data[page] == null) {
await _fetchNext();
}
setState(() {});
if(mounted) {
setState(() {});
}
} catch (e) {
setState(() {
_error = e.toString();
});
if(mounted) {
setState(() {
_error = e.toString();
});
}
}
}
} finally {
_loading[page] = false;
storeState();
}
}

Expand Down Expand Up @@ -1069,6 +1122,7 @@ class ComicListState extends State<ComicList> {
);
}
return SmoothCustomScrollView(
key: const PageStorageKey('scroll'),
controller: widget.controller,
slivers: [
if (widget.leadingSliver != null) widget.leadingSliver!,
Expand Down
2 changes: 0 additions & 2 deletions lib/components/components.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
library components;

import 'dart:async';
import 'dart:collection';
import 'dart:math' as math;
Expand Down
25 changes: 13 additions & 12 deletions lib/components/custom_slider.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:venera/foundation/app.dart';

/// patched slider.dart with RtL support
class _SliderDefaultsM3 extends SliderThemeData {
Expand All @@ -15,45 +16,45 @@ class _SliderDefaultsM3 extends SliderThemeData {
Color? get inactiveTrackColor => _colors.surfaceContainerHighest;

@override
Color? get secondaryActiveTrackColor => _colors.primary.withOpacity(0.54);
Color? get secondaryActiveTrackColor => _colors.primary.toOpacity(0.54);

@override
Color? get disabledActiveTrackColor => _colors.onSurface.withOpacity(0.38);
Color? get disabledActiveTrackColor => _colors.onSurface.toOpacity(0.38);

@override
Color? get disabledInactiveTrackColor => _colors.onSurface.withOpacity(0.12);
Color? get disabledInactiveTrackColor => _colors.onSurface.toOpacity(0.12);

@override
Color? get disabledSecondaryActiveTrackColor => _colors.onSurface.withOpacity(0.12);
Color? get disabledSecondaryActiveTrackColor => _colors.onSurface.toOpacity(0.12);

@override
Color? get activeTickMarkColor => _colors.onPrimary.withOpacity(0.38);
Color? get activeTickMarkColor => _colors.onPrimary.toOpacity(0.38);

@override
Color? get inactiveTickMarkColor => _colors.onSurfaceVariant.withOpacity(0.38);
Color? get inactiveTickMarkColor => _colors.onSurfaceVariant.toOpacity(0.38);

@override
Color? get disabledActiveTickMarkColor => _colors.onSurface.withOpacity(0.38);
Color? get disabledActiveTickMarkColor => _colors.onSurface.toOpacity(0.38);

@override
Color? get disabledInactiveTickMarkColor => _colors.onSurface.withOpacity(0.38);
Color? get disabledInactiveTickMarkColor => _colors.onSurface.toOpacity(0.38);

@override
Color? get thumbColor => _colors.primary;

@override
Color? get disabledThumbColor => Color.alphaBlend(_colors.onSurface.withOpacity(0.38), _colors.surface);
Color? get disabledThumbColor => Color.alphaBlend(_colors.onSurface.toOpacity(0.38), _colors.surface);

@override
Color? get overlayColor => WidgetStateColor.resolveWith((Set<WidgetState> states) {
if (states.contains(WidgetState.dragged)) {
return _colors.primary.withOpacity(0.1);
return _colors.primary.toOpacity(0.1);
}
if (states.contains(WidgetState.hovered)) {
return _colors.primary.withOpacity(0.08);
return _colors.primary.toOpacity(0.08);
}
if (states.contains(WidgetState.focused)) {
return _colors.primary.withOpacity(0.1);
return _colors.primary.toOpacity(0.1);
}

return Colors.transparent;
Expand Down
Loading

0 comments on commit 586874d

Please sign in to comment.