diff --git a/Examples/Example-Java/app/build.gradle b/Examples/Example-Java/app/build.gradle index dd0f41d..0bae8c3 100644 --- a/Examples/Example-Java/app/build.gradle +++ b/Examples/Example-Java/app/build.gradle @@ -37,7 +37,7 @@ android { } dependencies { - implementation 'com.izettle.payments:android-sdk-ui:1.36.1' + implementation 'com.izettle.payments:android-sdk-ui:1.36.7' implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.4.2' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0' diff --git a/Examples/Example-Java/app/src/main/java/com/izettle/payments/android/java_example/CardReaderActivity.java b/Examples/Example-Java/app/src/main/java/com/izettle/payments/android/java_example/CardReaderActivity.java index ca62474..f705636 100644 --- a/Examples/Example-Java/app/src/main/java/com/izettle/payments/android/java_example/CardReaderActivity.java +++ b/Examples/Example-Java/app/src/main/java/com/izettle/payments/android/java_example/CardReaderActivity.java @@ -18,6 +18,7 @@ import androidx.lifecycle.MutableLiveData; import com.google.android.material.snackbar.Snackbar; +import com.izettle.payments.android.payment.TippingStyle; import com.izettle.payments.android.payment.TransactionReference; import com.izettle.payments.android.payment.refunds.CardPaymentPayload; import com.izettle.payments.android.payment.refunds.RefundsManager; @@ -39,10 +40,11 @@ public class CardReaderActivity extends AppCompatActivity { private EditText refundAmountEditText; private Button settingsButton; private EditText amountEditText; - private CheckBox tippingCheckBox; + private Button tippingStyleButton; private CheckBox installmentsCheckBox; private CheckBox loginCheckBox; private MutableLiveData lastPaymentTraceId; + private TippingStyle tippingStyle = TippingStyle.None; @Override public void onCreate(Bundle savedInstanceState) { @@ -53,7 +55,7 @@ public void onCreate(Bundle savedInstanceState) { settingsButton = findViewById(R.id.settings_btn); amountEditText = findViewById(R.id.amount_input); refundAmountEditText = findViewById(R.id.refund_amount_input); - tippingCheckBox = findViewById(R.id.tipping_check_box); + tippingStyleButton = findViewById(R.id.tipping_style_btn); loginCheckBox = findViewById(R.id.login_check_box); installmentsCheckBox = findViewById(R.id.installments_check_box); lastPaymentTraceId = new MutableLiveData<>(); @@ -63,6 +65,15 @@ public void onCreate(Bundle savedInstanceState) { chargeButton.setOnClickListener(v -> onChargeClicked()); refundButton.setOnClickListener(v -> onRefundClicked()); settingsButton.setOnClickListener(v -> onSettingsClicked()); + tippingStyleButton.setOnClickListener(v -> onTippingStyleClicked()); + + setTippingStyleTitle(); + + getSupportFragmentManager().setFragmentResultListener(TippingStyleBottomSheet.REQUEST_KEY, this, (requestKey, result) -> { + TippingStyle newTippingStyle = (TippingStyle) result.getSerializable(TippingStyleBottomSheet.TIPPING_STYLE_KEY); + tippingStyle = newTippingStyle != null ? newTippingStyle : TippingStyle.None; + setTippingStyleTitle(); + }); } private final ActivityResultLauncher paymentLauncher = registerForActivityResult(new StartActivityForResult(), result -> { @@ -107,7 +118,7 @@ private void onChargeClicked() { } String internalTraceId = UUID.randomUUID().toString(); long amount = parseLong(amountEditText.getText()); - boolean enableTipping = tippingCheckBox.isChecked(); + TippingStyle tippingStyle = this.tippingStyle; boolean enableInstallments = installmentsCheckBox.isChecked(); boolean enableLogin = loginCheckBox.isChecked(); TransactionReference reference = new TransactionReference.Builder(internalTraceId) @@ -118,7 +129,7 @@ private void onChargeClicked() { .amount(amount) .reference(reference) .enableInstalments(enableInstallments) - .enableTipping(enableTipping) + .enableTipping(tippingStyle) .enableLogin(enableLogin) .build(); @@ -145,6 +156,15 @@ private void onRefundClicked() { ); } + private void onTippingStyleClicked() { + TippingStyleBottomSheet.newInstance().show(getSupportFragmentManager(), TippingStyleBottomSheet.class.getSimpleName()); + } + + private void setTippingStyleTitle() { + String tippingStyleTitle = "Tipping Style - " + tippingStyle.name(); + tippingStyleButton.setText(tippingStyleTitle); + } + private class RefundCallback implements RefundsManager.Callback { private final Long amount; diff --git a/Examples/Example-Java/app/src/main/java/com/izettle/payments/android/java_example/TippingStyleBottomSheet.java b/Examples/Example-Java/app/src/main/java/com/izettle/payments/android/java_example/TippingStyleBottomSheet.java new file mode 100644 index 0000000..6aac1be --- /dev/null +++ b/Examples/Example-Java/app/src/main/java/com/izettle/payments/android/java_example/TippingStyleBottomSheet.java @@ -0,0 +1,55 @@ +package com.izettle.payments.android.java_example; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import com.google.android.material.bottomsheet.BottomSheetDialogFragment; +import com.izettle.payments.android.payment.TippingStyle; + +public class TippingStyleBottomSheet extends BottomSheetDialogFragment { + + private View styleNoneView; + private View styleDefaultView; + private View styleAmountView; + private View stylePercentView; + + public static final String REQUEST_KEY = "TippingStyleBottomSheetRC"; + public static final String TIPPING_STYLE_KEY = "TippingStyleKey"; + + public static TippingStyleBottomSheet newInstance() { + return new TippingStyleBottomSheet(); + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_tipping_style, container, false); + styleNoneView = view.findViewById(R.id.tipping_style_none); + styleDefaultView = view.findViewById(R.id.tipping_style_default); + styleAmountView = view.findViewById(R.id.tipping_style_amount); + stylePercentView = view.findViewById(R.id.tipping_style_percent); + + return view; + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + styleNoneView.setOnClickListener(v -> setResultAndExit(TippingStyle.None)); + styleDefaultView.setOnClickListener(v -> setResultAndExit(TippingStyle.Default)); + styleAmountView.setOnClickListener(v -> setResultAndExit(TippingStyle.Amount)); + stylePercentView.setOnClickListener(v -> setResultAndExit(TippingStyle.Percentage)); + } + + private void setResultAndExit(TippingStyle tippingStyle) { + Bundle bundle = new Bundle(); + bundle.putSerializable(TIPPING_STYLE_KEY, tippingStyle); + + getParentFragmentManager().setFragmentResult(REQUEST_KEY, bundle); + dismiss(); + } +} diff --git a/Examples/Example-Java/app/src/main/res/layout/activity_card_reader.xml b/Examples/Example-Java/app/src/main/res/layout/activity_card_reader.xml index cb57c89..80bf246 100644 --- a/Examples/Example-Java/app/src/main/res/layout/activity_card_reader.xml +++ b/Examples/Example-Java/app/src/main/res/layout/activity_card_reader.xml @@ -60,14 +60,6 @@ android:layout_height="wrap_content" android:orientation="horizontal"> - - +