Skip to content

Commit

Permalink
Merge pull request #578 from project-violet/rf-6
Browse files Browse the repository at this point in the history
Refactor 011: Dedup codes
  • Loading branch information
violet-dev authored Nov 23, 2024
2 parents cfb78bf + 4fa0287 commit 4f69273
Show file tree
Hide file tree
Showing 25 changed files with 183 additions and 372 deletions.
9 changes: 0 additions & 9 deletions violet/lib/component/hentai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:violet/component/eh/eh_headers.dart';
import 'package:violet/component/eh/eh_parser.dart';
import 'package:violet/component/eh/eh_provider.dart';
import 'package:violet/component/hisoki/hisoki_getter.dart';
import 'package:violet/component/hisoki/hisoki_provider.dart';
import 'package:violet/component/hitomi/hitomi.dart';
import 'package:violet/component/hitomi/hitomi_parser.dart';
import 'package:violet/component/hitomi/hitomi_provider.dart';
Expand Down Expand Up @@ -568,13 +566,6 @@ class HentaiManager {
}
return HitomiImageProvider(imgList, qr.id().toString());
}

case 'Hisoki':
{
var urls = await HisokiGetter.getImages(qr.id());
if (urls == null || urls.isEmpty) break;
return HisokiImageProvider(infos: urls, id: qr.id());
}
}
} catch (e, st) {
Logger.error('[hentai-getImageProvider] E: $e\n'
Expand Down
32 changes: 0 additions & 32 deletions violet/lib/component/hisoki/hisoki_getter.dart

This file was deleted.

31 changes: 0 additions & 31 deletions violet/lib/component/hisoki/hisoki_hash.dart

This file was deleted.

68 changes: 0 additions & 68 deletions violet/lib/component/hisoki/hisoki_provider.dart

This file was deleted.

15 changes: 7 additions & 8 deletions violet/lib/component/hitomi/series_finder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class SeriesFinder {

if (kv.key.toLowerCase() == 'n/a') continue;

final qm = QueryManager.queryPagination(HitomiManager.translate2query(
'artist:${kv.key.replaceAll(' ', '_')}'));
qm.itemsPerPage = 99999;
final query = HitomiManager.translate2query(
'artist:${kv.key.replaceAll(' ', '_')}');
final qm = QueryManager.queryPagination(query, 99999);
final qr = await qm.next();

if (qr.length == 1) continue;
Expand All @@ -52,9 +52,9 @@ class SeriesFinder {

if (kv.key.toLowerCase() == 'n/a') continue;

final qm = QueryManager.queryPagination(HitomiManager.translate2query(
'artist:${kv.key.replaceAll(' ', '_')}'));
qm.itemsPerPage = 99999;
final query = HitomiManager.translate2query(
'artist:${kv.key.replaceAll(' ', '_')}');
final qm = QueryManager.queryPagination(query, 99999);
final qr = await qm.next();

if (qr.length == 1) continue;
Expand All @@ -77,8 +77,7 @@ class SeriesFinder {

static Future<void> doFind2() async {
final qm = QueryManager.queryPagination(
'SELECT Title, Artists, Groups FROM HitomiColumnModel');
qm.itemsPerPage = 999999;
'SELECT Title, Artists, Groups FROM HitomiColumnModel', 999999);
final qr = await qm.next();

final artists = <String, List<int>>{};
Expand Down
3 changes: 2 additions & 1 deletion violet/lib/database/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ class QueryManager {
return qm;
}

static QueryManager queryPagination(String rawQuery) {
static QueryManager queryPagination(String rawQuery, int itemsPerPage) {
QueryManager qm = QueryManager();
qm.isPagination = true;
qm.curPage = 0;
qm.queryString = rawQuery;
qm.itemsPerPage = itemsPerPage;
return qm;
}

Expand Down
86 changes: 58 additions & 28 deletions violet/lib/pages/after_loading/afterloading_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class AfterLoadingPageState extends State<AfterLoadingPage>

final PageController _pageController =
PageController(initialPage: defaultInitialPage);
final FocusNode _focusNode = FocusNode();
final FocusNode nestedFocusNode = FocusNode();

int get _currentPage => _pageController.hasClients
? _pageController.page!.round()
Expand Down Expand Up @@ -333,34 +335,62 @@ class AfterLoadingPageState extends State<AfterLoadingPage>
);
}
},
child: Scaffold(
bottomNavigationBar: _usesBottomNavigationBar
? _buildBottomNavigationBar(context)
: null,
drawer: _usesDrawer ? _buildDrawer(context) : null,
body: AnnotatedRegion<SystemUiOverlayStyle>(
value: !Settings.themeWhat
? SystemUiOverlayStyle.dark
: SystemUiOverlayStyle.light,
child: Stack(
children: [
if (kReleaseMode) const ScriptWebView(),
PageView(
controller: _pageController,
physics:
_usesDrawer ? const NeverScrollableScrollPhysics() : null,
onPageChanged: (newPage) {
setState(() {});
},
children: <Widget>[
SearchPage(key: _widgetKeys[0]),
HotPage(key: _widgetKeys[1]),
BookmarkPage(key: _widgetKeys[2]),
DownloadPage(key: _widgetKeys[3]),
SettingsPage(key: _widgetKeys[4]),
],
),
],
child: KeyboardListener(
focusNode: _focusNode,
autofocus: true,
onKeyEvent: (KeyEvent event) {
if (event is KeyDownEvent) {
switch (event.logicalKey) {
case LogicalKeyboardKey.keyA:
_pageController.animateToPage(
_currentPage - 1,
duration: const Duration(milliseconds: 250),
curve: Curves.easeInOut,
);
break;
case LogicalKeyboardKey.keyD:
_pageController.animateToPage(
_currentPage + 1,
duration: const Duration(milliseconds: 250),
curve: Curves.easeInOut,
);
break;
}
}
nestedFocusNode.requestFocus();
},
child: Scaffold(
bottomNavigationBar: _usesBottomNavigationBar
? _buildBottomNavigationBar(context)
: null,
drawer: _usesDrawer ? _buildDrawer(context) : null,
body: AnnotatedRegion<SystemUiOverlayStyle>(
value: !Settings.themeWhat
? SystemUiOverlayStyle.dark
: SystemUiOverlayStyle.light,
child: Stack(
children: [
if (kReleaseMode) const ScriptWebView(),
PageView(
controller: _pageController,
physics:
_usesDrawer ? const NeverScrollableScrollPhysics() : null,
onPageChanged: (newPage) {
setState(() {});
},
children: <Widget>[
SearchPage(
key: _widgetKeys[0],
focusNode: nestedFocusNode,
),
HotPage(key: _widgetKeys[1]),
BookmarkPage(key: _widgetKeys[2]),
DownloadPage(key: _widgetKeys[3]),
SettingsPage(key: _widgetKeys[4]),
],
),
],
),
),
),
),
Expand Down
57 changes: 6 additions & 51 deletions violet/lib/pages/artist_info/artist_info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'package:html_unescape/html_unescape_small.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:uuid/uuid.dart';
import 'package:violet/algorithm/distance.dart';
import 'package:violet/component/hitomi/hitomi.dart';
import 'package:violet/component/hitomi/indexes.dart';
import 'package:violet/component/hitomi/title_cluster.dart';
Expand Down Expand Up @@ -160,7 +159,7 @@ class _ArtistInfoPageState extends State<ArtistInfoPage> {
similarsAll = similars;
similars = similars.take(6).toList();

await querySimilars(similars, widget.type.name, qrs);
await querySimilars(similars, widget.type, qrs);

if (widget.type.isCharacter || widget.type.isSeries) {
if (widget.type.isCharacter) {
Expand All @@ -177,13 +176,13 @@ class _ArtistInfoPageState extends State<ArtistInfoPage> {

await querySimilars(
relatedCharacterOrSeries,
widget.type.name,
widget.type,
qrsCharacterOrSeries,
);

await querySimilars(
relatedCOSSingle,
widget.type.name,
widget.type,
qrsCOSSingle,
);
}
Expand Down Expand Up @@ -219,54 +218,10 @@ class _ArtistInfoPageState extends State<ArtistInfoPage> {
if (comments!.isNotEmpty) setState(() {});
}

Future<void> querySimilars(List<(String, double)> similars, String prefix,
Future<void> querySimilars(List<(String, double)> similars, ArtistType type,
List<List<QueryResult>> qrs) async {
var unescape = HtmlUnescape();
for (int i = 0; i < similars.length; i++) {
var postfix = similars[i].$1.toLowerCase().replaceAll(' ', '_');
var queryString = HitomiManager.translate2query(
'$prefix:$postfix ${Settings.includeTags} ${Settings.serializedExcludeTags}');
final qm = QueryManager.queryPagination(queryString);
qm.itemsPerPage = 10;

var x = await qm.next();
if (x.isEmpty) {
qrs.add(<QueryResult>[]);
continue;
}
var y = [x[0]];

var titles = [unescape.convert((x[0].title() as String).trim())];
if (titles[0].contains('Ch.')) {
titles[0] = titles[0].split('Ch.')[0];
} else if (titles[0].contains('ch.')) {
titles[0] = titles[0].split('ch.')[0];
}

for (int i = 1; i < x.length; i++) {
var skip = false;
var ff = unescape.convert((x[i].title() as String).trim());
if (ff.contains('Ch.')) {
ff = ff.split('Ch.')[0];
} else if (ff.contains('ch.')) {
ff = ff.split('ch.')[0];
}
for (int j = 0; j < titles.length; j++) {
var tt = titles[j];
if (Distance.levenshteinDistanceComparable(
tt.runes.map((e) => e.toString()).toList(),
ff.runes.map((e) => e.toString()).toList()) <
3) {
skip = true;
break;
}
}
if (skip) continue;
y.add(x[i]);
titles.add(ff.trim());
}

qrs.add(y);
for (final (name, _) in similars) {
qrs.add(await queryDedupedArtistArticles(type, name));
}
}

Expand Down
Loading

0 comments on commit 4f69273

Please sign in to comment.