animation in host config
This commit is contained in:
parent
3811c04179
commit
999b26de2b
@ -1,5 +1,7 @@
|
||||
package com.utsmm.kbz.ui.management;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
@ -40,6 +42,8 @@ public class ReprintReceiptFragment extends DataBindingFragment {
|
||||
private static final String TAG = ReprintReceiptFragment.class.getSimpleName();
|
||||
|
||||
private PayDetail payDetail;
|
||||
private ObjectAnimator slideUpAnimator;
|
||||
private View printingCard;
|
||||
|
||||
@Override
|
||||
protected void initViewModel() {
|
||||
@ -76,6 +80,7 @@ public class ReprintReceiptFragment extends DataBindingFragment {
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
stopPrintingAnimation();
|
||||
|
||||
}
|
||||
|
||||
@ -105,7 +110,7 @@ public class ReprintReceiptFragment extends DataBindingFragment {
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
printingCard = mBinding.getRoot().findViewById(R.id.printingCard);
|
||||
}
|
||||
|
||||
private void updateUIPrintReceiptFailure(PayDetail payDetail) {
|
||||
@ -140,6 +145,7 @@ public class ReprintReceiptFragment extends DataBindingFragment {
|
||||
}
|
||||
|
||||
} else if (PrintHelper.getInstance().paperRollStatus() == SdkResult.Success) {
|
||||
startPrintingAnimation();
|
||||
printReceipt(payDetail);
|
||||
}
|
||||
}
|
||||
@ -195,17 +201,44 @@ public class ReprintReceiptFragment extends DataBindingFragment {
|
||||
private PrintXStatus printXStatus = new PrintXStatus() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
stopPrintingAnimation();
|
||||
delayFunctionCall(ReprintReceiptFragment.this::navigateMainScreen);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
stopPrintingAnimation();
|
||||
updateUIPrintReceiptFailure(payDetail);
|
||||
|
||||
// checkPaperExists(payDetail);
|
||||
}
|
||||
};
|
||||
|
||||
private void startPrintingAnimation() {
|
||||
if (printingCard == null) {
|
||||
return;
|
||||
}
|
||||
if (slideUpAnimator != null && slideUpAnimator.isRunning()) {
|
||||
return;
|
||||
}
|
||||
|
||||
slideUpAnimator = ObjectAnimator.ofFloat(printingCard, View.TRANSLATION_Y, 0f, -20f);
|
||||
slideUpAnimator.setDuration(420);
|
||||
slideUpAnimator.setRepeatMode(ValueAnimator.REVERSE);
|
||||
slideUpAnimator.setRepeatCount(ValueAnimator.INFINITE);
|
||||
slideUpAnimator.start();
|
||||
}
|
||||
|
||||
private void stopPrintingAnimation() {
|
||||
if (slideUpAnimator != null) {
|
||||
slideUpAnimator.cancel();
|
||||
slideUpAnimator = null;
|
||||
}
|
||||
if (printingCard != null) {
|
||||
printingCard.setTranslationY(0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private void navigateMainScreen() {
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
package com.utsmm.kbz.ui.settings;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -15,6 +19,8 @@ import com.utsmm.kbz.databinding.FragmentHostConfigBinding;
|
||||
import com.utsmm.kbz.ui.core_viewmodel.SharedViewModel;
|
||||
import com.utsmyanmar.baselib.fragment.DataBindingFragment;
|
||||
import com.utsmyanmar.baselib.util.DataBindingConfig;
|
||||
import com.utsmyanmar.paylibs.print.printx.PrintXReceipt;
|
||||
import com.utsmyanmar.paylibs.print.printx.PrintXStatus;
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
||||
|
||||
|
||||
@ -26,6 +32,9 @@ public class HostConfigFragment extends DataBindingFragment {
|
||||
protected Printer printer;
|
||||
int FONT_NORMAL = 20;
|
||||
int FONT_HEADER = 24;
|
||||
private ObjectAnimator rollUpAnimator;
|
||||
private View hostCardView;
|
||||
private volatile boolean isPrintingHostConfig = false;
|
||||
|
||||
@Override
|
||||
protected void initViewModel() {
|
||||
@ -45,6 +54,7 @@ public class HostConfigFragment extends DataBindingFragment {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
FragmentHostConfigBinding binding = (FragmentHostConfigBinding) this.binding;
|
||||
hostCardView = binding.getRoot().findViewById(R.id.hostCard);
|
||||
viewModel.loadConfig();
|
||||
}
|
||||
|
||||
@ -56,6 +66,13 @@ public class HostConfigFragment extends DataBindingFragment {
|
||||
sharedViewModel.printerDisabled.setValue(!SystemParamsOperation.getInstance().getPrinterEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
stopRollUpAnimation();
|
||||
isPrintingHostConfig = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int currentId() {
|
||||
return R.id.hostConfigFragment;
|
||||
@ -81,7 +98,72 @@ public class HostConfigFragment extends DataBindingFragment {
|
||||
showDeclineDialog("Printer is disabled!");
|
||||
return;
|
||||
}
|
||||
sharedViewModel.printTerminalHostConfigs();
|
||||
if (isPrintingHostConfig) {
|
||||
return;
|
||||
}
|
||||
startHostConfigPrint();
|
||||
}
|
||||
}
|
||||
|
||||
private void startHostConfigPrint() {
|
||||
isPrintingHostConfig = true;
|
||||
startRollUpAnimation();
|
||||
|
||||
PrintXReceipt.getInstance().printTerminalHostConfig(new PrintXStatus() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
isPrintingHostConfig = false;
|
||||
stopRollUpAnimation();
|
||||
Log.d("PrintConfig", "Print Terminal Config Success.");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure() {
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
isPrintingHostConfig = false;
|
||||
stopRollUpAnimation();
|
||||
Log.e("PrintConfig", "Print Terminal Config Failure.");
|
||||
showDeclineDialog("Failed to print host config.");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void startRollUpAnimation() {
|
||||
if (hostCardView == null) {
|
||||
return;
|
||||
}
|
||||
if (rollUpAnimator != null && rollUpAnimator.isRunning()) {
|
||||
return;
|
||||
}
|
||||
hostCardView.post(() -> {
|
||||
int cardTop = hostCardView.getTop();
|
||||
int cardHeight = hostCardView.getHeight();
|
||||
if (cardHeight <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Move past the top edge so the card fully leaves the screen.
|
||||
float offScreenDistance = cardTop + cardHeight + 80f;
|
||||
|
||||
rollUpAnimator = ObjectAnimator.ofFloat(hostCardView, View.TRANSLATION_Y, 0f, -offScreenDistance);
|
||||
rollUpAnimator.setDuration(2500);
|
||||
rollUpAnimator.setInterpolator(new LinearInterpolator());
|
||||
rollUpAnimator.setRepeatMode(ValueAnimator.RESTART);
|
||||
rollUpAnimator.setRepeatCount(ValueAnimator.INFINITE);
|
||||
rollUpAnimator.start();
|
||||
});
|
||||
}
|
||||
|
||||
private void stopRollUpAnimation() {
|
||||
if (rollUpAnimator != null) {
|
||||
rollUpAnimator.cancel();
|
||||
rollUpAnimator = null;
|
||||
}
|
||||
if (hostCardView != null) {
|
||||
hostCardView.setTranslationY(0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user