2018-07-13 21:09:43 +00:00
|
|
|
package com.adlerosn.brasilfurfest
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.os.Bundle
|
2019-06-22 04:04:57 +00:00
|
|
|
import androidx.appcompat.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-28 00:28:48 +00:00
|
|
|
import com.adlerosn.brasilfurfest.helper.*
|
2019-06-04 23:14:19 +00:00
|
|
|
import com.adlerosn.brasilfurfest.notification.AppJobScheduler
|
2018-12-13 02:04:29 +00:00
|
|
|
import com.adlerosn.brasilfurfest.schedule.managers.ScheduleManagerGetter
|
2018-07-13 21:09:43 +00:00
|
|
|
import com.adlerosn.brasilfurfest.schedule.ScheduleActivity
|
2018-12-21 04:09:07 +00:00
|
|
|
import com.adlerosn.brasilfurfest.schedule.managers.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?) {
|
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-28 00:28:48 +00:00
|
|
|
resourcesAliased = this.resources
|
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-28 00:28:48 +00:00
|
|
|
countdownTitle.visibility = View.GONE
|
|
|
|
countdownData.visibility = View.GONE
|
2019-01-05 04:27:18 +00:00
|
|
|
val scheduleManager = ScheduleManagerGetter[ScheduleManager(this@SplashActivity)]
|
2018-07-13 21:09:43 +00:00
|
|
|
doAsync {
|
2019-01-05 04:27:18 +00:00
|
|
|
uiThread { loadSplash(scheduleManager.currentSplashAsset) }
|
2019-06-04 23:14:19 +00:00
|
|
|
uiThread { AppJobScheduler(applicationContext) }
|
2018-12-28 00:28:48 +00:00
|
|
|
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() }
|
|
|
|
}
|
2018-12-21 04:09:07 +00:00
|
|
|
}
|
2018-12-20 03:02:54 +00:00
|
|
|
}
|
2018-07-13 21:09:43 +00:00
|
|
|
}
|
|
|
|
|
2018-12-28 00:28:48 +00:00
|
|
|
private fun loadSplash(asset: String? = null) =
|
2019-01-05 04:27:18 +00:00
|
|
|
asset?.fromCache()?.toDrawable()?.run { asImageOf(imageSplash) }
|
2018-12-28 00:28:48 +00:00
|
|
|
|
2018-12-21 04:09:07 +00:00
|
|
|
private var scheduleLaunched = false
|
|
|
|
|
2018-07-13 21:09:43 +00:00
|
|
|
private fun launchSchedule() {
|
2018-12-21 04:09:07 +00:00
|
|
|
if (scheduleLaunched) return
|
|
|
|
scheduleLaunched = true
|
2018-07-13 21:09:43 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|