This commit is contained in:
2023-11-26 13:19:30 +03:00
parent 9f54b69a18
commit 964636333b
13 changed files with 67 additions and 11 deletions
+3 -1
View File
@@ -66,7 +66,7 @@ dependencies {
implementation("androidx.core:core-ktx:1.12.0") implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2") implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.activity:activity-compose:1.8.0") implementation("androidx.activity:activity-compose:1.8.1")
implementation(platform("androidx.compose:compose-bom:2023.03.00")) implementation(platform("androidx.compose:compose-bom:2023.03.00"))
implementation("androidx.compose.ui:ui") implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics") implementation("androidx.compose.ui:ui-graphics")
@@ -112,4 +112,6 @@ dependencies {
implementation("androidx.room:room-ktx:2.6.0") implementation("androidx.room:room-ktx:2.6.0")
ksp("androidx.room:room-compiler:2.6.0") ksp("androidx.room:room-compiler:2.6.0")
implementation("com.squareup.retrofit2:retrofit:2.9.0") implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation ("com.sun.mail:android-mail:1.6.2")
implementation ("com.sun.mail:android-activation:1.6.2")
} }
@@ -5,7 +5,7 @@ import com.google.gson.annotations.SerializedName
import java.io.Serializable import java.io.Serializable
data class Categories ( data class Categories (
@SerializedName("id") @Expose var id: Int, @SerializedName("categoryId") @Expose var categoryId: Int,
@SerializedName("name") @Expose var name: String, @SerializedName("name") @Expose var name: String,
@SerializedName("imagePath") @Expose var imagePath: String @SerializedName("imagePath") @Expose var imagePath: String
): Serializable ): Serializable
@@ -8,5 +8,6 @@ data class Product(
@SerializedName("Name") @Expose var name: String?, @SerializedName("Name") @Expose var name: String?,
@SerializedName("ImagePath") @Expose var imagePath: String?, @SerializedName("ImagePath") @Expose var imagePath: String?,
@SerializedName("Price") @Expose var price: Double?, @SerializedName("Price") @Expose var price: Double?,
@SerializedName("MenuItemId") @Expose var menuItemId: Int @SerializedName("MenuItemId") @Expose var menuItemId: Int,
@SerializedName("categoryId") @Expose var categoryId: Int
): Serializable ): Serializable
@@ -65,7 +65,7 @@ class UserRepository {
Log.w("SIGN_UP", "FAILURE", e) Log.w("SIGN_UP", "FAILURE", e)
} }
} }
isLoading.value = LOADING.DONE isLoading.value = LOADING.DONE
} else { } else {
isSignUp.value = false isSignUp.value = false
isLoading.value = LOADING.ERROR isLoading.value = LOADING.ERROR
@@ -11,8 +11,8 @@ interface DAOInterface {
suspend fun getCategories(): Response<List<Categories>> suspend fun getCategories(): Response<List<Categories>>
@GET("products/{id}") @GET("products")
suspend fun getProducts(@Path("id") id: Int): Response<List<Product>> suspend fun getProducts(@Path("categoryId") categoryId: Int): Response<List<Product>>
@@ -4,6 +4,7 @@ import android.app.Dialog
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@@ -15,11 +16,19 @@ import androidx.navigation.fragment.navArgs
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase
import com.yaros.sweetshopviki.R import com.yaros.sweetshopviki.R
import com.yaros.sweetshopviki.common.formatPrice import com.yaros.sweetshopviki.common.formatPrice
import com.yaros.sweetshopviki.common.getPaymentImages import com.yaros.sweetshopviki.common.getPaymentImages
import com.yaros.sweetshopviki.common.getPaymentNames import com.yaros.sweetshopviki.common.getPaymentNames
import com.yaros.sweetshopviki.databinding.FragmentPaymentBinding import com.yaros.sweetshopviki.databinding.FragmentPaymentBinding
import java.util.*
import javax.mail.*
import javax.mail.internet.InternetAddress
import javax.mail.internet.MimeMessage
class PaymentFragment : BottomSheetDialogFragment() { class PaymentFragment : BottomSheetDialogFragment() {
@@ -68,11 +77,18 @@ class PaymentFragment : BottomSheetDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val user = FirebaseAuth.getInstance().currentUser
val email = user?.email
val subject = "Ваш заказ"
val body = "Уважаемый пользователь \n Ваш заказ отправлен на указанный вами адрес\n Ваш заказ готовится и скоро приедит к вам :) \n С уважением Кондитерская Вики"
binding.apply { binding.apply {
closePaymentScreen.setOnClickListener { findNavController().popBackStack() } closePaymentScreen.setOnClickListener { findNavController().popBackStack() }
orderNow.setOnClickListener { orderNow.setOnClickListener {
if (orderAddress.text.isEmpty().not()) { if (orderAddress.text.isEmpty().not()) {
showOrderSuccessDialog() showOrderSuccessDialog()
sendMail(email!!, subject, body)
Log.d("Email", email)
viewModel.clearBasket() viewModel.clearBasket()
} else { } else {
orderAddress.error = getString(R.string.address_error) orderAddress.error = getString(R.string.address_error)
@@ -117,6 +133,34 @@ class PaymentFragment : BottomSheetDialogFragment() {
} }
} }
private fun sendMail(toEmail: String, subject: String, body: String) {
Thread {
val props = Properties()
props["mail.smtp.host"] = "smtp.yandex.ru"
props["mail.smtp.socketFactory.port"] = "465"
props["mail.smtp.socketFactory.class"] = "javax.net.ssl.SSLSocketFactory"
props["mail.smtp.auth"] = "true"
props["mail.smtp.port"] = "465"
val session = Session.getDefaultInstance(props,
object : Authenticator() {
override fun getPasswordAuthentication(): PasswordAuthentication {
return PasswordAuthentication("VikiSweetShop@yandex.ru", "wpvldcgiythzbouq")
}
})
val message = MimeMessage(session)
try {
message.setFrom(InternetAddress.parse("VikiSweetShop@yandex.ru")[0])
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail))
message.subject = subject
message.setText(body)
Transport.send(message)
Log.d("EMAIL", "SUCCESS")
} catch (e: MessagingException) {
Log.d("EMAIL", "Failed to send email", e)
}
}.start()
}
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
_binding = null _binding = null
@@ -45,10 +45,10 @@ class ProductsFragment : Fragment(R.layout.fragment_products) {
binding.apply { binding.apply {
viewModel.apply { viewModel.apply {
getProducts(category.id) getProducts(category.categoryId)
initObservers() initObservers()
tryAgain.setOnClickListener { tryAgain.setOnClickListener {
getProducts(category.id) getProducts(category.categoryId)
} }
} }
} }
@@ -58,7 +58,7 @@ class ProductDetailFragment : BottomSheetDialogFragment() {
addToBasket.setOnClickListener { addToBasket.setOnClickListener {
viewModel.addBookToBasket( viewModel.addBookToBasket(
ProductsBasketRoomModel( ProductsBasketRoomModel(
productId = product.menuItemId!!, productId = product.menuItemId,
productName = product.name, productName = product.name,
productCount = count, productCount = count,
productPrice = totalPrice, productPrice = totalPrice,
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>
+3 -1
View File
@@ -149,6 +149,7 @@
android:id="@+id/phoneNumberEditText" android:id="@+id/phoneNumberEditText"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="phone"
android:hint="@string/phone_number_hint" android:hint="@string/phone_number_hint"
android:textColor="@color/primary" android:textColor="@color/primary"
android:textColorHint="@color/primary" /> android:textColorHint="@color/primary" />
@@ -172,13 +173,14 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/confirmPasswordInputLayout" app:layout_constraintTop_toBottomOf="@+id/confirmPasswordInputLayout"
app:startIconDrawable="@drawable/ic_baseline_phone_24" app:startIconDrawable="@drawable/ic_username"
app:startIconTint="@color/primary"> app:startIconTint="@color/primary">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/userNameEditText" android:id="@+id/userNameEditText"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="@string/username_hint" android:hint="@string/username_hint"
android:textColor="@color/primary" android:textColor="@color/primary"
android:textColorHint="@color/primary" /> android:textColorHint="@color/primary" />
+1
View File
@@ -56,4 +56,5 @@
<string name="app_logo">Логотип приложения</string> <string name="app_logo">Логотип приложения</string>
<string name="credit_card">Банковская карта</string> <string name="credit_card">Банковская карта</string>
<string name="cash">Наличные</string> <string name="cash">Наличные</string>
<string name="yorsorder">Ваш заказ</string>
</resources> </resources>
+1
View File
@@ -55,6 +55,7 @@
<string name="app_logo">App Logo</string> <string name="app_logo">App Logo</string>
<string name="credit_card">Credit Card</string> <string name="credit_card">Credit Card</string>
<string name="cash">Cash</string> <string name="cash">Cash</string>
<string name="yorsorder">Ваш заказ</string>
<string-array name="app_logo_strings"> <string-array name="app_logo_strings">
<item>M255.7,459.08c-56,0 -111.95,-0.09 -167.92,0.06 -15.52,0 -26.35,-6.78 -32.73,-20.69 -1.7,-3.71 -2,-7.93 -2,-12q0,-170.16 0,-340.31c0,-19 14.19,-33 33.22,-33q169.66,-0.06 339.34,0C445,53.11 459,67.14 459,86.5q0.06,169.91 0,339.82c0,18.76 -14.09,32.73 -32.86,32.74Q340.91,459.12 255.7,459.08ZM197.48,147.88c-14.66,0 -29.32,0.19 -44,-0.12 -4,-0.08 -5.88,1.25 -7.31,4.82 -3.95,9.9 -7.93,19.79 -10.67,30.08 -5.25,19.76 -8.78,39.72 -5.17,60.23 3,17.09 10.58,31.37 25.42,41.27 8.24,5.5 17.41,8.26 27,9.63 3.87,0.56 4.82,2.11 4.74,5.78q-0.33,16.23 0,32.47c0.08,3.48 -0.91,4.94 -4.42,5.68 -9,1.9 -17.81,4.21 -26.68,6.49 -5.25,1.35 -8.63,5.88 -8.11,10.5a10.33,10.33 0,0 0,10.43 9q38.48,0.13 77,0c5.66,0 9.9,-3.77 10.49,-8.77s-2.55,-9.31 -8.27,-10.76c-8.87,-2.24 -17.74,-4.56 -26.68,-6.5 -3.29,-0.71 -4.2,-2.12 -4.14,-5.36 0.19,-10.82 0.26,-21.66 0,-32.48 -0.1,-3.9 0.89,-5.48 4.95,-6 14.23,-1.94 27,-7.23 36.87,-18.08 14.61,-16.07 17.71,-35.69 16.54,-56.35 -1.34,-23.72 -8.09,-46.1 -17.53,-67.79 -1.32,-3 -2.93,-3.75 -6,-3.72C227.13,148 212.3,147.88 197.48,147.88ZM383.12,191.59c0,-11.67 0,-21.16 0,-30.65 0,-8.19 -3.69,-13.05 -9.83,-13s-9.52,4.7 -9.55,12.68c0,6.17 0,12.33 0,18.49 0,9 0.13,18 -0.06,27 -0.14,6.28 -4.25,10.31 -9.92,10.29 -5.83,0 -9.41,-3.9 -9.61,-10.42 -0.05,-1.66 0,-3.33 0,-5q0,-21.24 0,-42.47c0,-4.66 -2.22,-7.88 -6.44,-9.79 -3.66,-1.65 -6.86,-0.56 -9.75,1.75s-3.53,5.84 -3.53,9.46q0,22.72 0,45.46c0,3.66 -0.64,7 -4,9.17a9.76,9.76 0,0 1,-10.41 0.68c-3.91,-2 -5.2,-5.41 -5.21,-9.49 0,-15.49 0,-31 0,-46.47 0,-6.74 -3.75,-11.12 -9.42,-11.32s-10.11,4.67 -10.14,11.25c-0.07,18.65 -0.63,37.33 0.16,56 1,22.83 11.91,39.41 33.77,47.77 2.49,0.95 2.83,2.13 2.59,4.39Q320,284 318.49,300.61c-1.27,13.93 -2.7,27.85 -3.58,41.8C314,357.23 327,367 340.78,362.15c9.35,-3.29 13.84,-11.25 12.77,-22.74 -2.16,-23.2 -4.22,-46.42 -6.65,-69.6 -0.47,-4.5 0.78,-6.24 4.94,-7.84 16.26,-6.24 26.39,-18.12 30,-35.18C384.52,214.44 382.46,201.87 383.12,191.59Z</item> <item>M255.7,459.08c-56,0 -111.95,-0.09 -167.92,0.06 -15.52,0 -26.35,-6.78 -32.73,-20.69 -1.7,-3.71 -2,-7.93 -2,-12q0,-170.16 0,-340.31c0,-19 14.19,-33 33.22,-33q169.66,-0.06 339.34,0C445,53.11 459,67.14 459,86.5q0.06,169.91 0,339.82c0,18.76 -14.09,32.73 -32.86,32.74Q340.91,459.12 255.7,459.08ZM197.48,147.88c-14.66,0 -29.32,0.19 -44,-0.12 -4,-0.08 -5.88,1.25 -7.31,4.82 -3.95,9.9 -7.93,19.79 -10.67,30.08 -5.25,19.76 -8.78,39.72 -5.17,60.23 3,17.09 10.58,31.37 25.42,41.27 8.24,5.5 17.41,8.26 27,9.63 3.87,0.56 4.82,2.11 4.74,5.78q-0.33,16.23 0,32.47c0.08,3.48 -0.91,4.94 -4.42,5.68 -9,1.9 -17.81,4.21 -26.68,6.49 -5.25,1.35 -8.63,5.88 -8.11,10.5a10.33,10.33 0,0 0,10.43 9q38.48,0.13 77,0c5.66,0 9.9,-3.77 10.49,-8.77s-2.55,-9.31 -8.27,-10.76c-8.87,-2.24 -17.74,-4.56 -26.68,-6.5 -3.29,-0.71 -4.2,-2.12 -4.14,-5.36 0.19,-10.82 0.26,-21.66 0,-32.48 -0.1,-3.9 0.89,-5.48 4.95,-6 14.23,-1.94 27,-7.23 36.87,-18.08 14.61,-16.07 17.71,-35.69 16.54,-56.35 -1.34,-23.72 -8.09,-46.1 -17.53,-67.79 -1.32,-3 -2.93,-3.75 -6,-3.72C227.13,148 212.3,147.88 197.48,147.88ZM383.12,191.59c0,-11.67 0,-21.16 0,-30.65 0,-8.19 -3.69,-13.05 -9.83,-13s-9.52,4.7 -9.55,12.68c0,6.17 0,12.33 0,18.49 0,9 0.13,18 -0.06,27 -0.14,6.28 -4.25,10.31 -9.92,10.29 -5.83,0 -9.41,-3.9 -9.61,-10.42 -0.05,-1.66 0,-3.33 0,-5q0,-21.24 0,-42.47c0,-4.66 -2.22,-7.88 -6.44,-9.79 -3.66,-1.65 -6.86,-0.56 -9.75,1.75s-3.53,5.84 -3.53,9.46q0,22.72 0,45.46c0,3.66 -0.64,7 -4,9.17a9.76,9.76 0,0 1,-10.41 0.68c-3.91,-2 -5.2,-5.41 -5.21,-9.49 0,-15.49 0,-31 0,-46.47 0,-6.74 -3.75,-11.12 -9.42,-11.32s-10.11,4.67 -10.14,11.25c-0.07,18.65 -0.63,37.33 0.16,56 1,22.83 11.91,39.41 33.77,47.77 2.49,0.95 2.83,2.13 2.59,4.39Q320,284 318.49,300.61c-1.27,13.93 -2.7,27.85 -3.58,41.8C314,357.23 327,367 340.78,362.15c9.35,-3.29 13.84,-11.25 12.77,-22.74 -2.16,-23.2 -4.22,-46.42 -6.65,-69.6 -0.47,-4.5 0.78,-6.24 4.94,-7.84 16.26,-6.24 26.39,-18.12 30,-35.18C384.52,214.44 382.46,201.87 383.12,191.59Z</item>
+1 -1
View File
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins { plugins {
id("com.android.application") version "8.1.3" apply false id("com.android.application") version "8.1.4" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false id("org.jetbrains.kotlin.android") version "1.9.0" apply false
id("com.google.gms.google-services") version "4.4.0" apply false id("com.google.gms.google-services") version "4.4.0" apply false
id("com.google.devtools.ksp") version "1.9.10-1.0.13" apply false id("com.google.devtools.ksp") version "1.9.10-1.0.13" apply false