2018-07-16 05:36:26 +00:00
|
|
|
package com.adlerosn.brasilfurfest.schedule
|
|
|
|
|
2018-12-12 04:30:34 +00:00
|
|
|
import android.annotation.SuppressLint
|
2018-07-18 15:01:16 +00:00
|
|
|
import android.content.Intent
|
2018-07-31 23:26:09 +00:00
|
|
|
import android.content.res.Resources
|
2018-07-27 20:24:09 +00:00
|
|
|
import android.graphics.Color
|
2018-07-16 05:36:26 +00:00
|
|
|
import android.graphics.drawable.Drawable
|
|
|
|
import android.os.Bundle
|
2018-12-12 04:30:34 +00:00
|
|
|
import android.provider.CalendarContract
|
2018-07-31 23:26:09 +00:00
|
|
|
import android.support.design.widget.Snackbar
|
|
|
|
import android.support.v4.content.ContextCompat
|
2018-07-16 05:36:26 +00:00
|
|
|
import android.support.v7.app.AppCompatActivity
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2018-07-27 20:24:09 +00:00
|
|
|
import android.view.WindowManager
|
2018-07-27 03:39:36 +00:00
|
|
|
import com.adlerosn.brasilfurfest.CountdownActivity
|
2018-07-16 05:36:26 +00:00
|
|
|
import com.adlerosn.brasilfurfest.R
|
2018-07-18 15:40:37 +00:00
|
|
|
import com.adlerosn.brasilfurfest.SplashActivity
|
2018-12-12 04:30:34 +00:00
|
|
|
import com.adlerosn.brasilfurfest.helper.*
|
2018-07-16 05:36:26 +00:00
|
|
|
import com.adlerosn.brasilfurfest.schedule.abstractDataTypes.managed.AttendeeConFavorite
|
2018-12-13 02:04:29 +00:00
|
|
|
import com.adlerosn.brasilfurfest.schedule.managers.ScheduleManagerGetter
|
2018-07-16 05:36:26 +00:00
|
|
|
import kotlinx.android.synthetic.main.activity_event.*
|
|
|
|
import kotlinx.android.synthetic.main.activity_event_content.*
|
|
|
|
import kotlinx.android.synthetic.main.activity_event_content_keypair.view.*
|
|
|
|
import java.text.SimpleDateFormat
|
2018-12-12 04:30:34 +00:00
|
|
|
import java.util.*
|
|
|
|
|
2018-07-16 05:36:26 +00:00
|
|
|
|
|
|
|
class EventActivity : AppCompatActivity() {
|
|
|
|
|
2018-07-18 15:01:16 +00:00
|
|
|
private var fromNotification = false
|
|
|
|
|
2018-12-12 04:30:34 +00:00
|
|
|
|
2018-07-16 05:36:26 +00:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
2018-12-12 04:30:34 +00:00
|
|
|
ActivitiesForFragments[this.javaClass.simpleName] = this
|
2018-07-16 05:36:26 +00:00
|
|
|
super.onCreate(savedInstanceState)
|
2018-07-27 20:24:09 +00:00
|
|
|
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
|
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
|
|
|
|
window.statusBarColor = Color.TRANSPARENT
|
2018-07-16 05:36:26 +00:00
|
|
|
setContentView(R.layout.activity_event)
|
|
|
|
setSupportActionBar(toolbar)
|
|
|
|
|
|
|
|
toolbar_layout.setCollapsedTitleTextAppearance(R.style.CollapsedAppBar)
|
|
|
|
toolbar_layout.setExpandedTitleTextAppearance(R.style.ExpandedAppBar)
|
|
|
|
|
2018-12-12 04:30:34 +00:00
|
|
|
val scheduleManager = ScheduleManagerGetter[this]
|
2018-07-16 05:36:26 +00:00
|
|
|
val favorite = intent.getSerializableExtra("favorite") as AttendeeConFavorite
|
|
|
|
val offerStar = intent.getBooleanExtra("offerStar", false)
|
2018-07-18 15:01:16 +00:00
|
|
|
fromNotification = intent.getBooleanExtra("fromNotification", false)
|
2018-07-16 05:36:26 +00:00
|
|
|
val event = favorite.findInConvention(scheduleManager.convention)
|
|
|
|
toolbar_layout.title = favorite.getString(this)
|
|
|
|
app_bar_image.setImageDrawable(
|
|
|
|
Drawable.createFromStream(
|
2018-12-13 02:04:29 +00:00
|
|
|
assets.open( (event?.assetImage?.get(runtimeLanguage)?.let {
|
|
|
|
if(it.isBlank()) null else it
|
|
|
|
} ?: KnownAssets.background)),
|
2018-07-16 05:36:26 +00:00
|
|
|
null
|
|
|
|
)
|
|
|
|
)
|
|
|
|
val language = runtimeLanguage
|
|
|
|
val hourFormatter = SimpleDateFormat("HH:mm", language.locale)
|
|
|
|
val dowFormatter = SimpleDateFormat("EEEE (d)", language.locale)
|
2018-07-27 03:39:36 +00:00
|
|
|
|
|
|
|
val timerClickListener = View.OnClickListener{
|
|
|
|
Intent(this, CountdownActivity::class.java).let {
|
|
|
|
it.putExtra("label", favorite.getString(this))
|
|
|
|
it.putExtra("counter", favorite.timeRange.start.timeInMillis)
|
2018-07-27 20:24:09 +00:00
|
|
|
it.putExtra("finishesAt", favorite.timeRange.finish.timeInMillis)
|
2018-07-27 03:39:36 +00:00
|
|
|
startActivity(it)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-16 05:36:26 +00:00
|
|
|
keypairs.removeAllViews()
|
|
|
|
inflateKeyPair(
|
|
|
|
getString(R.string.schedule_event_key_activity),
|
|
|
|
favorite.getString(this),
|
|
|
|
keypairs
|
|
|
|
)
|
|
|
|
if(event?.subtitles?.get(language)?.isNotEmpty() == true)
|
|
|
|
inflateKeyPair(
|
|
|
|
getString(R.string.schedule_event_key_detail),
|
|
|
|
event.subtitles[language]!!,
|
|
|
|
keypairs
|
|
|
|
)
|
2018-07-31 23:26:09 +00:00
|
|
|
val whenButton = inflateKeyPair(
|
2018-07-16 05:36:26 +00:00
|
|
|
getString(R.string.schedule_event_key_when),
|
|
|
|
getString(R.string.schedule_event_key_when_formatted).format(
|
|
|
|
dowFormatter.format(favorite.timeRange.start.timeInMillis),
|
|
|
|
hourFormatter.format(favorite.timeRange.start.timeInMillis),
|
|
|
|
hourFormatter.format(favorite.timeRange.finish.timeInMillis)
|
|
|
|
).capitalize(),
|
|
|
|
keypairs
|
2018-07-27 03:39:36 +00:00
|
|
|
).apply {
|
|
|
|
touchableIndicator.visibility = View.VISIBLE
|
|
|
|
setOnClickListener(timerClickListener)
|
|
|
|
}
|
2018-07-16 05:36:26 +00:00
|
|
|
if(event!=null) {
|
|
|
|
if(event.places.isNotEmpty())
|
|
|
|
inflateKeyPair(
|
|
|
|
if(event.places.size==1)
|
|
|
|
getString(R.string.schedule_event_key_place)
|
|
|
|
else
|
|
|
|
getString(R.string.schedule_event_key_places),
|
|
|
|
TextualJoiner(language)[event.places.map { it.names[language]!! }],
|
|
|
|
keypairs
|
|
|
|
)
|
|
|
|
if(event.language!=null)
|
|
|
|
inflateKeyPair(
|
|
|
|
getString(R.string.schedule_event_key_language),
|
|
|
|
getString(event.language.language),
|
|
|
|
keypairs
|
|
|
|
)
|
|
|
|
event.descriptions[language]?.let {
|
|
|
|
if(it.isNotEmpty())
|
|
|
|
inflateKeyPair(
|
|
|
|
getString(R.string.schedule_event_key_description),
|
|
|
|
it,
|
|
|
|
keypairs
|
|
|
|
)
|
|
|
|
if(event.tags.isNotEmpty())
|
|
|
|
inflateKeyPair(
|
|
|
|
getString(R.string.schedule_event_key_category),
|
|
|
|
TextualJoiner(language)[event.tags.map { it.names[language]!! }],
|
|
|
|
keypairs
|
|
|
|
)
|
|
|
|
if(event.conbookPages.isNotEmpty())
|
|
|
|
inflateKeyPair(
|
|
|
|
if(event.conbookPages.size==1)
|
|
|
|
getString(R.string.schedule_event_key_on_conbooks_page)
|
|
|
|
else
|
|
|
|
getString(R.string.schedule_event_key_on_conbooks_pages),
|
|
|
|
TextualJoiner(language)[event.conbookPages.map { it.toString() }],
|
|
|
|
keypairs
|
|
|
|
)
|
|
|
|
if(event.conbookId.isNotEmpty())
|
|
|
|
inflateKeyPair(
|
|
|
|
getString(R.string.schedule_event_key_identified_on_conbook_as),
|
|
|
|
event.conbookId,
|
|
|
|
keypairs
|
|
|
|
)
|
|
|
|
if(event.attendableBy.isNotEmpty())
|
|
|
|
inflateKeyPair(
|
|
|
|
if(event.attendableBy.size==1)
|
|
|
|
getString(R.string.schedule_event_key_elegible_registration)
|
|
|
|
else
|
|
|
|
getString(R.string.schedule_event_key_elegible_registrations),
|
|
|
|
TextualJoiner(language)[event.attendableBy.map { it.names[language]!! }],
|
|
|
|
keypairs
|
|
|
|
)
|
|
|
|
}
|
2018-12-12 04:30:34 +00:00
|
|
|
@SuppressLint("RestrictedApi")
|
|
|
|
if(event.hiddenFromTimeTable or (scheduleManager.attendeeFavorites.registrationTier.level !in event.attendableBy.map { it.level })) {
|
2018-07-16 05:36:26 +00:00
|
|
|
fab.visibility = View.GONE
|
2018-12-12 04:30:34 +00:00
|
|
|
fabCalendar.visibility = View.GONE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@SuppressLint("RestrictedApi")
|
|
|
|
if(!offerStar){
|
|
|
|
fab.visibility = View.GONE
|
|
|
|
fabCalendar.visibility = View.GONE
|
2018-07-16 05:36:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fab.setOnClickListener { _ ->
|
|
|
|
fab.setImageResource(R.drawable.ic_star_half_white_24dp)
|
|
|
|
if (favorite in scheduleManager.attendeeFavorites)
|
|
|
|
scheduleManager.attendeeFavorites.remove(favorite)
|
|
|
|
else
|
|
|
|
scheduleManager.attendeeFavorites.add(favorite)
|
|
|
|
}
|
2018-07-31 23:26:09 +00:00
|
|
|
fab.isLongClickable = true
|
|
|
|
fab.setOnLongClickListener {
|
|
|
|
Snackbar.make(it.rootView, R.string.add_or_remove_favorite, Snackbar.LENGTH_LONG).apply {
|
|
|
|
setActionTextColor(ContextCompat.getColor(this@EventActivity, R.color.colorBase20))
|
|
|
|
view.setBackgroundColor(ContextCompat.getColor(this@EventActivity, R.color.colorBase03))
|
|
|
|
view.let {
|
|
|
|
it.setPadding(
|
|
|
|
it.paddingLeft,
|
|
|
|
it.paddingTop,
|
|
|
|
it.paddingRight,
|
|
|
|
it.paddingBottom + (48 * Resources.getSystem().displayMetrics.density).toInt()
|
2018-12-12 04:30:34 +00:00
|
|
|
)
|
|
|
|
show()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
true
|
|
|
|
}
|
|
|
|
fabCalendar.setOnClickListener { _ ->
|
|
|
|
val intent = Intent(Intent.ACTION_EDIT)
|
|
|
|
intent.type = "vnd.android.cursor.item/event"
|
|
|
|
intent.putExtra(CalendarContract.Events.TITLE, favorite.getString(this))
|
|
|
|
if(event!=null) {
|
|
|
|
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, TextualJoiner(runtimeLanguage)[event.places.map { it.names[runtimeLanguage]?:"" }])
|
|
|
|
intent.putExtra(CalendarContract.Events.DESCRIPTION, event.descriptions[runtimeLanguage])
|
|
|
|
}
|
|
|
|
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
|
|
|
|
favorite.timeRange.start.timeInMillis)
|
|
|
|
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
|
|
|
|
favorite.timeRange.finish.timeInMillis)
|
|
|
|
startActivity(intent)
|
|
|
|
}
|
|
|
|
fabCalendar.isLongClickable = true
|
|
|
|
fabCalendar.setOnLongClickListener {
|
|
|
|
Snackbar.make(it.rootView, R.string.adds_to_your_agenda_app, Snackbar.LENGTH_LONG).apply {
|
|
|
|
setActionTextColor(ContextCompat.getColor(this@EventActivity, R.color.colorBase20))
|
|
|
|
view.setBackgroundColor(ContextCompat.getColor(this@EventActivity, R.color.colorBase03))
|
|
|
|
view.let {
|
|
|
|
it.setPadding(
|
|
|
|
it.paddingLeft,
|
|
|
|
it.paddingTop,
|
|
|
|
it.paddingRight,
|
|
|
|
it.paddingBottom + (48 * Resources.getSystem().displayMetrics.density).toInt()
|
2018-07-31 23:26:09 +00:00
|
|
|
)
|
|
|
|
show()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
true
|
|
|
|
}
|
|
|
|
whenButton.isLongClickable = true
|
|
|
|
whenButton.setOnLongClickListener {
|
|
|
|
Snackbar.make(it.rootView, R.string.opens_timer, Snackbar.LENGTH_LONG).apply {
|
|
|
|
setActionTextColor(ContextCompat.getColor(this@EventActivity, R.color.colorBase20))
|
|
|
|
view.setBackgroundColor(ContextCompat.getColor(this@EventActivity, R.color.colorBase03))
|
|
|
|
view.let {
|
|
|
|
it.setPadding(
|
|
|
|
it.paddingLeft,
|
|
|
|
it.paddingTop,
|
|
|
|
it.paddingRight,
|
|
|
|
it.paddingBottom + (48 * Resources.getSystem().displayMetrics.density).toInt()
|
|
|
|
)
|
|
|
|
show()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
true
|
|
|
|
}
|
2018-07-16 05:36:26 +00:00
|
|
|
scheduleManager.addObserver (Observer { _, _ ->
|
|
|
|
if (favorite in scheduleManager.attendeeFavorites)
|
|
|
|
fab.setImageResource(R.drawable.ic_star_white_24dp)
|
|
|
|
else
|
|
|
|
fab.setImageResource(R.drawable.ic_star_border_white_24dp)
|
|
|
|
}.apply { this.update(null, null) })
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun inflateKeyPair(key: String, value: String, into: ViewGroup? = null) =
|
|
|
|
layoutInflater.inflate(R.layout.activity_event_content_keypair).apply {
|
|
|
|
textKey.text = key
|
|
|
|
textValue.text = value
|
|
|
|
into?.addView(this)
|
2018-07-27 03:39:36 +00:00
|
|
|
touchableIndicator.visibility = View.GONE
|
2018-07-16 05:36:26 +00:00
|
|
|
}
|
2018-07-18 15:01:16 +00:00
|
|
|
|
|
|
|
override fun onBackPressed() {
|
|
|
|
if (!fromNotification)
|
|
|
|
super.onBackPressed()
|
|
|
|
else {
|
2018-07-18 15:40:37 +00:00
|
|
|
val intent = Intent(this, SplashActivity::class.java)
|
2018-07-18 15:01:16 +00:00
|
|
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_TASK_ON_HOME
|
2018-07-18 15:40:37 +00:00
|
|
|
intent.putExtra("fastStart", true)
|
2018-07-18 15:01:16 +00:00
|
|
|
this.startActivity(intent)
|
|
|
|
this.finish()
|
|
|
|
}
|
|
|
|
}
|
2018-07-16 05:36:26 +00:00
|
|
|
}
|