Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private fun configureRecyclerView(view: View){
- this.recyclerView = view.findViewById(R.id.fragment_list_recycler_view) as RecyclerView
- this.mAdapter = ListAdapter()
- this.recyclerView.adapter = this.mAdapter
- this.recyclerView.layoutManager = LinearLayoutManager(context)
- ItemClickSupport.addTo(recyclerView, R.layout.fragment_list_item)
- .setOnItemClickListener{ _, position,_ ->
- val property = mAdapter.getProperty(position)
- mCallback.onButtonClicked(property)
- Log.d(TAG, "Click on ${property.id}!")
- }
- }
- override fun onButtonClicked(property: Property) {
- if(detailFragment != null){
- Log.d(TAG, "onButtonClicked: ID: ${property.id}")
- detailFragment.updateUI(property)
- } else {
- Log.d(TAG, "onButtonClicked: detailFragment == null")
- this.configureAndShowDetailFragment()
- this.onButtonClicked(property)
- }
- }
- fun updateUI(property: Property){
- Log.d(TAG, "updateUI")
- Log.d(TAG, "Property not null: ${property.id}")
- // Show property inside the layout
- rootView.fragment_detail_data.visibility = View.VISIBLE
- rootView.fragment_detail_empty.visibility = View.GONE
- // pictures inside recyclerview
- this.setPictures(property.id)
- // description
- rootView.fragment_detail_description.text = property.description
- // geolocation
- this.setLatLng(property)
- this.configureMapsFragment()
- }
- private fun setLatLng(property: Property){
- val lat: Double = property.latitude
- val lng: Double = property.longitude
- this.latlng = LatLng(lat, lng)
- Log.d(TAG, "setLatLng: ${latlng.toString()}")
- }
- private fun configureMapsFragment(){
- val mapFragment: SupportMapFragment? = childFragmentManager.findFragmentById(R.id.fragment_detail_map) as? SupportMapFragment
- mapFragment?.getMapAsync(this)
- }
- private fun showProperty(){
- // Wait until map is ready
- if (map != null && latlng != null){
- // Center camera on marker
- map!!.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, ZOOM))
- }
- return
- }
- override fun onMapReady(googleMap: GoogleMap) {
- Log.d(TAG, "onMapReady")
- this.map = googleMap
- addMarkers()
- showProperty()
- }
- private fun addMarkers(){
- map!!.addMarker(MarkerOptions()
- .position(latlng!!))
- }
Add Comment
Please, Sign In to add comment