Skip to content

Commit

Permalink
Merge pull request #2 from klippa-app/feature/update-implementation
Browse files Browse the repository at this point in the history
Upgrade to support newest SDK versions.
  • Loading branch information
RobinFarmer authored Dec 23, 2021
2 parents eb93501 + 6ddddb5 commit 3a9535a
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 64 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ config.imageMovingMessage = "Too much movement";
config.model.fileName = "model";
config.model.modelLabels = "labelmap";
// If you would like to enable automatic capturing of images.
// If you want to adjust the timer options.
config.timer.allowed = true
config.timer.enabled = true;
config.timer.duration = 1.0;
Expand All @@ -195,6 +196,12 @@ config.success.message = "Success!";
// The amount of seconds the preview should be visible for, should be a float.
config.previewDuration = 1.0;
// To limit the amount of images that can be taken.
config.imageLimit = 10;
// The message to display when the limit has been reached.
config.imageLimitReachedMessage = "You have reached the image limit";
```

## Android only
Expand All @@ -209,12 +216,6 @@ config.storagePath = "/sdcard/scanner";
// The filename to use for the output images, supports replacement tokens %dateTime% and %randomUUID%.
config.outputFileName = "KlippaScannerExample-%dateTime%-%randomUUID%";
// To limit the amount of images that can be taken.
config.imageLimit = 10;
// The message to display when the limit has been reached.
config.imageLimitReachedMessage = "You have reached the image limit";
// The threshold sensitive the motion detection is. (lower value is higher sensitivity, default 50).
config.imageMovingSensitivityAndroid = 50;
```
Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ group 'com.klippa.scanner.klippa_scanner_sdk'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.5.20'
ext.kotlin_version = '1.6.10'
repositories {
google()
jcenter()
Expand Down Expand Up @@ -55,6 +55,6 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
def klippaScannerVersion = project.hasProperty('klippaScannerVersion') ? project.klippaScannerVersion : "2.0.3"
def klippaScannerVersion = project.hasProperty('klippaScannerVersion') ? project.klippaScannerVersion : "2.0.6"
implementation "com.klippa:scanner:$klippaScannerVersion"
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P
KlippaScanner.model.modelLabels = call.argument<String>("Model.modelLabels")!!
}

if (call.hasArgument("Timer.allowed")) {
KlippaScanner.menu.allowTimer = call.argument<Boolean>("Timer.allowed")!!
}

if (call.hasArgument("Timer.enabled")) {
KlippaScanner.menu.isTimerEnabled = call.argument<Boolean>("Timer.enabled")!!
}
Expand Down Expand Up @@ -159,8 +163,8 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P
KlippaScanner.shutterButton.allowShutterButton = call.argument<Boolean>("ShutterButton.allowshutterButton")!!
}

if (call.hasArgument("ShutterButton.hideShutterbutton")) {
KlippaScanner.shutterButton.hideShutterButton = call.argument<Boolean>("ShutterButton.hideShutterbutton")!!
if (call.hasArgument("ShutterButton.hideShutterButton")) {
KlippaScanner.shutterButton.hideShutterButton = call.argument<Boolean>("ShutterButton.hideShutterButton")!!
}

if (call.hasArgument("StoragePath")) {
Expand Down Expand Up @@ -215,19 +219,37 @@ class KlippaScannerSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAware, P
val receivedData = data ?: return false
val extras = receivedData.extras ?: return false

val images: ArrayList<Image> = extras.getParcelableArrayList<Image>(KlippaScanner.IMAGES) as ArrayList<Image>
Toast.makeText(context, "Result was " + images.size + " images", Toast.LENGTH_LONG).show()
val receivedImages: ArrayList<Image> = extras.getParcelableArrayList<Image>(KlippaScanner.IMAGES) as ArrayList<Image>

val images: MutableList<Map<String, String>> = mutableListOf()

for (image in receivedImages) {
val imageDict = mapOf("Filepath" to image.filePath)
images.add(imageDict)
}

val multipleDocuments: Boolean = extras.getBoolean(KlippaScanner.CREATE_MULTIPLE_RECEIPTS)
val cropEnabled: Boolean = extras.getBoolean(KlippaScanner.CROP)
val timerEnabled: Boolean = extras.getBoolean(KlippaScanner.TIMER_ENABLED)

val resultDict = mapOf(
"Images" to images,
"MultipleDocuments" to multipleDocuments,
"Crop" to cropEnabled,
"TimerEnabled" to timerEnabled)

resultHandler?.success(resultDict)
resultHandler = null
return true
} else if (requestCode == this.SESSION_REQUEST_CODE && resultCode == Activity.RESULT_CANCELED) {
var error: String? = null
if (data != null) {
error = data.getStringExtra(KlippaScanner.ERROR)
}
if (error != null) {
Toast.makeText(context, "Scanner was canceled with error: $error", Toast.LENGTH_LONG).show()
println(error)
resultHandler?.error(E_CANCELED, "Scanner was canceled with error: $error", null)
} else {
Toast.makeText(context, "Scanner was canceled", Toast.LENGTH_LONG).show()
resultHandler?.error(E_CANCELED, "Scanner was canceled", null)
}
return false
}
Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.5.20'
ext.kotlin_version = '1.6.10'
repositories {
google()
jcenter()
Expand All @@ -25,7 +25,7 @@ allprojects {
maven { url "https://jitpack.io/" }
}
project.ext {
klippaScannerVersion = "2.0.3"
klippaScannerVersion = "2.0.6"
}
}

Expand Down
2 changes: 1 addition & 1 deletion ios/.sdk_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.7
0.4.10
18 changes: 16 additions & 2 deletions ios/Classes/SwiftKlippaScannerSdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, ImageScannerC
KlippaScanner.setup.previewDuration = previewDuration as? Double ?? 0
}

