ParametersActivity.kt 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package fr.riff_app.riff
  2. import android.os.Bundle
  3. import android.view.MenuItem
  4. import fr.riff_app.riff.preferences.*
  5. class ParametersActivity : BaseActivity() {
  6. override fun onCreate(savedInstanceState: Bundle?) {
  7. super.onCreate(savedInstanceState)
  8. // UI Launch
  9. setTheme(R.style.AppTheme_Parameters)
  10. setContentView(R.layout.activity_parameters)
  11. // my_child_toolbar is defined in the layout file
  12. setSupportActionBar(findViewById(R.id.toolbar))
  13. // Get a support ActionBar corresponding to this toolbar and enable the Up button
  14. supportActionBar?.setDisplayHomeAsUpEnabled(true)
  15. val extra = if (savedInstanceState == null) {
  16. intent.extras?.getString("action")
  17. } else {
  18. savedInstanceState.getSerializable("action") as String
  19. }
  20. val fragmentToLoad = when(extra) {
  21. ActionOpenParam.ALARM.name -> AlarmFragment()
  22. ActionOpenParam.SLEEP.name -> SleepFragment()
  23. ActionOpenParam.CUSTOMIZE.name -> CustomizeFragment()
  24. else -> MainPreferenceFragment()
  25. }
  26. supportFragmentManager
  27. .beginTransaction()
  28. .replace(R.id.parameters_host_container, fragmentToLoad)
  29. .commit()
  30. }
  31. // Make the Up button function as back instead of always bringing us to the main activity
  32. override fun onOptionsItemSelected(item: MenuItem): Boolean {
  33. return when (item.itemId) {
  34. android.R.id.home -> {
  35. onBackPressed()
  36. true
  37. }
  38. else -> super.onOptionsItemSelected(item)
  39. }
  40. }
  41. }