ソースを参照

feat: add update onboard

Bax 6 日 前
コミット
501d46ed00

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

@@ -1,5 +1,6 @@
 package com.example.wabi.domain.navigation
 
+import android.util.Log
 import androidx.compose.runtime.Composable
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.NavHost
@@ -12,24 +13,34 @@ import com.example.wabi.view.screeens.signIn.SignIn
 import com.example.wabi.view.screeens.signUp.SignUp
 
 @Composable
-fun Navigation(navHostController: NavHostController) {
-    NavHost(navController = navHostController, startDestination = Routes.BASKET) {
+fun Navigation(navHostController: NavHostController, start: String) {
+
+    NavHost(
+        navController = navHostController, startDestination = start
+
+    ) {
         composable(Routes.BASKET) {
+            Log.d("navigation", "go to BASKET")
             Basket(navHostController)
         }
         composable(Routes.ONBOARD) {
+            Log.d("navigation", "go to ONBOARD")
             Onboard(navHostController)
         }
         composable(Routes.CATALOG) {
+            Log.d("navigation", "go to CATALOG")
             Catalog(navHostController)
         }
         composable(Routes.SIGNIN) {
+            Log.d("navigation", "go to SIGNIN")
             SignIn(navHostController)
         }
         composable(Routes.PROFILE) {
+            Log.d("navigation", "go to PROFILE")
             Profile(navHostController)
         }
         composable(Routes.SIGNUP) {
+            Log.d("navigation", "go to SIGNUP")
             SignUp(navHostController)
         }
     }

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

@@ -13,4 +13,25 @@ object PrefManager {
     var onboard: Boolean
         get() = localDataSp.getBoolean("onboard", true)
         set(value) = localDataSp.edit().putBoolean("onboard", value).apply()
+
+    var userTheme: Int
+        get() = localDataSp.getInt("userTheme", 0)
+        set(value) = localDataSp.edit().putInt("userTheme", value).apply()
+
+    fun saveDataCurrentUser(email: String, password: String) {
+        localDataSp.edit().putString("email", email).apply()
+        localDataSp.edit().putString("password", password).apply()
+    }
+
+    fun getDataCurrentUser(): List<String?> {
+        return listOf(
+            localDataSp.getString("email", null),
+            localDataSp.getString("password", null)
+        )
+    }
+
+    fun clearDataCurrentUser() {
+        localDataSp.edit().remove("email").apply()
+        localDataSp.edit().remove("password").apply()
+    }
 }

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

@@ -0,0 +1,9 @@
+package com.example.wabi.domain.repository
+
+import android.annotation.SuppressLint
+import android.content.Context
+
+@SuppressLint("StaticFieldLeak")
+object UserShareDate {
+    var context: Context? = null
+}

+ 4 - 1
mobile_app/new/wabi/app/src/main/java/com/example/wabi/domain/supabase/SupabaseService.kt

@@ -1,5 +1,8 @@
 package com.example.wabi.domain.supabase
 
-interface SupabaseService {
+import com.example.wabi.models.responses.Response
 
+interface SupabaseService {
+    suspend fun signIn(userEmail: String, userPasword: String): Response
+    suspend fun signOun(): Response
 }

+ 30 - 1
mobile_app/new/wabi/app/src/main/java/com/example/wabi/domain/supabase/SupabaseServiceImpl.kt

@@ -1,8 +1,37 @@
 package com.example.wabi.domain.supabase
 
+import android.util.Log
+import com.example.wabi.models.responses.Response
+import io.github.jan.supabase.SupabaseClient
+import io.github.jan.supabase.auth.auth
+import io.github.jan.supabase.auth.providers.builtin.Email
 import javax.inject.Inject
 
 
-class SupabaseServiceImpl @Inject constructor(private val supabase: SupabaseServiceProvider) : SupabaseService {
+class SupabaseServiceImpl @Inject constructor(private val supabase: SupabaseClient) :
+    SupabaseService {
+    override suspend fun signIn(userEmail: String, userPasword: String): Response {
+        return try {
+            var user = supabase.auth.signInWith(Email) {
+                email = userEmail
+                password = userPasword
+            }
+            Log.d("signIn", "The user is logged in")
+            Response(user.toString())
+        } catch (ex: Exception) {
+            Log.e("signIn", ex.message.toString())
+            Response("", ex.message.toString())
+        }
+    }
 
+    override suspend fun signOun(): Response {
+        return try {
+            var response = supabase.auth.signOut()
+            Log.d("signOut", "The user logged out")
+            Response(response.toString())
+        } catch (e: Exception) {
+            Log.d("signOut", e.message.toString())
+            Response("", e.message.toString())
+        }
+    }
 }

+ 8 - 0
mobile_app/new/wabi/app/src/main/java/com/example/wabi/models/responses/Responce.kt

@@ -0,0 +1,8 @@
+package com.example.wabi.models.responses
+
+import java.lang.Error
+
+data class Response(
+    var token: String = "",
+    var error: String = ""
+)

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

@@ -18,7 +18,9 @@ import androidx.hilt.navigation.compose.hiltViewModel
 import androidx.navigation.NavHostController
 import androidx.navigation.compose.rememberNavController
 import com.example.wabi.domain.navigation.Navigation
+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 dagger.hilt.android.AndroidEntryPoint
 
@@ -30,13 +32,14 @@ class MainActivity : ComponentActivity() {
         enableEdgeToEdge()
 
         setContent {
-            val context = LocalContext.current
+            UserShareDate.context = LocalContext.current
             val navHostController = rememberNavController()
             val isBottomBar = remember { mutableStateOf(false) }
             val isTopBar = remember { mutableStateOf(false) }
-            PrefManager.initPrefManager(context)
 
-            WabiTheme(themeState = 0) {
+            PrefManager.initPrefManager(UserShareDate.context!!)
+
+            WabiTheme(themeState = PrefManager.userTheme) {
                 Scaffold(modifier = Modifier.fillMaxSize(),
                     containerColor = WabiTheme.colors.backgroundColor,
                     bottomBar = {},
@@ -46,6 +49,7 @@ class MainActivity : ComponentActivity() {
                             .fillMaxSize()
                             .padding(innerPadding)
                     ) {
+
                         InitApp(navHostController)
                     }
                 }
@@ -56,5 +60,5 @@ class MainActivity : ComponentActivity() {
 
 @Composable
 fun InitApp(navHostController: NavHostController, vm: MainActivityViewModel = hiltViewModel()) {
-    Navigation(navHostController)
+    Navigation(navHostController, Routes.ONBOARD)
 }

+ 5 - 8
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/components/buttons/MainButton.kt

@@ -2,6 +2,8 @@ package com.example.wabi.view.components.buttons
 
 import android.annotation.SuppressLint
 import androidx.compose.foundation.BorderStroke
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
 import androidx.compose.material3.Button
 import androidx.compose.material3.ButtonColors
 import androidx.compose.material3.Text
@@ -24,18 +26,13 @@ fun MainButton(
 ): Unit {
     Button(
         border = BorderStroke(
-            2.dp,
-            color = color
-        ),
-        onClick = onClick,
-        enabled = enabled,
-        colors = ButtonColors(
+            2.dp, color = color
+        ), onClick = onClick, enabled = enabled, colors = ButtonColors(
             containerColor = color,
             contentColor = colorContent,
             disabledContainerColor = WabiTheme.colors.translucentColor,
             disabledContentColor = colorContent
-        ),
-        modifier = modifier
+        ), modifier = modifier.fillMaxWidth()
     ) {
         Text(
             text = textContent,

+ 87 - 1
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/screeens/onboard/Onboard.kt

@@ -1,10 +1,96 @@
 package com.example.wabi.view.screeens.onboard
 
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.pager.HorizontalPager
+import androidx.compose.foundation.pager.rememberPagerState
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
 import androidx.compose.runtime.Composable
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
+import androidx.compose.ui.input.pointer.motionEventSpy
+import androidx.compose.ui.unit.dp
+import androidx.hilt.navigation.compose.hiltViewModel
 import androidx.navigation.NavHostController
+import com.example.wabi.ui.theme.WabiTheme
+import com.example.wabi.view.components.buttons.ButtonLink
+import com.example.wabi.view.components.buttons.MainButton
+import com.example.wabi.view.screeens.onboard.items.OnboardListState
+import com.example.wabi.view.screeens.onboard.items.OnboardStateIndicator
+import com.example.wabi.view.screeens.onboard.items.PartSlider
+import kotlinx.coroutines.launch
 
 @Composable
-fun Onboard(navHostController: NavHostController) {
+fun Onboard(navHostController: NavHostController, vm: OnboardViewModel = hiltViewModel()) {
 
+    val listStates = listOf(
+        OnboardListState.First, OnboardListState.Second, OnboardListState.Third
+    )
+
+    val currentPageState = rememberPagerState(initialPage = 0) { listStates.size }
+
+    val scope = rememberCoroutineScope()
+
+    Column(
+        modifier = Modifier
+            .fillMaxSize()
+            .background(color = WabiTheme.colors.onBoardDark)
+            .verticalScroll(rememberScrollState()),
+        verticalArrangement = Arrangement.SpaceAround,
+        horizontalAlignment = Alignment.CenterHorizontally
+    ) {
+        HorizontalPager(
+            state = currentPageState, modifier = Modifier
+                .weight(0.8f)
+                .fillMaxWidth()
+        ) { state ->
+            PartSlider(listStates[state], Modifier.fillMaxSize())
+        }
+        Column(
+            modifier = Modifier
+                .weight(0.3f)
+                .fillMaxWidth(),
+            verticalArrangement = Arrangement.SpaceAround,
+            horizontalAlignment = Alignment.CenterHorizontally
+        ) {
+            OnboardStateIndicator(
+                pageSize = 3, currentPage = currentPageState.currentPage
+            )
+            Row(
+                modifier = Modifier.fillMaxWidth()
+            ) {
+                MainButton(
+                    onClick = {
+                        scope.launch {
+                            if (currentPageState.currentPage < listStates.size - 1) {
+                                currentPageState.animateScrollToPage(currentPageState.currentPage + 1)
+                            } else {
+                                vm.closeOnboard(navHostController)
+                            }
+                        }
+                    },
+                    color = WabiTheme.colors.onBoardLight,
+                    textContent = listStates[currentPageState.currentPage].buttonText,
+                    colorContent = WabiTheme.colors.onBoardDark,
+                    modifier = Modifier.padding(30.dp, 0.dp)
+                )
+            }
+            ButtonLink(
+                onClick = {
+                    vm.closeOnboard(navHostController)
+                },
+                colorContent = WabiTheme.colors.onBoardLight,
+                textContent = listStates[currentPageState.currentPage].linktext,
+                enabled = listStates[currentPageState.currentPage].linktext.isNotEmpty()
+            )
+        }
+    }
 }

+ 27 - 0
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/screeens/onboard/OnboardViewModel.kt

@@ -0,0 +1,27 @@
+package com.example.wabi.view.screeens.onboard
+
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import androidx.navigation.NavHostController
+import com.example.wabi.domain.navigation.NavigationProvider
+import com.example.wabi.domain.navigation.Routes
+import com.example.wabi.domain.repository.PrefManager
+import com.example.wabi.domain.repository.UserShareDate
+import dagger.hilt.android.lifecycle.HiltViewModel
+import kotlinx.coroutines.launch
+import javax.inject.Inject
+
+@HiltViewModel
+class OnboardViewModel @Inject constructor(private val nav: NavigationProvider) : ViewModel() {
+    fun closeOnboard(navHostController: NavHostController) {
+        viewModelScope.launch {
+            PrefManager.initPrefManager(UserShareDate.context!!)
+            PrefManager.onboard = false
+        }
+        nav.goToNextScreen(
+            navHostController = navHostController,
+            whereFrom = Routes.ONBOARD,
+            where = Routes.BASKET
+        )
+    }
+}

+ 36 - 0
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/screeens/onboard/items/OnboardListState.kt

@@ -0,0 +1,36 @@
+package com.example.wabi.view.screeens.onboard.items
+
+import androidx.annotation.DrawableRes
+import com.example.wabi.R
+
+sealed class OnboardListState(
+    @DrawableRes val image: Int,
+    val title: String,
+    val mainText: String,
+    val buttonText: String,
+    val linktext: String
+) {
+    object First : OnboardListState(
+        image = R.drawable.todo_vector,
+        title = "Чек-лист",
+        mainText = "Удобный список того, что нужно купить",
+        buttonText = "Далее",
+        linktext = "Пропустить"
+    )
+
+    object Second : OnboardListState(
+        image = R.drawable.vector_star_group,
+        title = "Оценки",
+        mainText = "Оценки от других пользователей",
+        buttonText = "Далее",
+        linktext = "Пропустить"
+    )
+
+    object Third : OnboardListState(
+        image = R.drawable.link_to_people_vector,
+        title = "Коннект",
+        mainText = "Возможность поделиться своей корзиной товаров с другими",
+        buttonText = "Завершить",
+        linktext = ""
+    )
+}

+ 40 - 0
mobile_app/new/wabi/app/src/main/java/com/example/wabi/view/screeens/onboard/items/OnboardStateIndicator.kt

@@ -0,0 +1,40 @@
+package com.example.wabi.view.screeens.onboard.items
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.unit.dp
+import com.example.wabi.ui.theme.WabiTheme
+
+@Composable
+fun OnboardStateIndicator(
+    pageSize: Int, currentPage: Int
+) {
+    Row(
+        horizontalArrangement = Arrangement.SpaceBetween
+    ) {
+        repeat(pageSize) {
+            Spacer(modifier = Modifier.width(1.5.dp))
+            Box(
+                modifier = Modifier
+                    .height(10.dp)
+                    .width(width = if (it == currentPage) 35.dp else 10.dp)
+                    .clip(
+                        RoundedCornerShape(
+                            10.dp
+                        )
+                    )
+                    .background(color = WabiTheme.colors.onBoardLight)
+            )
+            Spacer(modifier = Modifier.width(1.5.dp))
+        }
+    }
+}

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

@@ -0,0 +1,61 @@
+package com.example.wabi.view.screeens.onboard.items
+
+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.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.vector.ImageVector
+import androidx.compose.ui.res.vectorResource
+import androidx.compose.ui.unit.dp
+import com.example.wabi.ui.theme.WabiTheme
+
+@Composable
+fun PartSlider(onboardItem: OnboardListState, modifier: Modifier = Modifier) {
+    Column(
+        modifier = modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally
+    ) {
+        Column(
+            modifier = modifier
+                .weight(0.6f)
+                .background(color = WabiTheme.colors.onBoardLight)
+                .fillMaxWidth(),
+            verticalArrangement = Arrangement.Center,
+            horizontalAlignment = Alignment.CenterHorizontally
+        ) {
+            Image(
+                imageVector = ImageVector.vectorResource(onboardItem.image),
+                contentDescription = "onboardItem",
+            )
+        }
+        Column(
+            modifier = modifier
+                .weight(0.2f)
+                .background(color = WabiTheme.colors.onBoardDark)
+                .fillMaxWidth(),
+            horizontalAlignment = Alignment.CenterHorizontally,
+            verticalArrangement = Arrangement.SpaceAround
+        ) {
+            Text(
+                text = onboardItem.title,
+                style = WabiTheme.fonts.headerFont,
+                color = WabiTheme.colors.accentColorOne,
+            )
+            Text(
+                text = onboardItem.mainText,
+                style = WabiTheme.fonts.mainFont,
+                color = WabiTheme.colors.onBoardLight,
+                modifier = Modifier.padding(50.dp, 0.dp),
+                minLines = 3,
+                maxLines = 3
+            )
+        }
+    }
+}