68 lines
2.8 KiB
Kotlin
Executable File
68 lines
2.8 KiB
Kotlin
Executable File
package fishrungames.yelpmapapp
|
|
|
|
import android.app.Activity
|
|
import android.support.v4.content.ContextCompat
|
|
import android.view.View
|
|
import android.widget.ImageView
|
|
|
|
import com.google.android.gms.maps.model.Marker
|
|
import android.widget.TextView
|
|
import com.google.android.gms.maps.GoogleMap.InfoWindowAdapter
|
|
import fishrungames.yelpmapapp.Utils.Companion.getStarRatingId
|
|
import java.text.DecimalFormat
|
|
|
|
|
|
/**
|
|
* Created by mephi on 10.06.2017.
|
|
*/
|
|
|
|
class YelpInfoWindowProvider(val activity: Activity) : InfoWindowAdapter {
|
|
|
|
private val myContentsView: View = activity.layoutInflater.inflate(R.layout.yelp_info_contents, null)
|
|
|
|
var lastClickedMapMarker : MapMarkerClusterItem? = null
|
|
|
|
override fun getInfoContents(marker: Marker): View {
|
|
|
|
if (lastClickedMapMarker != null)
|
|
{
|
|
val nameTextView = myContentsView.findViewById(R.id.nameTextView) as TextView
|
|
val addressTextView = myContentsView.findViewById(R.id.addressTextView) as TextView
|
|
val ratingTextView = myContentsView.findViewById(R.id.ratingTextView) as TextView
|
|
|
|
|
|
val starImageView1 = myContentsView.findViewById(R.id.starImageView1) as ImageView
|
|
val starImageView2 = myContentsView.findViewById(R.id.starImageView2) as ImageView
|
|
val starImageView3 = myContentsView.findViewById(R.id.starImageView3) as ImageView
|
|
val starImageView4 = myContentsView.findViewById(R.id.starImageView4) as ImageView
|
|
val starImageView5 = myContentsView.findViewById(R.id.starImageView5) as ImageView
|
|
|
|
nameTextView.text = lastClickedMapMarker?.mapMarkerRecord?.name
|
|
|
|
addressTextView.text = lastClickedMapMarker?.mapMarkerRecord?.location?.display_address?.joinToString(" ")
|
|
|
|
|
|
if (lastClickedMapMarker?.mapMarkerRecord?.rating != null) {
|
|
|
|
val rating = lastClickedMapMarker?.mapMarkerRecord?.rating!!
|
|
|
|
val formatter = DecimalFormat("#0.00")
|
|
ratingTextView.text = formatter.format(rating)
|
|
|
|
starImageView1.setImageDrawable(ContextCompat.getDrawable(activity, getStarRatingId(rating, 0.0)))
|
|
starImageView2.setImageDrawable(ContextCompat.getDrawable(activity, getStarRatingId(rating, 1.0)))
|
|
starImageView3.setImageDrawable(ContextCompat.getDrawable(activity, getStarRatingId(rating, 2.0)))
|
|
starImageView4.setImageDrawable(ContextCompat.getDrawable(activity, getStarRatingId(rating, 3.0)))
|
|
starImageView5.setImageDrawable(ContextCompat.getDrawable(activity, getStarRatingId(rating, 4.0)))
|
|
|
|
}
|
|
}
|
|
|
|
return myContentsView
|
|
}
|
|
|
|
override fun getInfoWindow(marker: Marker): View? {
|
|
return null
|
|
}
|
|
|
|
} |