2018-07-13 21:09:43 +00:00
|
|
|
package com.adlerosn.brasilfurfest
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.graphics.drawable.Drawable
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.support.v7.app.AppCompatActivity
|
2018-07-26 02:29:15 +00:00
|
|
|
import android.view.View
|
2018-07-17 19:38:11 +00:00
|
|
|
import com.adlerosn.brasilfurfest.helper.KnownAssets
|
2018-07-18 02:25:06 +00:00
|
|
|
import com.adlerosn.brasilfurfest.notification.NextNotificationScheduler
|
2018-07-13 21:09:43 +00:00
|
|
|
import com.adlerosn.brasilfurfest.schedule.ScheduleActivity
|
2018-07-17 19:52:22 +00:00
|
|
|
import com.adlerosn.brasilfurfest.schedule.ScheduleManager
|
2018-07-18 15:01:16 +00:00
|
|
|
import kotlinx.android.synthetic.main.activity_splash.*
|
2018-07-13 21:09:43 +00:00
|
|
|
import org.jetbrains.anko.doAsync
|
|
|
|
import org.jetbrains.anko.uiThread
|
|
|
|
|
|
|
|
class SplashActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2018-07-18 15:40:37 +00:00
|
|
|
val fastStart = intent.getBooleanExtra("fastStart", false)
|
2018-07-13 21:09:43 +00:00
|
|
|
setContentView(R.layout.activity_splash)
|
2018-07-17 19:52:22 +00:00
|
|
|
val scheduleManager = ScheduleManager(this)
|
2018-07-26 02:29:15 +00:00
|
|
|
loadSplash(scheduleManager.currentSplashAsset)
|
2018-07-18 15:01:16 +00:00
|
|
|
scheduleManager.selfFixFirstStartup()
|
2018-07-18 02:25:06 +00:00
|
|
|
NextNotificationScheduler(this, scheduleManager)
|
2018-07-26 02:29:15 +00:00
|
|
|
val eventCountdown = scheduleManager.nextEditionStartCountdown
|
|
|
|
if(scheduleManager.editionHasStarted or (eventCountdown == null)){
|
|
|
|
countdownTitle.visibility = View.GONE
|
|
|
|
countdownData.visibility = View.GONE
|
|
|
|
}else{
|
|
|
|
countdownData.text = eventCountdown!!.let { (f,s, t) -> "%dd %dh %dm".format(f, s, t) }
|
|
|
|
}
|
2018-07-13 21:09:43 +00:00
|
|
|
doAsync {
|
2018-07-18 15:40:37 +00:00
|
|
|
Thread.sleep(if (fastStart) 100 else 3750)
|
2018-07-13 21:09:43 +00:00
|
|
|
uiThread { launchSchedule() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 02:29:15 +00:00
|
|
|
private fun loadSplash(asset: String = KnownAssets.background){
|
2018-07-18 15:01:16 +00:00
|
|
|
imageSplash.setImageDrawable(
|
2018-07-13 21:09:43 +00:00
|
|
|
Drawable.createFromStream(
|
2018-07-17 19:52:22 +00:00
|
|
|
assets.open(asset),
|
2018-07-13 21:09:43 +00:00
|
|
|
null
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun launchSchedule() {
|
|
|
|
val intent = Intent(this, ScheduleActivity::class.java)
|
|
|
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_TASK_ON_HOME
|
|
|
|
this.startActivity(intent)
|
|
|
|
this.finish()
|
|
|
|
}
|
|
|
|
}
|