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
hds
flexin
android-app
Commits
ef8bdadc
Commit
ef8bdadc
authored
Oct 29, 2017
by
Nastuzzi Samy
Browse files
Merge branch 'release/0.3.1'
parents
d625bbe4
7db0cc34
Changes
10
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/fr/utc/simde/payutc/ArticleCategoryActivity.java
View file @
ef8bdadc
...
...
@@ -3,7 +3,10 @@ package fr.utc.simde.payutc;
import
android.content.DialogInterface
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.ImageButton
;
import
android.widget.TabHost
;
import
android.widget.TextView
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
...
...
@@ -12,7 +15,7 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.List
;
import
fr.utc.simde.payutc.
fragment
s.ArticleGroupFragment
;
import
fr.utc.simde.payutc.
article
s.ArticleGroupFragment
;
/**
* Created by Samy on 27/10/2017.
...
...
@@ -21,18 +24,64 @@ import fr.utc.simde.payutc.fragments.ArticleGroupFragment;
public
class
ArticleCategoryActivity
extends
BaseActivity
{
private
static
final
String
LOG_TAG
=
"_ArticleCategoryActivit"
;
private
TabHost
categoryTabList
;
private
ImageButton
paramButton
;
private
ImageButton
deleteButton
;
private
TabHost
tabHost
;
private
Panier
panier
;
private
List
<
ArticleGroupFragment
>
articleGroupFragmentList
;
private
int
nbrCategories
;
public
class
Panier
{
private
int
totalPrice
;
private
List
<
Integer
>
articleList
=
new
ArrayList
<
Integer
>();
private
TextView
textView
;
public
Panier
(
TextView
textView
)
{
this
.
totalPrice
=
0
;
this
.
textView
=
textView
;
setText
();
}
public
void
setText
()
{
if
(
this
.
totalPrice
==
0
)
this
.
textView
.
setText
(
"Panier vide"
);
else
this
.
textView
.
setText
(
"Total: "
+
String
.
format
(
"%.2f"
,
new
Float
(
totalPrice
)
/
100.00f
)
+
"€"
);
}
public
void
addArticle
(
final
int
id
,
final
int
price
)
{
this
.
articleList
.
add
(
id
);
this
.
totalPrice
+=
price
;
setText
();
}
public
void
clear
()
{
this
.
articleList
.
clear
();
this
.
totalPrice
=
0
;
setText
();
}
}
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_article
s
_category
);
setContentView
(
R
.
layout
.
activity_article_category
);
this
.
nbrCategories
=
0
;
TextView
textView
=
findViewById
(
R
.
id
.
text_price
);
this
.
panier
=
new
Panier
(
textView
);
this
.
paramButton
=
findViewById
(
R
.
id
.
image_param
);
this
.
deleteButton
=
findViewById
(
R
.
id
.
image_delete
);
this
.
tabHost
=
findViewById
(
R
.
id
.
tab_categories
);
this
.
tabHost
.
setup
();
this
.
categoryTabList
=
findViewById
(
R
.
id
.
tab_categories
);
this
.
c
ategor
yTabList
.
setup
()
;
this
.
articleGroupFragmentList
=
new
ArrayList
<
ArticleGroupFragment
>(
);
this
.
nbrC
ategor
ies
=
0
;
try
{
createCategories
(
new
ObjectMapper
().
readTree
(
getIntent
().
getExtras
().
getString
(
"categoryList"
)),
new
ObjectMapper
().
readTree
(
getIntent
().
getExtras
().
getString
(
"articleList"
)));
...
...
@@ -54,6 +103,16 @@ public class ArticleCategoryActivity extends BaseActivity {
}
});
}
this
.
deleteButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
for
(
ArticleGroupFragment
articleGroupFragment
:
articleGroupFragmentList
)
articleGroupFragment
.
clear
();
panier
.
clear
();
}
});
}
@Override
...
...
@@ -89,11 +148,15 @@ public class ArticleCategoryActivity extends BaseActivity {
}
protected
void
createNewCategory
(
final
String
name
,
final
JsonNode
articleList
)
throws
Exception
{
TabHost
.
TabSpec
newTabSpec
=
this
.
categoryTabList
.
newTabSpec
(
name
);
ArticleGroupFragment
articleGroupFragment
=
new
ArticleGroupFragment
(
ArticleCategoryActivity
.
this
,
articleList
,
this
.
panier
);
TabHost
.
TabSpec
newTabSpec
=
this
.
tabHost
.
newTabSpec
(
name
);
newTabSpec
.
setIndicator
(
name
);
newTabSpec
.
setContent
(
new
ArticleGroupFragment
(
ArticleCategoryActivity
.
this
,
articleList
));
newTabSpec
.
setContent
(
articleGroupFragment
);
this
.
articleGroupFragmentList
.
add
(
articleGroupFragment
);
this
.
categoryTabLi
st
.
addTab
(
newTabSpec
);
this
.
tabHo
st
.
addTab
(
newTabSpec
);
nbrCategories
++;
}
}
app/src/main/java/fr/utc/simde/payutc/
fragment
s/Article
Fragment
.java
→
app/src/main/java/fr/utc/simde/payutc/
article
s/Article
Adapter
.java
View file @
ef8bdadc
package
fr.utc.simde.payutc.
fragment
s
;
package
fr.utc.simde.payutc.
article
s
;
import
android.annotation.SuppressLint
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.os.AsyncTask
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.BaseAdapter
;
import
android.widget.ImageView
;
import
android.widget.
Linear
Layout
;
import
android.widget.
Relative
Layout
;
import
android.widget.TextView
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
fr.utc.simde.payutc.R
;
import
fr.utc.simde.payutc.tools.HTTPRequest
;
import
static
android
.
content
.
ContentValues
.
TAG
;
/**
* Created by Samy on 28/10/2017.
*/
public
class
ArticleFragment
extends
View
{
private
static
final
String
LOG_TAG
=
"_ArticleFragment"
;
public
class
ArticleAdapter
extends
BaseAdapter
{
private
static
final
String
LOG_TAG
=
"_ArticleAdapter"
;
private
Activity
activity
;
private
JsonNode
articleList
;
private
Bitmap
[]
imageList
;
private
Integer
[]
nbrClicksList
;
private
TextView
[]
clickViewList
;
private
int
size
;
public
ArticleAdapter
(
final
Activity
activity
,
final
JsonNode
articleList
,
final
int
nbrColumns
)
throws
Exception
{
this
.
activity
=
activity
;
this
.
articleList
=
articleList
;
this
.
imageList
=
new
Bitmap
[
articleList
.
size
()];
this
.
nbrClicksList
=
new
Integer
[
articleList
.
size
()];
this
.
clickViewList
=
new
TextView
[
articleList
.
size
()];
switch
(
nbrColumns
)
{
case
1
:
this
.
size
=
250
;
break
;
case
2
:
this
.
size
=
200
;
break
;
case
3
:
this
.
size
=
150
;
break
;
case
4
:
this
.
size
=
125
;
break
;
case
5
:
default
:
this
.
size
=
100
;
break
;
}
for
(
int
i
=
0
;
i
<
this
.
nbrClicksList
.
length
;
i
++)
this
.
nbrClicksList
[
i
]
=
0
;
}
private
int
id
;
p
rivate
int
price
;
private
String
name
;
private
String
imageUrl
;
@Overr
id
e
p
ublic
int
getCount
()
{
return
this
.
articleList
.
size
()
;
}
private
LayoutInflater
layoutInflater
;
private
View
view
;
private
TextView
textView
;
@Override
public
Object
getItem
(
int
position
)
{
return
getArticle
(
position
);
}
private
ImageView
iv
;
private
HTTPRequest
request
;
@Override
public
long
getItemId
(
int
position
)
{
return
0
;
}
private
LinearLayout
linearLayout
;
@Override
public
View
getView
(
int
position
,
View
view
,
ViewGroup
viewGroup
)
{
JsonNode
article
=
this
.
articleList
.
get
(
position
);
public
ArticleFragment
(
final
Activity
activity
,
final
JsonNode
article
)
{
super
(
activity
);
/*
this.layoutInflater = LayoutInflater.from(activity);
this.view = this.layoutInflater.inflate(R.layout.fragment_article, null);
this.textView = view.findViewById(R.id.text_article);
this.textView.setText(article.get("name").textValue());*/
if
(
view
==
null
)
{
LayoutInflater
layoutInflater
=
LayoutInflater
.
from
(
this
.
activity
);
view
=
layoutInflater
.
inflate
(
R
.
layout
.
fragment_article
,
null
);
}
this
.
id
=
article
.
get
(
"id"
).
intValue
();
this
.
price
=
article
.
get
(
"price"
).
intValue
();
this
.
name
=
article
.
get
(
"name"
).
textValue
();
this
.
imageUrl
=
article
.
get
(
"image_url"
).
textValue
();
ImageView
imageView
=
view
.
findViewById
(
R
.
id
.
image_article
);
setView
(
activity
);
if
(
clickViewList
[
position
]
==
null
)
clickViewList
[
position
]
=
view
.
findViewById
(
R
.
id
.
text_nbr_clicks
);
TextView
textView
=
view
.
findViewById
(
R
.
id
.
text_article
);
int
imageSize
=
this
.
size
;
RelativeLayout
.
LayoutParams
parms
=
new
RelativeLayout
.
LayoutParams
(
imageSize
,
imageSize
);
imageView
.
setLayoutParams
(
parms
);
setImage
(
imageView
,
article
.
get
(
"image_url"
).
textValue
(),
position
);
setClickView
(
position
);
textView
.
setText
(
article
.
get
(
"name"
).
textValue
());
return
view
;
}
public
void
setView
(
final
Activity
activity
)
{
TextView
t
=
new
TextView
(
activity
);
iv
=
new
ImageView
(
activity
);
iv
.
setTag
(
"image_article_"
+
Integer
.
toString
(
this
.
id
));
iv
.
setImageResource
(
R
.
mipmap
.
ic_launcher
);
LinearLayout
.
LayoutParams
parms
=
new
LinearLayout
.
LayoutParams
(
200
,
200
);
iv
.
setLayoutParams
(
parms
);
t
.
setText
(
this
.
name
+
": "
);
TextView
t2
=
new
TextView
(
activity
);
t2
.
setText
((
this
.
price
/
100
)
+
"€"
+
((
this
.
price
%
100
)
==
0
?
""
:
(((
this
.
price
%
100
)
<
10
?
"0"
:
""
)
+
(
this
.
price
%
100
))));
this
.
linearLayout
=
new
LinearLayout
(
activity
);
linearLayout
.
addView
(
iv
);
linearLayout
.
addView
(
t
);
linearLayout
.
addView
(
t2
);
if
(
this
.
imageUrl
!=
null
&&
!
this
.
imageUrl
.
equals
(
""
))
{
new
Thread
(){
public
void
setClickView
(
final
int
position
)
{
if
(
this
.
clickViewList
[
position
]
!=
null
)
{
if
(
this
.
nbrClicksList
[
position
]
==
0
)
{
this
.
clickViewList
[
position
].
setText
(
""
);
this
.
clickViewList
[
position
].
setAlpha
(
0.0f
);
}
else
{
this
.
clickViewList
[
position
].
setText
(
Integer
.
toString
(
this
.
nbrClicksList
[
position
]));
this
.
clickViewList
[
position
].
setAlpha
(
1.0f
);
}
}
}
public
void
onClick
(
final
int
position
)
{
this
.
nbrClicksList
[
position
]++;
setClickView
(
position
);
}
public
void
clear
()
{
for
(
int
i
=
0
;
i
<
getCount
();
i
++)
{
this
.
nbrClicksList
[
i
]
=
0
;
setClickView
(
i
);
}
}
public
JsonNode
getArticle
(
final
int
position
)
{
return
this
.
articleList
.
get
(
position
);
}
public
void
setImage
(
final
ImageView
imageView
,
final
String
url
,
final
int
position
)
{
final
HTTPRequest
[]
request
=
new
HTTPRequest
[
1
];
if
(
imageList
[
position
]
!=
null
)
imageView
.
setImageBitmap
(
imageList
[
position
]);
else
if
(
url
!=
null
&&
!
url
.
equals
(
""
))
{
/*
new Thread(){
@Override
public void run() {
request
=
new
HTTPRequest
(
imageU
rl
);
request
[0]
= new HTTPRequest(
u
rl);
if
(
request
.
get
()
==
200
)
{
if (request
[0]
.get() == 200) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
iv
.
setImageBitmap
(
request
.
getImageResponse
());
imageList[position] = request[0].getImageResponse();
imageView.setImageBitmap(imageList[position]);
} catch (Exception e) {
e.printStackTrace();
}
...
...
@@ -102,16 +164,18 @@ public class ArticleFragment extends View {
});
}
}
}.
start
();
//
new DownloadImageTask(i
v).execute(this.imageU
rl);
}.start();
*/
new
DownloadImageTask
(
i
mageView
,
imageList
[
position
]).
execute
(
u
rl
);
}
}
public
class
DownloadImageTask
extends
AsyncTask
<
String
,
Void
,
Bitmap
>
{
private
ImageView
imageView
;
private
Bitmap
image
;
public
DownloadImageTask
(
ImageView
imageView
)
{
public
DownloadImageTask
(
ImageView
imageView
,
Bitmap
image
)
{
this
.
imageView
=
imageView
;
this
.
image
=
image
;
}
protected
Bitmap
doInBackground
(
String
...
urls
)
{
...
...
@@ -136,8 +200,4 @@ public class ArticleFragment extends View {
}
}
}
public
View
getView
()
{
return
this
.
linearLayout
;
}
}
app/src/main/java/fr/utc/simde/payutc/
fragment
s/ArticleGroupFragment.java
→
app/src/main/java/fr/utc/simde/payutc/
article
s/ArticleGroupFragment.java
View file @
ef8bdadc
package
fr.utc.simde.payutc.
fragment
s
;
package
fr.utc.simde.payutc.
article
s
;
import
android.app.Activity
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.widget.GridLayout
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.ScrollView
;
import
android.widget.AdapterView
;
import
android.widget.GridView
;
import
android.widget.TabHost
;
import
android.widget.T
extView
;
import
android.widget.T
oast
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
fr.utc.simde.payutc.ArticleCategoryActivity
;
import
fr.utc.simde.payutc.R
;
/**
...
...
@@ -24,32 +23,56 @@ public class ArticleGroupFragment implements TabHost.TabContentFactory {
private
LayoutInflater
layoutInflater
;
private
View
view
;
private
ScrollView
scroll
View
;
private
GridLayout
gridView
;
private
GridView
grid
View
;
private
ArticleAdapter
articleAdapter
;
public
ArticleGroupFragment
(
final
Activity
activity
,
final
JsonNode
articleList
)
throws
Exception
{
private
int
nbrColumns
;
private
ArticleCategoryActivity
.
Panier
panier
;
public
ArticleGroupFragment
(
final
Activity
activity
,
final
JsonNode
articleList
,
ArticleCategoryActivity
.
Panier
panier
)
throws
Exception
{
this
.
layoutInflater
=
LayoutInflater
.
from
(
activity
);
this
.
view
=
this
.
layoutInflater
.
inflate
(
R
.
layout
.
fragment_article_group
,
null
);
this
.
gridView
=
this
.
view
.
findViewById
(
R
.
id
.
grid_articles
);
this
.
panier
=
panier
;
setGridLayout
(
3
);
createArticles
(
activity
,
articleList
);
gridView
.
setAdapter
(
this
.
articleAdapter
);
}
public
void
setGridLayout
(
final
int
nbrColumns
)
{
this
.
nbrColumns
=
nbrColumns
;
gridView
.
setNumColumns
(
nbrColumns
);
}
public
void
createArticles
(
final
Activity
activity
,
final
JsonNode
articleList
)
throws
Exception
{
LinearLayout
linearLayout
=
new
LinearLayout
(
activity
);
linearLayout
.
setOrientation
(
LinearLayout
.
VERTICAL
);
this
.
articleAdapter
=
new
ArticleAdapter
(
activity
,
articleList
,
this
.
nbrColumns
);
for
(
JsonNode
article
:
articleList
)
{
if
(!
article
.
has
(
"id"
)
||
!
article
.
has
(
"price"
)
||
!
article
.
has
(
"name"
)
||
!
article
.
has
(
"active"
)
||
!
article
.
has
(
"cotisant"
)
||
!
article
.
has
(
"alcool"
)
||
!
article
.
has
(
"categorie_id"
)
||
!
article
.
has
(
"image_url"
)
||
!
article
.
has
(
"fundation_id"
))
throw
new
Exception
(
"Unexpected JSON"
);
gridView
.
setOnItemClickListener
(
new
AdapterView
.
OnItemClickListener
()
{
@Override
public
void
onItemClick
(
AdapterView
parent
,
View
view
,
int
position
,
long
id
)
{
JsonNode
article
=
((
JsonNode
)
articleAdapter
.
getArticle
(
position
));
articleAdapter
.
onClick
(
position
);
panier
.
addArticle
(
article
.
get
(
"id"
).
intValue
(),
article
.
get
(
"price"
).
intValue
());
}
});
if
(!
article
.
get
(
"active"
).
booleanValue
())
continue
;
gridView
.
setOnItemLongClickListener
(
new
AdapterView
.
OnItemLongClickListener
()
{
@Override
public
boolean
onItemLongClick
(
AdapterView
<?>
adapterView
,
View
view
,
int
position
,
long
id
)
{
JsonNode
article
=
((
JsonNode
)
articleAdapter
.
getArticle
(
position
));
Toast
.
makeText
(
activity
,
article
.
get
(
"name"
).
textValue
()
+
": "
+
String
.
format
(
"%.2f"
,
new
Float
(
article
.
get
(
"price"
).
intValue
())
/
100.00f
)
+
"€"
,
Toast
.
LENGTH_LONG
).
show
();
linearLayout
.
addView
(
new
ArticleFragment
(
activity
,
article
).
getView
());
}
return
false
;
}
});
}
this
.
gridView
.
addView
(
linearLayout
);
public
void
clear
()
{
articleAdapter
.
clear
();
}
@Override
...
...
app/src/main/res/drawable/article_click_background.xml
0 → 100644
View file @
ef8bdadc
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"rectangle"
>
<solid
android:color=
"@color/add"
/>
<stroke
android:width=
"2dp"
android:color=
"@color/white"
/>
<corners
android:radius=
"2dp"
/>
</shape>
\ No newline at end of file
app/src/main/res/layout/activity_article
s
_category.xml
→
app/src/main/res/layout/activity_article_category.xml
View file @
ef8bdadc
<?xml version="1.0" encoding="utf-8"?>
<
Linear
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<
Relative
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:orientation=
"vertical"
android:layout_width=
"match_parent"
...
...
@@ -8,7 +8,8 @@
<TabHost
android:id=
"@+id/tab_categories"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
android:layout_height=
"match_parent"
android:layout_marginBottom=
"50dp"
>
<LinearLayout
android:layout_width=
"match_parent"
...
...
@@ -19,21 +20,55 @@
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:fillViewport=
"true"
android:scrollbars=
"none"
>
android:scrollbars=
"none"
>
<TabWidget
android:id=
"@android:id/tabs"
android:layout_width=
"wrap_content"
android:layout_height=
"match_parent"
>
</TabWidget>
android:layout_height=
"match_parent"
></TabWidget>
</HorizontalScrollView>
<FrameLayout
android:id=
"@android:id/tabcontent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
</FrameLayout>
android:layout_height=
"match_parent"
></FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"50dp"
android:layout_alignParentBottom=
"true"
android:orientation=
"horizontal"
>
<ImageButton
android:id=
"@+id/image_param"
android:layout_weight=
"1.0"
android:layout_width=
"100dp"
android:layout_height=
"match_parent"
android:src=
"@android:drawable/ic_menu_manage"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_weight=
"8.0"
android:gravity=
"center"
android:orientation=
"horizontal"
>
<TextView
android:id=
"@+id/text_price"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:gravity=
"center"
android:textSize=
"20dp"
/>
</LinearLayout>
<ImageButton
android:id=
"@+id/image_delete"
android:layout_weight=
"1.0"
android:layout_width=
"100dp"
android:layout_height=
"match_parent"
android:src=
"@android:drawable/ic_menu_delete"
/>
</LinearLayout>
</RelativeLayout>
app/src/main/res/layout/activity_main.xml
View file @
ef8bdadc
...
...
@@ -19,7 +19,8 @@
android:layout_width=
"100dp"
android:layout_height=
"100dp"
android:layout_marginBottom=
"25dp"
android:src=
"@mipmap/ic_launcher_round"
/>
android:src=
"@mipmap/ic_launcher_round"
android:contentDescription=
"@string/app_name"
/>
<TextView
android:id=
"@+id/text_app_config"
...
...
app/src/main/res/layout/fragment_article.xml
View file @
ef8bdadc
<?xml version="1.0" encoding="utf-8"?>
<
Linear
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<
Grid
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
android:gravity=
"center_horizontal"
android:layout_rowWeight=
"1"
android:orientation=
"vertical"
android:layout_marginTop=
"15dp"