package com.adlerosn.brasilfurfest.schedule import android.app.AlertDialog import android.content.DialogInterface import android.content.Intent import android.graphics.Color import android.os.Bundle import android.support.design.widget.TabLayout import android.support.v4.app.FragmentPagerAdapter import android.support.v7.app.AppCompatActivity import android.view.Menu import android.view.MenuItem import android.view.WindowManager import com.adlerosn.brasilfurfest.R import com.adlerosn.brasilfurfest.developer.DeveloperActivity import com.adlerosn.brasilfurfest.helper.runtimeLanguage import com.adlerosn.brasilfurfest.legal.SoftwareLicensesActivity import com.adlerosn.brasilfurfest.schedule.adapters.DaysPagerAdapter import kotlinx.android.synthetic.main.activity_schedule.* class ScheduleActivity : AppCompatActivity() { private lateinit var scheduleManager: ScheduleManager lateinit var pagerAdapter: FragmentPagerAdapter override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_schedule) setSupportActionBar(toolbar) // Create the adapter that will return a fragment for each of the three // primary sections of the activity. scheduleManager = ScheduleManager(this) scheduleManager.onAttendeeIntentionsChanged() toolbar.title = scheduleManager.convention.name toolbar.subtitle = scheduleManager.convention.theme[this.runtimeLanguage] pagerAdapter = DaysPagerAdapter(supportFragmentManager, this, scheduleManager) tabs.setupWithViewPager(container) // Set up the ViewPager with the sections adapter. container.adapter = pagerAdapter container.offscreenPageLimit = pagerAdapter.count container.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabs)) tabs.addOnTabSelectedListener(TabLayout.ViewPagerOnTabSelectedListener(container)) fab.setOnClickListener { Intent(this, FavoritesActivity::class.java).apply { startActivity(this) } } } override fun onCreateOptionsMenu(menu: Menu): Boolean { // Inflate the menu; this adds items to the action bar if it is present. menuInflater.inflate(R.menu.menu_schedule, menu) 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) { R.id.action_clear_planning -> { val dialog = AlertDialog.Builder(this).create() dialog.setTitle(getString(R.string.schedule_clear_planning_question)) dialog.setMessage(getString(R.string.this_cannot_be_undone)) dialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.dialog_cancel)) { _: DialogInterface, _: Int -> dialog.dismiss() } dialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.dialog_confirm)) { _: DialogInterface, _: Int -> dialog.dismiss() scheduleManager.clearIntentions() scheduleManager.onAttendeeIntentionsChanged() } dialog.show() true } R.id.action_developer -> { Intent(this, DeveloperActivity::class.java).apply { startActivity(this) } true } else -> super.onOptionsItemSelected(item) } } override fun onBackPressed() { if (tabs.selectedTabPosition == 0) super.onBackPressed() else container.setCurrentItem(0, true) } }