This commit is contained in:
Serafim_Pankin 2025-02-19 16:19:08 +03:00
commit 8c05ab1325
14 changed files with 154 additions and 24 deletions

@ -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")
} }

@ -1,6 +1,7 @@
package com.displaynone.acss.ui.auth package com.displaynone.acss.ui.auth
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.graphics.drawable.TransitionDrawable
import android.os.Bundle import android.os.Bundle
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
@ -28,7 +29,6 @@ class AuthFragment: Fragment(R.layout.fragment_auth) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
_binding = FragmentAuthBinding.bind(view) _binding = FragmentAuthBinding.bind(view)
setupLoginButton() setupLoginButton()
viewModel.action.collectWithLifecycle(this) { action -> viewModel.action.collectWithLifecycle(this) { action ->
if (action is Action.GotoProfile) { if (action is Action.GotoProfile) {
blockLoginButton() // FIXME() При двойном нажатии вылетает с ошибкой blockLoginButton() // FIXME() При двойном нажатии вылетает с ошибкой

@ -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>

@ -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>

@ -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" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".MainActivity">
<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"
app:navGraph="@navigation/nav_graph" />
<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_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> </androidx.constraintlayout.widget.ConstraintLayout>

@ -69,6 +69,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="15dp" android:layout_margin="15dp"
android:maxLines="1"
android:hint="@string/login" android:hint="@string/login"

@ -18,6 +18,7 @@
android:paddingTop="50dp"> android:paddingTop="50dp">
<ImageView <ImageView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="200dp" android:layout_height="200dp"
android:foregroundGravity="center" android:foregroundGravity="center"
@ -40,8 +41,9 @@
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<LinearLayout <LinearLayout
android:background="@drawable/gradient_1"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:layout_width="280dp" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:gravity="center_horizontal"> android:gravity="center_horizontal">
@ -63,6 +65,8 @@
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginRight="70dp"
app:boxStrokeColor="@color/primary" app:boxStrokeColor="@color/primary"
app:hintTextColor="?attr/colorOnBackground" app:hintTextColor="?attr/colorOnBackground"
app:helperTextTextColor="?attr/colorOnBackground" app:helperTextTextColor="?attr/colorOnBackground"
@ -73,6 +77,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="14dp" android:padding="14dp"
android:maxLines="1"
android:hint="@string/login" android:hint="@string/login"
android:textColorHint="?attr/colorSecondary" android:textColorHint="?attr/colorSecondary"
@ -91,7 +97,10 @@
android:id="@+id/password" android:id="@+id/password"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginRight="70dp"
android:padding="14dp" android:padding="14dp"
android:maxLines="1"
android:hint="@string/password" android:hint="@string/password"
android:textColorHint="?attr/colorSecondary" android:textColorHint="?attr/colorSecondary"
@ -108,7 +117,7 @@
android:id="@+id/next" android:id="@+id/next"
app:cardElevation="8dp" app:cardElevation="8dp"
android:layout_width="match_parent" android:layout_width="200dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/continue_" android:text="@string/continue_"
android:padding="12dp" android:padding="12dp"

@ -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>

@ -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>