PulseActivity.kt 2.36 KB
Newer Older
nk2's avatar
nk2 committed
1 2
package ga.nk2ishere.dev.musclecar.features.pulse

nk2's avatar
nk2 committed
3 4 5 6
import android.animation.ArgbEvaluator
import android.animation.ObjectAnimator
import android.content.Intent
import android.graphics.Color
nk2's avatar
nk2 committed
7
import android.os.Bundle
nk2's avatar
nk2 committed
8
import android.support.design.widget.BottomSheetBehavior
nk2's avatar
nk2 committed
9
import android.support.v7.app.AppCompatActivity
nk2's avatar
nk2 committed
10 11 12 13
import android.view.View
import com.arellomobile.mvp.MvpAppCompatActivity
import com.arellomobile.mvp.presenter.InjectPresenter
import com.arellomobile.mvp.presenter.PresenterType
nk2's avatar
nk2 committed
14
import ga.nk2ishere.dev.musclecar.R
nk2's avatar
nk2 committed
15 16 17 18 19 20
import kotlinx.android.synthetic.main.activity_pulse.*
import org.jetbrains.anko.sdk25.coroutines.onClick
import android.animation.ValueAnimator
import android.animation.ValueAnimator.AnimatorUpdateListener


nk2's avatar
nk2 committed
21 22 23 24 25


/**
 * Created by nk2 on 04/02/2018.
 */
nk2's avatar
nk2 committed
26 27 28 29 30 31

class PulseActivity : MvpAppCompatActivity(), PulseView {

    @InjectPresenter(tag = "PULSEACTIVITY", type = PresenterType.WEAK, presenterId = "PULSEACTIVITY")
    lateinit var presenter: PulsePresenter

nk2's avatar
nk2 committed
32 33 34
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_pulse)
nk2's avatar
nk2 committed
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
        presenter.onInit(this)
        settings.onClick { presenter.onSettingsClick() }
        presenter.onDailyViewCreate(daysList)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if(data != null)
            presenter.onResult(data)
    }

    override fun updateMusclePulse(pulse: Int) {
        currentPulse.text = pulse.toString()
        rateGraph.addValue(pulse.toFloat())
    }

    override fun updateCurrentCount(count: Int) {
        currentDone.text = count.toString()
    }

    override fun initCurrentThreshold(threshold: Int) {
        currentThreshold.text = "$threshold"
    }

    override fun showBottomSheet(view: View) {
         BottomSheetBehavior.from(view).state = BottomSheetBehavior.STATE_EXPANDED
    }

    override fun hideBottomSheet(view: View) {
        BottomSheetBehavior.from(view).state = BottomSheetBehavior.STATE_COLLAPSED
    }

    override fun changeBackgroundColor(fromColor: Int, toColor: Int) {
        val colorAnimation = ValueAnimator.ofObject(ArgbEvaluator(), fromColor, toColor)
        colorAnimation.duration = 250
        colorAnimation.addUpdateListener { animator -> topPanel.setBackgroundColor(animator.animatedValue as Int) }
        colorAnimation.start()
nk2's avatar
nk2 committed
71 72
    }
}