feat: Refactor onClick attributes in LiteDemoActivity

This commit refactors the `onClick` attributes for `showDarwin`, `showAdelaide`, and `showAustralia` in `LiteDemoActivity` to use programmatic click listeners with View Binding for both the Java and Kotlin versions of the app.
This commit is contained in:
dkhawk 2025-10-09 21:46:08 -06:00
parent 6efedc0c04
commit b91d6f5d7c
4 changed files with 38 additions and 28 deletions

View File

@ -206,18 +206,18 @@ This file tracks the progress of refactoring `android:onClick` attributes to use
- [ ] Replaced in `java-app`
- [ ] Replaced in `kotlin-app`
- [ ] Removed from XML
- [ ] `showDarwin`
- [ ] Replaced in `java-app`
- [ ] Replaced in `kotlin-app`
- [ ] Removed from XML
- [ ] `showAdelaide`
- [ ] Replaced in `java-app`
- [ ] Replaced in `kotlin-app`
- [ ] Removed from XML
- [ ] `showAustralia`
- [ ] Replaced in `java-app`
- [ ] Replaced in `kotlin-app`
- [ ] Removed from XML
- [x] `showDarwin`
- [x] Replaced in `java-app`
- [x] Replaced in `kotlin-app`
- [x] Removed from XML
- [x] `showAdelaide`
- [x] Replaced in `java-app`
- [x] Replaced in `kotlin-app`
- [x] Removed from XML
- [x] `showAustralia`
- [x] Replaced in `java-app`
- [x] Replaced in `kotlin-app`
- [x] Removed from XML
- [ ] `onStreetNamesToggled`
- [ ] Replaced in `java-app`
- [ ] Replaced in `kotlin-app`

View File

@ -42,7 +42,6 @@
android:id="@+id/go_to_darwin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showDarwin"
android:text="@string/lite_go_to_darwin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/lite_demo_introtext" />
@ -51,7 +50,6 @@
android:id="@+id/go_to_adelaide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showAdelaide"
android:text="@string/lite_go_to_adelaide"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/go_to_darwin" />
@ -60,7 +58,6 @@
android:id="@+id/go_to_australia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showAustralia"
android:text="@string/lite_go_to_australia"
app:layout_constraintStart_toEndOf="@id/go_to_darwin"
app:layout_constraintStart_toStartOf="parent"

View File

@ -23,6 +23,7 @@ import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.PolygonOptions;
import com.example.common_ui.databinding.LiteDemoBinding;
import com.google.android.gms.maps.model.PolylineOptions;
import android.graphics.Color;
@ -62,18 +63,23 @@ public class LiteDemoActivity extends SamplesBaseActivity implements
private GoogleMap map;
private LiteDemoBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the layout
setContentView(com.example.common_ui.R.layout.lite_demo);
binding = LiteDemoBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
// Get the map and register for the ready callback
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(com.example.common_ui.R.id.map);
new OnMapAndViewReadyListener(mapFragment, this);
applyInsets(findViewById(com.example.common_ui.R.id.map_container));
applyInsets(binding.mapContainer);
binding.goToDarwin.setOnClickListener(this::showDarwin);
binding.goToAdelaide.setOnClickListener(this::showAdelaide);
binding.goToAustralia.setOnClickListener(this::showAustralia);
}
/**

View File

@ -17,7 +17,7 @@ import android.graphics.Color
import android.os.Bundle
import android.view.View
import com.example.common_ui.R
import com.example.common_ui.databinding.LiteDemoBinding
import com.example.kotlindemos.OnMapAndViewReadyListener.OnGlobalLayoutAndMapReadyListener
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
@ -32,16 +32,21 @@ import com.google.android.gms.maps.model.*
*/
class LiteDemoActivity : SamplesBaseActivity(), OnGlobalLayoutAndMapReadyListener {
private lateinit var map: GoogleMap
private lateinit var binding: LiteDemoBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Set the layout
setContentView(R.layout.lite_demo)
binding = LiteDemoBinding.inflate(layoutInflater)
setContentView(binding.root)
// Get the map and register for the ready callback
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
OnMapAndViewReadyListener(mapFragment, this)
applyInsets(findViewById<View?>(R.id.map_container))
applyInsets(binding.mapContainer)
binding.goToDarwin.setOnClickListener { showDarwin(it) }
binding.goToAdelaide.setOnClickListener { showAdelaide(it) }
binding.goToAustralia.setOnClickListener { showAustralia(it) }
}
/**
@ -90,10 +95,12 @@ class LiteDemoActivity : SamplesBaseActivity(), OnGlobalLayoutAndMapReadyListene
*/
override fun onMapReady(googleMap: GoogleMap?) {
// return early if the map was not initialised properly
map = googleMap ?: return
addMarkers()
addPolyObjects()
showAustralia(null)
if (googleMap != null) {
map = googleMap
addMarkers()
addPolyObjects()
showAustralia(null)
}
}
/**