Skip to content

Commit

Permalink
update long click listener
Browse files Browse the repository at this point in the history
  • Loading branch information
JahidHasanCO committed Aug 24, 2022
1 parent edc0da3 commit ca6b973
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 32 deletions.
Binary file added ART/Home.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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<String>()

Expand All @@ -44,8 +35,8 @@ constructor(context: Context, attrs: AttributeSet? = null) :
private var count = 0

private var seatViewList: ArrayList<TextView> = 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
Expand Down Expand Up @@ -74,6 +65,7 @@ constructor(context: Context, attrs: AttributeSet? = null) :


private var listener: SeatClickListener? = null
private var listenerLong: SeatLongClickListener? = null


init {
Expand Down Expand Up @@ -161,7 +153,6 @@ constructor(context: Context, attrs: AttributeSet? = null) :
5
) + 1) - (layout_padding * seatGaping)

Toast.makeText(context, "$seatSize", Toast.LENGTH_SHORT).show()
}
}

Expand Down Expand Up @@ -377,6 +368,10 @@ constructor(context: Context, attrs: AttributeSet? = null) :
seatClick(it)
}

view.setOnLongClickListener {
seatLongClick(it)
}

}

fun markAsBooked(view: TextView) {
Expand Down Expand Up @@ -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)
}

}
Expand All @@ -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<Int>, view: View)
fun onBookedSeatClick(view: View)
fun onReservedSeatClick(view: View)
}

interface SeatLongClickListener {
fun onAvailableSeatLongClick(view: View)
fun onBookedSeatLongClick(view: View)
fun onReservedSeatLongClick(view: View)
}


}

Expand Down
9 changes: 0 additions & 9 deletions SeatBookView/src/main/res/layout/seat_layout.xml

This file was deleted.

18 changes: 17 additions & 1 deletion app/src/main/java/dev/jahidhasanco/demo_app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,7 +54,6 @@ class MainActivity : AppCompatActivity() {
.setSeatGaping(5)
.setSeatSizeBySeatsColumn(6)
.setSeatsLayoutString(seats)
.setSeatLayoutPadding(10)
.isCustomTitle(true)
.setCustomTitle(title)
.setSelectSeatLimit(2)
Expand Down Expand Up @@ -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) {

}

})

}


Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
>

<dev.jahidhasanco.seatbookview.SeatBookView
android:layout_marginTop="10dp"
android:id="@+id/layoutSeat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Demo_app" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Demo_app" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Demo_app" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Demo_app" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down

0 comments on commit ca6b973

Please sign in to comment.