Guest User

Untitled

a guest
Jul 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. private fun configureRecyclerView(view: View){
  2. this.recyclerView = view.findViewById(R.id.fragment_list_recycler_view) as RecyclerView
  3. this.mAdapter = ListAdapter()
  4. this.recyclerView.adapter = this.mAdapter
  5. this.recyclerView.layoutManager = LinearLayoutManager(context)
  6. ItemClickSupport.addTo(recyclerView, R.layout.fragment_list_item)
  7. .setOnItemClickListener{ _, position,_ ->
  8. val property = mAdapter.getProperty(position)
  9. mCallback.onButtonClicked(property)
  10. Log.d(TAG, "Click on ${property.id}!")
  11. }
  12. }
  13.  
  14. override fun onButtonClicked(property: Property) {
  15. if(detailFragment != null){
  16. Log.d(TAG, "onButtonClicked: ID: ${property.id}")
  17. detailFragment.updateUI(property)
  18. } else {
  19. Log.d(TAG, "onButtonClicked: detailFragment == null")
  20. this.configureAndShowDetailFragment()
  21. this.onButtonClicked(property)
  22. }
  23. }
  24.  
  25. fun updateUI(property: Property){
  26. Log.d(TAG, "updateUI")
  27. Log.d(TAG, "Property not null: ${property.id}")
  28. // Show property inside the layout
  29. rootView.fragment_detail_data.visibility = View.VISIBLE
  30. rootView.fragment_detail_empty.visibility = View.GONE
  31.  
  32. // pictures inside recyclerview
  33. this.setPictures(property.id)
  34.  
  35. // description
  36. rootView.fragment_detail_description.text = property.description
  37.  
  38. // geolocation
  39. this.setLatLng(property)
  40. this.configureMapsFragment()
  41. }
  42.  
  43. private fun setLatLng(property: Property){
  44. val lat: Double = property.latitude
  45. val lng: Double = property.longitude
  46.  
  47. this.latlng = LatLng(lat, lng)
  48. Log.d(TAG, "setLatLng: ${latlng.toString()}")
  49. }
  50.  
  51. private fun configureMapsFragment(){
  52. val mapFragment: SupportMapFragment? = childFragmentManager.findFragmentById(R.id.fragment_detail_map) as? SupportMapFragment
  53. mapFragment?.getMapAsync(this)
  54. }
  55.  
  56. private fun showProperty(){
  57.  
  58. // Wait until map is ready
  59. if (map != null && latlng != null){
  60. // Center camera on marker
  61. map!!.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, ZOOM))
  62. }
  63. return
  64. }
  65.  
  66. override fun onMapReady(googleMap: GoogleMap) {
  67. Log.d(TAG, "onMapReady")
  68. this.map = googleMap
  69. addMarkers()
  70. showProperty()
  71. }
  72.  
  73. private fun addMarkers(){
  74. map!!.addMarker(MarkerOptions()
  75. .position(latlng!!))
  76. }
Add Comment
Please, Sign In to add comment