/**
 * DO NOT EDIT THIS FILE.
 *
 * This source code was autogenerated from source code within the `app/src/gms` directory
 * and is not intended for modifications. If any edits should be made, please do so in the
 * corresponding file under the `app/src/gms` directory.
 */
/*
 * Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.example.kotlindemos

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment

/**
 * This shows how to use Cloud-based Map Styling in a simple Activity. For more information on how
 * to style a map using this method, see:
 * https://developers.google.com/maps/documentation/android-sdk/cloud-based-map-styling
 */
class CloudBasedMapStylingDemoActivity : AppCompatActivity(), OnMapReadyCallback {
    private var map: GoogleMap? = null
    private var currentMapType = GoogleMap.MAP_TYPE_NORMAL
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (savedInstanceState != null) {
            currentMapType = savedInstanceState.getInt(MAP_TYPE_KEY)
        }

        // The underlying style the map will use has been set in the layout
        // `cloud_styling_basic_demo` under the SupportMapFragment's `map:mapId` attribute.
        setContentView(R.layout.cloud_styling_basic_demo)
        val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
        mapFragment!!.getMapAsync(this)
        setUpButtonListeners()
    }

    override fun onMapReady(map: GoogleMap) {
        this.map = map
        map.mapType = currentMapType
    }

    private fun setUpButtonListeners() {
        findViewById<View>(R.id.styling_normal_mode).setOnClickListener { setMapType(GoogleMap.MAP_TYPE_NORMAL) }
        findViewById<View>(R.id.styling_satellite_mode).setOnClickListener { setMapType(GoogleMap.MAP_TYPE_SATELLITE) }
        findViewById<View>(R.id.styling_hybrid_mode).setOnClickListener { setMapType(GoogleMap.MAP_TYPE_HYBRID) }
        findViewById<View>(R.id.styling_terrain_mode).setOnClickListener { setMapType(GoogleMap.MAP_TYPE_TERRAIN) }
    }

    private fun setMapType(mapType: Int) {
        currentMapType = mapType
        map?.mapType = mapType
    }

    companion object {
        private const val MAP_TYPE_KEY = "map_type"
    }
}