package com.hanwha.morakmorak.ui

import android.graphics.Color
import android.os.Bundle
import android.view.WindowManager
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.hanwha.morakmorak.core.BaseViewModel

/**
 * Created by aaron on 08/07/2019
 */
abstract class BindingActivity<T : ViewDataBinding, V : BaseViewModel> : AppCompatActivity() {

    @LayoutRes
    abstract fun getLayoutResId(): Int

    abstract fun getMyViewModel(): V

    protected lateinit var binding: T
        private set

    protected lateinit var viewModel: V
        private set

    override fun onCreate(savedInstanceState: Bundle?) {
        configWindow()

        super.onCreate(savedInstanceState)

        binding = DataBindingUtil.setContentView(this, getLayoutResId())
        viewModel = getMyViewModel()
    }

    /**
     * status bar 그라데이션 컬러 적용을 위한 셋팅
     */
    open fun configWindow() {
        window.run {
            addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
            clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
            statusBarColor = Color.TRANSPARENT
        }
    }

    open fun showLoadingProgress(isShow: Boolean) {
        viewModel.isProgressVisible.value = isShow
    }
}