Skip to content

Commit

Permalink
Use view binding for WidgetListAdapter
Browse files Browse the repository at this point in the history
Signed-off-by: Danny Baumann <[email protected]>
  • Loading branch information
maniac103 committed Aug 11, 2024
1 parent 2281f43 commit 823f67e
Show file tree
Hide file tree
Showing 46 changed files with 824 additions and 553 deletions.
11 changes: 5 additions & 6 deletions mobile/src/foss/java/org/openhab/habdroid/ui/MapViewHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ object MapViewHelper {

private class OsmViewHolder(initData: WidgetAdapter.ViewHolderInitData) :
WidgetAdapter.AbstractMapViewHolder(initData) {
private val mapView = baseMapView as MapView
private val handler: Handler = Handler(Looper.getMainLooper())

init {
with(mapView) {
binding.mapview.apply {
setTileSource(TileSourceFactory.MAPNIK)
isVerticalMapRepetitionEnabled = false
zoomController.setVisibility(Visibility.NEVER)
Expand All @@ -86,9 +85,9 @@ object MapViewHelper {
override fun bindAfterDataSaverCheck(widget: Widget) {
super.bindAfterDataSaverCheck(widget)
handler.post {
mapView.applyPositionAndLabel(
binding.mapview.applyPositionAndLabel(
boundWidget?.item,
labelView.text,
binding.icontext.label.text,
15.0f,
allowDrag = false,
allowScroll = false
Expand All @@ -97,11 +96,11 @@ object MapViewHelper {
}

override fun onStart() {
mapView.onResume()
binding.mapview.onResume()
}

override fun onStop() {
mapView.onPause()
binding.mapview.onPause()
}

override fun openPopup() {
Expand Down
14 changes: 10 additions & 4 deletions mobile/src/foss/res/layout/widgetlist_mapitem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@
android:orientation="vertical"
style="@style/WidgetListItemContainer">

<include layout="@layout/widgetlist_icontext_for_heavy_data" />
<include
android:id="@+id/icontext"
layout="@layout/widgetlist_icontext_for_heavy_data" />

<org.osmdroid.views.MapView
android:id="@+id/widget_content"
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="180dp" />

<include layout="@layout/widgetlist_mapitem_no_position" />
<include
android:id="@+id/no_position"
layout="@layout/widgetlist_mapitem_no_position" />

<include layout="@layout/widgetlist_data_saver" />
<include
android:id="@+id/data_saver"
layout="@layout/widgetlist_data_saver" />

</LinearLayout>
18 changes: 10 additions & 8 deletions mobile/src/full/java/org/openhab/habdroid/ui/MapViewHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import android.view.ViewGroup
import androidx.core.view.isGone
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.MapView
import com.google.android.gms.maps.MapsInitializer
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.LatLngBounds
Expand All @@ -40,11 +39,10 @@ object MapViewHelper {

private class GoogleMapsViewHolder(initData: WidgetAdapter.ViewHolderInitData) :
WidgetAdapter.AbstractMapViewHolder(initData) {
private val mapView = baseMapView as MapView
private var map: GoogleMap? = null

init {
mapView.onCreate(null)
binding.mapview.onCreate(null)
}

override fun bindAfterDataSaverCheck(widget: Widget) {
Expand All @@ -57,14 +55,18 @@ object MapViewHelper {

override fun onStart() {
super.onStart()
mapView.onStart()
mapView.onResume()
binding.mapview.apply {
onStart()
onResume()
}
}

override fun onStop() {
super.onStop()
mapView.onPause()
mapView.onStop()
binding.mapview.apply {
onPause()
onStop()
}
}

override fun openPopup() {
Expand All @@ -79,7 +81,7 @@ object MapViewHelper {
return
}

mapView.getMapAsync { map ->
binding.mapview.getMapAsync { map ->
this.map = map
with(map.uiSettings) {
setAllGesturesEnabled(false)
Expand Down
14 changes: 10 additions & 4 deletions mobile/src/full/res/layout/widgetlist_mapitem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@
android:orientation="vertical"
style="@style/WidgetListItemContainer">

<include layout="@layout/widgetlist_icontext_for_heavy_data" />
<include
android:id="@+id/icontext"
layout="@layout/widgetlist_icontext_for_heavy_data" />

<com.google.android.gms.maps.MapView
android:id="@+id/widget_content"
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="180dp"
app:liteMode="true" />

<include layout="@layout/widgetlist_mapitem_no_position" />
<include
android:id="@+id/no_position"
layout="@layout/widgetlist_mapitem_no_position" />

<include layout="@layout/widgetlist_data_saver" />
<include
android:id="@+id/data_saver"
layout="@layout/widgetlist_data_saver" />

</LinearLayout>
Loading

0 comments on commit 823f67e

Please sign in to comment.