Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
arianneorpilla committed Dec 10, 2021
1 parent 8586277 commit ccdab54
Show file tree
Hide file tree
Showing 20 changed files with 1,273 additions and 149 deletions.
1 change: 1 addition & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ gradle-wrapper.jar
/gradlew
/gradlew.bat
/local.properties
/google-services.json
GeneratedPluginRegistrant.java

# Remember to never publicly share your keystore.
Expand Down
8 changes: 6 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ android {
}
}
ndk {
abiFilters "arm64-v8a"
abiFilters "x86_64"
}
}

Expand Down Expand Up @@ -102,4 +102,8 @@ dependencies {
implementation 'com.google.mlkit:text-recognition-japanese:16.0.0-beta1'
// To recognize Korean script
implementation 'com.google.mlkit:text-recognition-korean:16.0.0-beta1'
}
}

// This must appear at the bottom of the file
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
39 changes: 39 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "63545661380",
"project_id": "jidoujisho",
"storage_bucket": "jidoujisho.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:63545661380:android:605d73f01b5d7a8df9f691",
"android_client_info": {
"package_name": "app.lrorpilla.jidoujisho"
}
},
"oauth_client": [
{
"client_id": "63545661380-ln7em14k3jfkalhh7rtndrff4hap65co.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyBaVvWVIynV1bA6KLCEnch2Vwrg7kfGGfA"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "63545661380-ln7em14k3jfkalhh7rtndrff4hap65co.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ buildscript {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.chaquo.python:gradle:10.0.1"
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
}
}

Expand Down
24 changes: 18 additions & 6 deletions lib/anki/enhancements/bing_search_enhancement.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class BingSearchEnhancement extends AnkiExportEnhancement {
enhancementField: AnkiExportField.image,
);

Map<String, http.Response> bingCache = {};

@override
Future<AnkiExportParams> enhanceParams({
required BuildContext context,
Expand Down Expand Up @@ -54,9 +56,11 @@ class BingSearchEnhancement extends AnkiExportEnhancement {
/// Notify the [CreatorPageState] that we are searching.
state.notifyImageSearching(searchTerm: searchTerm);

String cacheKey = "${appModel.getCurrentLanguage()}/$searchTerm";

try {
List<NetworkToFileImage> images =
await scrapeBingImages(context, searchTerm);
await scrapeBingImages(context, searchTerm, cacheKey);

if (images.isNotEmpty) {
params.imageFiles = images;
Expand All @@ -78,13 +82,21 @@ class BingSearchEnhancement extends AnkiExportEnhancement {
}

Future<List<NetworkToFileImage>> scrapeBingImages(
BuildContext context, String searchTerm) async {
BuildContext context, String searchTerm, String cacheKey) async {
List<NetworkToFileImage> images = [];

var client = http.Client();
http.Response response = await client.get(Uri.parse(
'https://www.bing.com/images/search?q=$searchTerm&FORM=HDRSC2'));
var document = parser.parse(response.body);
late http.Response response;

if (bingCache[cacheKey] != null) {
response = bingCache[cacheKey]!;
} else {
var client = http.Client();
response = await client.get(Uri.parse(
'https://www.bing.com/images/search?q=$searchTerm&FORM=HDRSC2'));
bingCache[cacheKey] = response;
}

dom.Document document = parser.parse(response.body);

List<dom.Element> imgElements = document.getElementsByClassName("iusc");

Expand Down
1 change: 1 addition & 0 deletions lib/anki/enhancements/clear_button_enhancement.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ClearButtonEnhancement extends AnkiExportEnhancement {
case AnkiExportField.audio:
params.audioFile = null;
params.audioSearch = "";
state.notifyAudioNotSearching();
break;
}

Expand Down
Loading

0 comments on commit ccdab54

Please sign in to comment.