if let isTimerAllowed = builderArgs?["Timer.allowed"] {
KlippaScanner.setup.allowTimer = isTimerAllowed as? Bool ?? false
}

if let isTimerEnabled = builderArgs?["Timer.enabled"] {
KlippaScanner.setup.isTimerEnabled = isTimerEnabled as? Bool ?? false
}
Expand All @@ -95,7 +99,7 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, ImageScannerC
}

if let allowShutterButton = builderArgs?["ShutterButton.allowShutterButton"] {
if let hideShutterButton = builderArgs?["ShutterButton.hideShutterbutton"] {
if let hideShutterButton = builderArgs?["ShutterButton.hideShutterButton"] {
KlippaScanner.setup.set(allowShutterButton: allowShutterButton as? Bool ?? true, hideShutterButton: hideShutterButton as? Bool ?? false)
}
}
Expand All @@ -107,6 +111,10 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, ImageScannerC
if let imageTooDarkMessage = builderArgs?["ImageTooDarkMessage"] {
KlippaScanner.setup.imageTooDarkMessage = imageTooDarkMessage as? String ?? ""
}

if let imageLimitReachedMessage = builderArgs?["ImageLimitReachedMessage"] {
KlippaScanner.setup.imageLimitReachedMessage = imageLimitReachedMessage as? String ?? ""
}

if let primaryColor = builderArgs?["PrimaryColor"] {
let color = primaryColor as? String ?? ""
Expand Down Expand Up @@ -164,6 +172,10 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, ImageScannerC
KlippaScanner.setup.storeImagesToCameraRoll = storeImagesToCameraRoll as? Bool ?? true
}

if let imageLimit = builderArgs?["ImageLimit"] {
KlippaScanner.setup.imageLimit = imageLimit as? Int ?? 0
}

let rootViewController = UIApplication.shared.windows.last!.rootViewController!

let modelFile = builderArgs?["Model.fileName"] as? String ?? ""
Expand Down Expand Up @@ -205,7 +217,9 @@ public class SwiftKlippaScannerSdkPlugin: NSObject, FlutterPlugin, ImageScannerC

let resultDict = [
"Images" : images,
"MultipleDocuments" : result.multipleDocumentsModeEnabled
"MultipleDocuments" : result.multipleDocumentsModeEnabled,
"Crop": result.cropEnabled,
"TimerEnabled" : result.timerEnabled
] as [String : Any]

resultHandler!(resultDict)
Expand Down
2 changes: 1 addition & 1 deletion ios/klippa_scanner_sdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'klippa_scanner_sdk'
s.version = '0.0.1'
s.version = '0.0.2'
s.summary = 'Allows you to do document scanning with the Klippa Scanner SDK from Flutter apps.'
s.description = <<-DESC
Allows you to do document scanning with the Klippa Scanner SDK from Flutter apps.
Expand Down
Loading

0 comments on commit 3a9535a

Please sign in to comment.