Skip to content

Commit

Permalink
first working android version
Browse files Browse the repository at this point in the history
  • Loading branch information
edavism committed Jun 2, 2024
0 parents commit c0b4a98
Show file tree
Hide file tree
Showing 95 changed files with 2,988 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
build/
36 changes: 36 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "a14f74ff3a1cbd521163c5f03d68113d50af93d3"
channel: "stable"

project_type: plugin

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
- platform: android
create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
- platform: ios
create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
- platform: web
create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Add your license here.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# flutter_khipu

A new Flutter plugin project.

## Getting Started

This project is a starting point for a Flutter
[plug-in package](https://flutter.dev/developing-packages/),
a specialized package that includes platform-specific implementation code for
Android and/or iOS.

For help getting started with Flutter development, view the
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.

4 changes: 4 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
9 changes: 9 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.cxx
69 changes: 69 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
group = "com.khipu.flutter_khipu"
version = "1.0-SNAPSHOT"

buildscript {
ext.kotlin_version = "1.7.10"
repositories {
google()
mavenCentral()
}

dependencies {
classpath("com.android.tools.build:gradle:7.3.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: "com.android.library"
apply plugin: "kotlin-android"

android {
if (project.android.hasProperty("namespace")) {
namespace = "com.khipu.flutter_khipu"
}

compileSdk = 34

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}

sourceSets {
main.java.srcDirs += "src/main/kotlin"
test.java.srcDirs += "src/test/kotlin"
}

defaultConfig {
minSdk = 21
}

dependencies {
implementation 'com.khipu:khipu-client-android:+'
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.mockito:mockito-core:5.0.0")
}

testOptions {
unitTests.all {
useJUnitPlatform()

testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen {false}
showStandardStreams = true
}
}
}
}
1 change: 1 addition & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'flutter_khipu'
3 changes: 3 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.khipu.flutter_khipu">
</manifest>
177 changes: 177 additions & 0 deletions android/src/main/kotlin/com/khipu/flutter_khipu/FlutterKhipuPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package com.khipu.flutter_khipu

import android.app.Activity
import android.content.Intent
import com.khipu.client.KHIPU_RESULT_EXTRA
import com.khipu.client.KhipuColors
import com.khipu.client.KhipuOptions
import com.khipu.client.KhipuResult
import com.khipu.client.getKhipuLauncherIntent

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.PluginRegistry

class FlutterKhipuPlugin : FlutterPlugin, MethodCallHandler, PluginRegistry.ActivityResultListener,
ActivityAware {

private lateinit var channel: MethodChannel
private var activity: Activity? = null
private lateinit var result: Result
private val KHIPU_START_OPERATION_CODE = 101010

override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "flutter_khipu")
channel.setMethodCallHandler(this)
}

override fun onMethodCall(call: MethodCall, result: Result) {
if (call.method == "startOperation") {
return startOperation(call, result)
} else {
result.notImplemented()
}
}

fun startOperation(call: MethodCall, result: Result) {
this.result = result

if (!call.hasArgument("operationId")) {
result.error("MISSING_OPERATION_ID", "OperationId is required", null)
return
}

val operationId = call.argument<String>("operationId")!!

val optionsBuilder = KhipuOptions.Builder()

call.argument<String>("title")?.let {
optionsBuilder.topBarTitle = it
}

call.argument<String>("locale")?.let {
optionsBuilder.locale = it
}

call.argument<Boolean>("skipExitPage")?.let {
optionsBuilder.skipExitPage = it
}

call.argument<String>("theme")?.let {
if (it == "light") {
optionsBuilder.theme = KhipuOptions.Theme.LIGHT
} else if (it == "dark") {
optionsBuilder.theme = KhipuOptions.Theme.DARK
} else if (it == "system") {
optionsBuilder.theme = KhipuOptions.Theme.SYSTEM
}
}

val colorsBuilder = KhipuColors.Builder()

call.argument<String>("lightPrimary")?.let {
colorsBuilder.lightPrimary = it
}
call.argument<String>("lightOnPrimary")?.let {
colorsBuilder.lightOnPrimary = it
}
call.argument<String>("lightBackground")?.let {
colorsBuilder.lightBackground = it
}
call.argument<String>("lightOnBackground")?.let {
colorsBuilder.lightOnBackground = it
}
call.argument<String>("lightTopBarContainer")?.let {
colorsBuilder.lightTopBarContainer = it
}
call.argument<String>("lightOnTopBarContainer")?.let {
colorsBuilder.lightOnTopBarContainer = it
}
call.argument<String>("darkPrimary")?.let {
colorsBuilder.darkPrimary = it
}
call.argument<String>("darkOnPrimary")?.let {
colorsBuilder.darkOnPrimary = it
}
call.argument<String>("darkBackground")?.let {
colorsBuilder.darkBackground = it
}
call.argument<String>("darkOnBackground")?.let {
colorsBuilder.darkOnBackground = it
}
call.argument<String>("darkTopBarContainer")?.let {
colorsBuilder.darkTopBarContainer = it
}
call.argument<String>("darkOnTopBarContainer")?.let {
colorsBuilder.darkOnTopBarContainer = it
}
optionsBuilder.colors = colorsBuilder.build()


val intent = activity?.let {
getKhipuLauncherIntent(
context = it.baseContext,
operationId = operationId,
options = optionsBuilder.build()
)

}
activity?.startActivityForResult(intent, KHIPU_START_OPERATION_CODE)
}


override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
if (requestCode == KHIPU_START_OPERATION_CODE) {
if (data != null) {
val khipuResult = data.getSerializableExtra(KHIPU_RESULT_EXTRA) as KhipuResult

val resultMap = HashMap<String, Any>()
resultMap["operationId"] = khipuResult.operationId
resultMap["result"] = khipuResult.result
resultMap["exitTitle"] = khipuResult.exitTitle
resultMap["exitMessage"] = khipuResult.exitMessage
khipuResult.exitUrl?.let { resultMap["exitUrl"] = it }
khipuResult.failureReason?.let { resultMap["failureReason"] = it }
khipuResult.continueUrl?.let { resultMap["continueUrl"] = it }
resultMap["events"] = khipuResult.events.map { event ->
hashMapOf(
"name" to event.name,
"type" to event.type,
"timestamp" to event.timestamp
)
}
result.success(resultMap)
return true
}
}
return false
}


override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}

override fun onAttachedToActivity(binding: ActivityPluginBinding) {
activity = binding.activity
binding.addActivityResultListener(this)
}

override fun onDetachedFromActivityForConfigChanges() {
activity = null
}

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
activity = binding.activity
binding.addActivityResultListener(this)
}

override fun onDetachedFromActivity() {
activity = null
}
}
Loading

0 comments on commit c0b4a98

Please sign in to comment.