package com.adealink.weparty.commonui.widget

import android.content.Context
import android.graphics.Rect
import android.util.AttributeSet
import android.view.View
import com.adealink.frame.util.DisplayUtil
import com.adealink.weparty.commonui.text.DraweeTextView

open class AutoMarqueeDraweeTextView : DraweeTextView {

    private val isLeft: Boolean = !DisplayUtil.isRtlLayout()

    constructor(context: Context) : this(context, null)

    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)

    constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {
    }

    override fun isFocused(): Boolean {
        return true
    }
    override fun onFocusChanged(focused: Boolean, direction: Int,
                                previouslyFocusedRect: Rect?) {
        if (focused) {
            super.onFocusChanged(focused, direction, previouslyFocusedRect)
        }
    }
    override fun getLayoutDirection(): Int {
        return if(isLeft) View.LAYOUT_DIRECTION_LTR else View.LAYOUT_DIRECTION_RTL
    }
    override fun getTextDirection(): Int {
        return if(isLeft) View.TEXT_DIRECTION_LTR else View.TEXT_DIRECTION_RTL
    }

    override fun onWindowFocusChanged(focused: Boolean) {
        if (focused) {
            super.onWindowFocusChanged(focused)
        }
    }
}
