diff --git a/app/src/main/java/es/verdnatura/presentation/common/PrinterDialogManager.kt b/app/src/main/java/es/verdnatura/presentation/common/PrinterDialogManager.kt new file mode 100644 index 00000000..03049540 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/common/PrinterDialogManager.kt @@ -0,0 +1,69 @@ +package es.verdnatura.presentation.common + +import android.app.AlertDialog +import android.content.Context +import android.text.InputType +import android.view.View +import es.verdnatura.R +import es.verdnatura.presentation.view.component.CustomDialogList + +class PrinterDialogManager(private val context: Context) { + fun showPrintDialog( + item: Long, + itemName: String, + onPrintClick: (Long, String, Int?, Int) -> Unit + ) { + val customDialogList = CustomDialogList(context) + customDialogList.getEditText().setRawInputType(InputType.TYPE_CLASS_NUMBER) + customDialogList.getEditTextThree().setRawInputType(InputType.TYPE_CLASS_NUMBER) + + customDialogList.setTitle(context.getString(R.string.itemName, item, itemName)) + .setOkButton(context.getString(R.string.printQr)) { + handlePrintClick(item, customDialogList, onPrintClick, "qr") + } + .setOkTwoButton(context.getString(R.string.printBarcode)) { + handlePrintClick(item, customDialogList, onPrintClick, "barcode") + + } + .setKoButton(context.getString(R.string.cancel)) { + customDialogList.dismiss() + } + .setHintValueThree(context.getString(R.string.labelNumber)) + .setHintValue(context.getString(R.string.optionalPacking)) + .setTextThree(View.VISIBLE) + .show() + customDialogList.getFocusThree() + } + + private fun handlePrintClick( + item: Long, + customDialogList: CustomDialogList, + onPrintClick: (Long, String, Int?, Int) -> Unit, + labelType: String + ) { + onPrintClick( + item, + labelType, + if (customDialogList.getValue().isEmpty()) null else customDialogList.getValue() + .toInt(), + if (customDialogList.getValueOptional() + .isEmpty() + ) 1 else customDialogList.getValueOptional().toInt() + ) + customDialogList.dismiss() + } +} + +class LabelDialogHelper(private val context: Context) { + fun showLabelDialog( + onItemSelected: (Int) -> Unit, + ) { + val builder = AlertDialog.Builder(context) + builder.setTitle(context.getString(R.string.selectLabeltoPrint)) + val labelCount = Array(10) { (it + 1).toString() } + builder.setItems(labelCount) { _, which -> + onItemSelected(which + 1) + } + builder.create().show() + } +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/ShowTicketFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/ShowTicketFragment.kt index 37e22b5b..fd894712 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/ShowTicketFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/collection/fragment/ShowTicketFragment.kt @@ -1,6 +1,5 @@ package es.verdnatura.presentation.view.feature.collection.fragment -import android.app.AlertDialog import android.content.Context import android.graphics.drawable.Drawable import android.os.Bundle @@ -17,6 +16,7 @@ import es.verdnatura.domain.ConstAndValues.SECTORFK import es.verdnatura.domain.ConstAndValues.VERTICKET import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.LabelDialogHelper import es.verdnatura.presentation.common.OnMistakeClickListener import es.verdnatura.presentation.common.OnOptionsSelectedListener import es.verdnatura.presentation.common.OnPackingClickListener @@ -138,16 +138,20 @@ class CollectionShowTicketFragment( } } if (isTicket) { - val builder = AlertDialog.Builder(context) - builder.setTitle(getString(R.string.selectLabeltoPrint)) - val labelCount = arrayOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "10") - builder.setItems(labelCount) { dialog, which -> - viewModel.collectionStickerPrint( - collectionFk = collection.collectionFk, labelCount = (which + 1) - ) - } - val dialog = builder.create() - dialog.show() + val labelDialogHelper = LabelDialogHelper(requireContext()) + labelDialogHelper.showLabelDialog( + onItemSelected = { labelCount -> + viewModel.collectionStickerPrint( + collectionFk = collection.collectionFk, + labelCount = labelCount + ) + + (getString(R.string.Imprimiendo) + mobileApplication.dataStoreApp.readDataStoreKey( + PRINTERNAME + )).toast(requireContext()) + } + ) + } else { viewModel.collectionStickerPrint( diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt index 8aac834e..8e1d8961 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/login/fragment/LoginFragment.kt @@ -3,6 +3,7 @@ package es.verdnatura.presentation.view.feature.login.fragment import android.annotation.SuppressLint import android.content.Intent import android.net.Uri +import android.os.Bundle import android.provider.Settings import android.view.View.GONE import android.view.View.VISIBLE @@ -41,7 +42,7 @@ import kotlinx.coroutines.runBlocking import java.util.Date import kotlin.system.exitProcess -class LoginFragment(private var imageUri: Uri?) : +class LoginFragment() : BaseFragment(LoginViewModel::class) { private lateinit var customDialogInput: CustomDialogInput @@ -50,9 +51,23 @@ class LoginFragment(private var imageUri: Uri?) : private var workFormAdapter: WorkFormAdapter? = null private lateinit var customDialogList: CustomDialogList private lateinit var listForms: List + private var imageUri: Uri? = null companion object { - fun newInstance(imageUri: Uri?) = LoginFragment(imageUri) + private const val ARG_IMAGE_URI = "image_uri" + + fun newInstance(imageUri: Uri?): LoginFragment { + return LoginFragment().apply { + arguments = Bundle().apply { + putParcelable(ARG_IMAGE_URI, imageUri) + } + } + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + imageUri = arguments?.getParcelable(ARG_IMAGE_URI) } override fun getLayoutId(): Int = R.layout.fragment_login