/*
 *    Copyright 2018-2019 adview.com, Inc.
 *
 *    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
 *
 *        http://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.adview.mobile.adviewkotlindemo.activities.ads.inapp

import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.widget.FrameLayout
import com.adview.sdk.AdSize
import com.adview.sdk.api.rendering.BannerView
import com.adview.mobile.adviewkotlindemo.activities.BaseAdActivity

class InAppDisplayBannerMultiSizeActivity : BaseAdActivity() {

    companion object {
        const val CONFIG_ID = "POSID0wbfijwzm430"; //official line
        const val WIDTH = 320 //728
        const val HEIGHT = 50 //90
    }

    private var adView: BannerView? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        createAd()

    }

    private fun createAd() {
        adView = BannerView(
            this,
            CONFIG_ID,
            AdSize(WIDTH, HEIGHT)
        )
        //for multi-size
        adView?.addAdditionalSizes(AdSize(300, 250))
        adView?.addAdditionalSizes(AdSize(320, 100))

        //layout centered
        val density = resources.displayMetrics.density
        val widthPx = (WIDTH * density).toInt()
        val heightPx = (HEIGHT * density).toInt()
        val layoutParams = FrameLayout.LayoutParams(widthPx, heightPx).apply {
            gravity = Gravity.CENTER_HORIZONTAL
        }

        adWrapperView.addView(adView, layoutParams)
        adView?.setAutoRefreshDelay(refreshTimeSeconds)
        adView?.loadAd()
    }


    override fun onDestroy() {
        super.onDestroy()
        adView?.destroy()
    }

}
