update navigation

This commit is contained in:
Ксении 2025-02-20 12:22:45 +03:00
parent 8f963606f7
commit 30127c6fc0
7 changed files with 125 additions and 26 deletions

View File

@ -2,12 +2,14 @@ package ru.myitschool.work.ui
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.util.Log
import androidx.activity.OnBackPressedCallback import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.createGraph import androidx.navigation.createGraph
import androidx.navigation.findNavController import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.fragment import androidx.navigation.fragment.fragment
import com.google.android.material.bottomnavigation.BottomNavigationView
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import ru.myitschool.work.R import ru.myitschool.work.R
import ru.myitschool.work.ui.login.LoginDestination import ru.myitschool.work.ui.login.LoginDestination
@ -30,21 +32,20 @@ class RootActivity : AppCompatActivity() {
val navController = navHostFragment?.navController ?: throw IllegalStateException("NavHostFragment not found") val navController = navHostFragment?.navController ?: throw IllegalStateException("NavHostFragment not found")
val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottom_navigation)
navController.setGraph(R.navigation.main_nav_graph) //navController.setGraph(R.navigation.main_nav_graph)
navController.navigate(R.id.fragment_profile) //navController.navigate(R.id.fragment_profile)
/*if (userRole == "ROLE_ADMIN") { Log.d("role", "$userRole")
//bottomNavigationView.menu.clear() if (userRole == "ROLE_ADMIN") {
//bottomNavigationView.inflateMenu(R.menu.bottom_menu_admin)
navController.setGraph(R.navigation.main_admin_nav_graph)
} else {
navController.setGraph(R.navigation.main_nav_graph) navController.setGraph(R.navigation.main_nav_graph)
navController.navigate(R.id.fragment_profile) navController.navigate(R.id.fragment_profile)
}*/ } else {
navController.setGraph(R.navigation.main_nav_graph)
bottomNavigationView.menu.clear()
navController.navigate(R.id.fragment_profile)
}

View File

@ -6,6 +6,7 @@ import android.util.Log
import android.view.View import android.view.View
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.squareup.picasso.Picasso import com.squareup.picasso.Picasso
import ru.myitschool.work.R import ru.myitschool.work.R
import ru.myitschool.work.databinding.FragmentProfileBinding import ru.myitschool.work.databinding.FragmentProfileBinding
@ -34,12 +35,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) {
requireActivity().finish() requireActivity().finish()
} }
viewBinding.qrScan.setOnClickListener{ viewBinding.qrScan.setOnClickListener{
val qrScanFragment = QrScanFragment() findNavController().navigate(R.id.action_fragment_profile_to_fragment_qr)
val fragmentManager = parentFragmentManager
val fragmentTransaction = fragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.fragment_container, qrScanFragment)
fragmentTransaction.addToBackStack(null)
fragmentTransaction.commit()
} }
val adapter = EntranceAdapter() val adapter = EntranceAdapter()
viewBinding.recyclerView.adapter = adapter viewBinding.recyclerView.adapter = adapter

View File

