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

119 lines
4.8 KiB
Kotlin
Raw Normal View History

2018-07-09 17:16:33 +00:00
package com.adlerosn.brasilfurfest.schedule
import android.app.AlertDialog
import android.content.DialogInterface
2018-07-14 19:43:24 +00:00
import android.content.Intent
2018-07-09 17:16:33 +00:00
import android.os.Bundle
2018-07-31 23:26:09 +00:00
import android.support.design.widget.Snackbar
2018-07-13 21:09:43 +00:00
import android.support.design.widget.TabLayout
import android.support.v4.app.FragmentPagerAdapter
2018-07-31 23:26:09 +00:00
import android.support.v4.content.ContextCompat
2018-07-09 17:16:33 +00:00
import android.support.v7.app.AppCompatActivity
2018-07-14 19:43:24 +00:00
import android.view.Menu
import android.view.MenuItem
2018-07-09 17:16:33 +00:00
import com.adlerosn.brasilfurfest.R
2018-07-17 19:38:11 +00:00
import com.adlerosn.brasilfurfest.developer.DeveloperActivity
2018-12-12 04:30:34 +00:00
import com.adlerosn.brasilfurfest.helper.ActivitiesForFragments
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.helper.runtimeLanguage
import com.adlerosn.brasilfurfest.schedule.adapters.DaysPagerAdapter
2018-12-13 02:04:29 +00:00
import com.adlerosn.brasilfurfest.schedule.managers.ScheduleManager
2018-07-09 17:16:33 +00:00
import kotlinx.android.synthetic.main.activity_schedule.*
class ScheduleActivity : AppCompatActivity() {
private lateinit var scheduleManager: ScheduleManager
2018-07-31 23:26:09 +00:00
private lateinit var pagerAdapter: FragmentPagerAdapter
2018-07-13 21:09:43 +00:00
2018-07-09 17:16:33 +00:00
override fun onCreate(savedInstanceState: Bundle?) {
2018-12-12 04:30:34 +00:00
ActivitiesForFragments[this.javaClass.simpleName] = this
2018-07-09 17:16:33 +00:00
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_schedule)
2018-07-13 21:09:43 +00:00
2018-07-09 17:16:33 +00:00
setSupportActionBar(toolbar)
2018-12-13 21:06:50 +00:00
// Create the filteredEventsListAdapter that will return a fragment for each of the three
2018-07-13 21:09:43 +00:00
// primary sections of the activity.
2018-07-09 17:16:33 +00:00
2018-12-12 04:30:34 +00:00
scheduleManager = ScheduleManagerGetter[this]
2018-07-14 19:43:24 +00:00
scheduleManager.onAttendeeIntentionsChanged()
2018-07-13 21:09:43 +00:00
toolbar.title = scheduleManager.convention.name
toolbar.subtitle = scheduleManager.convention.theme[this.runtimeLanguage]
pagerAdapter = DaysPagerAdapter(supportFragmentManager, this, scheduleManager)
tabs.setupWithViewPager(container)
2018-12-13 21:06:50 +00:00
// Set up the ViewPager with the sections filteredEventsListAdapter.
2018-07-13 21:09:43 +00:00
container.adapter = pagerAdapter
container.offscreenPageLimit = pagerAdapter.count
container.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabs))
tabs.addOnTabSelectedListener(TabLayout.ViewPagerOnTabSelectedListener(container))
2018-07-14 19:43:24 +00:00
fab.setOnClickListener {
Intent(this, FavoritesActivity::class.java).apply {
startActivity(this)
}
2018-07-09 17:16:33 +00:00
}
2018-07-31 23:26:09 +00:00
fab.isLongClickable = true
fab.setOnLongClickListener {
Snackbar.make(it, R.string.schedule_events_favorites, Snackbar.LENGTH_LONG).apply {
setActionTextColor(ContextCompat.getColor(this@ScheduleActivity, R.color.colorBase20))
view.setBackgroundColor(ContextCompat.getColor(this@ScheduleActivity, R.color.colorBase03))
show()
}
true
}
2018-07-09 17:16:33 +00:00
}
2018-07-13 21:09:43 +00:00
2018-07-09 17:16:33 +00:00
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
2018-07-13 21:09:43 +00:00
menuInflater.inflate(R.menu.menu_schedule, menu)
2018-07-09 17:16:33 +00:00
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
return when (item.itemId) {
2018-07-13 21:09:43 +00:00
R.id.action_clear_planning -> {
2018-07-17 19:38:11 +00:00
val dialog = AlertDialog.Builder(this).create()
2018-07-09 17:16:33 +00:00
dialog.setTitle(getString(R.string.schedule_clear_planning_question))
dialog.setMessage(getString(R.string.this_cannot_be_undone))
2018-07-17 19:38:11 +00:00
dialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.dialog_cancel)) { _: DialogInterface, _: Int ->
2018-07-09 17:16:33 +00:00
dialog.dismiss()
}
2018-07-17 19:38:11 +00:00
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.dialog_confirm)) { _: DialogInterface, _: Int ->
2018-07-09 17:16:33 +00:00
dialog.dismiss()
scheduleManager.clearIntentions()
2018-07-13 21:09:43 +00:00
scheduleManager.onAttendeeIntentionsChanged()
2018-07-09 17:16:33 +00:00
}
dialog.show()
true
}
2018-07-17 19:38:11 +00:00
R.id.action_developer -> {
Intent(this, DeveloperActivity::class.java).apply {
startActivity(this)
}
true
}
2018-12-12 04:30:34 +00:00
R.id.action_search_filter -> {
Intent(this, SearchFilterActivity::class.java).apply {
startActivity(this)
}
true
}
2018-07-09 17:16:33 +00:00
else -> super.onOptionsItemSelected(item)
}
}
2018-07-27 20:24:09 +00:00
override fun onBackPressed() {
if (tabs.selectedTabPosition == 0)
super.onBackPressed()
else
container.setCurrentItem(0, true)
}
2018-07-09 17:16:33 +00:00
}