Nav bar
This commit is contained in:
		
						commit
						8c05ab1325
					
				| @ -1,10 +1,20 @@ | ||||
| package com.displaynone.acss | ||||
| 
 | ||||
| import android.os.Bundle | ||||
| import android.util.Log | ||||
| import android.view.View | ||||
| import androidx.activity.enableEdgeToEdge | ||||
| import androidx.annotation.IdRes | ||||
| import androidx.appcompat.app.AppCompatActivity | ||||
| import androidx.appcompat.widget.Toolbar | ||||
| import androidx.core.view.ViewCompat | ||||
| 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() { | ||||
|     override fun onCreate(savedInstanceState: Bundle?) { | ||||
| @ -16,5 +26,40 @@ class MainActivity : AppCompatActivity() { | ||||
|             v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) | ||||
|             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, | ||||
|                                 pageSize: Int): Result<List<VisitDto>> { | ||||
|         if (!tokenManager.hasTokens()) { | ||||
|  | ||||
| @ -126,7 +126,7 @@ class UserRepository( | ||||
|         runCatching { | ||||
|             Log.d("UserRepository", login) | ||||
|             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 { | ||||
|                     append(HttpHeaders.Authorization, "Bearer $token") | ||||
|                 } | ||||
|  | ||||
| @ -1,6 +1,7 @@ | ||||
| package com.displaynone.acss.ui.auth | ||||
| 
 | ||||
| import android.annotation.SuppressLint | ||||
| import android.graphics.drawable.TransitionDrawable | ||||
| import android.os.Bundle | ||||
| import android.text.Editable | ||||
| import android.text.TextWatcher | ||||
| @ -28,7 +29,6 @@ class AuthFragment: Fragment(R.layout.fragment_auth) { | ||||
|         super.onViewCreated(view, savedInstanceState) | ||||
|         _binding = FragmentAuthBinding.bind(view) | ||||
|         setupLoginButton() | ||||
| 
 | ||||
|         viewModel.action.collectWithLifecycle(this) { action -> | ||||
|             if (action is Action.GotoProfile) { | ||||
|                 blockLoginButton() // FIXME() При двойном нажатии вылетает с ошибкой | ||||
|  | ||||
							
								
								
									
										4
									
								
								app/src/main/res/drawable/animated_gradient.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								app/src/main/res/drawable/animated_gradient.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| <transition xmlns:android="http://schemas.android.com/apk/res/android"> | ||||
|     <item android:drawable="@drawable/gradient_1" /> | ||||
|     <item android:drawable="@drawable/gradient_2" /> | ||||
| </transition> | ||||
							
								
								
									
										9
									
								
								app/src/main/res/drawable/gradient_1.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								app/src/main/res/drawable/gradient_1.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| <shape xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     > | ||||
|     <gradient | ||||
| 
 | ||||
|         android:startColor="#FFFFFF" | ||||
|         android:endColor="#BCE0E0" | ||||
|         android:angle="270" | ||||
|         android:type="linear" /> | ||||
| </shape> | ||||
							
								
								
									
										7
									
								
								app/src/main/res/drawable/gradient_2.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								app/src/main/res/drawable/gradient_2.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | ||||
| <shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||||
|     <gradient | ||||
|         android:startColor="#03a9f4" | ||||
|         android:endColor="#ffffff" | ||||
|         android:angle="270" | ||||
|         android:type="linear" /> | ||||
| </shape> | ||||
| @ -7,12 +7,37 @@ | ||||
|         android:layout_height="match_parent" | ||||
|         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 | ||||
|             android:id="@+id/nav_host_fragment" | ||||
|             android:name="androidx.navigation.fragment.NavHostFragment" | ||||
|             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" /> | ||||
| 
 | ||||
|         <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> | ||||
| @ -69,6 +69,7 @@ | ||||
|                 android:layout_width="match_parent" | ||||
|                 android:layout_height="wrap_content" | ||||
|                 android:layout_margin="15dp" | ||||
|                 android:maxLines="1" | ||||
|                 android:hint="@string/login" | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -18,6 +18,7 @@ | ||||
|         android:paddingTop="50dp"> | ||||
| 
 | ||||
|         <ImageView | ||||
| 
 | ||||
|             android:layout_width="match_parent" | ||||
|             android:layout_height="200dp" | ||||
|             android:foregroundGravity="center" | ||||
| @ -40,8 +41,9 @@ | ||||
|             app:layout_constraintTop_toTopOf="parent" /> | ||||
| 
 | ||||
|         <LinearLayout | ||||
|             android:background="@drawable/gradient_1" | ||||
|             android:layout_marginTop="10dp" | ||||
|             android:layout_width="280dp" | ||||
|             android:layout_width="match_parent" | ||||
|             android:layout_height="match_parent" | ||||
|             android:orientation="vertical" | ||||
|             android:gravity="center_horizontal"> | ||||
| @ -63,6 +65,8 @@ | ||||
|             <com.google.android.material.textfield.TextInputLayout | ||||
|                 android:layout_width="match_parent" | ||||
|                 android:layout_height="wrap_content" | ||||
|                 android:layout_marginLeft="70dp" | ||||
|                 android:layout_marginRight="70dp" | ||||
|                 app:boxStrokeColor="@color/primary" | ||||
|                 app:hintTextColor="?attr/colorOnBackground" | ||||
|                 app:helperTextTextColor="?attr/colorOnBackground" | ||||
| @ -73,6 +77,8 @@ | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="wrap_content" | ||||
|                     android:padding="14dp" | ||||
|                     android:maxLines="1" | ||||
| 
 | ||||
| 
 | ||||
|                     android:hint="@string/login" | ||||
|                     android:textColorHint="?attr/colorSecondary" | ||||
| @ -91,7 +97,10 @@ | ||||
|                     android:id="@+id/password" | ||||
|                     android:layout_width="match_parent" | ||||
|                     android:layout_height="wrap_content" | ||||
|                     android:layout_marginLeft="70dp" | ||||
|                     android:layout_marginRight="70dp" | ||||
|                     android:padding="14dp" | ||||
|                     android:maxLines="1" | ||||
| 
 | ||||
|                     android:hint="@string/password" | ||||
|                     android:textColorHint="?attr/colorSecondary" | ||||
| @ -108,7 +117,7 @@ | ||||
|                 android:id="@+id/next" | ||||
|                 app:cardElevation="8dp" | ||||
| 
 | ||||
|                 android:layout_width="match_parent" | ||||
|                 android:layout_width="200dp" | ||||
|                 android:layout_height="wrap_content" | ||||
|                 android:text="@string/continue_" | ||||
|                 android:padding="12dp" | ||||
|  | ||||
| @ -1,12 +1,17 @@ | ||||
| 
 | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <menu xmlns:android="http://schemas.android.com/apk/res/android"> | ||||
|     <item | ||||
|         android:id="@+id/scan_fragment" | ||||
|         android:id="@+id/nav_scan" | ||||
|         android:icon="@drawable/qr_code_scan" | ||||
|         android:title="@string/scan" /> | ||||
|     <item | ||||
|         android:id="@+id/nav_profile" | ||||
|         android:icon="@drawable/_user_" | ||||
|         android:title="@string/title_profile" /> | ||||
|     <item | ||||
|         android:id="@+id/nav_admin" | ||||
| 
 | ||||
|         android:icon="@drawable/_user_" | ||||
|         android:title="@string/admin" /> | ||||
| 
 | ||||
| </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" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
|     xmlns:tools="http://schemas.android.com/tools" | ||||
|     app:startDestination="@id/authFragment"> | ||||
|     app:startDestination="@id/nav_auth"> | ||||
|     <fragment | ||||
|         android:id="@+id/profileFragment" | ||||
|         android:id="@+id/nav_profile" | ||||
|         android:name="com.displaynone.acss.ui.profile.ProfileFragment" | ||||
|         android:label="ProfileFragment" | ||||
|         tools:layout="@layout/fragment_profile"> | ||||
|         <action | ||||
|             android:id="@+id/action_profileFragment_to_authFragment" | ||||
|             app:destination="@id/authFragment" /> | ||||
|             app:destination="@id/nav_auth" /> | ||||
|         <action | ||||
|             android:id="@+id/action_profileFragment_to_qrScanFragment" | ||||
|             app:destination="@id/qrScanFragment" /> | ||||
|             app:destination="@id/nav_scan" /> | ||||
|         <action | ||||
|             android:id="@+id/action_profileFragment_to_qrResultFragment" | ||||
|             app:destination="@id/qrResultFragment" /> | ||||
|         <action | ||||
|             android:id="@+id/action_profileFragment_to_adminFragment" | ||||
|             app:destination="@id/adminFragment" /> | ||||
|             app:destination="@id/nav_admin" /> | ||||
|     </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 | ||||
|         android:id="@+id/authFragment" | ||||
|         android:id="@+id/nav_auth" | ||||
|         android:name="com.displaynone.acss.ui.auth.AuthFragment" | ||||
|         android:label="AuthFragment" > | ||||
|         <action | ||||
|             android:id="@+id/action_authFragment_to_profileFragment" | ||||
|             app:destination="@id/profileFragment" /> | ||||
|             app:destination="@id/nav_profile" /> | ||||
|     </fragment> | ||||
|     <fragment | ||||
|         android:id="@+id/qrScanFragment" | ||||
|         android:id="@+id/nav_scan" | ||||
|         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 | ||||
|         android:id="@+id/qrResultFragment" | ||||
|         android:name="com.displaynone.acss.ui.result.QrResultFragment" | ||||
|         android:label="QrResultFragment" > | ||||
|         <action | ||||
|             android:id="@+id/action_qrResultFragment_to_profileFragment" | ||||
|             app:destination="@id/profileFragment" /> | ||||
|             app:destination="@id/nav_profile" /> | ||||
|     </fragment> | ||||
|     <fragment | ||||
|         android:id="@+id/adminFragment" | ||||
|         android:id="@+id/nav_admin" | ||||
|         android:name="com.displaynone.acss.ui.admin.AdminFragment" | ||||
|         android:label="AdminFragment" > | ||||
|         <action | ||||
|             android:id="@+id/action_adminFragment_to_profileFragment" | ||||
|             app:destination="@id/profileFragment" /> | ||||
|             app:destination="@id/nav_profile" /> | ||||
|     </fragment> | ||||
| </navigation> | ||||
| @ -18,6 +18,7 @@ | ||||
|     <string name="administrator_searc_button_search"> Search </string> | ||||
|     <string name="title_profile">Your profile</string> | ||||
|     <string name="сhange_rights">Change rights using smartphone</string> | ||||
|     <string name="admin">Admin panel</string> | ||||
| 
 | ||||
| 
 | ||||
| </resources> | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user