LogoLoadingView.kt 2.1 KB
Newer Older
1
package com.ydl.ydlcommon.ui
konghaorui committed
2 3 4 5 6 7

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.RelativeLayout
import com.ydl.ydl_image.module.GlideApp
8 9
import com.ydl.ydlcommon.R
import kotlinx.android.synthetic.main.platform_logo_loading_view.view.*
konghaorui committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

/**
 * Created by xj on 2019/7/26.
 */
class LogoLoadingView(context: Context?, attrs: AttributeSet?): RelativeLayout(context, attrs) {

    var DEFAULT_TYPE = TYPE_LOADING
    var mListener: LogoLoadingListener? = null

    companion object {
        const val TYPE_LOADING = 1 //加载中
        const val TYPE_NET_LOSS = 2 //无网络
        const val TYPE_DATA_SET = 3 //正常加载完成
    }

    init {
        initView()
    }

    private fun initView() {
30
        View.inflate(context, R.layout.platform_logo_loading_view,this)
konghaorui committed
31

konghaorui committed
32
        GlideApp.with(this).load(R.drawable.platform_loading_logo).into(logo_loading_gif)
konghaorui committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

        reset_btn.setOnClickListener {
            mListener?.onDataResetClick()
        }

        back_btn.setOnClickListener {
            mListener?.onBackClick()
        }
    }

    fun setListener(listener: LogoLoadingListener) {
        mListener = listener
    }

    //设置页面状态
    fun setViewType(type: Int, msg: String?) {
        DEFAULT_TYPE = type
        when (DEFAULT_TYPE) {
            TYPE_LOADING -> {
                logo_loading_gif_rl.visibility = View.VISIBLE
                empty_rl.visibility = View.GONE
                loading_rl.visibility = View.VISIBLE
            }
            TYPE_NET_LOSS -> {
                logo_loading_gif_rl.visibility = View.GONE
                empty_rl.visibility = View.VISIBLE
                loading_rl.visibility = View.VISIBLE
                msg?.let {
                    hint_msg.text = msg
                }
            }
            TYPE_DATA_SET -> {
                logo_loading_gif_rl.visibility = View.GONE
                empty_rl.visibility = View.GONE
                loading_rl.visibility = View.GONE
            }
        }
    }

    interface LogoLoadingListener {
        fun onDataResetClick()
        fun onBackClick()
    }
}