fixed amount screen issues
This commit is contained in:
parent
ff9450a50c
commit
d76b48d4ca
File diff suppressed because one or more lines are too long
@ -28,6 +28,9 @@
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
|
||||
<!-- Permission for exact alarms on Android 12+ -->
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
|
||||
<!-- android:noHistory="true"-->
|
||||
<!-- android:excludeFromRecents="true"-->
|
||||
|
||||
|
||||
@ -4,11 +4,25 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.utsmyanmar.paylibs.utils.LogUtil;
|
||||
|
||||
public class AutoAlarmReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = AutoAlarmReceiver.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
LogUtil.d(TAG, "AutoAlarmReceiver triggered at: " + new java.util.Date().toString());
|
||||
|
||||
boolean isTestAlarm = intent.getBooleanExtra("TEST_ALARM", false);
|
||||
if (isTestAlarm) {
|
||||
LogUtil.d(TAG, "This is a test alarm - AutoAlarmReceiver is working correctly!");
|
||||
}
|
||||
|
||||
// Start the service to send the API request
|
||||
Intent serviceIntent = new Intent(context, AutoSettleService.class);
|
||||
context.startService(serviceIntent);
|
||||
|
||||
LogUtil.d(TAG, "AutoSettleService started");
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,7 +22,10 @@ import javax.inject.Inject;
|
||||
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
|
||||
import com.utsmyanmar.paylibs.isobuilder.builderx.ISOMsgX;
|
||||
import com.utsmyanmar.paylibs.utils.LogUtil;
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
||||
|
||||
@AndroidEntryPoint
|
||||
public class AutoSettleService extends Service {
|
||||
@ -72,218 +75,189 @@ public class AutoSettleService extends Service {
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
// Perform the Settlement request here
|
||||
// ...
|
||||
LogUtil.d(TAG, "<<<<<<<<<<<<<<< Auto Settlement Service Started >>>>>>>>>>>>>>>>.");
|
||||
|
||||
LogUtil.d(TAG,"<<<<<<<<<<<<<<< This action was called >>>>>>>>>>>>>>>>.");
|
||||
try {
|
||||
sendDataToViewModel("Hello there");
|
||||
createNotification();
|
||||
|
||||
if (SystemParamsOperation.getInstance().getSettlementStatus()) {
|
||||
performSettlement();
|
||||
} else {
|
||||
LogUtil.d(TAG, "Settlement is disabled in system parameters");
|
||||
stopSelf();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.e(TAG, "Error in onStartCommand: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
sendDataToViewModel("Hello there");
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
createNotification();
|
||||
private void performSettlement() {
|
||||
final ISOMsgX isoMsgX = new ISOMsgX.ISOMsgXBuilder(
|
||||
com.utsmyanmar.paylibs.isobuilder.builderx.ISOVersion.VERSION_1993,
|
||||
com.utsmyanmar.paylibs.isobuilder.ISOMode.BOTH_HEADER_TPDU,
|
||||
com.utsmyanmar.paylibs.utils.enums.HostName.BPC
|
||||
).build();
|
||||
|
||||
// Observer<List<PayDetail>> settleObserver = new Observer<List<PayDetail>>() {
|
||||
// @Override
|
||||
// public void onChanged(List<PayDetail> list) {
|
||||
//
|
||||
//
|
||||
// if(list == null || list.size() == 0) {
|
||||
// LogUtil.d(TAG, "Settle is null");
|
||||
// return;
|
||||
// }
|
||||
// LogUtil.d(TAG,"Size Settle : "+list.size());
|
||||
//
|
||||
// for (PayDetail pay:list) {
|
||||
// repository.deletePayDetail(pay);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
// };
|
||||
//
|
||||
//
|
||||
// repository.getSettlementPOS().observeForever(settleObserver);
|
||||
//
|
||||
// repository.getSettlementPOS().removeObserver(settleObserver);
|
||||
//
|
||||
// Observer<List<PayDetail>> deleteTransObserver = new Observer<List<PayDetail>>() {
|
||||
// @Override
|
||||
// public void onChanged(List<PayDetail> lists) {
|
||||
// if(lists == null || lists.size() == 0) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// LogUtil.d(TAG,"Size Delete Trans : "+lists.size());
|
||||
// for (PayDetail pay:lists) {
|
||||
// repository.deletePayDetail(pay);
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// repository.getDeleteTrans(SystemParamsOperation.getInstance().getCurrentBatchNum()).observeForever(deleteTransObserver);
|
||||
//
|
||||
// repository.getDeleteTrans(SystemParamsOperation.getInstance().getCurrentBatchNum()).removeObserver(deleteTransObserver);
|
||||
//
|
||||
//
|
||||
repository.getSettlementPOS().observeForever(list -> {
|
||||
int saleCount = 0;
|
||||
long saleAmount = 0L;
|
||||
int preCount = 0;
|
||||
long preAmount = 0L;
|
||||
int refundCount = 0;
|
||||
long refundAmount = 0L;
|
||||
int caCount = 0;
|
||||
long caAmount = 0L;
|
||||
|
||||
// try{
|
||||
// handler.post(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// // Create and show the dialog
|
||||
// AlertDialog.Builder builder = new AlertDialog.Builder(SmileSettleService.this);
|
||||
// builder.setTitle("Auto Settle!")
|
||||
// .setMessage("Settlement process is going to start!")
|
||||
// .setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// // Handle OK button click
|
||||
// dialog.dismiss(); // Dismiss the dialog
|
||||
// }
|
||||
// })
|
||||
// .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// // Handle Cancel button click
|
||||
// dialog.dismiss(); // Dismiss the dialog
|
||||
// }
|
||||
// });
|
||||
//
|
||||
//
|
||||
// AlertDialog dialog = builder.create();
|
||||
//// dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
//// dialog.show();
|
||||
// }
|
||||
// });
|
||||
// }catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
|
||||
if(com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation.getInstance().getSettlementStatus()) {
|
||||
final com.utsmyanmar.paylibs.isobuilder.builderx.ISOMsgX isoMsgX = new com.utsmyanmar.paylibs.isobuilder.builderx.ISOMsgX.ISOMsgXBuilder(
|
||||
com.utsmyanmar.paylibs.isobuilder.builderx.ISOVersion.VERSION_1993,
|
||||
com.utsmyanmar.paylibs.isobuilder.ISOMode.BOTH_HEADER_TPDU,
|
||||
com.utsmyanmar.paylibs.utils.enums.HostName.BPC
|
||||
).build();
|
||||
|
||||
repository.getSettlementPOS().observeForever(list -> {
|
||||
int saleCount = 0;
|
||||
long saleAmount = 0L;
|
||||
int preCount = 0;
|
||||
long preAmount = 0L;
|
||||
int refundCount = 0;
|
||||
long refundAmount = 0L;
|
||||
int caCount = 0;
|
||||
long caAmount = 0L;
|
||||
|
||||
if(list != null && !list.isEmpty()) {
|
||||
for (com.utsmyanmar.paylibs.model.PayDetail pay : list) {
|
||||
if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.SALE && !pay.isCanceled) {
|
||||
saleCount++;
|
||||
saleAmount += pay.getAmount();
|
||||
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.PRE_SALE_COMPLETE && !pay.isCanceled) {
|
||||
preCount++;
|
||||
preAmount += pay.getAmount();
|
||||
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.REFUND) {
|
||||
refundCount++;
|
||||
refundAmount += pay.getAmount();
|
||||
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.CASH_ADVANCE) {
|
||||
caCount++;
|
||||
caAmount += pay.getAmount();
|
||||
}
|
||||
if (list != null && !list.isEmpty()) {
|
||||
for (com.utsmyanmar.paylibs.model.PayDetail pay : list) {
|
||||
if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.SALE && !pay.isCanceled) {
|
||||
saleCount++;
|
||||
saleAmount += pay.getAmount();
|
||||
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.PRE_SALE_COMPLETE && !pay.isCanceled) {
|
||||
preCount++;
|
||||
preAmount += pay.getAmount();
|
||||
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.REFUND) {
|
||||
refundCount++;
|
||||
refundAmount += pay.getAmount();
|
||||
} else if (pay.getTransactionType() == com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.CASH_ADVANCE) {
|
||||
caCount++;
|
||||
caAmount += pay.getAmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
com.utsmyanmar.paylibs.model.TradeData tradeData = com.utsmyanmar.paylibs.utils.params.Params.newTrade(true);
|
||||
com.utsmyanmar.paylibs.model.PayDetail payDetail = tradeData.getPayDetail();
|
||||
com.utsmyanmar.paylibs.model.TradeData tradeData = com.utsmyanmar.paylibs.utils.params.Params.newTrade(true);
|
||||
com.utsmyanmar.paylibs.model.PayDetail payDetail = tradeData.getPayDetail();
|
||||
|
||||
String bitmap = com.utsmyanmar.paylibs.utils.iso_utils.BitmapConfig.BPC_SETTLEMENT;
|
||||
payDetail.setTransType(com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.name);
|
||||
payDetail.setTransactionType(com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.SETTLEMENT);
|
||||
payDetail.setProcessCode(com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.processCode);
|
||||
payDetail.setBatchNo(com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation.getInstance().getCurrentBatchNum());
|
||||
String bitmap = com.utsmyanmar.paylibs.utils.iso_utils.BitmapConfig.BPC_SETTLEMENT;
|
||||
payDetail.setTransType(com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.name);
|
||||
payDetail.setTransactionType(com.utsmyanmar.paylibs.utils.iso_utils.TransactionType.SETTLEMENT);
|
||||
payDetail.setProcessCode(com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.processCode);
|
||||
payDetail.setBatchNo(com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation.getInstance().getCurrentBatchNum());
|
||||
|
||||
com.utsmyanmar.paylibs.model.SettleData settleData = new com.utsmyanmar.paylibs.model.SettleData(
|
||||
saleCount,
|
||||
saleAmount,
|
||||
preCount,
|
||||
preAmount,
|
||||
refundCount,
|
||||
refundAmount,
|
||||
caCount,
|
||||
caAmount
|
||||
);
|
||||
payDetail.setSettleDataObj(settleData);
|
||||
com.utsmyanmar.paylibs.model.SettleData settleData = new com.utsmyanmar.paylibs.model.SettleData(
|
||||
saleCount,
|
||||
saleAmount,
|
||||
preCount,
|
||||
preAmount,
|
||||
refundCount,
|
||||
refundAmount,
|
||||
caCount,
|
||||
caAmount
|
||||
);
|
||||
payDetail.setSettleDataObj(settleData);
|
||||
|
||||
long totalAmount = saleAmount + preAmount + refundAmount + caAmount;
|
||||
String settlementData;
|
||||
if (refundAmount != 0L) {
|
||||
long creditTotal = saleAmount + preAmount + caAmount;
|
||||
long subTotal = creditTotal - refundAmount;
|
||||
if (subTotal < 0L) {
|
||||
settlementData = "D" + String.format(java.util.Locale.getDefault(), "%012d", Math.abs(subTotal));
|
||||
} else {
|
||||
settlementData = "C" + String.format(java.util.Locale.getDefault(), "%012d", subTotal);
|
||||
}
|
||||
long totalAmount = saleAmount + preAmount + refundAmount + caAmount;
|
||||
String settlementData;
|
||||
if (refundAmount != 0L) {
|
||||
long creditTotal = saleAmount + preAmount + caAmount;
|
||||
long subTotal = creditTotal - refundAmount;
|
||||
if (subTotal < 0L) {
|
||||
settlementData = "D" + String.format(java.util.Locale.getDefault(), "%012d", Math.abs(subTotal));
|
||||
} else {
|
||||
settlementData = "C" + String.format(java.util.Locale.getDefault(), "%012d", totalAmount);
|
||||
settlementData = "C" + String.format(java.util.Locale.getDefault(), "%012d", subTotal);
|
||||
}
|
||||
payDetail.setSettleData(settlementData);
|
||||
payDetail.setAmount(totalAmount);
|
||||
} else {
|
||||
settlementData = "C" + String.format(java.util.Locale.getDefault(), "%012d", totalAmount);
|
||||
}
|
||||
payDetail.setSettleData(settlementData);
|
||||
payDetail.setAmount(totalAmount);
|
||||
|
||||
tradeData.setPayDetail(payDetail);
|
||||
tradeData.setField60(com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation.getInstance().getCurrentBatchNum());
|
||||
tradeData.setPayDetail(payDetail);
|
||||
tradeData.setField60(com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation.getInstance().getCurrentBatchNum());
|
||||
|
||||
byte[] sendBytes = isoMsgX.buildISOPackets(tradeData, bitmap, com.utsmyanmar.paylibs.utils.MessageType.SETTLEMENT);
|
||||
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().enqueue(sendBytes, sendBytes.length, false, new com.utsmyanmar.paylibs.network.ISOCallback() {
|
||||
@Override
|
||||
public void onReceive(byte[] bytes, int length) {
|
||||
java.util.Map<String, com.utsmyanmar.paylibs.model.MsgField> responseMap = isoMsgX.parseISOPackets(bytes, length);
|
||||
if (responseMap != null) {
|
||||
String resultStr = "";
|
||||
try {
|
||||
resultStr = responseMap.get("F039").getDataStr();
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
payDetail.setIsNeedReversal(true);
|
||||
return;
|
||||
}
|
||||
payDetail.setTradeAnswerCode(resultStr);
|
||||
if (TextUtils.equals(resultStr, com.utsmyanmar.paylibs.Constant.ANSWER_CODE_ACCEPT) || TextUtils.equals(resultStr, com.utsmyanmar.paylibs.Constant.ANSWER_CODE_APPROVED)) {
|
||||
payDetail.setIsNeedReversal(false);
|
||||
} else if (TextUtils.equals(resultStr, "95") || TextUtils.equals(resultStr, "095")) {
|
||||
payDetail.setIsNeedReversal(true);
|
||||
}
|
||||
byte[] sendBytes = isoMsgX.buildISOPackets(tradeData, bitmap, com.utsmyanmar.paylibs.utils.MessageType.SETTLEMENT);
|
||||
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().enqueue(sendBytes, sendBytes.length, false, new com.utsmyanmar.paylibs.network.ISOCallback() {
|
||||
@Override
|
||||
public void onReceive(byte[] bytes, int length) {
|
||||
java.util.Map<String, com.utsmyanmar.paylibs.model.MsgField> responseMap = isoMsgX.parseISOPackets(bytes, length);
|
||||
if (responseMap != null) {
|
||||
String resultStr = "";
|
||||
try {
|
||||
resultStr = responseMap.get("F039").getDataStr();
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
payDetail.setIsNeedReversal(true);
|
||||
return;
|
||||
}
|
||||
payDetail.setTradeAnswerCode(resultStr);
|
||||
if (TextUtils.equals(resultStr, com.utsmyanmar.paylibs.Constant.ANSWER_CODE_ACCEPT) || TextUtils.equals(resultStr, com.utsmyanmar.paylibs.Constant.ANSWER_CODE_APPROVED)) {
|
||||
payDetail.setIsNeedReversal(false);
|
||||
} else if (TextUtils.equals(resultStr, "95") || TextUtils.equals(resultStr, "095")) {
|
||||
payDetail.setIsNeedReversal(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String msg) {
|
||||
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().switchIp();
|
||||
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().enqueue(sendBytes, sendBytes.length, false, this);
|
||||
}
|
||||
@Override
|
||||
public void onError(String msg) {
|
||||
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().switchIp();
|
||||
com.utsmyanmar.paylibs.network.ISOSocket.getInstance().enqueue(sendBytes, sendBytes.length, false, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
if(list != null && !list.isEmpty()) {
|
||||
for (com.utsmyanmar.paylibs.model.PayDetail p : list) {
|
||||
repository.deletePayDetail(p);
|
||||
}
|
||||
@Override
|
||||
public void onComplete() {
|
||||
LogUtil.d(TAG, "Auto settlement transaction completed successfully");
|
||||
|
||||
if (list != null && !list.isEmpty()) {
|
||||
for (com.utsmyanmar.paylibs.model.PayDetail p : list) {
|
||||
repository.deletePayDetail(p);
|
||||
}
|
||||
repository.insertPayDetail(payDetail);
|
||||
}
|
||||
repository.insertPayDetail(payDetail);
|
||||
|
||||
try {
|
||||
// Remove the non-serializable SettleData object before passing through Intent
|
||||
// Create a clean copy of PayDetail without the problematic SettleData object
|
||||
com.utsmyanmar.paylibs.model.PayDetail cleanPayDetail = new com.utsmyanmar.paylibs.model.PayDetail();
|
||||
cleanPayDetail.setTransType(payDetail.getTransType());
|
||||
cleanPayDetail.setTransactionType(payDetail.getTransactionType());
|
||||
cleanPayDetail.setProcessCode(payDetail.getProcessCode());
|
||||
cleanPayDetail.setBatchNo(payDetail.getBatchNo());
|
||||
cleanPayDetail.setSettleData(payDetail.getSettleData());
|
||||
cleanPayDetail.setAmount(payDetail.getAmount());
|
||||
cleanPayDetail.setTradeAnswerCode(payDetail.getTradeAnswerCode());
|
||||
cleanPayDetail.setIsNeedReversal(payDetail.getIsNeedReversal());
|
||||
// Note: Not setting SettleDataObj as it's not serializable
|
||||
|
||||
Intent uiIntent = new Intent(getApplicationContext(), com.utsmm.kbz.MainActivity.class);
|
||||
uiIntent.putExtra("AUTO_SETTLEMENT", true);
|
||||
uiIntent.putExtra("EXTRA_TRANSACTION_TYPE", com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.value);
|
||||
uiIntent.putExtra("EXTRA_PAY_DETAIL", payDetail);
|
||||
uiIntent.putExtra("EXTRA_PAY_DETAIL", cleanPayDetail);
|
||||
uiIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
startActivity(uiIntent);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return START_NOT_STICKY;
|
||||
LogUtil.d(TAG, "MainActivity started successfully with auto settlement result");
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtil.e(TAG, "Error starting MainActivity: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
||||
// Fallback: start MainActivity without the PayDetail extra
|
||||
try {
|
||||
Intent fallbackIntent = new Intent(getApplicationContext(), com.utsmm.kbz.MainActivity.class);
|
||||
fallbackIntent.putExtra("AUTO_SETTLEMENT", true);
|
||||
fallbackIntent.putExtra("EXTRA_TRANSACTION_TYPE", com.utsmyanmar.paylibs.utils.iso_utils.TransactionsType.SETTLEMENT.value);
|
||||
fallbackIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
startActivity(fallbackIntent);
|
||||
|
||||
LogUtil.d(TAG, "MainActivity started with fallback approach");
|
||||
|
||||
} catch (Exception fallbackException) {
|
||||
LogUtil.e(TAG, "Fallback also failed: " + fallbackException.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Stop the service
|
||||
stopSelf();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -101,33 +101,19 @@ public class InputAmountViewModel extends ViewModel {
|
||||
inputAmount.deleteCharAt(inputAmount.length() - 1);
|
||||
inputAmountView.setValue(inputAmount.toString());
|
||||
} else if (!inputAmountView.getValue().equals("0")) {
|
||||
StringBuilder inputAmount = new StringBuilder();
|
||||
inputAmount.append(inputAmountView.getValue());
|
||||
if (inputAmount.length() > 4) {
|
||||
String currentValue = inputAmountView.getValue();
|
||||
|
||||
if(inputAmount.toString().contains(",")) {
|
||||
int commaIndex = inputAmount.indexOf(",");
|
||||
inputAmount.deleteCharAt(commaIndex);
|
||||
} else {
|
||||
inputAmount.deleteCharAt(inputAmount.length() - 1);
|
||||
}
|
||||
inputAmountView.setValue(inputAmount.toString());
|
||||
String rawNumber = currentValue.replace(",", "");
|
||||
|
||||
if (rawNumber.length() > 1) {
|
||||
rawNumber = rawNumber.substring(0, rawNumber.length() - 1);
|
||||
|
||||
// inputAmount.deleteCharAt(inputAmount.toString().length() - 4);
|
||||
// if (inputAmount.charAt(inputAmount.toString().length() - 4) == ',') {
|
||||
// inputAmount.deleteCharAt(inputAmount.toString().length() - 4);
|
||||
// }
|
||||
// inputAmountView.setValue(inputAmount.toString());
|
||||
} else if(inputAmount.length() == 1) {
|
||||
inputAmountView.setValue("0");
|
||||
double amt = Double.parseDouble(rawNumber);
|
||||
DecimalFormat formatter = new DecimalFormat("#,###");
|
||||
inputAmountView.setValue(formatter.format(amt));
|
||||
} else {
|
||||
StringBuilder currentAmount = new StringBuilder();
|
||||
currentAmount.append(inputAmountView.getValue());
|
||||
currentAmount.deleteCharAt(currentAmount.length() - 1);
|
||||
inputAmountView.setValue(currentAmount.toString());
|
||||
inputAmountView.setValue("0");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
package com.utsmm.kbz.ui.tms;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
@ -27,6 +31,7 @@ import com.utsmm.kbz.util.enums.TMSDownloadStatus;
|
||||
import com.utsmm.kbz.util.tms.TMSUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||
@ -228,11 +233,14 @@ public class TMSProcessFragment extends DataBindingFragment {
|
||||
|
||||
private void scheduleAutoSettlement() {
|
||||
String timeStr = SystemParamsOperation.getInstance().getClearBatchTime();
|
||||
LogUtil.d(TAG,"timeStr:" + timeStr );
|
||||
if(timeStr == null || timeStr.trim().isEmpty()) {
|
||||
LogUtil.d(TAG, "Clear batch time is empty, skipping auto settlement scheduling");
|
||||
return;
|
||||
}
|
||||
String[] parts = timeStr.trim().split(":");
|
||||
if(parts.length != 2) {
|
||||
LogUtil.d(TAG, "Invalid time format: " + timeStr + ", expected HH:MM");
|
||||
return;
|
||||
}
|
||||
int hour;
|
||||
@ -240,34 +248,97 @@ public class TMSProcessFragment extends DataBindingFragment {
|
||||
try {
|
||||
hour = Integer.parseInt(parts[0]);
|
||||
minute = Integer.parseInt(parts[1]);
|
||||
|
||||
// Validate time range
|
||||
if (hour < 0 || hour > 23 || minute < 0 || minute > 59) {
|
||||
LogUtil.d(TAG, "Invalid time values - hour: " + hour + ", minute: " + minute);
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.d(TAG, "Error parsing time string: " + timeStr + ", error: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
android.app.AlarmManager alarmManager = (android.app.AlarmManager) requireContext().getSystemService(android.content.Context.ALARM_SERVICE);
|
||||
if(alarmManager == null) return;
|
||||
LogUtil.d(TAG, "Scheduling auto settlement for hour:" + hour + " minute:" + minute);
|
||||
AlarmManager alarmManager = (AlarmManager) requireContext().getSystemService(Context.ALARM_SERVICE);
|
||||
if (alarmManager == null) {
|
||||
LogUtil.d(TAG, "AlarmManager is null, cannot schedule alarm");
|
||||
return;
|
||||
}
|
||||
|
||||
java.util.Calendar calendar = java.util.Calendar.getInstance();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
calendar.set(java.util.Calendar.HOUR_OF_DAY, hour);
|
||||
calendar.set(java.util.Calendar.MINUTE, minute);
|
||||
calendar.set(java.util.Calendar.SECOND, 0);
|
||||
calendar.set(java.util.Calendar.MILLISECOND, 0);
|
||||
|
||||
long triggerAtMillis = calendar.getTimeInMillis();
|
||||
if(System.currentTimeMillis() > triggerAtMillis) {
|
||||
calendar.add(java.util.Calendar.DAY_OF_YEAR, 1);
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
LogUtil.d(TAG, "Current time: " + new java.util.Date(currentTime).toString());
|
||||
LogUtil.d(TAG, "Initial trigger time: " + new java.util.Date(triggerAtMillis).toString());
|
||||
|
||||
if (currentTime > triggerAtMillis) {
|
||||
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
||||
triggerAtMillis = calendar.getTimeInMillis();
|
||||
LogUtil.d(TAG, "Trigger time is in the past, scheduling for next day: " + new java.util.Date(triggerAtMillis).toString());
|
||||
}
|
||||
|
||||
android.content.Intent intent = new android.content.Intent(requireContext(), AutoAlarmReceiver.class);
|
||||
android.app.PendingIntent pendingIntent = android.app.PendingIntent.getBroadcast(
|
||||
Intent intent = new Intent(requireContext(), AutoAlarmReceiver.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(
|
||||
requireContext(),
|
||||
1001,
|
||||
intent,
|
||||
android.app.PendingIntent.FLAG_UPDATE_CURRENT
|
||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
|
||||
);
|
||||
|
||||
alarmManager.setRepeating(android.app.AlarmManager.RTC_WAKEUP, triggerAtMillis, android.app.AlarmManager.INTERVAL_DAY, pendingIntent);
|
||||
try {
|
||||
// For Android 12+ (API 31+), we need to handle exact alarms differently
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
// Check if the app can schedule exact alarms
|
||||
if (alarmManager.canScheduleExactAlarms()) {
|
||||
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, AlarmManager.INTERVAL_DAY, pendingIntent);
|
||||
LogUtil.d(TAG, "Auto settlement alarm scheduled successfully for: " + new java.util.Date(triggerAtMillis).toString());
|
||||
} else {
|
||||
LogUtil.d(TAG, "App doesn't have permission to schedule exact alarms. Using inexact alarm.");
|
||||
// Use inexact alarm as fallback
|
||||
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, AlarmManager.INTERVAL_DAY, pendingIntent);
|
||||
LogUtil.d(TAG, "Auto settlement inexact alarm scheduled for: " + new java.util.Date(triggerAtMillis).toString());
|
||||
}
|
||||
} else {
|
||||
// For older Android versions
|
||||
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, AlarmManager.INTERVAL_DAY, pendingIntent);
|
||||
LogUtil.d(TAG, "Auto settlement alarm scheduled successfully for: " + new java.util.Date(triggerAtMillis).toString());
|
||||
}
|
||||
|
||||
// Also try to schedule a test alarm 30 seconds from now for debugging
|
||||
long testTriggerTime = currentTime + 30000; // 30 seconds from now
|
||||
Intent testIntent = new Intent(requireContext(), AutoAlarmReceiver.class);
|
||||
testIntent.putExtra("TEST_ALARM", true);
|
||||
PendingIntent testPendingIntent = PendingIntent.getBroadcast(
|
||||
requireContext(),
|
||||
1002,
|
||||
testIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
|
||||
);
|
||||
|
||||
// Schedule test alarm
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
|
||||
if (alarmManager.canScheduleExactAlarms()) {
|
||||
alarmManager.setExact(AlarmManager.RTC_WAKEUP, testTriggerTime, testPendingIntent);
|
||||
} else {
|
||||
alarmManager.set(AlarmManager.RTC_WAKEUP, testTriggerTime, testPendingIntent);
|
||||
}
|
||||
} else {
|
||||
alarmManager.set(AlarmManager.RTC_WAKEUP, testTriggerTime, testPendingIntent);
|
||||
}
|
||||
LogUtil.d(TAG, "Test alarm scheduled for: " + new java.util.Date(testTriggerTime).toString());
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtil.d(TAG, "Error scheduling alarm: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -285,8 +285,8 @@ public class NetworkModule {
|
||||
tmsAddress = getTMSUrlFromNative();
|
||||
}
|
||||
|
||||
// String baseUrl = tmsAddress.trim() + "/api/v1/";
|
||||
String baseUrl = tmsAddress.trim() + "/";
|
||||
String baseUrl = tmsAddress.trim() + "/api/v1/";
|
||||
// String baseUrl = tmsAddress.trim() + "/";
|
||||
|
||||
final Gson gson =
|
||||
new GsonBuilder().create();
|
||||
|
||||
@ -42,8 +42,8 @@ public class SystemParamsSettings implements Serializable {
|
||||
|
||||
// private String tmsAddress = "https://tms.smile-mm.com";
|
||||
// private String tmsAddress = "http://128.199.170.203";
|
||||
// private String tmsAddress = "http://sirius-nest.utsmyanmar.com";
|
||||
private String tmsAddress = "https://api-tms-uat.kbzbank.com:8443/sirius";
|
||||
private String tmsAddress = "http://sirius-nest.utsmyanmar.com";
|
||||
// private String tmsAddress = "https://api-tms-uat.kbzbank.com:8443/sirius";
|
||||
private String ereceiptAddress = "http://receipt-nest.utsmyanmar.com";
|
||||
|
||||
private String terminalCapability = "E0E8C8";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user