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

137 lines
5.3 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
2019-05-23 14:58:10 +00:00
import android.net.Uri
2018-07-09 17:16:33 +00:00
import android.os.Bundle
import com.google.android.material.snackbar.Snackbar
import androidx.fragment.app.FragmentPagerAdapter
import androidx.appcompat.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-28 00:28:48 +00:00
import com.adlerosn.brasilfurfest.helper.*
2019-05-23 14:58:10 +00:00
import com.adlerosn.brasilfurfest.schedule.abstractDataTypes.managed.AttendeeConFavorite
2018-07-13 21:09:43 +00:00
import com.adlerosn.brasilfurfest.schedule.adapters.DaysPagerAdapter
2018-12-13 02:04:29 +00:00
import com.adlerosn.brasilfurfest.schedule.managers.ScheduleManager
2019-05-23 14:58:10 +00:00
import com.adlerosn.brasilfurfest.schedule.managers.ScheduleManagerGetter
import com.google.gson.GsonBuilder
import com.google.zxing.integration.android.IntentIntegrator
2018-07-09 17:16:33 +00:00
import kotlinx.android.synthetic.main.activity_schedule.*
2019-05-23 14:58:10 +00:00
import org.jetbrains.anko.longToast
2018-07-09 17:16:33 +00:00
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)
setSupportActionBar(toolbar)
2018-12-28 00:28:48 +00:00
resourcesAliased = this.resources
2018-12-12 04:30:34 +00:00
scheduleManager = ScheduleManagerGetter[this]
2018-12-28 00:28:48 +00:00
2018-07-14 19:43:24 +00:00
scheduleManager.onAttendeeIntentionsChanged()
2018-07-13 21:09:43 +00:00
toolbar.title = scheduleManager.convention.name
2018-12-28 00:28:48 +00:00
toolbar.subtitle = scheduleManager.convention.theme.solved
pagerAdapter = DaysPagerAdapter(supportFragmentManager, scheduleManager)
2018-07-13 21:09:43 +00:00
container.adapter = pagerAdapter
2018-12-28 00:28:48 +00:00
tabs.fullSetup(container)
2018-07-13 21:09:43 +00:00
2018-12-28 00:28:48 +00:00
container.offscreenPageLimit = pagerAdapter.count
2018-07-13 21:09:43 +00:00
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 {
2018-12-28 00:28:48 +00:00
setActionTextColor(this@ScheduleActivity.getColorCompat(R.color.colorBase20))
view.setBackgroundColor(this@ScheduleActivity.getColorCompat(R.color.colorBase03))
2018-07-31 23:26:09 +00:00
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 {
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 {
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-12-28 00:28:48 +00:00
dialog.setTitle(R.string.schedule_clear_planning_question.getString())
dialog.setMessage(R.string.this_cannot_be_undone.getString())
dialog.setButton(AlertDialog.BUTTON_NEUTRAL, R.string.dialog_cancel.getString()) { _: DialogInterface, _: Int ->
2018-07-09 17:16:33 +00:00
dialog.dismiss()
}
2018-12-28 00:28:48 +00:00
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, R.string.dialog_confirm.getString()) { _: 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
}
2019-05-23 14:58:10 +00:00
R.id.action_scan_qr_code -> {
IntentIntegrator(this).apply {
setDesiredBarcodeFormats(IntentIntegrator.QR_CODE)
setOrientationLocked(true)
setBarcodeImageEnabled(false)
setBeepEnabled(false)
initiateScan()
}
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
2019-05-23 14:58:10 +00:00
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
result?.contents?.also { url ->
val uri = Uri.parse(url)
if (uri.path == "/app/roomparty"){
try {
GsonBuilder().create().fromJson(Uri.decode(uri.encodedFragment!!), AttendeeConFavorite::class.java)
}catch (e: Throwable){
longToast(getString(R.string.error_broken_invite))
return
}
startActivity(Intent(Intent.ACTION_SEND, uri, this, RoomPartyPreviewerActivity::class.java).apply {
putExtra("notQr", false)
})
}
}
}
2018-07-09 17:16:33 +00:00
}