Browse Source

feat: add update bottombar

Bax 6 days ago
parent
commit
19dc2a0773

+ 8 - 0
mobile_app/new/wabi/.idea/deploymentTargetSelector.xml

@@ -4,6 +4,14 @@
     <selectionStates>
       <SelectionState runConfigName="app">
         <option name="selectionMode" value="DROPDOWN" />
+        <DropdownSelection timestamp="2024-11-22T21:44:11.710793400Z">
+          <Target type="DEFAULT_BOOT">
+            <handle>
+              <DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\bax\.android\avd\Medium_Phone_API_30.avd" />
+            </handle>
+          </Target>
+        </DropdownSelection>
+        <DialogSelection />
       </SelectionState>
     </selectionStates>
   </component>

+ 6 - 1
mobile_app/new/wabi/app/src/main/java/com/example/wabi/domain/navigation/Navigation.kt

@@ -2,6 +2,7 @@ package com.example.wabi.domain.navigation
 
 import android.util.Log
 import androidx.compose.runtime.Composable
+import androidx.compose.runtime.MutableState
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.NavHost
 import androidx.navigation.compose.composable
@@ -13,17 +14,21 @@ import com.example.wabi.view.screeens.signIn.SignIn
 import com.example.wabi.view.screeens.signUp.SignUp
 
 @Composable
