Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LdS 2020 Grupo14
App La Justa
Commits
8bb419a0
Commit
8bb419a0
authored
Feb 15, 2021
by
Daniel Cesanelli
Browse files
Agregado cart
parent
00d9c4c1
Changes
29
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/cesanelli/lajusta/MainActivity.java
View file @
8bb419a0
...
...
@@ -90,6 +90,9 @@ public class MainActivity extends AppCompatActivity {
if
(
response
.
isSuccessful
())
{
token
.
setValue
(
jwt
);
token
.
setUser
(
response
.
body
());
}
else
{
sharedpreferences
.
edit
().
putString
(
"JWT"
,
""
).
apply
();
sharedpreferences
.
edit
().
putString
(
"UserID"
,
""
).
apply
();
}
}
catch
(
Exception
ex
)
{
sharedpreferences
.
edit
().
putString
(
"JWT"
,
""
).
apply
();
...
...
@@ -118,7 +121,7 @@ public class MainActivity extends AppCompatActivity {
@Override
public
boolean
onOptionsItemSelected
(
@NonNull
MenuItem
item
)
{
return
NavigationUI
.
onNavDestinationSelected
(
item
,
navController
)
||
super
.
onOptionsItemSelected
(
item
);
return
NavigationUI
.
onNavDestinationSelected
(
item
,
navController
)
||
super
.
onOptionsItemSelected
(
item
);
}
@Override
...
...
app/src/main/java/com/cesanelli/lajusta/io/ApiAdapter.java
View file @
8bb419a0
...
...
@@ -16,7 +16,8 @@ public class ApiAdapter {
// Creamos un interceptor y le indicamos el log level a usar
HttpLoggingInterceptor
logging
=
new
HttpLoggingInterceptor
();
logging
.
setLevel
(
HttpLoggingInterceptor
.
Level
.
BODY
);
// logging.setLevel(HttpLoggingInterceptor.Level.BODY);
logging
.
setLevel
(
HttpLoggingInterceptor
.
Level
.
BASIC
);
// Asociamos el interceptor a las peticiones
OkHttpClient
.
Builder
httpClient
=
new
OkHttpClient
.
Builder
();
...
...
app/src/main/java/com/cesanelli/lajusta/io/ApiService.java
View file @
8bb419a0
package
com.cesanelli.lajusta.io
;
import
com.cesanelli.lajusta.io.models.Cart
;
import
com.cesanelli.lajusta.io.models.General
;
import
com.cesanelli.lajusta.io.models.News
;
import
com.cesanelli.lajusta.io.models.Producer
;
import
com.cesanelli.lajusta.io.models.Product
;
import
com.cesanelli.lajusta.io.models.Signup
;
...
...
@@ -38,4 +41,13 @@ public interface ApiService {
@GET
(
"user/{id}"
)
Call
<
User
>
getUser
(
@Path
(
"id"
)
int
id
,
@Header
(
"Authorization"
)
String
authHeader
);
@GET
(
"news"
)
Call
<
News
>
getNews
();
@POST
(
"cart"
)
Call
<
Cart
>
postCart
(
@Body
Cart
body
,
@Header
(
"Authorization"
)
String
authHeader
);
@GET
(
"general/active"
)
Call
<
General
>
getNodes
();
}
app/src/main/java/com/cesanelli/lajusta/io/models/ActiveNode.java
0 → 100644
View file @
8bb419a0
package
com.cesanelli.lajusta.io.models
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
public
class
ActiveNode
{
private
Integer
id
;
private
Node
node
;
private
String
day
;
private
String
dateTimeFrom
;
private
String
dateTimeTo
;
public
ActiveNode
()
{
}
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
Node
getNode
()
{
return
node
;
}
public
void
setNode
(
Node
node
)
{
this
.
node
=
node
;
}
public
String
getDay
()
{
return
day
;
}
public
void
setDay
(
String
day
)
{
this
.
day
=
day
;
}
public
String
getDateTimeFrom
()
{
return
dateTimeFrom
;
}
public
void
setDateTimeFrom
(
String
dateTimeFrom
)
{
this
.
dateTimeFrom
=
dateTimeFrom
;
}
public
String
getDateTimeTo
()
{
return
dateTimeTo
;
}
public
void
setDateTimeTo
(
String
dateTimeTo
)
{
this
.
dateTimeTo
=
dateTimeTo
;
}
public
String
getOpen
()
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss.000'Z'"
);
try
{
Date
date
=
format
.
parse
(
day
);
SimpleDateFormat
formatterOut
=
new
SimpleDateFormat
(
"dd/MM/yyyy"
);
return
formatterOut
.
format
(
date
)
+
" de "
+
dateTimeFrom
+
" hs a "
+
dateTimeTo
+
" hs."
;
}
catch
(
ParseException
e
)
{
return
""
;
}
}
}
app/src/main/java/com/cesanelli/lajusta/io/models/Address.java
View file @
8bb419a0
...
...
@@ -5,6 +5,7 @@ public class Address {
private
String
street
;
private
String
number
;
private
String
description
;
private
String
betweenStreets
;
private
float
latitude
;
private
float
longitude
;
...
...
@@ -55,4 +56,17 @@ public class Address {
public
void
setLongitude
(
float
longitude
)
{
this
.
longitude
=
longitude
;
}
public
String
getBetweenStreets
()
{
return
betweenStreets
;
}
public
void
setBetweenStreets
(
String
betweenStreets
)
{
this
.
betweenStreets
=
betweenStreets
;
}
@Override
public
String
toString
()
{
return
street
+
((
number
==
null
||
number
.
isEmpty
())?
""
:
" Nº "
+
number
)
+
" "
+
betweenStreets
;
}
}
app/src/main/java/com/cesanelli/lajusta/io/models/Cart.java
View file @
8bb419a0
...
...
@@ -3,21 +3,26 @@ package com.cesanelli.lajusta.io.models;
import
java.util.ArrayList
;
public
class
Cart
{
private
ArrayList
<
CartItem
>
items
;
private
ArrayList
<
CartItem
>
cartProducts
;
private
boolean
isCanceled
;
private
Integer
quantity
;
private
float
total
;
public
Cart
(){
items
=
new
ArrayList
<
CartItem
>();
private
ActiveNode
nodeDate
;
public
Cart
()
{
cartProducts
=
new
ArrayList
<
CartItem
>();
quantity
=
0
;
total
=
0
;
isCanceled
=
false
;
nodeDate
=
null
;
}
public
ArrayList
<
CartItem
>
get
Item
s
()
{
return
item
s
;
public
ArrayList
<
CartItem
>
get
CartProduct
s
()
{
return
cartProduct
s
;
}
public
void
set
Item
s
(
ArrayList
<
CartItem
>
item
s
)
{
this
.
items
=
item
s
;
public
void
set
CartProduct
s
(
ArrayList
<
CartItem
>
cartProduct
s
)
{
this
.
cartProducts
=
cartProduct
s
;
}
public
Integer
getQuantity
()
{
...
...
@@ -35,4 +40,12 @@ public class Cart {
public
void
setTotal
(
float
total
)
{
this
.
total
=
total
;
}
public
ActiveNode
getNode
()
{
return
nodeDate
;
}
public
void
setNode
(
ActiveNode
node
)
{
this
.
nodeDate
=
node
;
}
}
app/src/main/java/com/cesanelli/lajusta/io/models/General.java
0 → 100644
View file @
8bb419a0
package
com.cesanelli.lajusta.io.models
;
import
java.util.ArrayList
;
public
class
General
{
private
ArrayList
<
ActiveNode
>
activeNodes
;
public
General
(){
}
public
ArrayList
<
ActiveNode
>
getActiveNodes
()
{
return
activeNodes
;
}
public
void
setActiveNodes
(
ArrayList
<
ActiveNode
>
activeNodes
)
{
this
.
activeNodes
=
activeNodes
;
}
}
app/src/main/java/com/cesanelli/lajusta/io/models/News.java
0 → 100644
View file @
8bb419a0
package
com.cesanelli.lajusta.io.models
;
import
java.util.ArrayList
;
public
class
News
{
private
ArrayList
<
NewsItem
>
page
;
private
Integer
totalElements
;
public
News
(){
}
public
ArrayList
<
NewsItem
>
getPage
()
{
return
page
;
}
public
void
setPage
(
ArrayList
<
NewsItem
>
page
)
{
this
.
page
=
page
;
}
public
Integer
getTotalElements
()
{
return
totalElements
;
}
public
void
setTotalElements
(
Integer
totalElements
)
{
this
.
totalElements
=
totalElements
;
}
}
app/src/main/java/com/cesanelli/lajusta/io/models/NewsItem.java
0 → 100644
View file @
8bb419a0
package
com.cesanelli.lajusta.io.models
;
public
class
NewsItem
{
private
String
title
;
private
String
subtitle
;
private
String
text
;
private
Image
image
;
public
NewsItem
()
{
}
public
NewsItem
(
String
title
,
String
subtitle
,
String
text
,
Image
image
)
{
this
.
title
=
title
;
this
.
subtitle
=
subtitle
;
this
.
text
=
text
;
this
.
image
=
image
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getSubtitle
()
{
return
subtitle
;
}
public
void
setSubtitle
(
String
subtitle
)
{
this
.
subtitle
=
subtitle
;
}
public
String
getText
()
{
return
text
;
}
public
void
setText
(
String
text
)
{
this
.
text
=
text
;
}
public
Image
getImage
()
{
return
image
;
}
public
void
setImage
(
Image
image
)
{
this
.
image
=
image
;
}
}
app/src/main/java/com/cesanelli/lajusta/io/models/Node.java
0 → 100644
View file @
8bb419a0
package
com.cesanelli.lajusta.io.models
;
import
java.util.ArrayList
;
public
class
Node
{
private
Integer
id
;
private
String
name
;
private
String
description
;
private
Address
address
;
private
String
phone
;
public
Node
(){
}
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
Address
getAddress
()
{
return
address
;
}
public
void
setAddress
(
Address
address
)
{
this
.
address
=
address
;
}
public
String
getPhone
()
{
return
phone
;
}
public
void
setPhone
(
String
phone
)
{
this
.
phone
=
phone
;
}
}
app/src/main/java/com/cesanelli/lajusta/io/models/Producer.java
View file @
8bb419a0
...
...
@@ -9,13 +9,6 @@ public class Producer {
private
String
description
;
private
Image
[]
images
;
private
String
phone
;
private
String
youtubeVideoId
;
private
String
deletedAt
;
private
Product
[]
products
;
private
Product
[]
productCataloge
;
private
String
[]
tags
;
private
Address
address
;
private
boolean
isCompany
;
public
int
getId
()
{
return
id
;
...
...
@@ -81,60 +74,5 @@ public class Producer {
this
.
phone
=
phone
;
}
public
String
getYoutubeVideoId
()
{
return
youtubeVideoId
;
}
public
void
setYoutubeVideoId
(
String
youtubeVideoId
)
{
this
.
youtubeVideoId
=
youtubeVideoId
;
}
public
String
getDeletedAt
()
{
return
deletedAt
;
}
public
void
setDeletedAt
(
String
deletedAt
)
{
this
.
deletedAt
=
deletedAt
;
}
public
Product
[]
getProducts
()
{
return
products
;
}
public
void
setProducts
(
Product
[]
products
)
{
this
.
products
=
products
;
}
public
Product
[]
getProductCataloge
()
{
return
productCataloge
;
}
public
void
setProductCataloge
(
Product
[]
productCataloge
)
{
this
.
productCataloge
=
productCataloge
;
}
public
String
[]
getTags
()
{
return
tags
;
}
public
void
setTags
(
String
[]
tags
)
{
this
.
tags
=
tags
;
}
public
Address
getAddress
()
{
return
address
;
}
public
void
setAddress
(
Address
address
)
{
this
.
address
=
address
;
}
public
boolean
isCompany
()
{
return
isCompany
;
}
public
void
setCompany
(
boolean
company
)
{
isCompany
=
company
;
}
}
app/src/main/java/com/cesanelli/lajusta/io/models/Product.java
View file @
8bb419a0
...
...
@@ -16,7 +16,6 @@ public class Product {
private
boolean
isPromotion
;
private
Category
[]
categories
;
private
Image
[]
images
;
private
Producer
producer
;
private
Unit
unit
;
private
int
unitQuantity
;
...
...
@@ -84,14 +83,6 @@ public class Product {
this
.
images
=
images
;
}
public
Producer
getProducer
()
{
return
producer
;
}
public
void
setProducer
(
Producer
producer
)
{
this
.
producer
=
producer
;
}
public
Unit
getUnit
()
{
return
unit
;
}
...
...
@@ -110,7 +101,7 @@ public class Product {
@BindingAdapter
(
"android:productImage"
)
public
static
void
loadImage
(
ImageView
imageView
,
Image
[]
images
){
if
(
images
.
length
>
0
)
{
if
(
images
.
length
>
0
&&
images
[
0
].
getValue
()
!=
null
)
{
String
cleanImage
=
images
[
0
].
getValue
().
replace
(
"data:image/png;base64,"
,
""
).
replace
(
"data:image/jpeg;base64,"
,
""
);
byte
[]
decodedString
=
Base64
.
decode
(
cleanImage
,
Base64
.
DEFAULT
);
Bitmap
decodedByte
=
BitmapFactory
.
decodeByteArray
(
decodedString
,
0
,
decodedString
.
length
);
...
...
app/src/main/java/com/cesanelli/lajusta/ui/CartFragment.java
View file @
8bb419a0
package
com.cesanelli.lajusta.ui
;
import
android.os.Bundle
;
import
android.preference.PreferenceManager
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
...
...
@@ -17,9 +18,16 @@ import androidx.recyclerview.widget.RecyclerView;
import
com.cesanelli.lajusta.R
;
import
com.cesanelli.lajusta.databinding.FragmentCartListBinding
;
import
com.cesanelli.lajusta.io.ApiAdapter
;
import
com.cesanelli.lajusta.io.models.Cart
;
import
com.cesanelli.lajusta.io.models.CartItem
;
import
com.cesanelli.lajusta.io.models.User
;
import
com.cesanelli.lajusta.ui.viewmodel.CartViewModel
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
public
class
CartFragment
extends
Fragment
implements
CartRecyclerViewAdapter
.
OnCartListener
{
private
FragmentCartListBinding
fragmentCartListBinding
;
private
CartViewModel
cartViewModel
;
...
...
app/src/main/java/com/cesanelli/lajusta/ui/CartRecyclerViewAdapter.java
View file @
8bb419a0
...
...
@@ -30,14 +30,14 @@ public class CartRecyclerViewAdapter extends RecyclerView.Adapter<CartRecyclerVi
@Override
public
void
onBindViewHolder
(
final
ViewHolder
holder
,
int
position
)
{
CartItem
cartItem
=
cart
.
get
Item
s
().
get
(
position
);
CartItem
cartItem
=
cart
.
get
CartProduct
s
().
get
(
position
);
holder
.
fragmentCartBinding
.
setCartItem
(
cartItem
);
holder
.
fragmentCartBinding
.
setOnCartListener
(
onCartListener
);;
}
@Override
public
int
getItemCount
()
{
return
cart
.
get
Item
s
().
size
();
return
cart
.
get
CartProduct
s
().
size
();
}
public
interface
OnCartListener
{
...
...
app/src/main/java/com/cesanelli/lajusta/ui/NewsFragment.java
View file @
8bb419a0
package
com.cesanelli.lajusta.ui
;
import
android.content.Context
;
import
android.os.Bundle
;
import
androidx.fragment.app.Fragment
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.fragment.app.Fragment
;
import
androidx.lifecycle.ViewModelProvider
;
import
androidx.navigation.Navigation
;
import
androidx.recyclerview.widget.LinearLayoutManager
;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.cesanelli.lajusta.R
;
import
com.cesanelli.lajusta.io.ApiAdapter
;
import
com.cesanelli.lajusta.io.models.Image
;
import
com.cesanelli.lajusta.io.models.News
;
import
com.cesanelli.lajusta.io.models.NewsItem
;
import
com.cesanelli.lajusta.io.models.Producer
;
import
com.cesanelli.lajusta.ui.viewmodel.NewsListViewModel
;
import
com.cesanelli.lajusta.ui.viewmodel.ProducerListViewModel
;
import
com.cesanelli.lajusta.ui.viewmodel.ProducerViewModel
;
import
java.util.ArrayList
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
/**
* A simple {@link Fragment} subclass.
* Use the {@link NewsFragment#newInstance} factory method to
* create an instance of this fragment.
* A fragment representing a list of Items.
*/
public
class
NewsFragment
extends
Fragment
{
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private
static
final
String
ARG_PARAM1
=
"param1"
;
private
static
final
String
ARG_PARAM2
=
"param2"
;
// TODO: Rename and change types of parameters
private
String
mParam1
;
private
String
mParam2
;
private
NewsListViewModel
newsListViewModel
;
public
NewsFragment
()
{
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment NewsFragment.
*/
// TODO: Rename and change types and number of parameters
public
static
NewsFragment
newInstance
(
String
param1
,
String
param2
)
{
public
static
NewsFragment
newInstance
()
{
NewsFragment
fragment
=
new
NewsFragment
();
Bundle
args
=
new
Bundle
();
args
.
putString
(
ARG_PARAM1
,
param1
);
args
.
putString
(
ARG_PARAM2
,
param2
);
fragment
.
setArguments
(
args
);
return
fragment
;
}
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
if
(
getArguments
()
!=
null
)
{
mParam1
=
getArguments
().
getString
(
ARG_PARAM1
);
mParam2
=
getArguments
().
getString
(
ARG_PARAM2
);
}
}
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
// Inflate the layout for this fragment
return
inflater
.
inflate
(
R
.
layout
.
fragment_news
,
container
,
false
);