Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nqmgaming committed May 24, 2024
1 parent 8f42b42 commit 893feec
Show file tree
Hide file tree
Showing 16 changed files with 652 additions and 4 deletions.
35 changes: 35 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,15 @@ dependencies {

// Bottom sheet
implementation(libs.input)

// Test
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("com.linkedin.dexmaker:dexmaker-mockito-inline:2.28.1")

testImplementation("junit:junit:4.13.2")
testImplementation("androidx.test:core:1.4.0")
testImplementation("org.mockito:mockito-android:4.2.0")
testImplementation("org.mockito:mockito-inline:4.2.0")
testImplementation("org.mockito:mockito-core:4.2.0")
testImplementation ("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.0")
}
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/nike"
tools:replace="android:label"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:replace="android:label"
tools:targetApi="31">
<activity
android:name=".ui.activities.checkout.CheckoutActivity"
android:exported="false" />
<activity
android:name=".ui.activities.productDetail.ProductDetailActivity"
android:exported="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,8 @@ interface ShoesApi {
@Header("Authorization") token: String,
@Path("id") id: String
)

/**
* This part is for order
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package com.nqmgaming.shoseshop.ui.activities.checkout

import android.os.Bundle
import android.text.InputType
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.maxkeppeler.sheets.input.InputSheet
import com.maxkeppeler.sheets.input.ValidationResult
import com.maxkeppeler.sheets.input.type.InputEditText
import com.nqmgaming.shoseshop.R
import com.nqmgaming.shoseshop.databinding.ActivityCheckoutBinding
import com.nqmgaming.shoseshop.util.SharedPrefUtils
import com.wajahatkarim3.easyvalidation.core.view_ktx.validEmail
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class CheckoutActivity : AppCompatActivity() {
private lateinit var binding: ActivityCheckoutBinding
private val viewModel: CheckoutViewModel by viewModels()
private lateinit var email: String
private lateinit var phoneNumber: String
private lateinit var address: String
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
binding = ActivityCheckoutBinding.inflate(layoutInflater)
setContentView(binding.root)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}

email = SharedPrefUtils.getString(this, "email") ?: ""
phoneNumber = SharedPrefUtils.getString(this, "phoneNumber") ?: ""
address = SharedPrefUtils.getString(this, "address") ?: ""
binding.apply {
emailTv.text = email
phoneTv.text = phoneNumber
addressTv.text = address
editEmailIv.setOnClickListener {
var isEmailValid = false
val oldEmail: String = email
InputSheet().show(this@CheckoutActivity) {
title("Edit Email")
with(InputEditText {
required()
label("Email")
hint("Enter your email")
defaultValue(email)
inputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS)
maxLines(1)
startIconDrawable(R.drawable.ic_email)
validationListener { value ->
isEmailValid = value.toString().validEmail()
ValidationResult(isEmailValid, "Invalid email")
}
changeListener { value ->
email = value.toString()
}
resultListener {
emailTv.text = email
}
onPositive {
if (isEmailValid) {
SharedPrefUtils.saveString(this@CheckoutActivity, "email", email)
} else {
email = oldEmail
Toast.makeText(
this@CheckoutActivity,
"Invalid email",
Toast.LENGTH_SHORT
).show()
}
}
onNegative {
email = oldEmail
emailTv.text = email
}
})
}
}

editAddressIv.setOnClickListener {
var isAddressValid = false
val oldAddress: String = address
InputSheet().show(this@CheckoutActivity) {
title("Edit Address")
with(InputEditText {
required()
label("Address")
hint("Enter your address")
defaultValue(address)
maxLines(1)
startIconDrawable(R.drawable.ic_location)
validationListener { value ->
isAddressValid = value.toString().isNotEmpty()
ValidationResult(isAddressValid, "Address cannot be empty")
}
changeListener { value ->
address = value.toString()
}
resultListener {
addressTv.text = address
}
onPositive {
SharedPrefUtils.saveString(this@CheckoutActivity, "address", address)
}
onNegative {
address = oldAddress
addressTv.text = address
}
})
}
}

editPhoneIv.setOnClickListener {
var isPhoneValid = false
val oldPhone: String = phoneNumber
InputSheet().show(this@CheckoutActivity) {
title("Edit Phone Number")
with(InputEditText {
required()
label("Phone Number")
hint("Enter your phone number")
defaultValue(phoneNumber)
maxLines(1)
startIconDrawable(R.drawable.ic_telephone)
validationListener { value ->
isPhoneValid = value.toString().isNotEmpty()
ValidationResult(isPhoneValid, "Phone number cannot be empty")
}
changeListener { value ->
phoneNumber = value.toString()
}
resultListener {
phoneTv.text = phoneNumber
}
onPositive {
SharedPrefUtils.saveString(
this@CheckoutActivity,
"phoneNumber",
phoneNumber
)
}
onNegative {
phoneNumber = oldPhone
phoneTv.text = phoneNumber
}
})
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.nqmgaming.shoseshop.ui.activities.checkout

import androidx.lifecycle.ViewModel
import com.nqmgaming.shoseshop.data.repository.ShoesRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
@HiltViewModel
class CheckoutViewModel @Inject constructor(
private val shoesRepository: ShoesRepository
):ViewModel(){

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ class SignInActivity : AppCompatActivity() {
viewModel.signInUser(email!!, password) { response ->
if (response != null) {
// navigate to main activity
Log.d("SignInActivity", "User signed in successfully")
SharedPrefUtils.saveString(this, "id", response.data.id)
SharedPrefUtils.saveString(this, "email", response.data.email)
SharedPrefUtils.saveString(this, "avatar", response.data.avatar)
SharedPrefUtils.saveString(this, "firstName", response.data.firstName)
SharedPrefUtils.saveString(this, "lastName", response.data.lastName)
SharedPrefUtils.saveString(this, "birthDate", response.data.birthDate)
Expand All @@ -65,6 +63,7 @@ class SignInActivity : AppCompatActivity() {
.setHeading("Sign in success!")
.setDescription("Welcome back to shoesshop")
.setCancelable(false)
.setDismissButtonText("OK")
.showDialog(object : OnDialogButtonClickListener() {
override fun onDismissClicked(dialog: Dialog) {
super.onDismissClicked(dialog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class SignUpActivity : AppCompatActivity() {
}.addSuccessCallback {
binding.passwordEt.error = null
}.check()
address.validator().nonEmpty().addErrorCallback {
address.validator().nonEmpty().minLength(10).addErrorCallback {
binding.addressEt.error = it
binding.addressEt.requestFocus()
error = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.nqmgaming.shoseshop.adapter.cart.CartAdapter
import com.nqmgaming.shoseshop.data.model.cart.Cart
import com.nqmgaming.shoseshop.data.model.product.Product
import com.nqmgaming.shoseshop.databinding.FragmentCartBinding
import com.nqmgaming.shoseshop.ui.activities.checkout.CheckoutActivity
import com.nqmgaming.shoseshop.ui.activities.productDetail.ProductDetailActivity
import com.nqmgaming.shoseshop.util.SharedPrefUtils
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -37,6 +38,12 @@ class CartFragment : Fragment() {
val bearerToken = "Bearer $token"
val userId = SharedPrefUtils.getString(requireContext(), "id", "") ?: ""

binding.paymentBtn.setOnClickListener {
Intent(requireContext(), CheckoutActivity::class.java).apply {
startActivity(this)
}
}

viewModel.getAllCartsMain(bearerToken, userId) { carts ->
if (carts != null) {
binding.cartRv.adapter = CartAdapter(viewModel, bearerToken).apply {
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_edit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="m4.76,18.81s0.08,0 0.11,0l2.93,-0.27c0.41,-0.04 0.79,-0.22 1.08,-0.51l11.06,-11.06c0.52,-0.52 0.81,-1.21 0.81,-1.94s-0.29,-1.42 -0.81,-1.94l-0.71,-0.71c-1.04,-1.04 -2.85,-1.04 -3.89,0l-1.41,1.41s0,0 0,0l-9.64,9.64c-0.29,0.29 -0.47,0.67 -0.5,1.08l-0.27,2.93c-0.03,0.37 0.1,0.73 0.36,1 0.24,0.24 0.55,0.37 0.88,0.37zM17.29,3.07c0.32,0 0.64,0.12 0.88,0.37l0.71,0.71c0.24,0.24 0.37,0.55 0.37,0.88s-0.13,0.65 -0.37,0.88l-0.88,0.88 -2.47,-2.47 0.88,-0.88c0.24,-0.24 0.56,-0.37 0.88,-0.37zM5.28,14.65c0,-0.06 0.03,-0.11 0.07,-0.15l9.11,-9.12 2.47,2.47 -9.11,9.11s-0.1,0.07 -0.15,0.07l-2.63,0.24 0.24,-2.63zM22.75,22c0,0.41 -0.34,0.75 -0.75,0.75h-20c-0.41,0 -0.75,-0.34 -0.75,-0.75s0.34,-0.75 0.75,-0.75h20c0.41,0 0.75,0.34 0.75,0.75z"/>
</vector>
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/rounded_border.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorWhite" />
<stroke
android:width="1dp"
android:color="@color/colorGrey" />
<corners android:radius="8dp" />
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp" />
</shape>
Loading

0 comments on commit 893feec

Please sign in to comment.