Skip to content

Commit 8ec7f3a

Browse files
committed
Add beacon group support
1 parent 1a0a318 commit 8ec7f3a

File tree

5 files changed

+95
-3
lines changed

5 files changed

+95
-3
lines changed

app/src/androidTest/java/com/kylecorry/trailsensecore/domain/navigation/NavigationServiceTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class NavigationServiceTest {
3737
val near5km = service.nearby(mtWashington, beacons, 5000f).map { it.id }
3838
val near500m = service.nearby(mtWashington, beacons, 500f).map { it.id }
3939

40-
assertEquals(listOf(0, 1, 2), near5km)
41-
assertEquals(listOf(0, 1), near500m)
40+
assertEquals(listOf(0L, 1L, 2L), near5km)
41+
assertEquals(listOf(0L, 1L), near500m)
4242
}
4343

4444
@Test

app/src/main/java/com/kylecorry/trailsensecore/domain/navigation/Beacon.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@ package com.kylecorry.trailsensecore.domain.navigation
22

33
import com.kylecorry.trailsensecore.domain.geo.Coordinate
44

5-
data class Beacon(val id: Int, val name: String, val coordinate: Coordinate, val visible: Boolean = true, val comment: String? = null, val beaconGroupId: Int? = null, val elevation: Float? = null)
5+
data class Beacon(
6+
override val id: Long,
7+
override val name: String,
8+
val coordinate: Coordinate,
9+
val visible: Boolean = true,
10+
val comment: String? = null,
11+
val beaconGroupId: Int? = null,
12+
val elevation: Float? = null
13+
) : IBeacon
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.kylecorry.trailsensecore.domain.navigation
2+
3+
data class BeaconGroup(override val id: Long, override val name: String): IBeacon
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.kylecorry.trailsensecore.domain.navigation
2+
3+
interface IBeacon {
4+
val name: String
5+
val id: Long
6+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.kylecorry.trailsensecore.infrastructure.view
2+
3+
import android.view.LayoutInflater
4+
import android.view.View
5+
import android.view.ViewGroup
6+
import androidx.annotation.LayoutRes
7+
import androidx.recyclerview.widget.DividerItemDecoration
8+
import androidx.recyclerview.widget.LinearLayoutManager
9+
import androidx.recyclerview.widget.RecyclerView
10+
11+
class ListView<T>(
12+
private val view: RecyclerView,
13+
@LayoutRes private val itemLayoutId: Int,
14+
private val onViewBind: (View, T) -> Unit
15+
) {
16+
17+
private val adapter: Adapter
18+
private val layoutInflater: LayoutInflater
19+
private val layoutManager: LinearLayoutManager
20+
21+
init {
22+
layoutManager = LinearLayoutManager(view.context)
23+
view.layoutManager = layoutManager
24+
25+
layoutInflater = LayoutInflater.from(view.context)
26+
27+
adapter = Adapter(listOf())
28+
view.adapter = adapter
29+
}
30+
31+
fun setData(data: List<T>) {
32+
adapter.data = data
33+
}
34+
35+
fun addLineSeparator() {
36+
val dividerItemDecoration = DividerItemDecoration(
37+
view.context,
38+
layoutManager.orientation
39+
)
40+
view.addItemDecoration(dividerItemDecoration)
41+
}
42+
43+
44+
inner class Adapter(mData: List<T>) : RecyclerView.Adapter<Holder>() {
45+
46+
var data: List<T> = mData
47+
set(value) {
48+
field = value
49+
notifyDataSetChanged()
50+
}
51+
52+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
53+
val view = layoutInflater.inflate(itemLayoutId, parent, false)
54+
return Holder(view)
55+
}
56+
57+
override fun getItemCount(): Int {
58+
return data.size
59+
}
60+
61+
override fun onBindViewHolder(holder: Holder, position: Int) {
62+
holder.bind(data[position])
63+
}
64+
65+
}
66+
67+
inner class Holder(itemView: View) : RecyclerView.ViewHolder(itemView) {
68+
69+
fun bind(detail: T) {
70+
onViewBind(itemView, detail)
71+
}
72+
}
73+
74+
75+
}

0 commit comments

Comments
 (0)