Skip to content

Commit

Permalink
A bunch of changes
Browse files Browse the repository at this point in the history
- update to flutter 3.16
- update deps (dart_vlc is now taken from main git)
- bump targetSdkVersion to 34
- show init state during app start on special screen
- new booru handler to view Downloads
- rework how item filtering works and used (fixes lags during fast scroll and loading of new pages)
- added DB indexing (may cause long first start after the update for some)
- reworked "tab with this tag exists" indication
- added ability to filter snatched items and items with AI related tags
- downloads drawer [WIP]
- moved from WillPopScope to PopScope
- reworked tab selector [a bit incomplete, needs another bug and design pass] + rework history viewer
- fixed scaling bugs with notes (error in calc when fully zoomed, sample images didn't scale position properly, takes image dimensions directly from the loaded image through photo_view)
- scroll to search in tagview on focus
- attempt to make double tap zoom to tap position (works poorly, still needs work, see photo_view fork)
- added double-tap-drag-zoom
- old tag searches from booru now properly cancel when starting a new one, which fixes race condition when old results could override newer ones
- fixed videos unpausing after restate when they shouldn't
- thumbnails scrollbar is now interactive (fixed in inner_drawer fork, it had a container which blocked interaction)
- other small fixes
  • Loading branch information
NANI-SORE committed Nov 19, 2023
1 parent cb2c127 commit 89e9dbb
Show file tree
Hide file tree
Showing 107 changed files with 4,043 additions and 2,416 deletions.
2 changes: 1 addition & 1 deletion .fvm/fvm_config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"flutterSdkVersion": "3.10.6",
"flutterSdkVersion": "3.16.0",
"flavors": {}
}
2 changes: 0 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@ linter:
implementation_imports: true
implicit_reopen: true
invalid_case_patterns: true
iterable_contains_unrelated_type: true
join_return_with_assignment: true
leading_newlines_in_multiline_strings: true
library_annotations: true
library_names: true
library_prefixes: true
library_private_types_in_public_api: true
list_remove_unrelated_type: true
literal_only_boolean_expressions: true
missing_whitespace_between_adjacent_strings: true
no_adjacent_strings_in_list: true
Expand Down
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 33
compileSdkVersion 34

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -64,7 +64,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId packageName
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.9.0'
repositories {
google()
mavenCentral()
Expand Down
43 changes: 30 additions & 13 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'package:lolisnatcher/src/handlers/tag_handler.dart';
import 'package:lolisnatcher/src/handlers/theme_handler.dart';
import 'package:lolisnatcher/src/handlers/viewer_handler.dart';
import 'package:lolisnatcher/src/pages/desktop_home_page.dart';
import 'package:lolisnatcher/src/pages/init_home_page.dart';
import 'package:lolisnatcher/src/pages/mobile_home_page.dart';
import 'package:lolisnatcher/src/pages/settings/booru_edit_page.dart';
import 'package:lolisnatcher/src/services/image_writer.dart';
Expand All @@ -39,7 +40,7 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();

if (Platform.isWindows || Platform.isLinux) {
await DartVLC.initialize();
DartVLC.initialize();

// Init db stuff
sqfliteFfiInit();
Expand Down Expand Up @@ -149,12 +150,13 @@ class _MainAppState extends State<MainApp> {
Future<void> initHandlers() async {
// should init earlier than tabs so tags color properly on first render of search box
// TODO but this possibly could lead to bad preformance on start if tag storage is too big?
await Future.wait([
tagHandler.initialize(),
searchHandler.restoreTabs(),
]);

settingsHandler.alice.setNavigatorKey(navigationHandler.navigatorKey);
await settingsHandler.postInit(() async {
settingsHandler.postInitMessage.value = 'Loading tags...';
await tagHandler.initialize();
settingsHandler.postInitMessage.value = 'Restoring tabs...';
await searchHandler.restoreTabs();
});
}

Future<void> setMaxFPS() async {
Expand Down Expand Up @@ -399,13 +401,28 @@ class _HomeState extends State<Home> with WidgetsBindingObserver {
}
}

return Obx(() {
if (settingsHandler.appMode.value.isMobile) {
return const MobileHome();
} else {
return const DesktopHome();
}
});
return ColoredBox(
color: Theme.of(context).colorScheme.background,
child: Obx(() {
return AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: Builder(
key: ValueKey('init:${settingsHandler.isPostInit.value}-mobile:${settingsHandler.appMode.value.isMobile}'),
builder: (context) {
if (settingsHandler.isPostInit.value == false) {
return const InitHomePage();
}

if (settingsHandler.appMode.value.isMobile) {
return const MobileHome();
} else {
return const DesktopHome();
}
},
),
);
}),
);

// with lockscreen:
// return Obx(() {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/boorus/booru_on_rails_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class BooruOnRailsHandler extends BooruHandler {
['-fwslash-', '/'],
['-bwslash-', r'\'],
['-dot-', '.'],
['-plus-', '+']
['-plus-', '+'],
];

@override
Expand Down
5 changes: 4 additions & 1 deletion lib/src/boorus/booru_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

enum BooruType {
AutoDetect,
//
//
AGNPH,
BooruOnRails,
Danbooru,
Expand All @@ -27,17 +27,20 @@ enum BooruType {
// [Special types]
GelbooruAlike,
Merge,
Downloads,
Favourites;

static List<BooruType> get dropDownValues {
return [...values]
..remove(BooruType.Downloads)
..remove(BooruType.Favourites)
..remove(BooruType.Merge)
..remove(BooruType.GelbooruAlike);
}

static List<BooruType> get detectable {
return [...values]
..remove(BooruType.Downloads)
..remove(BooruType.Favourites)
..remove(BooruType.Merge)
..remove(BooruType.AutoDetect)
Expand Down
68 changes: 68 additions & 0 deletions lib/src/boorus/downloads_handler.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'package:dio/dio.dart';

import 'package:lolisnatcher/src/handlers/booru_handler.dart';
import 'package:lolisnatcher/src/handlers/settings_handler.dart';
import 'package:lolisnatcher/src/utils/logger.dart';

class DownloadsHandler extends BooruHandler {
DownloadsHandler(super.booru, super.limit);

@override
String validateTags(String tags) {
return tags;
}

@override
Future search(String tags, int? pageNumCustom, {bool withCaptchaCheck = true}) async {
// set custom page number
if (pageNumCustom != null) {
pageNum = pageNumCustom;
}

// validate tags
tags = validateTags(tags.trim());

// if tags are different than previous tags, reset fetched
if (prevTags != tags) {
fetched.value = [];
totalCount.value = 0;
}

// get amount of items before fetching
final int length = fetched.length;

final newItems = await SettingsHandler.instance.dbHandler.searchDB(
tags,
(pageNum * limit).toString(),
limit.toString(),
'DESC',
'Favourites',
isDownloads: true,
);

await afterParseResponse(newItems);
prevTags = tags;

if (fetched.isEmpty || fetched.length == length) {
Logger.Inst().log('dbhandler dbLocked', 'DownloadsHandler', 'search', LogTypes.booruHandlerInfo);
locked = true;
}

return fetched;
}

@override
Future<List<String>> tagSearch(String input, {CancelToken? cancelToken}) async {
final List<String> tags = await SettingsHandler.instance.dbHandler.getTags(input, limit);
return tags;
}

@override
Future<void> searchCount(String input) async {
totalCount.value = await SettingsHandler.instance.dbHandler.searchDBCount(
input,
isDownloads: true,
);
return;
}
}
2 changes: 1 addition & 1 deletion lib/src/boorus/e621_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class e621Handler extends BooruHandler {
...current['tags']['artist'],
...current['tags']['meta'],
...current['tags']['general'],
...current['tags']['species']
...current['tags']['species'],
],
postURL: makePostURL(current['id'].toString()),
fileExt: current['file']['ext'],
Expand Down
23 changes: 13 additions & 10 deletions lib/src/boorus/favourites_handler.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:dio/dio.dart';

import 'package:lolisnatcher/src/handlers/booru_handler.dart';
import 'package:lolisnatcher/src/handlers/settings_handler.dart';
import 'package:lolisnatcher/src/utils/logger.dart';
Expand All @@ -18,7 +20,7 @@ class FavouritesHandler extends BooruHandler {
}

// validate tags
tags = validateTags(tags);
tags = validateTags(tags.trim());

// if tags are different than previous tags, reset fetched
if (prevTags != tags) {
Expand All @@ -29,15 +31,16 @@ class FavouritesHandler extends BooruHandler {
// get amount of items before fetching
final int length = fetched.length;

fetched.addAll(
await SettingsHandler.instance.dbHandler.searchDB(
tags,
(pageNum * limit).toString(),
limit.toString(),
'DESC',
'Favourites',
),
final newItems = await SettingsHandler.instance.dbHandler.searchDB(
tags,
(pageNum * limit).toString(),
limit.toString(),
'DESC',
'Favourites',
);

await afterParseResponse(newItems);

prevTags = tags;

if (fetched.isEmpty || fetched.length == length) {
Expand All @@ -49,7 +52,7 @@ class FavouritesHandler extends BooruHandler {
}

@override
Future<List<String>> tagSearch(String input) async {
Future<List<String>> tagSearch(String input, {CancelToken? cancelToken}) async {
final List<String> tags = await SettingsHandler.instance.dbHandler.getTags(input, limit);
return tags;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/boorus/gelbooru_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GelbooruHandler extends BooruHandler {
Map<String, String> getHeaders() {
return {
...super.getHeaders(),
'Cookie': 'fringeBenefits=yup;' // unlocks restricted content (but it's probably not necessary)
'Cookie': 'fringeBenefits=yup;', // unlocks restricted content (but it's probably not necessary)
};
}

Expand Down Expand Up @@ -118,6 +118,7 @@ class GelbooruHandler extends BooruHandler {
Future<void> afterParseResponse(List<BooruItem> newItems) async {
final int lengthBefore = fetched.length;
fetched.addAll(newItems);
filterFetched();
await populateTagHandler(newItems); // difference from default afterParse
unawaited(setMultipleTrackedValues(lengthBefore, fetched.length));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/boorus/hydrus_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'package:lolisnatcher/src/widgets/common/flash_elements.dart';
class HydrusHandler extends BooruHandler {
HydrusHandler(super.booru, super.limit);

var _fileIDs;
dynamic _fileIDs;

@override
Map<String, String> getHeaders() {
Expand Down
4 changes: 3 additions & 1 deletion lib/src/boorus/ink_bunny_handler.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:async';
import 'dart:math';

import 'package:dio/dio.dart';

import 'package:lolisnatcher/src/data/booru_item.dart';
import 'package:lolisnatcher/src/handlers/booru_handler.dart';
import 'package:lolisnatcher/src/utils/logger.dart';
Expand Down Expand Up @@ -219,7 +221,7 @@ class InkBunnyHandler extends BooruHandler {
}

@override
Future<List<String>> tagSearch(String input) async {
Future<List<String>> tagSearch(String input, {CancelToken? cancelToken}) async {
final List<String> searchTags = [];
final String url = makeTagURL(input);
try {
Expand Down
5 changes: 3 additions & 2 deletions lib/src/boorus/mergebooru_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert';

import 'package:crypto/crypto.dart';
import 'package:dio/dio.dart';

import 'package:lolisnatcher/src/boorus/booru_type.dart';
import 'package:lolisnatcher/src/data/booru.dart';
Expand Down Expand Up @@ -146,8 +147,8 @@ class MergebooruHandler extends BooruHandler {
}

@override
Future<List<String>> tagSearch(String input) async {
return booruHandlers[0].tagSearch(input);
Future<List<String>> tagSearch(String input, {CancelToken? cancelToken}) async {
return booruHandlers[0].tagSearch(input, cancelToken: cancelToken);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/boorus/philomena_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class PhilomenaHandler extends BooruHandler {
['-fwslash-', '/'],
['-bwslash-', r'\'],
['-dot-', '.'],
['-plus-', '+']
['-plus-', '+'],
];

String tag = responseItem['slug'].toString();
Expand Down
4 changes: 2 additions & 2 deletions lib/src/boorus/rainbooru_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RainbooruHandler extends BooruHandler {
@override
Future<BooruItem?> parseItemFromResponse(dynamic responseItem, int index) async {
String thumbURL = '';
final urlElem = responseItem.firstChild!;
final urlElem = responseItem.firstChild;
thumbURL += urlElem.firstChild!.attributes['src']!;
final String url = makePostURL(urlElem.attributes['href']!.split('img/')[1]);
final responseInner = await DioNetwork.get(url, headers: getHeaders());
Expand Down Expand Up @@ -97,7 +97,7 @@ class RainbooruHandler extends BooruHandler {
['-fwslash-', '/'],
['-bwslash-', r'\'],
['-dot-', '.'],
['-plus-', '+']
['-plus-', '+'],
];

String tag = responseItem['slug'].toString();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/boorus/sankaku_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class SankakuHandler extends BooruHandler {
// 'User-Agent': 'SCChannelApp/4.0',
'User-Agent': Constants.defaultBrowserUserAgent,
'Referer': 'https://sankaku.app/',
'Origin': 'https://sankaku.app'
'Origin': 'https://sankaku.app',
};
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/boorus/szurubooru_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SzurubooruHandler extends BooruHandler {
'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': Tools.browserUserAgent,
if (booru.apiKey?.isNotEmpty == true) 'Authorization': "Token ${base64Encode(utf8.encode("${booru.userID}:${booru.apiKey}"))}"
if (booru.apiKey?.isNotEmpty == true) 'Authorization': "Token ${base64Encode(utf8.encode("${booru.userID}:${booru.apiKey}"))}",
};
}

Expand Down
Loading

0 comments on commit 89e9dbb

Please sign in to comment.