Skip to content

Commit c4ddd96

Browse files
authored
Merge pull request #1 from xcam/master
Initial commit
2 parents e2e4be8 + 592fbbb commit c4ddd96

33 files changed

+799
-0
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
codeiris
2+
*.iml
3+
.gradle
4+
/local.properties
5+
/.idea/workspace.xml
6+
/.idea/libraries
7+
.DS_Store
8+
/build
9+
/captures
10+
/.idea
11+
*/build
12+
gradle.properties
13+
projectFilesBackup/

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apply plugin: 'com.android.library'
2+
apply plugin: 'kotlin-android'
3+
4+
android {
5+
compileSdkVersion 25
6+
buildToolsVersion "25.0.2"
7+
defaultConfig {
8+
minSdkVersion 22
9+
targetSdkVersion 25
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25+
exclude group: 'com.android.support', module: 'support-annotations'
26+
})
27+
compile 'com.android.support:appcompat-v7:25.2.0'
28+
testCompile 'junit:junit:4.12'
29+
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
30+
}
31+
repositories {
32+
mavenCentral()
33+
}

app/proguard-rules.pro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/a.kuznetsov/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile

app/src/main/AndroidManifest.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
3+
package="ru.evotor.integrations">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
13+
</application>
14+
15+
</manifest>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package ru.evotor.integrations
2+
3+
import android.os.Bundle
4+
import android.os.Message
5+
6+
/**
7+
* Created by nixan on 01.03.17.
8+
*/
9+
10+
sealed class Event(val eventId: Int) {
11+
12+
open fun toMessage() = Message.obtain().apply {
13+
what = eventId
14+
data = Bundle()
15+
}
16+
17+
sealed class Receipt(eventId: Int) : Event(eventId) {
18+
19+
class Opened(val receiptId: Long) : Receipt(EVENT_RECEIPT_OPENED) {
20+
override fun toMessage() = super.toMessage().apply { data.putLong("receiptId", receiptId) }
21+
}
22+
23+
class ProductAdded(val receiptId: Long, val productUuid: String) : Receipt(EVENT_RECEIPT_PRODUCT_ADDED) {
24+
override fun toMessage() = super.toMessage().apply {
25+
data.putLong("receiptId", receiptId)
26+
data.putString("productUuid", productUuid)
27+
}
28+
}
29+
30+
class ProductRemoved(val receiptId: Long, val productUuid: String) : Receipt(EVENT_RECEIPT_PRODUCT_REMOVED) {
31+
override fun toMessage() = super.toMessage().apply {
32+
data.putLong("receiptId", receiptId)
33+
data.putString("productUuid", productUuid)
34+
}
35+
}
36+
37+
class Closed(val isSellOperation: Boolean) : Receipt(EVENT_RECEIPT_CLOSED) {
38+
override fun toMessage() = super.toMessage().apply { data.putBoolean("isSellOperation", isSellOperation) }
39+
}
40+
41+
class Deleted(val receiptId: Long) : Receipt(EVENT_RECEIPT_DELETED) {
42+
override fun toMessage() = super.toMessage().apply { data.putLong("receiptId", receiptId) }
43+
}
44+
45+
}
46+
47+
companion object {
48+
49+
const val EVENT_RECEIPT_OPENED = 100
50+
const val EVENT_RECEIPT_CLOSED = 101
51+
const val EVENT_RECEIPT_DELETED = 102
52+
const val EVENT_RECEIPT_PRODUCT_ADDED = 103
53+
const val EVENT_RECEIPT_PRODUCT_REMOVED = 104
54+
55+
fun fromMessage(message: Message) = when (message.what) {
56+
EVENT_RECEIPT_OPENED -> Receipt.Opened(message.data.getLong("receiptId", 0))
57+
EVENT_RECEIPT_PRODUCT_ADDED -> Receipt.ProductAdded(message.data.getLong("receiptId", 0), message.data.getString("productUuid"))
58+
EVENT_RECEIPT_PRODUCT_REMOVED -> Receipt.ProductRemoved(message.data.getLong("receiptId", 0), message.data.getString("productUuid"))
59+
EVENT_RECEIPT_CLOSED -> Receipt.Closed(message.data.getBoolean("isSellOperation", false))
60+
EVENT_RECEIPT_DELETED -> Receipt.Deleted(message.data.getLong("receiptId", 0))
61+
else -> throw UnknownEventException("${message.what} - ${message.data} is unknown")
62+
}
63+
}
64+
65+
}
66+
67+
sealed class PluginEvent(val eventId: Int) {
68+
69+
open fun toMessage() = Message.obtain().apply {
70+
what = eventId
71+
data = Bundle()
72+
}
73+
74+
sealed class Payment(eventId: Int) : PluginEvent(eventId) {
75+
76+
class Start : Payment(EVENT_PAYMENT_START)
77+
class ReadyToPrint : Payment(EVENT_PAYMENT_READY_TO_PRINT)
78+
79+
}
80+
81+
companion object {
82+
83+
const val EVENT_PAYMENT_START = 100
84+
const val EVENT_PAYMENT_READY_TO_PRINT = 101
85+
86+
fun fromMessage(message: Message) = when (message.what) {
87+
EVENT_PAYMENT_START -> Payment.Start()
88+
EVENT_PAYMENT_READY_TO_PRINT -> Payment.ReadyToPrint()
89+
else -> throw UnknownEventException("${message.what} - ${message.data} is unknown")
90+
}
91+
}
92+
93+
}
94+
95+
//class PluginEventWrapper(val pluginEvent: PluginEvent, val messenger: Messenger) {
96+
// fun toIntent() = pluginEvent.toIntent().apply { putExtra("callback", messenger) }
97+
//
98+
// companion object {
99+
// fun fromIntent(intent: Intent) = PluginEventWrapper(PluginEvent.fromIntent(intent), intent.getParcelableExtra("callback"))
100+
// }
101+
//}
102+
103+
class UnknownEventException(error: String) : Exception(error)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package ru.evotor.integrations
2+
3+
import android.os.Handler
4+
import android.os.Message
5+
6+
/**
7+
* Created by nixan on 09.03.17.
8+
*/
9+
10+
sealed class IntegrationCallbackMessage(val resultCode: Int) {
11+
12+
class Success : IntegrationCallbackMessage(100)
13+
14+
class Error : IntegrationCallbackMessage(200)
15+
16+
class InProgress : IntegrationCallbackMessage(300)
17+
18+
companion object {
19+
20+
fun fromMessage(message: Message): IntegrationCallbackMessage {
21+
return when (message.what) {
22+
100 -> Success()
23+
200 -> Error()
24+
300 -> InProgress()
25+
else -> throw UnknownResultException()
26+
}
27+
}
28+
29+
fun toMessage(callbackMessage: IntegrationCallbackMessage): Message {
30+
return Message.obtain().apply {
31+
what = callbackMessage.resultCode
32+
}
33+
}
34+
35+
}
36+
37+
class UnknownResultException : Exception()
38+
}
39+
40+
class IntegrationCallbackHandler(val onSuccess: () -> Unit, val onError: () -> Unit, val onInProgress: () -> Unit) : Handler() {
41+
42+
override fun handleMessage(msg: Message) {
43+
super.handleMessage(msg)
44+
val callbackMessage = IntegrationCallbackMessage.fromMessage(msg)
45+
when (callbackMessage) {
46+
is IntegrationCallbackMessage.Success -> onSuccess.invoke()
47+
is IntegrationCallbackMessage.Error -> onError.invoke()
48+
is IntegrationCallbackMessage.InProgress -> onInProgress.invoke()
49+
}
50+
}
51+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.evotor.integrations
2+
3+
import android.net.Uri
4+
import java.math.BigDecimal
5+
6+
/**
7+
* Created by nixan on 06.03.17.
8+
*/
9+
10+
val INVENTORY_URI: Uri = Uri.parse("content://ru.evotor.evotorpos.inventory/Commodity")
11+
12+
data class Product(val uuid: String, val productName: String, val price: BigDecimal, val quantity: BigDecimal, val description: String?)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ru.evotor.integrations
2+
3+
import android.net.Uri
4+
import java.math.BigDecimal
5+
6+
/**
7+
* Created by nixan on 06.03.17.
8+
*/
9+
10+
val CURRENT_RECEIPT_URI: Uri = Uri.parse("content://ru.evotor.evotorpos.receipt/sell")
11+
val CURRENT_RECEIPT_ITEMS_URI: Uri = Uri.parse("content://ru.evotor.evotorpos.receipt/sellReceiptPositions")
12+
val CURRENT_RECEIPT_PAYMENTS_URI: Uri = Uri.parse("content://ru.evotor.evotorpos.receipt/sellReceiptPayments")
13+
14+
class Receipt(val uuid: String) {
15+
16+
}
17+
18+
data class ReceiptApiObject(val uuid: String, val number: Long, val totalSum: BigDecimal, val discount: BigDecimal, val originalTotalSum: BigDecimal, val positionDiscountSum: BigDecimal, val positionsCount: Int)
19+
20+
data class ReceiptItemApiObject(val uuid: String, val type: String, val code: String, val measure: String, val price: BigDecimal, val priceWithDiscount: BigDecimal, val quantity: BigDecimal, val barcode: String, val mark: String)
21+
22+
data class ReceiptPaymentApiObject(val uuid: String, val amount: BigDecimal)
23+
24+
sealed class PrintGroupApiObject(val uuid: String) {
25+
26+
class FiscalReceipt(uuid: String) : PrintGroupApiObject(uuid)
27+
28+
class NonFiscalReceipt(uuid: String, val organizationName: String, val organizationVat: String) : PrintGroupApiObject(uuid)
29+
30+
class SimplifiedTaxationSystemReceipt(uuid: String, val organizationName: String, val organizationVat: String) : PrintGroupApiObject(uuid)
31+
32+
}

0 commit comments

Comments
 (0)