This is the home of the new hsoApp!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.1KB

  1. /**
  2. * ProjectLaogai
  3. *
  4. * Copyright 2018 <seil0@mosad.xyz>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19. * MA 02110-1301, USA.
  20. *
  21. */
  22. package org.mosad.seil0.projectlaogai
  23. import android.os.Bundle
  24. import android.support.design.widget.Snackbar
  25. import android.support.design.widget.NavigationView
  26. import android.support.v4.view.GravityCompat
  27. import android.support.v7.app.ActionBarDrawerToggle
  28. import android.support.v7.app.AppCompatActivity
  29. import android.view.Menu
  30. import android.view.MenuItem
  31. import kotlinx.android.synthetic.main.activity_main.*
  32. import kotlinx.android.synthetic.main.app_bar_main.*
  33. class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
  34. //TODO make toolbar and navbar global
  35. override fun onCreate(savedInstanceState: Bundle?) {
  36. super.onCreate(savedInstanceState)
  37. setContentView(R.layout.activity_main)
  38. setSupportActionBar(toolbar)
  39. //init home fragment TODO make a abstract fragment class
  40. val homeFragment = HomeFragment()
  41. val fragmentTransaction: android.support.v4.app.FragmentTransaction = supportFragmentManager.beginTransaction()
  42. fragmentTransaction.replace(R.id.fragment_container, homeFragment)
  43. fragmentTransaction.commit()
  44. fab.setOnClickListener { view ->
  45. Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
  46. .setAction("Action", null).show()
  47. }
  48. val toggle = ActionBarDrawerToggle(
  49. this, drawer_layout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close
  50. )
  51. drawer_layout.addDrawerListener(toggle)
  52. toggle.syncState()
  53. nav_view.setNavigationItemSelectedListener(this)
  54. }
  55. override fun onBackPressed() {
  56. if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
  57. drawer_layout.closeDrawer(GravityCompat.START)
  58. } else {
  59. super.onBackPressed()
  60. }
  61. }
  62. override fun onCreateOptionsMenu(menu: Menu): Boolean {
  63. // Inflate the menu; this adds items to the action bar if it is present.
  64. menuInflater.inflate(R.menu.main, menu)
  65. return true
  66. }
  67. override fun onOptionsItemSelected(item: MenuItem): Boolean {
  68. // Handle action bar item clicks here. The action bar will
  69. // automatically handle clicks on the Home/Up button, so long
  70. // as you specify a parent activity in AndroidManifest.xml.
  71. return when (item.itemId) {
  72. R.id.action_settings -> true
  73. else -> super.onOptionsItemSelected(item)
  74. }
  75. }
  76. override fun onNavigationItemSelected(item: MenuItem): Boolean {
  77. // Handle navigation view item clicks here.
  78. when (item.itemId) {
  79. R.id.nav_home -> {
  80. // Handle the home action
  81. }
  82. R.id.nav_mensa -> {
  83. //val mensaFragment: MensaFragment = MensaFragment()
  84. //val fragmentTransaction: android.support.v4.app.FragmentTransaction = supportFragmentManager.beginTransaction()
  85. //fragmentTransaction.replace(R.id.fragment_container, mensaFragment)
  86. //fragmentTransaction.commit()
  87. }
  88. R.id.nav_timetable -> {
  89. }
  90. R.id.nav_moodle -> {
  91. }
  92. R.id.nav_email -> {
  93. }
  94. R.id.nav_settings -> {
  95. }
  96. }
  97. drawer_layout.closeDrawer(GravityCompat.START)
  98. return true
  99. }
  100. }