2020-02-28 17:08:54 +01:00
|
|
|
package com.h.pixeldroid
|
|
|
|
|
2020-03-06 08:49:26 +01:00
|
|
|
import android.content.Intent
|
2020-02-28 17:08:54 +01:00
|
|
|
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
|
2020-03-05 22:49:16 +01:00
|
|
|
import androidx.fragment.app.Fragment
|
2020-03-05 21:07:10 +01:00
|
|
|
import com.google.android.material.navigation.NavigationView
|
|
|
|
import com.h.pixeldroid.settings.ui.*
|
2020-03-04 18:04:55 +01:00
|
|
|
import android.util.Log
|
|
|
|
import com.h.pixeldroid.api.PixelfedAPI
|
|
|
|
import com.h.pixeldroid.objects.Status
|
|
|
|
import retrofit2.Call
|
|
|
|
import retrofit2.Callback
|
|
|
|
import retrofit2.Response
|
|
|
|
import retrofit2.Retrofit
|
|
|
|
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
|
|
|
import retrofit2.converter.gson.GsonConverterFactory
|
2020-03-06 08:49:26 +01:00
|
|
|
import android.view.View
|
|
|
|
import android.widget.Button
|
2020-03-06 00:11:12 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
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) {
|
2020-03-05 22:49:16 +01:00
|
|
|
launchFragment(AccountFragment())
|
2020-03-05 21:07:10 +01:00
|
|
|
navigationView.setCheckedItem(R.id.nav_account)
|
|
|
|
}
|
2020-03-08 11:17:26 +01:00
|
|
|
|
2020-03-07 19:02:45 +01:00
|
|
|
val button_login = findViewById<Button>(R.id.button_start_login)
|
|
|
|
button_login.setOnClickListener((View.OnClickListener {
|
2020-03-06 08:49:26 +01:00
|
|
|
val intent = Intent(this, LoginActivity::class.java)
|
|
|
|
startActivity(intent) }))
|
2020-03-04 18:04:55 +01:00
|
|
|
|
2020-03-06 00:11:12 +01:00
|
|
|
val button = findViewById<Button>(R.id.button)
|
|
|
|
button.setOnClickListener((View.OnClickListener {
|
|
|
|
val intent = Intent(this, ProfileActivity::class.java)
|
|
|
|
startActivity(intent) }))
|
2020-03-05 21:07:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
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){
|
2020-03-05 22:49:16 +01:00
|
|
|
R.id.nav_account -> launchFragment(AccountFragment())
|
|
|
|
R.id.nav_accessibility -> launchFragment(AccessibilityFragment())
|
|
|
|
R.id.nav_settings -> launchFragment(SettingsFragment())
|
2020-03-05 21:07:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
drawerLayout.closeDrawer(GravityCompat.START)
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-03-05 22:49:16 +01:00
|
|
|
/*
|
|
|
|
Launches the given fragment and put it as the current "activity"
|
|
|
|
*/
|
|
|
|
private fun launchFragment(fragment: Fragment) {
|
|
|
|
supportFragmentManager.beginTransaction().replace(R.id.fragment_container, fragment).commit()
|
|
|
|
}
|
|
|
|
|
2020-03-05 21:07:10 +01:00
|
|
|
/*
|
|
|
|
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
|
|
|
}
|
2020-03-04 18:04:55 +01:00
|
|
|
|
2020-02-28 17:08:54 +01:00
|
|
|
}
|