|
@@ -0,0 +1,715 @@
|
|
|
+package com.sambath.sbc.base
|
|
|
+
|
|
|
+import android.animation.ValueAnimator
|
|
|
+import android.annotation.SuppressLint
|
|
|
+import android.os.Bundle
|
|
|
+import android.view.LayoutInflater
|
|
|
+import android.view.View
|
|
|
+import android.view.ViewGroup
|
|
|
+import android.widget.TextView
|
|
|
+import android.widget.Toast
|
|
|
+import androidx.annotation.LayoutRes
|
|
|
+import androidx.fragment.app.Fragment
|
|
|
+import com.cocking.fight.screen.dialogfragment.StatementDialogViewModel
|
|
|
+import com.mazenrashed.printooth.Printooth
|
|
|
+import com.mazenrashed.printooth.data.printable.Printable
|
|
|
+import com.mazenrashed.printooth.data.printable.TextPrintable
|
|
|
+import com.mazenrashed.printooth.data.printer.DefaultPrinter
|
|
|
+import com.mazenrashed.printooth.utilities.Printing
|
|
|
+import com.sambath.sbc.app.App
|
|
|
+import com.sambath.sbc.app.ShareActivity
|
|
|
+import com.sambath.sbc.remote.LottoSet
|
|
|
+import com.sambath.sbc.remote.ReportOne
|
|
|
+import com.sambath.sbc.remote.User
|
|
|
+import com.sambath.sbc.util.Const
|
|
|
+import com.sambath.sbc.util.ModelPreferencesManager
|
|
|
+import java.text.DecimalFormat
|
|
|
+import java.text.SimpleDateFormat
|
|
|
+import java.util.*
|
|
|
+
|
|
|
+abstract class BaseFragment(
|
|
|
+ @LayoutRes private val layoutRes: Int
|
|
|
+) : Fragment() {
|
|
|
+ private lateinit var user: User
|
|
|
+ private var printing: Printing? = null
|
|
|
+ override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
+ super.onCreate(savedInstanceState)
|
|
|
+ if (Printooth.hasPairedPrinter()) printing = Printooth.printer()
|
|
|
+ user = ModelPreferencesManager.get<User>(Const.USER_KEY)!!
|
|
|
+ }
|
|
|
+
|
|
|
+ fun currencyType() : String{
|
|
|
+ when (user.currencyType) {
|
|
|
+ 1 -> {//dollar
|
|
|
+ return "$"
|
|
|
+ }
|
|
|
+ 2 -> {//riel
|
|
|
+ return "៛"
|
|
|
+ }
|
|
|
+ 3 -> {//baht
|
|
|
+ return "฿"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onCreateView(
|
|
|
+ inflater: LayoutInflater,
|
|
|
+ container: ViewGroup?,
|
|
|
+ savedInstanceState: Bundle?
|
|
|
+ ): View? {
|
|
|
+ return inflater.inflate(layoutRes, container, false)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
+ super.onViewCreated(view, savedInstanceState)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun currencyFormat(amount: Int): String {
|
|
|
+ val formatter = DecimalFormat("#,###")
|
|
|
+ return formatter.format(amount)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun currencyFormatKh(amount: Double): String? {
|
|
|
+ val formatter = DecimalFormat("#,###")
|
|
|
+ return formatter.format(amount)
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("SimpleDateFormat")
|
|
|
+ open fun formatShowDate(showDate: Date): String {
|
|
|
+ val formatter = SimpleDateFormat(("dd/MM/yyyy HH:mm:ss"))
|
|
|
+ return formatter.format(showDate)
|
|
|
+ }
|
|
|
+
|
|
|
+ fun findLottoSet(lottoSet: List<LottoSet>, type_of_betting: String): LottoSet {
|
|
|
+
|
|
|
+ return lottoSet.find { type_of_betting == it.typeOfBetting }!!
|
|
|
+ }
|
|
|
+
|
|
|
+ fun animateTextView(initialValue: Int, finalValue: Int, textview: TextView): ValueAnimator {
|
|
|
+ val valueAnimator = ValueAnimator.ofInt(initialValue, finalValue)
|
|
|
+ valueAnimator.duration = 50
|
|
|
+ valueAnimator.addUpdateListener { animator ->
|
|
|
+ textview.text = animator.animatedValue.toString()
|
|
|
+ }
|
|
|
+ valueAnimator.start()
|
|
|
+
|
|
|
+ return valueAnimator
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ fun printSomePrintable(
|
|
|
+ userName: String,
|
|
|
+ ticketID: String,
|
|
|
+ gameID: String,
|
|
|
+ betDate: String,
|
|
|
+ betType: String,
|
|
|
+ betCast: String,
|
|
|
+ winLose: String
|
|
|
+ ) {
|
|
|
+ if (Printooth.hasPairedPrinter() && printing == null) printing = Printooth.printer()
|
|
|
+ if (printing == null) {
|
|
|
+ Toast.makeText(requireContext(), "No printing paired", Toast.LENGTH_SHORT).show()
|
|
|
+ } else {
|
|
|
+ val printables =
|
|
|
+ getSomePrintables(userName, ticketID, gameID, betDate, betType, betCast, winLose)
|
|
|
+ printing?.print(printables)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private fun getSomePrintables(
|
|
|
+ userName: String,
|
|
|
+ ticketID: String,
|
|
|
+ gameID: String,
|
|
|
+ betDate: String,
|
|
|
+ betType: String,
|
|
|
+ betCast: String,
|
|
|
+ winLose: String
|
|
|
+ ) = ArrayList<Printable>().apply {
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText(userName)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setAlignment(DefaultPrinter.ALIGNMENT_CENTER)
|
|
|
+ .setLineSpacing(DefaultPrinter.LINE_SPACING_30)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("----------------")
|
|
|
+ .setLineSpacing(DefaultPrinter.LINE_SPACING_30)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC1252)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Ticket ID: $ticketID")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Game ID : $gameID")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Date : $betDate")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Bet Type : $betType")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Bet Point: $betCast")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Win/Lose : $winLose")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("----------------")
|
|
|
+ .setLineSpacing(DefaultPrinter.LINE_SPACING_30)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("www.wa855.net")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setAlignment(DefaultPrinter.ALIGNMENT_CENTER)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC437)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ fun printCfPrintable(
|
|
|
+ userName: String,
|
|
|
+ fightNo: String,
|
|
|
+ betDate: String,
|
|
|
+ betType: String,
|
|
|
+ amount: String,
|
|
|
+ payout: String
|
|
|
+ ) {
|
|
|
+ if (Printooth.hasPairedPrinter() && printing == null) printing = Printooth.printer()
|
|
|
+ if (printing == null) {
|
|
|
+ Toast.makeText(requireContext(), "No printing paired", Toast.LENGTH_SHORT).show()
|
|
|
+ } else {
|
|
|
+ printing?.print(getCfPrintables(userName, fightNo, betDate, betType, amount, payout))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun printCfPrintable(
|
|
|
+ user: User,
|
|
|
+ fightNo: String,
|
|
|
+ betDate: String,
|
|
|
+ betType: String,
|
|
|
+ amount: String,
|
|
|
+ payoutRate: String,
|
|
|
+ payout: String,
|
|
|
+ id: String,
|
|
|
+ channelId: Int
|
|
|
+ ) {
|
|
|
+ if (Printooth.hasPairedPrinter() && printing == null) printing = Printooth.printer()
|
|
|
+ if (printing == null) {
|
|
|
+ Toast.makeText(requireContext(), "No printing paired", Toast.LENGTH_SHORT).show()
|
|
|
+ } else {
|
|
|
+ var currencyType: String = ""
|
|
|
+ when (user.currencyType) {
|
|
|
+ 1 -> {
|
|
|
+ currencyType = "Dollar"
|
|
|
+ }
|
|
|
+ 2 -> {
|
|
|
+ currencyType = "Riel"
|
|
|
+ }
|
|
|
+ 3 -> {
|
|
|
+ currencyType = "Baht"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ printing?.print(
|
|
|
+ getCfPrintables(
|
|
|
+ user.userName,
|
|
|
+ currencyType,
|
|
|
+ fightNo,
|
|
|
+ betDate,
|
|
|
+ betType,
|
|
|
+ amount,
|
|
|
+ payoutRate,
|
|
|
+ payout,
|
|
|
+ id,
|
|
|
+ channelId
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getCfPrintables(
|
|
|
+ userName: String,
|
|
|
+ currencyType: String,
|
|
|
+ fightNo: String,
|
|
|
+ betDate: String,
|
|
|
+ betType: String,
|
|
|
+ amount: String,
|
|
|
+ payoutRate: String,
|
|
|
+ payout: String,
|
|
|
+ id: String,
|
|
|
+ channelId: Int
|
|
|
+ ) = ArrayList<Printable>().apply {
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("SBC2888")
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setAlignment(DefaultPrinter.ALIGNMENT_CENTER)
|
|
|
+ .setLineSpacing(DefaultPrinter.LINE_SPACING_30)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Channel : $channelId")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Bet ID : ${id}")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("----------------")
|
|
|
+ .setLineSpacing(DefaultPrinter.LINE_SPACING_30)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC1252)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Fight No : $fightNo")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Account:")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText(userName)
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setAlignment(DefaultPrinter.ALIGNMENT_CENTER)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Bet Type : $betType")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Date : $betDate")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+// add(
|
|
|
+// TextPrintable.Builder()
|
|
|
+// .setText("Bet Point")
|
|
|
+// .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+// .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+// .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+// .setNewLinesAfter(1)
|
|
|
+// .build()
|
|
|
+// )
|
|
|
+// add(
|
|
|
+// TextPrintable.Builder()
|
|
|
+// .setText("$amount x $payoutRate")
|
|
|
+// .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+// .setAlignment(DefaultPrinter.ALIGNMENT_CENTER)
|
|
|
+// .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+// .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+// .setNewLinesAfter(1)
|
|
|
+// .build()
|
|
|
+// )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Currency Type : $currencyType")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Bet point : $payout")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("----------------")
|
|
|
+ .setLineSpacing(DefaultPrinter.LINE_SPACING_30)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("www.wa855.net")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setAlignment(DefaultPrinter.ALIGNMENT_CENTER)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC437)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getCfPrintables(
|
|
|
+ userName: String,
|
|
|
+ fightNo: String,
|
|
|
+ betDate: String,
|
|
|
+ betType: String,
|
|
|
+ amount: String,
|
|
|
+ payout: String
|
|
|
+ ) = ArrayList<Printable>().apply {
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("SBC2888")
|
|
|
+ .setUnderlined(DefaultPrinter.UNDERLINED_MODE_ON)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setAlignment(DefaultPrinter.ALIGNMENT_CENTER)
|
|
|
+ .setLineSpacing(DefaultPrinter.LINE_SPACING_30)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("----------------")
|
|
|
+ .setLineSpacing(DefaultPrinter.LINE_SPACING_10)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC1252)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Round : $fightNo")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Date : $betDate")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Account: $userName")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Type : $betType")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Bet x Odds:")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("$amount x $payout")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setAlignment(DefaultPrinter.ALIGNMENT_CENTER)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Payout : $amount")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("----------------")
|
|
|
+ .setLineSpacing(DefaultPrinter.LINE_SPACING_10)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("www.wa855.net")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setAlignment(DefaultPrinter.ALIGNMENT_CENTER)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC437)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getLastFourChars(str: String, n: Int): String {
|
|
|
+ var lastChars = str
|
|
|
+ if (lastChars.length > n) {
|
|
|
+ lastChars = lastChars.substring(lastChars.length - n, lastChars.length)
|
|
|
+ }
|
|
|
+ return lastChars
|
|
|
+ }
|
|
|
+
|
|
|
+ fun printSBCPrintable(reportOne: ReportOne, currencyType: Int, channelId: Int) {
|
|
|
+ if (Printooth.hasPairedPrinter() && printing == null) printing = Printooth.printer()
|
|
|
+ if (printing == null) {
|
|
|
+ Toast.makeText(requireContext(), "No printing paired", Toast.LENGTH_SHORT).show()
|
|
|
+ } else {
|
|
|
+ var winOrLose: String = ""
|
|
|
+ var sign: String = ""
|
|
|
+ winOrLose = if (reportOne.is_win == true) {
|
|
|
+ "WIN"
|
|
|
+ } else {
|
|
|
+ "LOSE"
|
|
|
+ }
|
|
|
+ when (currencyType) {
|
|
|
+ 1 -> {
|
|
|
+ sign = "Dollar"
|
|
|
+ }
|
|
|
+ 2 -> {
|
|
|
+ sign = "Riel"
|
|
|
+ }
|
|
|
+ 3 -> {
|
|
|
+ sign = "Baht"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ printing?.print(getSBCPrintables(reportOne, getLastFourChars(reportOne._id, 4), winOrLose, sign, channelId))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getSBCPrintables(
|
|
|
+ reportOne: ReportOne,
|
|
|
+ betId: String,
|
|
|
+ winLose: String,
|
|
|
+ currencyType: String,
|
|
|
+ channelId: Int
|
|
|
+ ) = ArrayList<Printable>().apply {
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("SBC2888")
|
|
|
+ .setUnderlined(DefaultPrinter.UNDERLINED_MODE_ON)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setAlignment(DefaultPrinter.ALIGNMENT_CENTER)
|
|
|
+ .setLineSpacing(DefaultPrinter.LINE_SPACING_30)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Channel : $channelId")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Bet ID : $betId")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("----------------")
|
|
|
+ .setLineSpacing(DefaultPrinter.LINE_SPACING_10)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC1252)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Fight No : ${reportOne.fightNo}")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Bet Type : ${reportOne.betName}")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Date : ${reportOne.date}")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Amount : ${reportOne.amount}")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Payout : ${reportOne.payout}")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Cast : ${reportOne.cast}")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Amount Win : ${reportOne.amountWin}")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Currency Type : $currencyType")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Result : ${reportOne.resultName}")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("Win/Lose : $winLose")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_SMALL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC850)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("----------------")
|
|
|
+ .setLineSpacing(DefaultPrinter.LINE_SPACING_10)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ add(
|
|
|
+ TextPrintable.Builder()
|
|
|
+ .setText("www.wa855.net")
|
|
|
+ .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
|
|
|
+ .setAlignment(DefaultPrinter.ALIGNMENT_CENTER)
|
|
|
+ .setFontSize(DefaultPrinter.FONT_SIZE_NORMAL)
|
|
|
+ .setCharacterCode(DefaultPrinter.CHARCODE_PC437)
|
|
|
+ .setNewLinesAfter(1)
|
|
|
+ .build()
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|