@ -0,0 +1,48 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:pathData="M16,18C18.761,18 21,15.761 21,13C21,10.239 18.761,8 16,8C13.239,8 11,10.239 11,13C11,15.761 13.239,18 16,18Z"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#A7A7A7"
android:strokeLineCap="round"/>
<path
android:pathData="M23,28C23,26.143 22.263,24.363 20.95,23.05C19.637,21.737 17.857,21 16,21C14.144,21 12.363,21.737 11.05,23.05C9.738,24.363 9,26.143 9,28H23Z"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#A7A7A7"
android:strokeLineCap="round"/>
<path
android:pathData="M24,14C24.852,14 25.69,13.782 26.435,13.367C27.179,12.952 27.805,12.354 28.253,11.629C28.701,10.904 28.957,10.076 28.995,9.225C29.033,8.373 28.853,7.526 28.472,6.764C28.091,6.002 27.521,5.349 26.817,4.869C26.113,4.389 25.298,4.097 24.449,4.02C23.6,3.944 22.746,4.085 21.967,4.432C21.188,4.778 20.511,5.318 20,6"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#A7A7A7"
android:strokeLineCap="round"/>
<path
android:pathData="M25,24H31C31,22.143 30.263,20.363 28.95,19.05C27.637,17.737 25.857,17 24,17"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#A7A7A7"
android:strokeLineCap="round"/>
<path
android:pathData="M12,6C11.489,5.318 10.811,4.778 10.033,4.432C9.254,4.085 8.4,3.944 7.551,4.02C6.702,4.097 5.887,4.389 5.183,4.869C4.479,5.349 3.909,6.002 3.528,6.764C3.147,7.526 2.967,8.373 3.005,9.225C3.043,10.076 3.299,10.904 3.747,11.629C4.195,12.354 4.821,12.952 5.565,13.367C6.31,13.782 7.148,14 8,14"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#A7A7A7"
android:strokeLineCap="round"/>
<path
android:pathData="M8,17C6.143,17 4.363,17.737 3.05,19.05C1.737,20.363 1,22.143 1,24H7"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#A7A7A7"
android:strokeLineCap="round"/>
</vector>

View File

@ -10,4 +10,19 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:defaultNavHost="true" /> app:defaultNavHost="true" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_menu_admin"
android:background="@color/white"
app:itemIconTint="@color/grey"
app:labelVisibilityMode="unlabeled"
app:itemRippleColor="@color/orange"
app:itemActiveIndicatorStyle="@color/orange" />
</FrameLayout> </FrameLayout>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/fragment_profile"
android:enabled="true"
android:icon="@drawable/ic_profile"
android:title="@string/profile" />
<item
android:id="@+id/fragment_admin"
android:enabled="true"
android:icon="@drawable/ic_users"
android:title="@string/user_view" />
</menu>

View File

@ -1,17 +1,39 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<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"
android:id="@+id/admin_main_nav_graph"> android:id="@+id/admin_main_nav_graph">
<!--<fragment
android:id="@+id/fragment_profile"
android:name=""
android:label="Profile"
tools:layout="@layout/fragment_profile" />
<fragment <fragment
android:id="@+id/fragment_user_list" android:id="@+id/fragment_profile"
android:name="ru.sicampus.bootcamp2025.ui.userList.FreeVolunteersListFragment" android:name="ru.myitschool.work.ui.profile.ProfileFragment"
android:label="UserList" android:label="Profile"
tools:layout="@layout/fragment_free_volunteers_list" />--> tools:layout="@layout/fragment_profile">
<action
android:id="@+id/action_fragment_profile_to_fragment_qr"
app:destination="@id/fragment_qr" />
</fragment>
<fragment
android:id="@+id/fragment_qr"
android:name="ru.myitschool.work.ui.qr.scan.QrScanFragment"
android:label="QrScan"
tools:layout="@layout/fragment_qr_scan" >
<action
android:id="@+id/action_fragment_qr_to_fragment_qr_result"
app:destination="@id/fragment_qr_result" />
<action
android:id="@+id/action_fragment_qr_to_fragment_profile"
app:destination="@id/fragment_profile" />
</fragment>
<fragment
android:id="@+id/fragment_qr_result"
android:name="ru.myitschool.work.ui.qr.result.QrResultFragment"
android:label="QrResult"
tools:layout="@layout/fragment_qr_result" >
<action
android:id="@+id/action_fragment_qr_result_to_fragment_profile"
app:destination="@id/fragment_profile" />
</fragment>
</navigation> </navigation>

View File

@ -16,4 +16,6 @@
<string name="qr_success_result">Успешно</string> <string name="qr_success_result">Успешно</string>
<string name="qr_wrong_result">Что-то пошло не так</string> <string name="qr_wrong_result">Что-то пошло не так</string>
<string name="qr_null_result">Вход был отменён</string> <string name="qr_null_result">Вход был отменён</string>
<string name="profile">Профиль</string>
<string name="user_view">Просмотр пользователя</string>
</resources> </resources>