private fun joinGamePopup(gameJoin: JoinGameModel,position:Int) { val dialog = Dialog(context) dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.window?.let { window -> window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog.setContentView(R.layout.popup_join_game) val lp = WindowManager.LayoutParams() lp.copyFrom(window.attributes) lp.width = WindowManager.LayoutParams.MATCH_PARENT lp.height = WindowManager.LayoutParams.MATCH_PARENT lp.gravity = Gravity.CENTER lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE lp.windowAnimations = R.style.DialogAnimation window.attributes = lp dialog.setCancelable(false) dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) paymentInfo(dialog.cardnumTv,dialog.switchTv,dialog.addPaymentTv,dialog.paymentLL,dialog.cardIv) dialog.spotTv.text = gameJoin.spotLeft dialog.date_timeTv.text = gameJoin.gameDay+"\n"+gameJoin.date_time dialog.addressTv.text = gameJoin.location val d = gameJoin.cost!!.toDouble() var count:Int=0 var Playercount:Int=1 if (d.rem(1).compareTo(0) == 1){ // true it contains decimal value dialog.amountTv.text = "$${gameJoin.cost}" dialog.playernumTv.text = "$${gameJoin.cost} x ${Playercount} players" }else{ // false not contain decimal value dialog.amountTv.text = "$${gameJoin.cost.toString().replace(".0","")}" dialog.playernumTv.text = "$${gameJoin.cost.toString().replace(".0","")} x ${Playercount} players" } dialog.moreIv.setOnClickListener { paymentProcessPopup() } dialog.plusIv.setOnClickListener { count = count+1 Playercount = Playercount+1 var Plcount = count+gameJoin.players.size if (Plcount>gameJoin.max_player_count){ }else{ dialog.friendcountTv.text = ""+count if (d.rem(1).compareTo(0) == 1){ // true it contains decimal value dialog.playernumTv.text = "$${gameJoin.cost} x ${Playercount} players" dialog.amountTv.text = "$${"%.2f".format(gameJoin.cost!!.toDouble()!!*(Playercount))}" }else{ // false not contain decimal value dialog.playernumTv.text = "$${gameJoin.cost.toString().replace(".0","")} x ${Playercount} players" dialog.amountTv.text = "$${gameJoin.cost.toString().replace(".0","")!!.toInt()!!*(Playercount)}" } } } dialog.minusIv.setOnClickListener { if (count >0 ){ count = count-1 Playercount = Playercount-1 dialog.friendcountTv.text = ""+count if (d.rem(1).compareTo(0) == 1){ // true it contains decimal value dialog.playernumTv.text = "$${gameJoin.cost}x ${Playercount} players" dialog.amountTv.text = "$${"%.2f".format(gameJoin.cost!!.toDouble()!!*(Playercount))}" }else{ // false not contain decimal value dialog.playernumTv.text = "$${gameJoin.cost.toString().replace(".0","")} x ${Playercount} players" dialog.amountTv.text = "$${gameJoin.cost.toString().replace(".0","")!!.toInt()!!*(Playercount)}" } } } dialog.addPaymentTv.setOnClickListener { dialog.dismiss() val intent= Intent(context,PaymentActivity::class.java) startActivity(intent) context?.overridePendingTransition(R.anim.slide_in, R.anim.slide_out) } dialog.switchTv.setOnClickListener { dialog.dismiss() val intent= Intent(context,PaymentActivity::class.java) startActivity(intent) context?.overridePendingTransition(R.anim.slide_in, R.anim.slide_out) } dialog.joingameTv.setOnClickListener { if (isPaymentAdded){ joinGame(gameJoin.id,count,dialog,position) }else{ context?.alert("You must have a card on file to join a game", "Error") { positiveButton("Ok"){ } }?.show().apply { this?.getButton(AlertDialog.BUTTON_POSITIVE)?.let { context?.resources?.getColor(R.color.colorPrimary)?.let { it1 -> it.setTextColor(it1) } } } } } dialog.cancelgameTv.setOnClickListener { dialog.dismiss() } dialog.show() //show payment popup if first tym joining val firstTimeLogin = sharedPreference.getBoolanValue(SHARED_PREF_ISFIRST, true) if (firstTimeLogin) { handler.postDelayed({ paymentProcessPopup() }, 1000) } } }