Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
Summative_Sam_Markey
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sam.markey
Summative_Sam_Markey
Commits
f5f53ffc
Commit
f5f53ffc
authored
May 04, 2021
by
Sam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FINAL VERSION with added EditTexts in the cafe and shop recyclerview
parent
96c2a5fe
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
114 additions
and
37 deletions
+114
-37
cafe_activity.java
...java/com/example/museumworld/cafe_shop/cafe_activity.java
+26
-9
item_adapter.java
.../java/com/example/museumworld/cafe_shop/item_adapter.java
+56
-16
shop_activity.java
...java/com/example/museumworld/cafe_shop/shop_activity.java
+28
-10
checkout.java
.../main/java/com/example/museumworld/checkout/checkout.java
+2
-1
activity_cafe_viewholder.xml
app/src/main/res/layout/activity_cafe_viewholder.xml
+2
-1
No files found.
app/src/main/java/com/example/museumworld/cafe_shop/cafe_activity.java
View file @
f5f53ffc
...
@@ -81,17 +81,34 @@ public class cafe_activity extends AppCompatActivity implements View.OnClickList
...
@@ -81,17 +81,34 @@ public class cafe_activity extends AppCompatActivity implements View.OnClickList
recyclerView
.
setLayoutManager
(
layoutManager
);
recyclerView
.
setLayoutManager
(
layoutManager
);
recyclerView
.
setAdapter
(
adapter
);
recyclerView
.
setAdapter
(
adapter
);
//click listener for the buttons in the cafe and shop activites if pressed the counter will change
//click listener for the buttons in the cafe and shop activites if pressed the counter will change
adapter
.
setOnItemClickListener
((
position
,
b
)
->
{
adapter
.
setOnItemClickListener
((
position
,
buttonChecker
,
quantity_counter
)
->
{
int
quantCounter
=
Integer
.
valueOf
(
cafeItemList
.
get
(
position
).
getQuantity
());
int
quantityCounter
;
if
(
b
)
{
String
quant_CounterString
=
quantity_counter
.
getText
().
toString
();
quantCounter
+=
1
;
if
(
quant_CounterString
.
length
()
<
1
)
{
quantityCounter
=
0
;
}
else
{
}
else
{
if
(!
cafeItemList
.
get
(
position
).
getQuantity
().
equals
(
"0"
))
{
quantityCounter
=
Integer
.
valueOf
(
String
.
valueOf
(
quantity_counter
.
getText
()));
quantCounter
-=
1
;
}
}
if
(
buttonChecker
&&
!
quant_CounterString
.
equals
(
"99"
))
{
quantityCounter
++;
}
else
if
(!
buttonChecker
&&
!
quant_CounterString
.
equals
(
"0"
)
&&
!
quant_CounterString
.
equals
(
""
))
{
quantityCounter
--;
}
else
{
quantityCounter
=
0
;
quantity_counter
.
setText
(
"0"
);
}
}
cafeItemList
.
get
(
position
).
setQuantity
(
String
.
valueOf
(
quantCounter
));
cafeItemList
.
get
(
position
).
setQuantity
(
String
.
valueOf
(
quant
ity
Counter
));
adapter
.
notifyItemChanged
(
position
);
adapter
.
notifyItemChanged
(
position
);
});
adapter
.
setEdListener
((
position
,
qc
)
->
{
cafeItemList
.
get
(
position
).
setQuantity
(
qc
.
getText
().
toString
());
});
});
}
}
...
@@ -156,6 +173,7 @@ public class cafe_activity extends AppCompatActivity implements View.OnClickList
...
@@ -156,6 +173,7 @@ public class cafe_activity extends AppCompatActivity implements View.OnClickList
itemPriceCafe
=
new
ArrayList
<>();
itemPriceCafe
=
new
ArrayList
<>();
ArrayList
<
ArrayList
>
cafeItems
=
new
ArrayList
<>();
ArrayList
<
ArrayList
>
cafeItems
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
cafeItemList
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
cafeItemList
.
size
();
i
++)
{
String
cafeQuantity
=
cafeItemList
.
get
(
i
).
getQuantity
();
String
cafeQuantity
=
cafeItemList
.
get
(
i
).
getQuantity
();
String
cafeName
=
cafeItemList
.
get
(
i
).
getItem
();
String
cafeName
=
cafeItemList
.
get
(
i
).
getItem
();
...
@@ -165,7 +183,6 @@ public class cafe_activity extends AppCompatActivity implements View.OnClickList
...
@@ -165,7 +183,6 @@ public class cafe_activity extends AppCompatActivity implements View.OnClickList
itemNameCafe
.
add
(
cafeName
);
itemNameCafe
.
add
(
cafeName
);
itemPriceCafe
.
add
(
cafePrice
);
itemPriceCafe
.
add
(
cafePrice
);
}
}
}
}
if
(
itemNameCafe
.
size
()
>
0
)
{
if
(
itemNameCafe
.
size
()
>
0
)
{
...
...
app/src/main/java/com/example/museumworld/cafe_shop/item_adapter.java
View file @
f5f53ffc
package
com
.
example
.
museumworld
.
cafe_shop
;
package
com
.
example
.
museumworld
.
cafe_shop
;
import
android.text.Editable
;
import
android.text.TextWatcher
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
android.widget.EditText
;
import
android.widget.ImageButton
;
import
android.widget.ImageButton
;
import
android.widget.TextView
;
import
android.widget.TextView
;
...
@@ -17,10 +20,10 @@ public class item_adapter extends RecyclerView.Adapter<item_adapter.ViewHolder_i
...
@@ -17,10 +20,10 @@ public class item_adapter extends RecyclerView.Adapter<item_adapter.ViewHolder_i
private
ArrayList
<
items
>
itemList
;
private
ArrayList
<
items
>
itemList
;
private
OnItemClickListener
itemListener
;
private
OnItemClickListener
itemListener
;
private
OnEditTextChange
EdListener
;
public
item_adapter
(
ArrayList
<
items
>
itemList
)
{
public
item_adapter
(
ArrayList
<
items
>
itemList
)
{
this
.
itemList
=
itemList
;
this
.
itemList
=
itemList
;
}
}
public
void
setOnItemClickListener
(
OnItemClickListener
listener
)
{
public
void
setOnItemClickListener
(
OnItemClickListener
listener
)
{
...
@@ -28,11 +31,15 @@ public class item_adapter extends RecyclerView.Adapter<item_adapter.ViewHolder_i
...
@@ -28,11 +31,15 @@ public class item_adapter extends RecyclerView.Adapter<item_adapter.ViewHolder_i
}
}
public
void
setEdListener
(
OnEditTextChange
listener
)
{
EdListener
=
listener
;
}
@NonNull
@NonNull
@Override
@Override
public
ViewHolder_item
onCreateViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
)
{
public
ViewHolder_item
onCreateViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
)
{
View
v
=
LayoutInflater
.
from
(
parent
.
getContext
()).
inflate
(
R
.
layout
.
activity_cafe_viewholder
,
parent
,
false
);
View
v
=
LayoutInflater
.
from
(
parent
.
getContext
()).
inflate
(
R
.
layout
.
activity_cafe_viewholder
,
parent
,
false
);
ViewHolder_item
cvh
=
new
ViewHolder_item
(
v
,
itemListener
);
ViewHolder_item
cvh
=
new
ViewHolder_item
(
v
,
itemListener
,
EdListener
);
return
cvh
;
return
cvh
;
}
}
...
@@ -42,8 +49,10 @@ public class item_adapter extends RecyclerView.Adapter<item_adapter.ViewHolder_i
...
@@ -42,8 +49,10 @@ public class item_adapter extends RecyclerView.Adapter<item_adapter.ViewHolder_i
items
currentItem
=
itemList
.
get
(
position
);
items
currentItem
=
itemList
.
get
(
position
);
holder
.
itemText
.
setText
(
currentItem
.
getItem
());
holder
.
itemText
.
setText
(
currentItem
.
getItem
());
holder
.
priceText
.
setText
(
"£"
+
currentItem
.
getPrice
()+
".00"
);
holder
.
priceText
.
setText
(
"£"
+
currentItem
.
getPrice
()
+
".00"
);
holder
.
quantity_counter
.
setText
(
currentItem
.
getQuantity
());
holder
.
quantity_counter
.
setText
(
currentItem
.
getQuantity
());
holder
.
quantity_counter
.
setTag
(
position
);
}
}
...
@@ -53,40 +62,71 @@ public class item_adapter extends RecyclerView.Adapter<item_adapter.ViewHolder_i
...
@@ -53,40 +62,71 @@ public class item_adapter extends RecyclerView.Adapter<item_adapter.ViewHolder_i
}
}
public
interface
OnItemClickListener
{
public
interface
OnItemClickListener
{
void
onItemClick
(
int
position
,
boolean
b
);
void
onItemClick
(
int
position
,
boolean
buttonChecker
,
EditText
quantity_counter
);
}
public
interface
OnEditTextChange
{
void
onETChange
(
int
position
,
EditText
qc
);
}
}
public
static
class
ViewHolder_item
extends
RecyclerView
.
ViewHolder
{
public
static
class
ViewHolder_item
extends
RecyclerView
.
ViewHolder
{
TextView
itemText
,
priceText
,
quantity_counter
;
TextView
itemText
,
priceText
;
EditText
quantity_counter
;
ImageButton
plus_btn
,
minus_btn
;
ImageButton
plus_btn
,
minus_btn
;
public
ViewHolder_item
(
@NonNull
View
itemView
,
OnItemClickListener
listener
)
{
public
ViewHolder_item
(
@NonNull
View
itemView
,
OnItemClickListener
listener
,
OnEditTextChange
EditTextChange
)
{
super
(
itemView
);
super
(
itemView
);
itemText
=
itemView
.
findViewById
(
R
.
id
.
item_textView
);
itemText
=
itemView
.
findViewById
(
R
.
id
.
item_textView
);
priceText
=
itemView
.
findViewById
(
R
.
id
.
price_textView
);
priceText
=
itemView
.
findViewById
(
R
.
id
.
price_textView
);
quantity_counter
=
itemView
.
findViewById
(
R
.
id
.
quantity_counter
);
quantity_counter
=
itemView
.
findViewById
(
R
.
id
.
quantity_counter
);
quantity_counter
.
addTextChangedListener
(
new
TextWatcher
()
{
@Override
public
void
beforeTextChanged
(
CharSequence
charSequence
,
int
i
,
int
i1
,
int
i2
)
{
}
@Override
public
void
onTextChanged
(
CharSequence
charSequence
,
int
i
,
int
i1
,
int
i2
)
{
}
@Override
public
void
afterTextChanged
(
Editable
editable
)
{
if
(
EditTextChange
!=
null
)
{
int
position
=
getAdapterPosition
();
if
(
position
!=
RecyclerView
.
NO_POSITION
)
{
EditTextChange
.
onETChange
(
position
,
quantity_counter
);
}
}
}
});
plus_btn
=
itemView
.
findViewById
(
R
.
id
.
plus_btn
);
plus_btn
=
itemView
.
findViewById
(
R
.
id
.
plus_btn
);
minus_btn
=
itemView
.
findViewById
(
R
.
id
.
minus_btn
);
minus_btn
=
itemView
.
findViewById
(
R
.
id
.
minus_btn
);
plus_btn
.
setOnClickListener
(
view
->
{
plus_btn
.
setOnClickListener
(
view
->
{
if
(
listener
!=
null
)
{
if
(
listener
!=
null
)
{
int
position
=
getAdapterPosition
();
int
position
=
getAdapterPosition
();
if
(
position
!=
RecyclerView
.
NO_POSITION
){
if
(
position
!=
RecyclerView
.
NO_POSITION
)
{
listener
.
onItemClick
(
position
,
true
);
listener
.
onItemClick
(
position
,
true
,
quantity_counter
);
}
}
}
}
});
});
//event listener for the minus
na
d plus buttons in each views
//event listener for the minus
an
d plus buttons in each views
minus_btn
.
setOnClickListener
(
view
->
{
minus_btn
.
setOnClickListener
(
view
->
{
if
(
listener
!=
null
){
if
(
listener
!=
null
)
{
int
position
=
getAdapterPosition
();
int
position
=
getAdapterPosition
();
if
(
position
!=
RecyclerView
.
NO_POSITION
){
if
(
position
!=
RecyclerView
.
NO_POSITION
)
{
listener
.
onItemClick
(
position
,
false
);
listener
.
onItemClick
(
position
,
false
,
quantity_counter
);
}
}
}
}
...
...
app/src/main/java/com/example/museumworld/cafe_shop/shop_activity.java
View file @
f5f53ffc
...
@@ -36,6 +36,7 @@ public class shop_activity extends AppCompatActivity implements View.OnClickList
...
@@ -36,6 +36,7 @@ public class shop_activity extends AppCompatActivity implements View.OnClickList
private
ImageView
top_img
;
private
ImageView
top_img
;
private
String
topImgURL
;
private
String
topImgURL
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
...
@@ -55,6 +56,7 @@ public class shop_activity extends AppCompatActivity implements View.OnClickList
...
@@ -55,6 +56,7 @@ public class shop_activity extends AppCompatActivity implements View.OnClickList
langaugeDefault
=
"en"
;
langaugeDefault
=
"en"
;
}
}
URL
+=
langaugeDefault
;
URL
+=
langaugeDefault
;
MuseumDetails
md
=
new
MuseumDetails
();
MuseumDetails
md
=
new
MuseumDetails
();
top_img
=
findViewById
(
R
.
id
.
top_img
);
top_img
=
findViewById
(
R
.
id
.
top_img
);
topImgURL
=
getIntent
().
getStringExtra
(
"topURL"
);
topImgURL
=
getIntent
().
getStringExtra
(
"topURL"
);
...
@@ -78,17 +80,35 @@ public class shop_activity extends AppCompatActivity implements View.OnClickList
...
@@ -78,17 +80,35 @@ public class shop_activity extends AppCompatActivity implements View.OnClickList
adapter
=
new
item_adapter
(
shopItemList
);
adapter
=
new
item_adapter
(
shopItemList
);
recyclerView
.
setLayoutManager
(
layoutManager
);
recyclerView
.
setLayoutManager
(
layoutManager
);
recyclerView
.
setAdapter
(
adapter
);
recyclerView
.
setAdapter
(
adapter
);
adapter
.
setOnItemClickListener
((
position
,
b
)
->
{
adapter
.
setOnItemClickListener
((
position
,
buttonChecker
,
quantity_counter
)
->
{
int
quantCounter
=
Integer
.
valueOf
(
shopItemList
.
get
(
position
).
getQuantity
());
int
quantityCounter
;
if
(
b
)
{
String
quant_CounterString
=
quantity_counter
.
getText
().
toString
();
quantCounter
+=
1
;
if
(
quant_CounterString
.
length
()
<
1
)
{
quantityCounter
=
0
;
}
else
{
}
else
{
if
(!
shopItemList
.
get
(
position
).
getQuantity
().
equals
(
"0"
))
{
quantityCounter
=
Integer
.
valueOf
(
String
.
valueOf
(
quantity_counter
.
getText
()));
quantCounter
-=
1
;
}
}
if
(
buttonChecker
&&
!
quant_CounterString
.
equals
(
"99"
))
{
quantityCounter
++;
}
else
if
(!
buttonChecker
&&
!
quant_CounterString
.
equals
(
"0"
)
&&
!
quant_CounterString
.
equals
(
""
))
{
quantityCounter
--;
}
else
{
quantityCounter
=
0
;
quantity_counter
.
setText
(
"0"
);
}
}
shopItemList
.
get
(
position
).
setQuantity
(
String
.
valueOf
(
quantCounter
));
shopItemList
.
get
(
position
).
setQuantity
(
String
.
valueOf
(
quant
ity
Counter
));
adapter
.
notifyItemChanged
(
position
);
adapter
.
notifyItemChanged
(
position
);
});
adapter
.
setEdListener
((
position
,
qc
)
->
{
shopItemList
.
get
(
position
).
setQuantity
(
qc
.
getText
().
toString
());
});
});
...
@@ -108,8 +128,6 @@ public class shop_activity extends AppCompatActivity implements View.OnClickList
...
@@ -108,8 +128,6 @@ public class shop_activity extends AppCompatActivity implements View.OnClickList
}
}
}
}
RecyclerViewInit
();
//initialising the recycler view with the data
//initialising the recycler view with the data
RecyclerViewInit
();
RecyclerViewInit
();
}
catch
(
JSONException
e
)
{
}
catch
(
JSONException
e
)
{
...
...
app/src/main/java/com/example/museumworld/checkout/checkout.java
View file @
f5f53ffc
...
@@ -105,7 +105,7 @@ public class checkout extends AppCompatActivity implements View.OnClickListener
...
@@ -105,7 +105,7 @@ public class checkout extends AppCompatActivity implements View.OnClickListener
allItems
.
addAll
(
ItemNames
);
allItems
.
addAll
(
ItemNames
);
allQuantities
.
addAll
(
ItemQuantity
);
allQuantities
.
addAll
(
ItemQuantity
);
allPrices
.
addAll
(
ItemPrices
);
Log
.
d
(
"ItemNames"
,
ItemNames
.
toString
());
Log
.
d
(
"ItemNames"
,
ItemNames
.
toString
());
Log
.
d
(
"allItemsT"
,
allItems
.
toString
());
Log
.
d
(
"allItemsT"
,
allItems
.
toString
());
...
@@ -144,6 +144,7 @@ public class checkout extends AppCompatActivity implements View.OnClickListener
...
@@ -144,6 +144,7 @@ public class checkout extends AppCompatActivity implements View.OnClickListener
ShopitemsPrice_CV_text
.
setText
(
ShopitemsPrice_CV_text
.
getText
()
+
"\n"
+
"£"
+
totalOfItem
+
".00"
);
ShopitemsPrice_CV_text
.
setText
(
ShopitemsPrice_CV_text
.
getText
()
+
"\n"
+
"£"
+
totalOfItem
+
".00"
);
totalShop
+=
totalOfItem
;
totalShop
+=
totalOfItem
;
}
}
allPrices
.
add
(
String
.
valueOf
(
totalOfItem
));
TotalnumberOfItems
+=
currentQuantity
;
TotalnumberOfItems
+=
currentQuantity
;
totalOfCheckout
+=
totalOfItem
;
totalOfCheckout
+=
totalOfItem
;
}
}
...
...
app/src/main/res/layout/activity_cafe_viewholder.xml
View file @
f5f53ffc
...
@@ -85,12 +85,13 @@
...
@@ -85,12 +85,13 @@
>
>
<
TextView
<
EditText
android:id=
"@+id/quantity_counter"
android:id=
"@+id/quantity_counter"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:fontFamily=
"@font/roboto"
android:fontFamily=
"@font/roboto"
android:text=
"0"
android:text=
"0"
android:inputType=
"number"
android:padding=
"5dp"
android:padding=
"5dp"
android:maxLength=
"2"
android:maxLength=
"2"
android:textAlignment=
"center"
android:textAlignment=
"center"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment