70 lines
3.0 KiB
Kotlin
70 lines
3.0 KiB
Kotlin
package com.adlerosn.brasilfurfest
|
|
|
|
import android.content.Intent
|
|
import android.os.Bundle
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import android.view.View
|
|
import android.view.WindowManager
|
|
import com.adlerosn.brasilfurfest.helper.*
|
|
import com.adlerosn.brasilfurfest.notification.AppJobScheduler
|
|
import com.adlerosn.brasilfurfest.schedule.managers.ScheduleManagerGetter
|
|
import com.adlerosn.brasilfurfest.schedule.ScheduleActivity
|
|
import com.adlerosn.brasilfurfest.schedule.managers.ScheduleManager
|
|
import kotlinx.android.synthetic.main.activity_splash.*
|
|
import org.jetbrains.anko.doAsync
|
|
import org.jetbrains.anko.uiThread
|
|
|
|
class SplashActivity : AppCompatActivity() {
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
ActivitiesForFragments[this.javaClass.simpleName] = this
|
|
super.onCreate(savedInstanceState)
|
|
setContentView(R.layout.activity_splash)
|
|
resourcesAliased = this.resources
|
|
val fastStart = intent.getBooleanExtra("fastStart", false)
|
|
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)
|
|
countdownTitle.visibility = View.GONE
|
|
countdownData.visibility = View.GONE
|
|
val scheduleManager = ScheduleManagerGetter[ScheduleManager(this@SplashActivity)]
|
|
doAsync {
|
|
uiThread { loadSplash(scheduleManager.currentSplashAsset) }
|
|
uiThread { AppJobScheduler(applicationContext) }
|
|
val eventCountdown = scheduleManager.nextEditionStartCountdown
|
|
uiThread {
|
|
if (scheduleManager.editionHasStarted or (eventCountdown == null)) {
|
|
countdownTitle.visibility = View.GONE
|
|
countdownData.visibility = View.GONE
|
|
} else {
|
|
countdownTitle.visibility = View.VISIBLE
|
|
countdownData.visibility = View.VISIBLE
|
|
countdownData.text = eventCountdown!!.let { (f, s, t) -> "%dd %dh %dm".format(f, s, t) }
|
|
}
|
|
if (!fastStart) {
|
|
imageSplash.setOnClickListener { launchSchedule() }
|
|
}
|
|
doAsync {
|
|
Thread.sleep(if (fastStart) 100 else 3750)
|
|
uiThread { launchSchedule() }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private fun loadSplash(asset: String? = null) =
|
|
asset?.fromCache()?.toDrawable()?.run { asImageOf(imageSplash) }
|
|
|
|
private var scheduleLaunched = false
|
|
|
|
private fun launchSchedule() {
|
|
if (scheduleLaunched) return
|
|
scheduleLaunched = true
|
|
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()
|
|
}
|
|
}
|