added navigation bottom bar
This commit is contained in:
parent
e1f507deae
commit
58def7160d
@ -1,10 +1,20 @@
|
|||||||
package com.displaynone.acss
|
package com.displaynone.acss
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
|
import android.view.View
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
|
import androidx.annotation.IdRes
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.appcompat.widget.Toolbar
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import androidx.navigation.fragment.NavHostFragment
|
||||||
|
import androidx.navigation.ui.AppBarConfiguration
|
||||||
|
import androidx.navigation.ui.NavigationUI
|
||||||
|
import com.displaynone.acss.components.auth.models.user.UserServiceST
|
||||||
|
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@ -16,5 +26,40 @@ class MainActivity : AppCompatActivity() {
|
|||||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
||||||
insets
|
insets
|
||||||
}
|
}
|
||||||
|
Log.d("123", R.id.action_nav_main_to_nav_profile.toString())
|
||||||
|
Log.d("123", R.id.action_nav_main_to_nav_auth.toString())
|
||||||
|
|
||||||
|
val navController: NavController = this.setupNavigation()
|
||||||
|
|
||||||
|
if(isUserAuthenticated()) { navigateTo(navController, R.id.action_nav_main_to_nav_profile)} else {navigateTo(navController, R.id.action_nav_main_to_nav_auth)}
|
||||||
|
}
|
||||||
|
fun navigateTo(navController: NavController, @IdRes actionId: Int) {
|
||||||
|
navController.navigate(actionId)
|
||||||
|
}
|
||||||
|
private fun setupNavigation(): NavController {
|
||||||
|
val navView = findViewById<BottomNavigationView>(R.id.bottom_navigation)
|
||||||
|
|
||||||
|
val toolbar = findViewById<Toolbar>(R.id.toolbar);
|
||||||
|
setSupportActionBar(toolbar)
|
||||||
|
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as? NavHostFragment
|
||||||
|
if (navHostFragment == null){
|
||||||
|
throw IllegalStateException("NavHostFragment is null")
|
||||||
|
}
|
||||||
|
|
||||||
|
val navController = navHostFragment.navController
|
||||||
|
val appBarConfiguration = AppBarConfiguration(setOf(R.id.nav_auth,R.id.nav_scan, R.id.nav_profile, R.id.nav_admin))
|
||||||
|
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration)
|
||||||
|
NavigationUI.setupWithNavController(navView, navController)
|
||||||
|
|
||||||
|
navController.addOnDestinationChangedListener { _, destination, _ ->
|
||||||
|
Log.d("Navigate", "Navigate to " + destination.label)
|
||||||
|
navView.visibility = if (destination.id == R.id.nav_auth) View.GONE else View.VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
return navController
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isUserAuthenticated(): Boolean {
|
||||||
|
return UserServiceST.getInstance().hasTokens()
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -37,6 +37,9 @@ class UserServiceST(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fun hasTokens(): Boolean {
|
||||||
|
return tokenManager.hasTokens()
|
||||||
|
}
|
||||||
suspend fun getMyLastVisits(pageNum: Int,
|
suspend fun getMyLastVisits(pageNum: Int,
|
||||||
pageSize: Int): Result<List<VisitDto>> {
|
pageSize: Int): Result<List<VisitDto>> {
|
||||||
if (!tokenManager.hasTokens()) {
|
if (!tokenManager.hasTokens()) {
|
||||||
|
@ -126,7 +126,7 @@ class UserRepository(
|
|||||||
runCatching {
|
runCatching {
|
||||||
Log.d("UserRepository", login)
|
Log.d("UserRepository", login)
|
||||||
val encodedLogin = login.encodeURLPath()
|
val encodedLogin = login.encodeURLPath()
|
||||||
val result = Network.client.get("$serverUrl/api/acs/login/visits/${encodedLogin}?page=$pageNum&size=$pageSize") {
|
val result = Network.client.get("$serverUrl/api/acs/visits/login/${encodedLogin}?page=$pageNum&size=$pageSize") {
|
||||||
headers {
|
headers {
|
||||||
append(HttpHeaders.Authorization, "Bearer $token")
|
append(HttpHeaders.Authorization, "Bearer $token")
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,36 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/root"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:popupTheme="@style/Base.Theme.ACSS"/>
|
||||||
<androidx.fragment.app.FragmentContainerView
|
<androidx.fragment.app.FragmentContainerView
|
||||||
android:id="@+id/nav_host_fragment"
|
android:id="@+id/nav_host_fragment"
|
||||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_weight="1"
|
||||||
|
app:defaultNavHost="true"
|
||||||
|
android:layout_height="0dp"
|
||||||
app:navGraph="@navigation/nav_graph" />
|
app:navGraph="@navigation/nav_graph" />
|
||||||
|
<com.google.android.material.bottomnavigation.BottomNavigationView
|
||||||
|
android:id="@+id/bottom_navigation"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:labelVisibilityMode="labeled"
|
||||||
|
app:menu="@menu/bottom_nav_menu"
|
||||||
|
app:itemIconSize="24dp" />
|
||||||
|
</LinearLayout>
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,12 +1,17 @@
|
|||||||
|
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/scan_fragment"
|
android:id="@+id/nav_scan"
|
||||||
android:icon="@drawable/qr_code_scan"
|
android:icon="@drawable/qr_code_scan"
|
||||||
android:title="@string/scan" />
|
android:title="@string/scan" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_profile"
|
android:id="@+id/nav_profile"
|
||||||
android:icon="@drawable/_user_"
|
android:icon="@drawable/_user_"
|
||||||
android:title="@string/title_profile" />
|
android:title="@string/title_profile" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/nav_admin"
|
||||||
|
|
||||||
|
android:icon="@drawable/_user_"
|
||||||
|
android:title="@string/admin" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
9
app/src/main/res/menu/toolbar.xml
Normal file
9
app/src/main/res/menu/toolbar.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/logout"
|
||||||
|
android:title="logout"
|
||||||
|
android:icon="@drawable/ic_photo"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
</menu>
|
@ -2,51 +2,63 @@
|
|||||||
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
app:startDestination="@id/authFragment">
|
app:startDestination="@id/nav_auth">
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/profileFragment"
|
android:id="@+id/nav_profile"
|
||||||
android:name="com.displaynone.acss.ui.profile.ProfileFragment"
|
android:name="com.displaynone.acss.ui.profile.ProfileFragment"
|
||||||
android:label="ProfileFragment"
|
android:label="ProfileFragment"
|
||||||
tools:layout="@layout/fragment_profile">
|
tools:layout="@layout/fragment_profile">
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_profileFragment_to_authFragment"
|
android:id="@+id/action_profileFragment_to_authFragment"
|
||||||
app:destination="@id/authFragment" />
|
app:destination="@id/nav_auth" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_profileFragment_to_qrScanFragment"
|
android:id="@+id/action_profileFragment_to_qrScanFragment"
|
||||||
app:destination="@id/qrScanFragment" />
|
app:destination="@id/nav_scan" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_profileFragment_to_qrResultFragment"
|
android:id="@+id/action_profileFragment_to_qrResultFragment"
|
||||||
app:destination="@id/qrResultFragment" />
|
app:destination="@id/qrResultFragment" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_profileFragment_to_adminFragment"
|
android:id="@+id/action_profileFragment_to_adminFragment"
|
||||||
app:destination="@id/adminFragment" />
|
app:destination="@id/nav_admin" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_nav_main_to_nav_profile"
|
||||||
|
app:destination="@id/nav_profile" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_nav_main_to_nav_auth"
|
||||||
|
app:destination="@id/nav_auth" />
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/authFragment"
|
android:id="@+id/nav_auth"
|
||||||
android:name="com.displaynone.acss.ui.auth.AuthFragment"
|
android:name="com.displaynone.acss.ui.auth.AuthFragment"
|
||||||
android:label="AuthFragment" >
|
android:label="AuthFragment" >
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_authFragment_to_profileFragment"
|
android:id="@+id/action_authFragment_to_profileFragment"
|
||||||
app:destination="@id/profileFragment" />
|
app:destination="@id/nav_profile" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/qrScanFragment"
|
android:id="@+id/nav_scan"
|
||||||
android:name="com.displaynone.acss.ui.scan.QrScanFragment"
|
android:name="com.displaynone.acss.ui.scan.QrScanFragment"
|
||||||
android:label="QrScanFragment" />
|
android:label="QrScanFragment" >
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_nav_scan_to_nav_profile"
|
||||||
|
app:destination="@id/nav_profile" />
|
||||||
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/qrResultFragment"
|
android:id="@+id/qrResultFragment"
|
||||||
android:name="com.displaynone.acss.ui.result.QrResultFragment"
|
android:name="com.displaynone.acss.ui.result.QrResultFragment"
|
||||||
android:label="QrResultFragment" >
|
android:label="QrResultFragment" >
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_qrResultFragment_to_profileFragment"
|
android:id="@+id/action_qrResultFragment_to_profileFragment"
|
||||||
app:destination="@id/profileFragment" />
|
app:destination="@id/nav_profile" />
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/adminFragment"
|
android:id="@+id/nav_admin"
|
||||||
android:name="com.displaynone.acss.ui.admin.AdminFragment"
|
android:name="com.displaynone.acss.ui.admin.AdminFragment"
|
||||||
android:label="AdminFragment" >
|
android:label="AdminFragment" >
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_adminFragment_to_profileFragment"
|
android:id="@+id/action_adminFragment_to_profileFragment"
|
||||||
app:destination="@id/profileFragment" />
|
app:destination="@id/nav_profile" />
|
||||||
</fragment>
|
</fragment>
|
||||||
</navigation>
|
</navigation>
|
@ -18,6 +18,7 @@
|
|||||||
<string name="administrator_searc_button_search"> Search </string>
|
<string name="administrator_searc_button_search"> Search </string>
|
||||||
<string name="title_profile">Your profile</string>
|
<string name="title_profile">Your profile</string>
|
||||||
<string name="сhange_rights">Change rights using smartphone</string>
|
<string name="сhange_rights">Change rights using smartphone</string>
|
||||||
|
<string name="admin">Admin panel</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user