Skip to content
This repository was archived by the owner on Jul 17, 2023. It is now read-only.

M3 postwork 8 #25

Merged
merged 3 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .idea/misc.xml

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

3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,8 @@ dependencies {

implementation 'com.google.android.gms:play-services-location:18.0.0'

testImplementation "com.google.truth:truth:1.0.1"
androidTestImplementation "com.google.truth:truth:1.0.1"

implementation 'com.android.support:support-compat:28.0.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.myapplication

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test

class ResourceComparerTest{

lateinit var resourceComparer:ResourceComparer
lateinit var context: Context

@Before
fun setup(){
resourceComparer = ResourceComparer()
context = ApplicationProvider.getApplicationContext()
}

@Test
fun stringResourceSameAsStringGiven(){
val result = resourceComparer.isEqual(context,R.string.app_name,"Bedu Shop")
assertThat(result).isTrue()
}

@Test
fun stringResourceDifferentAsStringGiven_returnsFalse(){
val result = resourceComparer.isEqual(context,R.string.app_name,"Testing")
assertThat(result).isFalse()
}

}
25 changes: 25 additions & 0 deletions app/src/main/java/com/example/myapplication/LoginCheck.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.myapplication

object LoginCheck {

fun checkEmailAndPassword(email:String,password:String):String{
if(password.isNotEmpty() && email.isNotEmpty()){
return if(password.length < 8){
"PASSWORD_CHARACTERS_IS_LESS_THAN_8"
}else{
"SUCCESSFUL_LOGIN"
}

}else{
return if(password.isEmpty() && email.isNotEmpty()){
"PASSWORD_IS_EMPTY"
}else if(password.isNotEmpty() && email.isEmpty()){
"EMAIL_IS_EMPTY"
}else{
"EMPTY_FIELDS"
}

}
}

}
70 changes: 52 additions & 18 deletions app/src/main/java/com/example/myapplication/LoginFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,66 @@ class LoginFragment : Fragment() {

private fun setClickListeners(view: View) {
loginButton.setOnClickListener {
val emailNotEmpty: Boolean = !loginFormUser.editText?.text.isNullOrEmpty()
val passNotEmpty: Boolean = !loginFormPassword.editText?.text.isNullOrEmpty()

if (emailNotEmpty && passNotEmpty){
loginProgressBar.visibility = View.VISIBLE
loginButton.isEnabled = false
checkUser(view)
}
else {
if (!emailNotEmpty) {
when(LoginCheck.checkEmailAndPassword(userInputText.text.toString(),passwordInputText.text.toString())){
"SUCCESSFUL_LOGIN"->{
loginProgressBar.visibility = View.VISIBLE
loginButton.isEnabled = false
checkUser(view)
}
"EMPTY_FIELDS" ->{
loginFormUser.error = getString(R.string.notice_incomplete_field)
loginFormPassword.error = getString(R.string.notice_incomplete_field)
Snackbar.make(
view,
getString(R.string.notice_in_complete_fields),
Snackbar.LENGTH_SHORT
)
.setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_FADE)
.setAction(getString(R.string.snack_bar_button)) {}.show()
}
"EMAIL_IS_EMPTY"->{
loginFormUser.error = getString(R.string.notice_incomplete_field)
Snackbar.make(
view,
getString(R.string.notice_in_complete_fields),
Snackbar.LENGTH_SHORT
)
.setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_FADE)
.setAction(getString(R.string.snack_bar_button)) {}.show()
}
if (!passNotEmpty) {
"PASSWORD_IS_EMPTY"->{
loginFormPassword.error = getString(R.string.notice_incomplete_field)
Snackbar.make(
view,
getString(R.string.notice_in_complete_fields),
Snackbar.LENGTH_SHORT
)
.setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_FADE)
.setAction(getString(R.string.snack_bar_button)) {}.show()
}
"PASSWORD_CHARACTERS_IS_LESS_THAN_8"->{
loginFormPassword.error = getString(R.string.notice_password_characters_less_than_8)
Snackbar.make(
view,
getString(R.string.notice_in_complete_fields),
Snackbar.LENGTH_SHORT
)
.setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_FADE)
.setAction(getString(R.string.snack_bar_button)) {}.show()
}
else ->{

}

Snackbar.make(
view,
getString(R.string.notice_in_complete_fields),
Snackbar.LENGTH_SHORT
)
.setAnimationMode(BaseTransientBottomBar.ANIMATION_MODE_FADE)
.setAction(getString(R.string.snack_bar_button)) {}.show()
}


}





registerRedirectBtn.setOnClickListener {
findNavController().navigate(
R.id.action_loginFragment2_to_registerFragment2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ProductCartAdapter(

fun render(product: Product, position: Int) {
productCartTitle.text = product.title
productCartPrice.text = "$ ${product.price}"
productCartPrice.text = "$ %.2f".format(product.amountAddedToCart?.let { product.price?.times(it)})
Picasso.get().load(product.image).into(productCartImage)
productCartAmount.text = product.amountAddedToCart.toString()
setListeners(product, position)
Expand All @@ -52,6 +52,7 @@ class ProductCartAdapter(
?.amountAddedToCart
.toString()
}
productCartPrice.text = "$ %.2f".format(product.amountAddedToCart?.let { product.price?.times(it)})
}

productCartRemoveSign.setOnClickListener {
Expand All @@ -68,6 +69,7 @@ class ProductCartAdapter(
notifyItemRangeChanged(position, product_list.size)
}
}
productCartPrice.text = "$ %.2f".format(product.amountAddedToCart?.let { product.price?.times(it)})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.view.ViewGroup
import android.widget.ImageView


class productCartContact : Fragment() {
class ProductCartContact : Fragment() {
private lateinit var addItem: ImageView
private lateinit var removeItem: ImageView

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ProfileFragment : Fragment() {
private fun getOptionsClickListener(): (String) -> Unit {
return {
when (it) {
"Mis direcciones" -> {
getString(R.string.my_address) -> {
val addressFragment = AddressFragment()
addressFragment.show(parentFragmentManager, "fragment")
}
Expand Down
20 changes: 12 additions & 8 deletions app/src/main/java/com/example/myapplication/RegisterFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,18 @@ class RegisterFragment : Fragment() {
registerButton.setOnClickListener {
if(isFormValid()) {

sharedPreferences?.edit()
?.putString("USER_EMAIL", emailInputText.text.toString())
?.putString("USER_PASSWORD", passwordInputText.text.toString())
?.apply()


val action = RegisterFragmentDirections.actionRegisterFragment2ToLoginFragment2()
Navigation.findNavController(view).navigate(action)
if(passwordInputText.text.toString().length<8){
regFormPassword.error=getString(R.string.notice_password_characters_less_than_8)
}else{
sharedPreferences?.edit()
?.putString("USER_EMAIL", emailInputText.text.toString())
?.putString("USER_PASSWORD", passwordInputText.text.toString())
?.apply()


val action = RegisterFragmentDirections.actionRegisterFragment2ToLoginFragment2()
Navigation.findNavController(view).navigate(action)
}

} else {
if(nameInputText.text.isNullOrEmpty()){regFormUser.error=getString(R.string.notice_incomplete_field)}
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/example/myapplication/ResourceComparer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.myapplication

import android.content.Context

class ResourceComparer {

fun isEqual (context: Context, resId:Int, string:String) :Boolean{
return context.getString(resId) == string
}

}
1 change: 1 addition & 0 deletions app/src/main/res/values-en-rUS/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@
<string name="send_shop_cart">Shipment</string>
<string name="current_payment_method">Current payment method</string>
<string name="search_toast_deac">Search is unavailable</string>
<string name="notice_password_characters_less_than_8">Must be greater than 7 characters</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-es-rAR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@
<string name="send_shop_cart">Envío</string>
<string name="current_payment_method">Método de pago actual</string>
<string name="search_toast_deac">La búsqueda está deshabilitada</string>
<string name="notice_password_characters_less_than_8">Debe ser mayor a 7 caracteres</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<string name="notice_check_in">Registrarse…</string>
<string name="notice_in_complete_fields">Por favor, complete todos los campos</string>
<string name="notice_incomplete_field">Campo incompleto</string>
<string name="notice_password_characters_less_than_8">Debe ser mayor a 7 caracteres</string>
<string name="notice_user_not_found">Usuario no encontrado</string>
<string name="hello_blank_fragment">Blank Fragment</string>

Expand Down
38 changes: 38 additions & 0 deletions app/src/test/java/com/example/myapplication/LoginCheckTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.myapplication

import com.google.common.truth.Truth.assertThat
import org.junit.Test


class LoginCheckTest {

@Test
fun `empty email and empty password return EMPTY_FIELDS`() {
val result = LoginCheck.checkEmailAndPassword("","")
assertThat(result).contains("EMPTY_FIELDS")
}

@Test
fun `correct email and correct password return SUCCESSFUL_LOGIN`() {
val result = LoginCheck.checkEmailAndPassword("[email protected]","george123")
assertThat(result).contains("SUCCESSFUL_LOGIN")
}

@Test
fun `password characters is less than 8 return PASSWORD_CHARACTERS_IS_LESS_THAN_8`() {
val result = LoginCheck.checkEmailAndPassword("[email protected]","george")
assertThat(result).contains("PASSWORD_CHARACTERS_IS_LESS_THAN_8")
}

@Test
fun `empty email and correct password return EMAIL_IS_EMPTY`() {
val result = LoginCheck.checkEmailAndPassword("","george123")
assertThat(result).contains("EMAIL_IS_EMPTY")
}

@Test
fun `correct email and empty password return PASSWORD_IS_EMPTY`() {
val result = LoginCheck.checkEmailAndPassword("[email protected]","")
assertThat(result).contains("PASSWORD_IS_EMPTY")
}
}