conventionschedule-android/app/src/main/java/com/adlerosn/brasilfurfest/SplashActivity.kt

64 lines
2.5 KiB
Kotlin
Raw Normal View History

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-27 20:24:09 +00:00
import android.view.WindowManager
2018-12-12 04:30:34 +00:00
import com.adlerosn.brasilfurfest.helper.ActivitiesForFragments
2018-07-17 19:38:11 +00:00
import com.adlerosn.brasilfurfest.helper.KnownAssets
2018-12-13 02:04:29 +00:00
import com.adlerosn.brasilfurfest.schedule.managers.ScheduleManagerGetter
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-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?) {
2018-12-12 04:30:34 +00:00
ActivitiesForFragments[this.javaClass.simpleName] = this
2018-07-13 21:09:43 +00:00
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
2018-12-12 04:30:34 +00:00
val fastStart = intent.getBooleanExtra("fastStart", false)
2018-07-27 20:24:09 +00:00
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
2018-12-12 04:30:34 +00:00
val scheduleManager = ScheduleManagerGetter[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() }
}
}
private fun loadSplash(asset: String? = null){
asset?.let {
imageSplash.setImageDrawable(
Drawable.createFromStream(
assets.open(it),
null
)
)
}
2018-07-13 21:09:43 +00:00
}
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()
}
}