Browse Source

Bug fixes

hbw_build
Wong Joon Hui 3 years ago
parent
commit
0d94a2d50d
  1. 21
      app/src/main/java/com/cst/im30/MainApplication.java
  2. 80
      app/src/main/java/com/cst/im30/activity/MainActivity.java
  3. 3
      app/src/main/java/com/cst/im30/activity/ResponseActivity.java
  4. 10
      app/src/main/java/com/cst/im30/api/RetrofitClient.java
  5. 14
      app/src/main/java/com/cst/im30/utility/PaymentUtils.java

21
app/src/main/java/com/cst/im30/MainApplication.java

@ -32,6 +32,11 @@ public class MainApplication extends Application {
public static AppCompatActivity currentActivity; public static AppCompatActivity currentActivity;
public static EchoClient paymentClient;
public static EchoClient icClient;
public static boolean paymentIsConnected = false;
public static boolean icIsConnected = false;
public static boolean working = false; public static boolean working = false;
public static String incomingCode = null; public static String incomingCode = null;
@ -57,6 +62,22 @@ public class MainApplication extends Application {
return instance; return instance;
} }
public EchoClient getPaymentClient() {
return paymentClient;
}
public void setPaymentClient(EchoClient paymentClient) {
this.paymentClient = paymentClient;
}
public EchoClient getIcClient() {
return icClient;
}
public void setIcClient(EchoClient icClient) {
this.icClient = icClient;
}
public static void reset() { public static void reset() {
working = false; working = false;
incomingCode = null; incomingCode = null;

80
app/src/main/java/com/cst/im30/activity/MainActivity.java

@ -10,7 +10,6 @@ import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
@ -54,10 +53,6 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
ImageView load; ImageView load;
AnimationDrawable animationDrawable; AnimationDrawable animationDrawable;
private EchoClient paymentClient;
private EchoClient icClient;
private boolean paymentIsConnected = false;
private boolean icIsConnected = false;
private String status; private String status;
@ -68,6 +63,7 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
ActivityResultLauncher<Intent> icVerificationLauncher = registerForActivityResult( ActivityResultLauncher<Intent> icVerificationLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(), new ActivityResultContracts.StartActivityForResult(),
result -> { result -> {
Logger.logV("Back from ICCActivity: " + result.getResultCode());
IDVerificationService service = new IDVerificationService(MainActivity.this); IDVerificationService service = new IDVerificationService(MainActivity.this);
if (result.getResultCode() == Activity.RESULT_OK) { if (result.getResultCode() == Activity.RESULT_OK) {
Intent incomingData = result.getData(); Intent incomingData = result.getData();
@ -105,15 +101,23 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
load = findViewById(R.id.loading_image_mt); load = findViewById(R.id.loading_image_mt);
//setupTextSlider(); //setupTextSlider();
initEchoClient();
connectEchoClient();
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (!MainApplication.icIsConnected) {
initEchoClientIC();
connectEchoClientIC();
}
if (!MainApplication.paymentIsConnected) {
initEchoClientPayment();
connectEchoClientPayment();
}
MainApplication.currentActivity = this; MainApplication.currentActivity = this;
Intent incomingIntent = getIntent(); Intent incomingIntent = getIntent();
@ -240,7 +244,7 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
} else if (Constants.PAY_FUNCTION_INQUIRY.equalsIgnoreCase(payFunction)) { } else if (Constants.PAY_FUNCTION_INQUIRY.equalsIgnoreCase(payFunction)) {
//handlePayFunctionPreAuth(eventLogDetailed); //handlePayFunctionPreAuth(eventLogDetailed);
} else if (Constants.PAY_FUNCTION_CANCEL.equalsIgnoreCase(payFunction)) { } else if (Constants.PAY_FUNCTION_CANCEL.equalsIgnoreCase(payFunction)) {
handlePayFunctionCancel(eventLogDetailed); handlePayFunctionCancel();
} else if (Constants.PAY_FUNCTION_SETTLEMENT.equalsIgnoreCase(payFunction)) { } else if (Constants.PAY_FUNCTION_SETTLEMENT.equalsIgnoreCase(payFunction)) {
//handlePayFunctionPreAuth(eventLogDetailed); //handlePayFunctionPreAuth(eventLogDetailed);
} else if (Constants.PAY_FUNCTION_SET_DATE_TIME.equalsIgnoreCase(payFunction)) { } else if (Constants.PAY_FUNCTION_SET_DATE_TIME.equalsIgnoreCase(payFunction)) {
@ -277,7 +281,7 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
} }
} }
private void handlePayFunctionCancel(EventLogDetailed eventLogDetailed) { private void handlePayFunctionCancel() {
CancelRequest request = new CancelRequest(); CancelRequest request = new CancelRequest();
initCancel(request); initCancel(request);
} }
@ -352,6 +356,8 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
if (cancelAction) { if (cancelAction) {
if (MainApplication.working && MainApplication.currentActivity instanceof ICCActivity) { if (MainApplication.working && MainApplication.currentActivity instanceof ICCActivity) {
((ICCActivity) MainApplication.currentActivity).cancel(); ((ICCActivity) MainApplication.currentActivity).cancel();
} else {
resetView();
} }
} else { } else {
if (MainApplication.working) { if (MainApplication.working) {
@ -575,35 +581,47 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
disconnectEchoClient(); disconnectEchoClientIC();
disconnectEchoClientPayment();
}
private void initEchoClientIC() {
Logger.logD("echoClient IC: " + BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT);
MainApplication.icClient = new EchoClient(this, BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT);
}
private void initEchoClientPayment() {
Logger.logD("echoClient Payment: " + BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT);
MainApplication.paymentClient = new EchoClient(this, BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT);
}
private void connectEchoClientIC() {
MainApplication.icClient.connect(this::onConnectSuccessIC, this::onConnectFailureIC);
} }
private void initEchoClient() { private void connectEchoClientPayment() {
Logger.logD("echoClient: " + BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT); MainApplication.paymentClient.connect(this::onConnectSuccessPayment, this::onConnectFailurePayment);
paymentClient = new EchoClient(this, BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT);
icClient = new EchoClient(this, BuildConfig.ECHO_SERVER_URL + ":" + BuildConfig.ECHO_SERVER_PORT);
} }
private void connectEchoClient() { private void disconnectEchoClientIC() {
paymentClient.connect(this::onConnectSuccessPayment, this::onConnectFailurePayment); MainApplication.icClient.disconnect();
icClient.connect(this::onConnectSuccessIC, this::onConnectFailureIC); MainApplication.icIsConnected = false;
Logger.logD("Disconnect EchoClient IC");
} }
private void disconnectEchoClient() { private void disconnectEchoClientPayment() {
paymentClient.disconnect(); MainApplication.paymentClient.disconnect();
paymentIsConnected = false; MainApplication.paymentIsConnected = false;
icClient.disconnect(); Logger.logD("Disconnect EchoClient Payment");
icIsConnected = false;
Logger.logD("Disconnect EchoClient");
} }
private void onConnectSuccessPayment(Object[] args) { private void onConnectSuccessPayment(Object[] args) {
paymentIsConnected = true; MainApplication.paymentIsConnected = true;
try { try {
String channelID = BuildConfig.SOCKET_PREFIX + BuildConfig.PAYMENT_CHANNEL_ID + BuildConfig.KIOSK_CODE; String channelID = BuildConfig.SOCKET_PREFIX + BuildConfig.PAYMENT_CHANNEL_ID + BuildConfig.KIOSK_CODE;
String eventType = BuildConfig.PAYMENT_EVENT_TYPE; String eventType = BuildConfig.PAYMENT_EVENT_TYPE;
EchoCallback echoCallback = this::receiveMessagePayment; EchoCallback echoCallback = this::receiveMessagePayment;
paymentClient.channel(channelID).listen(eventType, echoCallback); MainApplication.paymentClient.channel(channelID).listen(eventType, echoCallback);
Logger.logD("Listening to: " + eventType + " on " + channelID); Logger.logD("Listening to: " + eventType + " on " + channelID);
} catch (Exception ex) { } catch (Exception ex) {
Logger.logE("Error on contact: " + ex.getMessage()); Logger.logE("Error on contact: " + ex.getMessage());
@ -611,16 +629,17 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
} }
private void onConnectFailurePayment(Object[] args) { private void onConnectFailurePayment(Object[] args) {
paymentIsConnected = false; MainApplication.paymentIsConnected = false;
Logger.logW("Failed To Connect Payment");
} }
private void onConnectSuccessIC(Object[] args) { private void onConnectSuccessIC(Object[] args) {
icIsConnected = true; MainApplication.icIsConnected = true;
try { try {
String channelID = BuildConfig.SOCKET_PREFIX + BuildConfig.IC_CHANNEL_ID + BuildConfig.KIOSK_CODE; String channelID = BuildConfig.SOCKET_PREFIX + BuildConfig.IC_CHANNEL_ID + BuildConfig.KIOSK_CODE;
String eventType = BuildConfig.IC_EVENT_TYPE; String eventType = BuildConfig.IC_EVENT_TYPE;
EchoCallback echoCallback = this::receiveMessageIC; EchoCallback echoCallback = this::receiveMessageIC;
icClient.channel(channelID).listen(eventType, echoCallback); MainApplication.icClient.channel(channelID).listen(eventType, echoCallback);
Logger.logD("Listening to: " + eventType + " on " + channelID); Logger.logD("Listening to: " + eventType + " on " + channelID);
} catch (Exception ex) { } catch (Exception ex) {
Logger.logE("Error on contact: " + ex.getMessage()); Logger.logE("Error on contact: " + ex.getMessage());
@ -628,7 +647,8 @@ public class MainActivity extends AppCompatActivity implements CallableInterface
} }
private void onConnectFailureIC(Object[] args) { private void onConnectFailureIC(Object[] args) {
icIsConnected = false; MainApplication.icIsConnected = false;
Logger.logW("Failed To Connect IC");
} }
public void startWork() { public void startWork() {

3
app/src/main/java/com/cst/im30/activity/ResponseActivity.java

@ -314,7 +314,8 @@ public class ResponseActivity extends AppCompatActivity implements CallableInter
MainApplication.reset(); MainApplication.reset();
Intent intent = new Intent(ResponseActivity.this, MainActivity.class); Intent intent = new Intent(ResponseActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
if (showResult) { if (showResult) {
intent.setAction(Constants.INTENT_REFRESH); intent.setAction(Constants.INTENT_REFRESH);

10
app/src/main/java/com/cst/im30/api/RetrofitClient.java

@ -1,8 +1,18 @@
package com.cst.im30.api; package com.cst.im30.api;
import android.util.Log;
import androidx.annotation.NonNull;
import com.cst.im30.utility.Logger;
import java.io.IOException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit; import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory; import retrofit2.converter.scalars.ScalarsConverterFactory;

14
app/src/main/java/com/cst/im30/utility/PaymentUtils.java

@ -6,6 +6,8 @@ import com.cst.im30.model.SaleCompletionRequest;
import com.cst.im30.model.SaleRequest; import com.cst.im30.model.SaleRequest;
import com.cst.im30.model.VoidRequest; import com.cst.im30.model.VoidRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.DecimalFormat; import java.text.DecimalFormat;
public class PaymentUtils { public class PaymentUtils {
@ -65,7 +67,17 @@ public class PaymentUtils {
request.setPayAuthCode(eventLogDetailed.getPayAuthCode()); request.setPayAuthCode(eventLogDetailed.getPayAuthCode());
request.setPayRefNum(eventLogDetailed.getPayRefNum()); request.setPayRefNum(eventLogDetailed.getPayRefNum());
request.setToken(eventLogDetailed.getToken());
String token = eventLogDetailed.getToken();
try {
token = URLDecoder.decode(token, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Logger.logV("Token: " + token);
request.setToken(token);
return request; return request;
} }

Loading…
Cancel
Save