cahier fixed, now it send redirect-signal with amout to pinpad and recieve redirect-success
This commit is contained in:
parent
30055a1a14
commit
491fcb8d94
|
@ -3,31 +3,39 @@ package com.dspread.pos.ui.cashier;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.lifecycle.viewmodel.CreationExtras;
|
import androidx.lifecycle.viewmodel.CreationExtras;
|
||||||
|
|
||||||
import com.dspread.pos.common.base.BaseFragment;
|
import com.dspread.pos.common.base.BaseFragment;
|
||||||
import com.dspread.pos.TitleProviderListener;
|
import com.dspread.pos.TitleProviderListener;
|
||||||
import com.dspread.pos.ui.main.MainActivity;
|
|
||||||
import com.dspread.pos.ui.main.MainViewModel;
|
|
||||||
import com.dspread.pos.ui.mulberry.MulberryViewModel;
|
|
||||||
import com.dspread.pos_android_app.R;
|
import com.dspread.pos_android_app.R;
|
||||||
import com.dspread.pos_android_app.databinding.FragmentCashierBinding;
|
import com.dspread.pos_android_app.databinding.FragmentCashierBinding;
|
||||||
|
|
||||||
import com.dspread.pos_android_app.BR;
|
import com.dspread.pos_android_app.BR;
|
||||||
|
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class CashierFragment extends BaseFragment<FragmentCashierBinding, CashierViewModel >
|
public class CashierFragment extends BaseFragment<FragmentCashierBinding, CashierViewModel >
|
||||||
implements TitleProviderListener{
|
implements TitleProviderListener{
|
||||||
|
private EditText etAmountInput;
|
||||||
@Override
|
@Override
|
||||||
public void initViewObservable() {
|
public void initViewObservable() {
|
||||||
// Observe item click events
|
|
||||||
// Handle fragment navigation
|
|
||||||
|
|
||||||
// Observe payment info LiveData
|
// Observe payment info LiveData
|
||||||
viewModel.getPaymentInfo().observe(getViewLifecycleOwner(), paymentInfo -> {
|
viewModel.getPaymentInfo().observe(getViewLifecycleOwner(), paymentInfo -> {
|
||||||
|
@ -58,6 +66,109 @@ public class CashierFragment extends BaseFragment<FragmentCashierBinding, Cashie
|
||||||
return BR.viewModel;
|
return BR.viewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initData() {
|
||||||
|
super.initData();
|
||||||
|
|
||||||
|
// Setup amount input field
|
||||||
|
setupAmountInput();
|
||||||
|
}
|
||||||
|
private void setupAmountInput() {
|
||||||
|
// Find the EditText in layout
|
||||||
|
etAmountInput = binding.getRoot().findViewById(R.id.etAmountInput);
|
||||||
|
|
||||||
|
if (etAmountInput != null) {
|
||||||
|
// Request focus
|
||||||
|
etAmountInput.requestFocus();
|
||||||
|
|
||||||
|
// Add text watcher to update amount in real-time
|
||||||
|
etAmountInput.addTextChangedListener(new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
String input = s.toString().trim();
|
||||||
|
if (!input.isEmpty()) {
|
||||||
|
try {
|
||||||
|
// Convert cents to dollars and update ViewModel
|
||||||
|
double dollars = Double.parseDouble(input) / 100.0;
|
||||||
|
viewModel.amount.set(String.format("%.2f", dollars));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// Handle invalid input
|
||||||
|
viewModel.amount.set("0.00");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
viewModel.amount.set("0.00");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set up Enter key listener
|
||||||
|
etAmountInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
|
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||||
|
handleEnterPressed();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle physical keyboard Enter key
|
||||||
|
etAmountInput.setOnKeyListener(new View.OnKeyListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||||
|
if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
|
||||||
|
handleEnterPressed();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleEnterPressed() {
|
||||||
|
if (etAmountInput != null) {
|
||||||
|
String amount = etAmountInput.getText().toString().trim();
|
||||||
|
|
||||||
|
if (!amount.isEmpty()) {
|
||||||
|
try {
|
||||||
|
// Create JSON signal
|
||||||
|
JSONObject paymentData = new JSONObject();
|
||||||
|
paymentData.put("type", "redirect");
|
||||||
|
paymentData.put("amount", amount);
|
||||||
|
paymentData.put("currencySymbol", "$");
|
||||||
|
paymentData.put("id", "01534090202502210065");
|
||||||
|
paymentData.put("status", "signal");
|
||||||
|
|
||||||
|
// Send via WebSocket
|
||||||
|
viewModel.sendMessage(paymentData.toString());
|
||||||
|
|
||||||
|
// Reset input field
|
||||||
|
etAmountInput.setText("");
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("CashierFragment", "Error creating JSON", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
// Request focus when fragment resumes
|
||||||
|
if (etAmountInput != null) {
|
||||||
|
etAmountInput.requestFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public CreationExtras getDefaultViewModelCreationExtras() {
|
public CreationExtras getDefaultViewModelCreationExtras() {
|
||||||
|
|
|
@ -165,7 +165,6 @@ public class CashierViewModel extends BaseAppViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPaymentRedirected(String jsonString) {
|
protected void onPaymentRedirected(String jsonString) {
|
||||||
Log.d(TAG, "onPaymentRedirected - processing redirect payment");
|
Log.d(TAG, "onPaymentRedirected - processing redirect payment");
|
||||||
|
@ -202,4 +201,15 @@ public class CashierViewModel extends BaseAppViewModel {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Add this method to your existing CashierViewModel class:
|
||||||
|
public void sendMessage(String message) {
|
||||||
|
try {
|
||||||
|
sendWebSocketMessage(message);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Error sending WebSocket message", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,26 @@
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:padding="16dp">
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<!-- Real-time amount display -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@{viewModel.amount + ` ` + viewModel.currencyCode}"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:gravity="center"/>
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etAmountInput"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="numberDecimal"
|
||||||
|
android:hint="Enter amount"
|
||||||
|
android:imeOptions="actionDone"
|
||||||
|
android:maxLines="1"/>
|
||||||
|
|
||||||
<!-- Waiting State -->
|
<!-- Waiting State -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/waitingLayout"
|
android:id="@+id/waitingLayout"
|
||||||
|
@ -30,7 +50,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Please tap or scan QR code on M50 pinpad"
|
android:text="Enter amount for pinpad M50 to pay"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:gravity="center" />
|
android:gravity="center" />
|
||||||
|
@ -45,13 +65,13 @@
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:visibility="@{viewModel.paymentStatus == PaymentStatus.SUCCESS ? View.VISIBLE : View.GONE}">
|
android:visibility="@{viewModel.paymentStatus == PaymentStatus.SUCCESS ? View.VISIBLE : View.GONE}">
|
||||||
|
|
||||||
<TextView
|
<!-- <TextView-->
|
||||||
android:layout_width="wrap_content"
|
<!-- android:layout_width="wrap_content"-->
|
||||||
android:layout_height="wrap_content"
|
<!-- android:layout_height="wrap_content"-->
|
||||||
android:text="@{viewModel.amount + ` ` + viewModel.currencyCode}"
|
<!-- android:text="@{viewModel.amount + ` ` + viewModel.currencyCode}"-->
|
||||||
android:textSize="24sp"
|
<!-- android:textSize="24sp"-->
|
||||||
android:textStyle="bold"
|
<!-- android:textStyle="bold"-->
|
||||||
android:gravity="center" />
|
<!-- android:gravity="center" />-->
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Reference in New Issue