animation in host config
This commit is contained in:
parent
3811c04179
commit
999b26de2b
@ -1,5 +1,7 @@
|
|||||||
package com.utsmm.kbz.ui.management;
|
package com.utsmm.kbz.ui.management;
|
||||||
|
|
||||||
|
import android.animation.ObjectAnimator;
|
||||||
|
import android.animation.ValueAnimator;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
@ -40,6 +42,8 @@ public class ReprintReceiptFragment extends DataBindingFragment {
|
|||||||
private static final String TAG = ReprintReceiptFragment.class.getSimpleName();
|
private static final String TAG = ReprintReceiptFragment.class.getSimpleName();
|
||||||
|
|
||||||
private PayDetail payDetail;
|
private PayDetail payDetail;
|
||||||
|
private ObjectAnimator slideUpAnimator;
|
||||||
|
private View printingCard;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initViewModel() {
|
protected void initViewModel() {
|
||||||
@ -76,6 +80,7 @@ public class ReprintReceiptFragment extends DataBindingFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
stopPrintingAnimation();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +110,7 @@ public class ReprintReceiptFragment extends DataBindingFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
printingCard = mBinding.getRoot().findViewById(R.id.printingCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUIPrintReceiptFailure(PayDetail payDetail) {
|
private void updateUIPrintReceiptFailure(PayDetail payDetail) {
|
||||||
@ -140,6 +145,7 @@ public class ReprintReceiptFragment extends DataBindingFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (PrintHelper.getInstance().paperRollStatus() == SdkResult.Success) {
|
} else if (PrintHelper.getInstance().paperRollStatus() == SdkResult.Success) {
|
||||||
|
startPrintingAnimation();
|
||||||
printReceipt(payDetail);
|
printReceipt(payDetail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,17 +201,44 @@ public class ReprintReceiptFragment extends DataBindingFragment {
|
|||||||
private PrintXStatus printXStatus = new PrintXStatus() {
|
private PrintXStatus printXStatus = new PrintXStatus() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess() {
|
public void onSuccess() {
|
||||||
|
stopPrintingAnimation();
|
||||||
delayFunctionCall(ReprintReceiptFragment.this::navigateMainScreen);
|
delayFunctionCall(ReprintReceiptFragment.this::navigateMainScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure() {
|
public void onFailure() {
|
||||||
|
stopPrintingAnimation();
|
||||||
updateUIPrintReceiptFailure(payDetail);
|
updateUIPrintReceiptFailure(payDetail);
|
||||||
|
|
||||||
// checkPaperExists(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")
|
@SuppressWarnings("ConstantConditions")
|
||||||
private void navigateMainScreen() {
|
private void navigateMainScreen() {
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
package com.utsmm.kbz.ui.settings;
|
package com.utsmm.kbz.ui.settings;
|
||||||
|
|
||||||
|
import android.animation.ObjectAnimator;
|
||||||
|
import android.animation.ValueAnimator;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.animation.LinearInterpolator;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -15,6 +19,8 @@ import com.utsmm.kbz.databinding.FragmentHostConfigBinding;
|
|||||||
import com.utsmm.kbz.ui.core_viewmodel.SharedViewModel;
|
import com.utsmm.kbz.ui.core_viewmodel.SharedViewModel;
|
||||||
import com.utsmyanmar.baselib.fragment.DataBindingFragment;
|
import com.utsmyanmar.baselib.fragment.DataBindingFragment;
|
||||||
import com.utsmyanmar.baselib.util.DataBindingConfig;
|
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;
|
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
||||||
|
|
||||||
|
|
||||||
@ -26,6 +32,9 @@ public class HostConfigFragment extends DataBindingFragment {
|
|||||||
protected Printer printer;
|
protected Printer printer;
|
||||||
int FONT_NORMAL = 20;
|
int FONT_NORMAL = 20;
|
||||||
int FONT_HEADER = 24;
|
int FONT_HEADER = 24;
|
||||||
|
private ObjectAnimator rollUpAnimator;
|
||||||
|
private View hostCardView;
|
||||||
|
private volatile boolean isPrintingHostConfig = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initViewModel() {
|
protected void initViewModel() {
|
||||||
@ -45,6 +54,7 @@ public class HostConfigFragment extends DataBindingFragment {
|
|||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
FragmentHostConfigBinding binding = (FragmentHostConfigBinding) this.binding;
|
FragmentHostConfigBinding binding = (FragmentHostConfigBinding) this.binding;
|
||||||
|
hostCardView = binding.getRoot().findViewById(R.id.hostCard);
|
||||||
viewModel.loadConfig();
|
viewModel.loadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +66,13 @@ public class HostConfigFragment extends DataBindingFragment {
|
|||||||
sharedViewModel.printerDisabled.setValue(!SystemParamsOperation.getInstance().getPrinterEnabled());
|
sharedViewModel.printerDisabled.setValue(!SystemParamsOperation.getInstance().getPrinterEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
stopRollUpAnimation();
|
||||||
|
isPrintingHostConfig = false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int currentId() {
|
protected int currentId() {
|
||||||
return R.id.hostConfigFragment;
|
return R.id.hostConfigFragment;
|
||||||
@ -81,7 +98,72 @@ public class HostConfigFragment extends DataBindingFragment {
|
|||||||
showDeclineDialog("Printer is disabled!");
|
showDeclineDialog("Printer is disabled!");
|
||||||
return;
|
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