-fun Navigation(navHostController: NavHostController, start: String) {
+fun Navigation(
+    navHostController: NavHostController, start: String, isBottomBar: MutableState<Boolean>
+) {
 
     NavHost(
         navController = navHostController, startDestination = start
 
     ) {
         composable(Routes.BASKET) {
+            isBottomBar.value = true
             Log.d("navigation", "go to BASKET")
             Basket(navHostController)
         }
         composable(Routes.ONBOARD) {
+            isBottomBar.value = false
             Log.d("navigation", "go to ONBOARD")
             Onboard(navHostController)
         }

+ 2 - 0
mobile_app/new/wabi/app/src/main/java/com/example/wabi/domain/repository/UserShareDate.kt

@@ -2,8 +2,10 @@ package com.example.wabi.domain.repository
 
 import android.annotation.SuppressLint
 import android.content.Context
+import com.example.wabi.domain.navigation.Routes
 
 @SuppressLint("StaticFieldLeak")
 object UserShareDate {
     var context: Context? = null
+    val currentRoute: String = Routes.BASKET
 }

+ 23 - 5
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/MainActivity.kt

@@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.fillMaxSize
 import androidx.compose.foundation.layout.padding
 import androidx.compose.material3.Scaffold
 import androidx.compose.runtime.Composable
+import androidx.compose.runtime.MutableState
 import androidx.compose.runtime.mutableStateOf
 import androidx.compose.runtime.remember
 import androidx.compose.ui.Modifier
@@ -22,6 +23,7 @@ import com.example.wabi.domain.navigation.Routes
 import com.example.wabi.domain.repository.PrefManager
 import com.example.wabi.domain.repository.UserShareDate
 import com.example.wabi.ui.theme.WabiTheme
+import com.example.wabi.view.components.bars.bottom.BottomBar
 import dagger.hilt.android.AndroidEntryPoint
 
 @AndroidEntryPoint
@@ -34,7 +36,7 @@ class MainActivity : ComponentActivity() {
         setContent {
             UserShareDate.context = LocalContext.current
             val navHostController = rememberNavController()
-            val isBottomBar = remember { mutableStateOf(false) }
+            val isBottomBar = remember { mutableStateOf(true) }
             val isTopBar = remember { mutableStateOf(false) }
 
             PrefManager.initPrefManager(UserShareDate.context!!)
@@ -42,7 +44,13 @@ class MainActivity : ComponentActivity() {
             WabiTheme(themeState = PrefManager.userTheme) {
                 Scaffold(modifier = Modifier.fillMaxSize(),
                     containerColor = WabiTheme.colors.backgroundColor,
-                    bottomBar = {},
+                    bottomBar = {
+                        if (isBottomBar.value) {
+                            BottomBar(
+                                navHostController = navHostController, isSession = false
+                            )
+                        }
+                    },
                     topBar = {}) { innerPadding ->
                     Box(
                         modifier = Modifier
@@ -50,7 +58,7 @@ class MainActivity : ComponentActivity() {
                             .padding(innerPadding)
                     ) {
 
-                        InitApp(navHostController)
+                        InitApp(navHostController, isBottomBar)
                     }
                 }
             }
@@ -59,6 +67,16 @@ class MainActivity : ComponentActivity() {
 }
 
 @Composable
-fun InitApp(navHostController: NavHostController, vm: MainActivityViewModel = hiltViewModel()) {
-    Navigation(navHostController, Routes.ONBOARD)
+fun InitApp(
+    navHostController: NavHostController,
+    isBottomBar: MutableState<Boolean>,
+    vm: MainActivityViewModel = hiltViewModel()
+) {
+    Navigation(
+        navHostController, start = if (PrefManager.onboard) {
+            Routes.ONBOARD
+        } else {
+            UserShareDate.currentRoute
+        }, isBottomBar
+    )
 }

+ 3 - 2
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/MainActivityViewModel.kt

@@ -1,11 +1,12 @@
 package com.example.wabi.view
 
 import androidx.lifecycle.ViewModel
-import com.example.wabi.domain.navigation.NavigationProvider
+import com.example.wabi.domain.supabase.SupabaseServiceImpl
 import dagger.hilt.android.lifecycle.HiltViewModel
 import javax.inject.Inject
 
 @HiltViewModel
-class MainActivityViewModel @Inject constructor(private val nav: NavigationProvider) : ViewModel() {
+class MainActivityViewModel @Inject constructor(private val supabase: SupabaseServiceImpl) :
+    ViewModel() {
 
 }

+ 102 - 0
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/components/bars/bottom/BottomBar.kt

@@ -0,0 +1,102 @@
+package com.example.wabi.view.components.bars.bottom
+
+import androidx.compose.foundation.BorderStroke
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.offset
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.Button
+import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.Icon
+import androidx.compose.material3.NavigationBar
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.graphics.vector.ImageVector
+import androidx.compose.ui.res.vectorResource
+import androidx.compose.ui.unit.dp
+import androidx.hilt.navigation.compose.hiltViewModel
+import androidx.navigation.NavHostController
+import androidx.navigation.compose.currentBackStackEntryAsState
+import com.example.wabi.ui.theme.WabiTheme
+
+@Composable
+fun BottomBar(
+    navHostController: NavHostController,
+    modifier: Modifier = Modifier,
+    isSession: Boolean,
+    vm: BottomBarViewModel = hiltViewModel()
+) {
+    val screens = listOf(
+        DestinationBB.Catalog, DestinationBB.Basket, DestinationBB.Profile
+    )
+
+    NavigationBar(
+        modifier = modifier.clip(shape = RoundedCornerShape(topEnd = 15.dp, topStart = 15.dp)),
+        containerColor = WabiTheme.colors.mainColor
+    ) {
+        val navBackStackEntry by navHostController.currentBackStackEntryAsState()
+        val currentRoute = navBackStackEntry?.destination?.route
+
+        Row(
+            modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceAround
+        ) {
+            screens.forEach { screen ->
+                if (screen.route == currentRoute || screen.anotherRoute == currentRoute) {
+                    Button(
+                        onClick = {
+                            vm.changeScreen(
+                                navHostController = navHostController,
+                                whereFrom = currentRoute,
+                                where = if (isSession) screen.route else screen.anotherRoute
+                            )
+                        },
+                        contentPadding = PaddingValues(10.dp),
+                        modifier = Modifier
+                            .size(60.dp)
+                            .offset(y = (-8).dp),
+                        colors = ButtonDefaults.buttonColors(
+                            contentColor = WabiTheme.colors.backgroundColor,
+                            containerColor = WabiTheme.colors.mainColor
+                        ),
+                        border = BorderStroke(
+                            width = 3.dp, color = WabiTheme.colors.backgroundColor
+                        )
+                    ) {
+                        Icon(
+                            imageVector = ImageVector.vectorResource(screen.iconId),
+                            contentDescription = screen.route,
+                            modifier = Modifier.size(30.dp)
+                        )
+                    }
+                } else {
+                    Button(
+                        onClick = {
+                            vm.changeScreen(
+                                navHostController = navHostController,
+                                whereFrom = currentRoute!!,
+                                where = if (isSession) screen.route else screen.anotherRoute
+                            )
+                        },
+                        contentPadding = PaddingValues(10.dp),
+                        modifier = Modifier.size(60.dp),
+                        colors = ButtonDefaults.buttonColors(
+                            contentColor = WabiTheme.colors.backgroundColor,
+                            containerColor = WabiTheme.colors.mainColor
+                        ),
+                    ) {
+                        Icon(
+                            imageVector = ImageVector.vectorResource(screen.iconId),
+                            contentDescription = screen.route,
+                            modifier = Modifier.size(30.dp)
+                        )
+                    }
+                }
+            }
+        }
+    }
+}

+ 18 - 0
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/components/bars/bottom/BottomBarViewModel.kt

@@ -0,0 +1,18 @@
+package com.example.wabi.view.components.bars.bottom
+
+import androidx.lifecycle.ViewModel
+import androidx.navigation.NavHostController
+import com.example.wabi.domain.navigation.NavigationProvider
+import dagger.hilt.android.lifecycle.HiltViewModel
+import javax.inject.Inject
+
+@HiltViewModel
+class BottomBarViewModel @Inject constructor(private val nav: NavigationProvider) : ViewModel() {
+    fun changeScreen(
+        navHostController: NavHostController, whereFrom: String, where: String
+    ) {
+        nav.goToNextScreen(
+            navHostController = navHostController, whereFrom = whereFrom, where = where
+        )
+    }
+}

+ 20 - 0
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/components/bars/bottom/DestinationBB.kt

@@ -0,0 +1,20 @@
+package com.example.wabi.view.components.bars.bottom
+
+import com.example.wabi.R
+import com.example.wabi.domain.navigation.Routes
+
+sealed class DestinationBB(
+    val route: String, val anotherRoute: String, val iconId: Int
+) {
+    data object Basket : DestinationBB(
+        route = Routes.BASKET, anotherRoute = Routes.BASKET, iconId = R.drawable.user_basket_vector
+    )
+
+    data object Catalog : DestinationBB(
+        route = Routes.CATALOG, anotherRoute = Routes.CATALOG, iconId = R.drawable.catalog_vector
+    )
+
+    data object Profile : DestinationBB(
+        route = Routes.PROFILE, anotherRoute = Routes.SIGNIN, iconId = R.drawable.man_vector
+    )
+}

+ 5 - 4
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/screeens/onboard/items/PartSlider.kt

@@ -4,10 +4,10 @@ import androidx.compose.foundation.Image
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.Spacer
 import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
 import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
 import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.Alignment
@@ -39,7 +39,8 @@ fun PartSlider(onboardItem: OnboardListState, modifier: Modifier = Modifier) {
             modifier = modifier
                 .weight(0.2f)
                 .background(color = WabiTheme.colors.onBoardDark)
-                .fillMaxWidth(),
+                .fillMaxWidth()
+                .verticalScroll(rememberScrollState()),
             horizontalAlignment = Alignment.CenterHorizontally,
             verticalArrangement = Arrangement.SpaceAround
         ) {
@@ -54,7 +55,7 @@ fun PartSlider(onboardItem: OnboardListState, modifier: Modifier = Modifier) {
                 color = WabiTheme.colors.onBoardLight,
                 modifier = Modifier.padding(50.dp, 0.dp),
                 minLines = 3,
-                maxLines = 3
+                maxLines = 3,
             )
         }
     }