Skip to content

Commit

Permalink
Merge pull request #119 from venera-app/dev
Browse files Browse the repository at this point in the history
v1.1.3
  • Loading branch information
wgh136 authored Dec 26, 2024
2 parents 18f450a + d27efb1 commit a5c745f
Show file tree
Hide file tree
Showing 23 changed files with 471 additions and 290 deletions.
1 change: 0 additions & 1 deletion debian/gui/venera.desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[Desktop Entry]
Version={{Version}}
Name=Venera
GenericName=Venera
Comment=venera
Expand Down
92 changes: 63 additions & 29 deletions lib/components/comic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -342,30 +342,50 @@ class ComicTile extends StatelessWidget {
}

List<String> _splitText(String text) {
// split text by space, comma. text in brackets will be kept together.
// split text by comma, brackets
var words = <String>[];
var buffer = StringBuffer();
var inBracket = false;
String? prevBracket;
for (var i = 0; i < text.length; i++) {
var c = text[i];
if (c == '[' || c == '(') {
inBracket = true;
if (inBracket) {
buffer.write(c);
} else {
if (buffer.isNotEmpty) {
words.add(buffer.toString().trim());
buffer.clear();
}
inBracket = true;
prevBracket = c;
}
} else if (c == ']' || c == ')') {
inBracket = false;
} else if (c == ' ' || c == ',') {
if (prevBracket == '[' && c == ']' || prevBracket == '(' && c == ')') {
if (buffer.isNotEmpty) {
words.add(buffer.toString().trim());
buffer.clear();
}
inBracket = false;
} else {
buffer.write(c);
}
} else if (c == ',') {
if (inBracket) {
buffer.write(c);
} else {
words.add(buffer.toString());
words.add(buffer.toString().trim());
buffer.clear();
}
} else {
buffer.write(c);
}
}
if (buffer.isNotEmpty) {
words.add(buffer.toString());
words.add(buffer.toString().trim());
}
words.removeWhere((element) => element == "");
words = words.toSet().toList();
return words;
}

Expand All @@ -383,26 +403,33 @@ class ComicTile extends StatelessWidget {
return StatefulBuilder(builder: (context, setState) {
return ContentDialog(
title: 'Block'.tl,
content: Wrap(
runSpacing: 8,
spacing: 8,
children: [
for (var word in all)
OptionChip(
text: word,
isSelected: words.contains(word),
onTap: () {
setState(() {
if (!words.contains(word)) {
words.add(word);
} else {
words.remove(word);
}
});
},
),
],
).paddingHorizontal(16),
content: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: math.min(400, context.height - 136),
),
child: SingleChildScrollView(
child: Wrap(
runSpacing: 8,
spacing: 8,
children: [
for (var word in all)
OptionChip(
text: word,
isSelected: words.contains(word),
onTap: () {
setState(() {
if (!words.contains(word)) {
words.add(word);
} else {
words.remove(word);
}
});
},
),
],
),
).paddingHorizontal(16),
),
actions: [
Button.filled(
onPressed: () {
Expand Down Expand Up @@ -833,6 +860,7 @@ class ComicList extends StatefulWidget {
this.menuBuilder,
this.controller,
this.refreshHandlerCallback,
this.enablePageStorage = false,
});

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

final void Function(VoidCallback c)? refreshHandlerCallback;

final bool enablePageStorage;

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

String? _nextUrl;

late bool enablePageStorage = widget.enablePageStorage;

Map<String, dynamic> get state => {
'maxPage': _maxPage,
'data': _data,
Expand All @@ -878,7 +910,7 @@ class ComicListState extends State<ComicList> {
};

void restoreState(Map<String, dynamic>? state) {
if (state == null) {
if (state == null || !enablePageStorage) {
return;
}
_maxPage = state['maxPage'];
Expand All @@ -892,7 +924,9 @@ class ComicListState extends State<ComicList> {
}

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

void refresh() {
Expand Down Expand Up @@ -1122,7 +1156,7 @@ class ComicListState extends State<ComicList> {
);
}
return SmoothCustomScrollView(
key: const PageStorageKey('scroll'),
key: enablePageStorage ? PageStorageKey('scroll$_page') : null,
controller: widget.controller,
slivers: [
if (widget.leadingSliver != null) widget.leadingSliver!,
Expand Down
1 change: 1 addition & 0 deletions lib/components/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ class ContentDialog extends StatelessWidget {
: const EdgeInsets.symmetric(horizontal: 16),
elevation: 2,
shadowColor: context.colorScheme.shadow,
backgroundColor: context.colorScheme.surface,
child: AnimatedSize(
duration: const Duration(milliseconds: 200),
alignment: Alignment.topCenter,
Expand Down
2 changes: 1 addition & 1 deletion lib/foundation/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export "widget_utils.dart";
export "context.dart";

class _App {
final version = "1.1.2";
final version = "1.1.3";

bool get isAndroid => Platform.isAndroid;

Expand Down
8 changes: 0 additions & 8 deletions lib/foundation/history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ class HistoryManager with ChangeNotifier {

Map<String, bool>? _cachedHistory;

static const _kMaxHistoryLength = 200;

Future<void> init() async {
_db = sqlite3.open("${App.dataPath}/history.db");

Expand All @@ -228,12 +226,6 @@ class HistoryManager with ChangeNotifier {
///
/// This function would be called when user start reading.
Future<void> addHistory(History newItem) async {
while(count() >= _kMaxHistoryLength) {
_db.execute("""
delete from history
where time == (select min(time) from history);
""");
}
_db.execute("""
insert or replace into history (id, title, subtitle, cover, time, type, ep, page, readEpisode, max_page)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
Expand Down
Loading

0 comments on commit a5c745f

Please sign in to comment.