Skip to content

Commit e7d37de

Browse files
authored
Merge pull request #24 from evotor/develop
Discounts WIP
2 parents 16954ff + 70cf2bb commit e7d37de

File tree

8 files changed

+198
-83
lines changed

8 files changed

+198
-83
lines changed

app/build.gradle

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
33

4-
apply plugin: 'maven-publish'
5-
64
android {
75
compileSdkVersion 25
86
buildToolsVersion "25.0.2"
@@ -26,30 +24,4 @@ dependencies {
2624
}
2725
repositories {
2826
mavenCentral()
29-
}
30-
31-
32-
publishing {
33-
publications {
34-
35-
maven(MavenPublication) {
36-
groupId 'ru.evotor'
37-
artifactId "integration-library"
38-
version "1.0.16-dev"
39-
artifact "${project.buildDir}/outputs/aar/${project.archivesBaseName}-release.aar"
40-
41-
//generate pom nodes for dependencies
42-
pom.withXml {
43-
def dependenciesNode = asNode().appendNode('dependencies')
44-
configurations.compile.allDependencies.each { dependency ->
45-
if (dependency.group) {
46-
def dependencyNode = dependenciesNode.appendNode('dependency')
47-
dependencyNode.appendNode('groupId', dependency.group)
48-
dependencyNode.appendNode('artifactId', dependency.name)
49-
dependencyNode.appendNode('version', dependency.version)
50-
}
51-
}
52-
}
53-
}
54-
}
5527
}

app/src/main/java/ru/evotor/framework/core/action/command/edit_positions_command/EditPositionsCommand.java

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package ru.evotor.framework.core.action.command.open_receipt_command;
2+
3+
import android.content.ComponentName;
4+
import android.content.Context;
5+
import android.os.Bundle;
6+
import android.os.Handler;
7+
import android.os.Looper;
8+
import android.os.Parcelable;
9+
10+
import java.util.List;
11+
import java.util.Objects;
12+
13+
import ru.evotor.framework.Utils;
14+
import ru.evotor.framework.core.ICanStartActivity;
15+
import ru.evotor.framework.core.IntegrationManagerCallback;
16+
import ru.evotor.framework.core.IntegrationManagerImpl;
17+
import ru.evotor.framework.core.action.datamapper.ChangesMapper;
18+
import ru.evotor.framework.core.action.event.receipt.changes.IChange;
19+
import ru.evotor.framework.core.action.event.receipt.changes.position.PositionAdd;
20+
21+
/**
22+
* Created by a.kuznetsov on 26/04/2017.
23+
*/
24+
25+
public class OpenReceiptCommand {
26+
27+
public static final String NAME = "evo.v2.receipt.sell.openReceipt";
28+
private static final String KEY_CHANGES = "changes";
29+
30+
public static OpenReceiptCommand create(Bundle bundle) {
31+
Parcelable[] changesParcelable = bundle.getParcelableArray(KEY_CHANGES);
32+
return new OpenReceiptCommand(Utils.filterByClass(
33+
ChangesMapper.INSTANCE.create(changesParcelable),
34+
PositionAdd.class
35+
));
36+
}
37+
38+
private final List<PositionAdd> changes;
39+
40+
public OpenReceiptCommand(List<PositionAdd> changes) {
41+
this.changes = changes;
42+
}
43+
44+
public void process(final Context context, final ICanStartActivity activityStarter, IntegrationManagerCallback callback) {
45+
Objects.requireNonNull(activityStarter);
46+
Objects.requireNonNull(context);
47+
48+
List<ComponentName> componentNameList = IntegrationManagerImpl.convertImplicitIntentToExplicitIntent(NAME, context.getApplicationContext());
49+
if (componentNameList == null || componentNameList.isEmpty()) {
50+
return;
51+
}
52+
new IntegrationManagerImpl(context.getApplicationContext())
53+
.call(OpenReceiptCommand.NAME,
54+
55+
componentNameList.get(0),
56+
this.toBundle(),
57+
activityStarter,
58+
callback,
59+
new Handler(Looper.getMainLooper())
60+
);
61+
}
62+
63+
public Bundle toBundle() {
64+
Bundle bundle = new Bundle();
65+
Parcelable[] changesParcelable = new Parcelable[changes.size()];
66+
for (int i = 0; i < changesParcelable.length; i++) {
67+
IChange change = changes.get(i);
68+
changesParcelable[i] = ChangesMapper.INSTANCE.toBundle(change);
69+
}
70+
bundle.putParcelableArray(KEY_CHANGES, changesParcelable);
71+
return bundle;
72+
}
73+
74+
public List<PositionAdd> getChanges() {
75+
return changes;
76+
}
77+
}

app/src/main/java/ru/evotor/framework/core/action/command/edit_positions_command/EditPositionsCommandResult.java renamed to app/src/main/java/ru/evotor/framework/core/action/command/open_receipt_command/OpenReceiptCommandResult.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package ru.evotor.framework.core.action.command.edit_positions_command;
1+
package ru.evotor.framework.core.action.command.open_receipt_command;
22

33
import android.os.Bundle;
44

@@ -8,17 +8,18 @@
88
* Created by a.kuznetsov on 26/04/2017.
99
*/
1010

11-
public class EditPositionsCommandResult {
11+
public class OpenReceiptCommandResult {
1212

1313
private static final String KEY_RESULT = "result";
1414
private static final String KEY_ERROR_CODE = "errorCode";
1515

1616
public static final int ERROR_CODE_OK = 0;
17+
public static final int ERROR_CODE_RECEIPT_IS_ALREADY_OPEN = -1;
1718

18-
public static EditPositionsCommandResult create(Bundle bundle) {
19+
public static OpenReceiptCommandResult create(Bundle bundle) {
1920
String resultName = bundle.getString(KEY_RESULT);
2021

21-
return new EditPositionsCommandResult(
22+
return new OpenReceiptCommandResult(
2223
Utils.safeValueOf(Result.class, resultName, Result.UNKNOWN),
2324
bundle.getInt(KEY_ERROR_CODE, ERROR_CODE_OK)
2425
);
@@ -27,7 +28,7 @@ public static EditPositionsCommandResult create(Bundle bundle) {
2728
private final Result result;
2829
private final int errorCode;
2930

30-
public EditPositionsCommandResult(
31+
public OpenReceiptCommandResult(
3132
Result result,
3233
int errorCode
3334
) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package ru.evotor.framework.core.action.event.receipt.discount;
2+
3+
import android.os.Bundle;
4+
5+
import java.math.BigDecimal;
6+
7+
public class ReceiptDiscountEvent {
8+
private static final String TAG = "ReceiptDiscountEvent";
9+
10+
public static final String NAME = "evo.v2.receipt.sell.receiptDiscount";
11+
private static final String KEY_DISCOUNT = "discount";
12+
13+
public static ReceiptDiscountEvent create(Bundle bundle) {
14+
BigDecimal discount = new BigDecimal(bundle.getString(KEY_DISCOUNT, "0"));
15+
return new ReceiptDiscountEvent(discount);
16+
}
17+
18+
private BigDecimal discount;
19+
20+
public ReceiptDiscountEvent(BigDecimal discount) {
21+
this.discount = discount;
22+
}
23+
24+
public Bundle toBundle() {
25+
Bundle result = new Bundle();
26+
result.putString(KEY_DISCOUNT, discount.toPlainString());
27+
return result;
28+
}
29+
30+
public BigDecimal getDiscount() {
31+
return discount;
32+
}
33+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ru.evotor.framework.core.action.event.receipt.discount;
2+
3+
import ru.evotor.framework.core.IntegrationActivity;
4+
5+
public class ReceiptDiscountEventActivity extends IntegrationActivity {
6+
public void setIntegrationResult(ReceiptDiscountEventResult result) {
7+
setIntegrationResult(result == null ? null : result.toBundle());
8+
}
9+
10+
public ReceiptDiscountEvent getEvent() {
11+
return ReceiptDiscountEvent.create(getSourceBundle());
12+
}
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ru.evotor.framework.core.action.event.receipt.discount;
2+
3+
import android.os.Bundle;
4+
5+
import ru.evotor.framework.core.action.processor.ActionProcessor;
6+
7+
public abstract class ReceiptDiscountEventProcessor extends ActionProcessor {
8+
public ReceiptDiscountEventProcessor() {
9+
super(ReceiptDiscountEvent.NAME);
10+
}
11+
12+
@Override
13+
public void process(Bundle bundle, Callback callback) {
14+
call(ReceiptDiscountEvent.create(bundle), callback);
15+
}
16+
17+
public abstract void call(ReceiptDiscountEvent event, Callback callback);
18+
}
19+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package ru.evotor.framework.core.action.event.receipt.discount;
2+
3+
import android.os.Bundle;
4+
5+
import java.math.BigDecimal;
6+
7+
import ru.evotor.framework.Utils;
8+
9+
public class ReceiptDiscountEventResult {
10+
11+
private static final String KEY_RESULT = "result";
12+
private static final String KEY_DISCOUNT = "discount";
13+
14+
public static ReceiptDiscountEventResult create(Bundle bundle) {
15+
String resultName = bundle.getString(KEY_RESULT);
16+
BigDecimal discount = new BigDecimal(bundle.getString(KEY_DISCOUNT, "0"));
17+
return new ReceiptDiscountEventResult(
18+
Utils.safeValueOf(Result.class, resultName, Result.UNKNOWN),
19+
discount
20+
);
21+
}
22+
23+
private final Result result;
24+
private final BigDecimal discount;
25+
26+
public ReceiptDiscountEventResult(Result result, BigDecimal discount) {
27+
this.result = result;
28+
this.discount = discount;
29+
}
30+
31+
public Bundle toBundle() {
32+
Bundle bundle = new Bundle();
33+
bundle.putString(KEY_RESULT, result.name());
34+
bundle.putString(KEY_DISCOUNT, discount.toPlainString());
35+
return bundle;
36+
}
37+
38+
public BigDecimal getDiscount() {
39+
return discount;
40+
}
41+
42+
public Result getResult() {
43+
return result;
44+
}
45+
46+
public enum Result {
47+
OK,
48+
UNKNOWN;
49+
}
50+
}

0 commit comments

Comments
 (0)