diff --git a/ART/Home.jpg b/ART/Home.jpg new file mode 100644 index 0000000..0fb9661 Binary files /dev/null and b/ART/Home.jpg differ diff --git a/SeatBookView/src/main/java/dev/jahidhasanco/seatbookview/SeatBookView.kt b/SeatBookView/src/main/java/dev/jahidhasanco/seatbookview/SeatBookView.kt index a1ec814..f967830 100644 --- a/SeatBookView/src/main/java/dev/jahidhasanco/seatbookview/SeatBookView.kt +++ b/SeatBookView/src/main/java/dev/jahidhasanco/seatbookview/SeatBookView.kt @@ -10,7 +10,6 @@ import android.view.View import android.view.ViewGroup import android.widget.LinearLayout import android.widget.TextView -import android.widget.Toast import androidx.core.content.withStyledAttributes @@ -20,15 +19,7 @@ constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs) { private lateinit var viewGroupLayout: ViewGroup - private var seats = ( - "/UU_RR" + - "/AA_AA" + - "/UA_AR" + - "/AA_AA" + - "/AA_AU" + - "/RA_AA" + - "/AA_AA" + - "/AAAAA") + private var seats = "" private var title = listOf() @@ -44,8 +35,8 @@ constructor(context: Context, attrs: AttributeSet? = null) : private var count = 0 private var seatViewList: ArrayList = arrayListOf() - private var seatSize = 300 - private var seatGaping = 10 + private var seatSize = 100 + private var seatGaping = 0 private var layout_padding = 0 private val STATUS_AVAILABLE = 1 @@ -74,6 +65,7 @@ constructor(context: Context, attrs: AttributeSet? = null) : private var listener: SeatClickListener? = null + private var listenerLong: SeatLongClickListener? = null init { @@ -161,7 +153,6 @@ constructor(context: Context, attrs: AttributeSet? = null) : 5 ) + 1) - (layout_padding * seatGaping) - Toast.makeText(context, "$seatSize", Toast.LENGTH_SHORT).show() } } @@ -377,6 +368,10 @@ constructor(context: Context, attrs: AttributeSet? = null) : seatClick(it) } + view.setOnLongClickListener { + seatLongClick(it) + } + } fun markAsBooked(view: TextView) { @@ -408,19 +403,14 @@ constructor(context: Context, attrs: AttributeSet? = null) : if (view.id in selectedIdList) { selectedIdList.remove(view.id) view.setBackgroundResource(bookDrawable) - listener!!.onAvailableSeatClick(selectedIdList, view) selectedSeats-- + listener!!.onAvailableSeatClick(selectedIdList, view) } else { if (selectedSeats < selectSeatLimit) { selectedIdList.add(view.id) view.setBackgroundResource(selectedDrawable) - listener!!.onAvailableSeatClick(selectedIdList, view) selectedSeats++ - Toast.makeText( - context, - "You Can Not select Seat more than $selectSeatLimit", - Toast.LENGTH_SHORT - ).show() + listener!!.onAvailableSeatClick(selectedIdList, view) } } @@ -431,16 +421,42 @@ constructor(context: Context, attrs: AttributeSet? = null) : } } + private fun seatLongClick(view: View): Boolean { + if (view.tag as Int == STATUS_AVAILABLE) { + listenerLong!!.onAvailableSeatLongClick(view) + return true + } else if (view.tag as Int == STATUS_BOOKED) { + listenerLong!!.onBookedSeatLongClick(view) + return true + } else if (view.tag as Int == STATUS_RESERVED) { + listenerLong!!.onReservedSeatLongClick(view) + return true + } + return false + } + + fun setSeatClickListener(listener: SeatClickListener) { this.listener = listener } + fun setSeatLongClickListener(listener: SeatLongClickListener) { + this.listenerLong = listener + } + + interface SeatClickListener { fun onAvailableSeatClick(selectedIdList: List, view: View) fun onBookedSeatClick(view: View) fun onReservedSeatClick(view: View) } + interface SeatLongClickListener { + fun onAvailableSeatLongClick(view: View) + fun onBookedSeatLongClick(view: View) + fun onReservedSeatLongClick(view: View) + } + } diff --git a/SeatBookView/src/main/res/layout/seat_layout.xml b/SeatBookView/src/main/res/layout/seat_layout.xml deleted file mode 100644 index b369847..0000000 --- a/SeatBookView/src/main/res/layout/seat_layout.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/java/dev/jahidhasanco/demo_app/MainActivity.kt b/app/src/main/java/dev/jahidhasanco/demo_app/MainActivity.kt index 9f17add..24e374f 100644 --- a/app/src/main/java/dev/jahidhasanco/demo_app/MainActivity.kt +++ b/app/src/main/java/dev/jahidhasanco/demo_app/MainActivity.kt @@ -5,6 +5,7 @@ import android.os.Bundle import android.view.View import android.view.ViewGroup import android.widget.TextView +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.view.setPadding import dev.jahidhasanco.seatbookview.SeatBookView @@ -53,7 +54,6 @@ class MainActivity : AppCompatActivity() { .setSeatGaping(5) .setSeatSizeBySeatsColumn(6) .setSeatsLayoutString(seats) - .setSeatLayoutPadding(10) .isCustomTitle(true) .setCustomTitle(title) .setSelectSeatLimit(2) @@ -90,6 +90,22 @@ class MainActivity : AppCompatActivity() { }) + seatBookView.setSeatLongClickListener(object:SeatBookView.SeatLongClickListener{ + + override fun onAvailableSeatLongClick(view: View) { + Toast.makeText(this@MainActivity,"Long Pressed",Toast.LENGTH_SHORT).show() + } + + override fun onBookedSeatLongClick(view: View) { + + } + + override fun onReservedSeatLongClick(view: View) { + + } + + }) + } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e461805..f4b42de 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -13,6 +13,7 @@ > -