2020-02-28 17:08:54 +01:00
|
|
|
package com.h.pixeldroid
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
import android.os.Bundle
|
2020-03-05 21:07:10 +01:00
|
|
|
import android.view.MenuItem
|
|
|
|
import androidx.annotation.NonNull
|
|
|
|
import androidx.appcompat.app.ActionBarDrawerToggle
|
|
|
|
import androidx.appcompat.widget.Toolbar
|
|
|
|
import androidx.core.view.GravityCompat
|
|
|
|
import androidx.drawerlayout.widget.DrawerLayout
|
|
|
|
import com.google.android.material.navigation.NavigationView
|
|
|
|
import com.h.pixeldroid.settings.ui.*
|
2020-02-28 17:08:54 +01:00
|
|
|
|
2020-03-05 21:07:10 +01:00
|
|
|
class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
|
|
|
|
|
|
|
|
private lateinit var drawerLayout: DrawerLayout
|
2020-02-28 17:08:54 +01:00
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
setContentView(R.layout.activity_main)
|
2020-03-05 21:07:10 +01:00
|
|
|
|
2020-03-05 21:48:25 +01:00
|
|
|
// setup the top toolbar
|
2020-03-05 21:07:10 +01:00
|
|
|
val toolbar : Toolbar = findViewById(R.id.toolbar)
|
|
|
|
setSupportActionBar(toolbar)
|
|
|
|
|
2020-03-05 21:48:25 +01:00
|
|
|
// Setup the drawer
|
2020-03-05 21:07:10 +01:00
|
|
|
drawerLayout = findViewById(R.id.drawer_layout)
|
|
|
|
val navigationView: NavigationView = findViewById(R.id.nav_view)
|
|
|
|
navigationView.setNavigationItemSelectedListener(this)
|
|
|
|
|
|
|
|
val toggle = ActionBarDrawerToggle(this, drawerLayout, toolbar,
|
|
|
|
R.string.navigation_drawer_open, R.string.navigation_drawer_close)
|
|
|
|
drawerLayout.addDrawerListener(toggle)
|
|
|
|
toggle.syncState()
|
|
|
|
|
|
|
|
// On startup ONLY, start at the account settings
|
|
|
|
if(savedInstanceState == null) {
|
|
|
|
supportFragmentManager.beginTransaction().replace(R.id.fragment_container,
|
|
|
|
AccountFragment()).commit()
|
|
|
|
navigationView.setCheckedItem(R.id.nav_account)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-03-05 21:48:25 +01:00
|
|
|
When clicking in the drawer menu, go to the corresponding activity
|
2020-03-05 21:07:10 +01:00
|
|
|
*/
|
|
|
|
override fun onNavigationItemSelected(@NonNull item: MenuItem): Boolean {
|
|
|
|
when (item.itemId){
|
|
|
|
R.id.nav_account -> supportFragmentManager.beginTransaction().replace(R.id.fragment_container,
|
|
|
|
AccountFragment()).commit()
|
|
|
|
R.id.nav_accessibility -> supportFragmentManager.beginTransaction().replace(R.id.fragment_container,
|
|
|
|
AccessibilityFragment()).commit()
|
|
|
|
R.id.nav_settings -> supportFragmentManager.beginTransaction().replace(R.id.fragment_container,
|
|
|
|
SettingsFragment()).commit()
|
|
|
|
}
|
|
|
|
|
|
|
|
drawerLayout.closeDrawer(GravityCompat.START)
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Makes it possible to drag the settings menu from the left
|
|
|
|
*/
|
|
|
|
override fun onBackPressed() {
|
|
|
|
if(drawerLayout.isDrawerOpen(GravityCompat.START)){
|
|
|
|
drawerLayout.closeDrawer(GravityCompat.START)
|
|
|
|
} else {
|
|
|
|
super.onBackPressed()
|
|
|
|
}
|
2020-02-28 17:08:54 +01:00
|
|
|
}
|
|
|
|
}
|