Skip to content
GitLab
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
1ed54ce9
Commit
1ed54ce9
authored
Nov 07, 2017
by
Nastuzzi Samy
Browse files
Options optimization
Bug fix Handle option clicks
parent
efcf3bb3
Changes
10
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/fr/utc/simde/payutc/BaseActivity.java
View file @
1ed54ce9
...
...
@@ -360,7 +360,7 @@ public abstract class BaseActivity extends NFCActivity {
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
try
{
if
(
nemopaySession
.
getRequest
().
getResponseCode
()
==
40
4
)
if
(
nemopaySession
.
getRequest
().
getResponseCode
()
==
40
0
)
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
...
...
app/src/main/java/fr/utc/simde/payutc/FoundationsOptionsActivity.java
View file @
1ed54ce9
...
...
@@ -32,6 +32,8 @@ public class FoundationsOptionsActivity extends BaseActivity {
ListView
foundationList
;
ListView
optionList
;
String
[]
rightsNeeded
;
FoundationsAdapter
foundationsAdapter
;
@Override
...
...
@@ -43,12 +45,15 @@ public class FoundationsOptionsActivity extends BaseActivity {
this
.
foundationList
=
findViewById
(
R
.
id
.
list_foundations
);
this
.
optionList
=
findViewById
(
R
.
id
.
list_options
);
this
.
rightsNeeded
=
getResources
().
getStringArray
(
R
.
array
.
options_rights
);
this
.
tabHost
.
setup
();
this
.
tabHost
.
addTab
(
this
.
tabHost
.
newTabSpec
(
getString
(
R
.
string
.
foundations
)).
setIndicator
(
getString
(
R
.
string
.
foundations
)).
setContent
(
R
.
id
.
list_foundations
));
this
.
tabHost
.
addTab
(
this
.
tabHost
.
newTabSpec
(
getString
(
R
.
string
.
options
)).
setIndicator
(
getString
(
R
.
string
.
options
)).
setContent
(
R
.
id
.
list_options
));
try
{
setFoundationList
((
ArrayNode
)
new
ObjectMapper
().
readTree
(
getIntent
().
getExtras
().
getString
(
"foundationList"
)));
setOptionList
();
}
catch
(
Exception
e
)
{
Log
.
wtf
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
dialog
.
errorDialog
(
this
,
getResources
().
getString
(
R
.
string
.
information_collection
),
getResources
().
getString
(
R
.
string
.
error_unexpected
),
new
DialogInterface
.
OnClickListener
()
{
...
...
@@ -64,17 +69,6 @@ public class FoundationsOptionsActivity extends BaseActivity {
protected
void
onIdentification
(
final
String
badgeId
)
{}
protected
void
setFoundationList
(
final
ArrayNode
foundationList
)
throws
Exception
{
/*ArrayList<String> arrlist = new ArrayList<String>();
for (final JsonNode foundation : foundationList) {
if (!foundation.has("name") || !foundation.has("fun_id"))
throw new Exception("Unexpected JSON");
arrlist.add(foundation.get("name").textValue());
}
this.foundationList.setAdapter(new ArrayAdapter<String>(FoundationsOptionsActivity.this, R.layout.fragment_list, arrlist));
*/
this
.
foundationsAdapter
=
new
FoundationsAdapter
(
FoundationsOptionsActivity
.
this
,
foundationList
);
this
.
foundationList
.
setOnItemClickListener
(
new
AdapterView
.
OnItemClickListener
()
{
...
...
@@ -95,4 +89,18 @@ public class FoundationsOptionsActivity extends BaseActivity {
this
.
foundationList
.
setAdapter
(
this
.
foundationsAdapter
);
}
protected
void
setOptionList
()
{
this
.
optionList
.
setOnItemClickListener
(
new
AdapterView
.
OnItemClickListener
()
{
@Override
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
hasRights
(
getString
(
R
.
string
.
user_rights_list_collecting
),
rightsNeeded
[
position
].
split
(
" "
),
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
infoDialog
(
FoundationsOptionsActivity
.
this
,
getString
(
R
.
string
.
user_rights_list_collecting
),
"C'est ok !"
);
}
});
}
});
}
}
app/src/main/java/fr/utc/simde/payutc/adapters/FoundationsAdapter.java
View file @
1ed54ce9
...
...
@@ -43,16 +43,7 @@ public class FoundationsAdapter extends BaseAdapter {
}
@Override
public
View
getView
(
int
position
,
View
view
,
ViewGroup
viewGroup
)
{
/*
LinearLayout linearLayout = new LinearLayout(this.activity);
TextView textView = new TextView(this.activity);
textView.setText(getFoundationName(position));
textView.setGravity(View.TEXT_ALIGNMENT_CENTER);
linearLayout.addView(textView);
return linearLayout;*/
public
View
getView
(
int
position
,
View
view
,
ViewGroup
viewGroup
)
{
LayoutInflater
layoutInflater
=
LayoutInflater
.
from
(
this
.
activity
);
view
=
layoutInflater
.
inflate
(
R
.
layout
.
fragment_list
,
null
);
...
...
app/src/main/java/fr/utc/simde/payutc/articles/ArticlesAdapter.java
deleted
100644 → 0
View file @
efcf3bb3
package
fr.utc.simde.payutc.articles
;
import
android.annotation.SuppressLint
;
import
android.app.Activity
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.media.Image
;
import
android.os.AsyncTask
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.BaseAdapter
;
import
android.widget.GridView
;
import
android.widget.ImageView
;
import
android.widget.RelativeLayout
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
fr.utc.simde.payutc.ArticleCategoryActivity
;
import
fr.utc.simde.payutc.R
;
import
fr.utc.simde.payutc.tools.HTTPRequest
;
/**
* Created by Samy on 28/10/2017.
*/
abstract
class
ArticlesAdapter
extends
BaseAdapter
{
private
static
final
String
LOG_TAG
=
"_ArticlesAdapter"
;
protected
Activity
activity
;
protected
Boolean
printCotisant
;
protected
Boolean
print18
;
protected
Bitmap
[]
imageList
;
protected
Integer
[]
nbrClicksList
;
protected
View
[]
viewList
;
protected
TextView
[]
clickViewList
;
protected
ArrayNode
articleList
;
public
ArticlesAdapter
(
final
Activity
activity
,
final
ArrayNode
articleList
,
final
Boolean
printCotisant
,
final
Boolean
print18
)
throws
Exception
{
this
.
activity
=
activity
;
this
.
printCotisant
=
printCotisant
;
this
.
print18
=
print18
;
this
.
articleList
=
articleList
;
this
.
imageList
=
new
Bitmap
[
articleList
.
size
()];
this
.
nbrClicksList
=
new
Integer
[
articleList
.
size
()];
this
.
viewList
=
new
View
[
articleList
.
size
()];
this
.
clickViewList
=
new
TextView
[
articleList
.
size
()];
for
(
int
i
=
0
;
i
<
this
.
nbrClicksList
.
length
;
i
++)
this
.
nbrClicksList
[
i
]
=
0
;
}
@Override
public
int
getCount
()
{
return
this
.
articleList
.
size
();
}
@Override
public
Object
getItem
(
int
position
)
{
return
getArticle
(
position
);
}
@Override
public
long
getItemId
(
int
position
)
{
return
0
;
}
@Override
public
View
getView
(
int
position
,
View
view
,
ViewGroup
viewGroup
)
{
return
view
;
}
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
toast
(
final
int
position
,
int
lengthLong
)
{
Toast
.
makeText
(
this
.
activity
,
articleList
.
get
(
position
).
get
(
"name"
).
textValue
()
+
": "
+
String
.
format
(
"%.2f"
,
new
Float
(
articleList
.
get
(
position
).
get
(
"price"
).
intValue
())
/
100.00f
)
+
"€"
,
lengthLong
).
show
();
}
public
void
setInfos
(
JsonNode
article
,
ImageView
imageCotisant
,
ImageView
image18
)
{
if
(
this
.
printCotisant
)
{
if
(
article
.
get
(
"cotisant"
).
booleanValue
())
imageCotisant
.
setAlpha
(
1.0f
);
else
imageCotisant
.
setAlpha
(
0.3f
);
}
else
imageCotisant
.
setVisibility
(
View
.
GONE
);
if
(
this
.
print18
)
{
if
(
article
.
get
(
"alcool"
).
booleanValue
())
image18
.
setAlpha
(
1.0f
);
else
image18
.
setAlpha
(
0.3f
);
}
else
image18
.
setVisibility
(
View
.
GONE
);
}
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
[
0
]
=
new
HTTPRequest
(
url
);
if
(
request
[
0
].
get
()
==
200
)
{
activity
.
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
imageList
[
position
]
=
request
[
0
].
getImageResponse
();
imageView
.
setImageBitmap
(
imageList
[
position
]);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
});
}
}
}.
start
();
//new DownloadImageTask(imageView, imageList[position]).execute(url);
}
}
public
class
DownloadImageTask
extends
AsyncTask
<
String
,
Void
,
Bitmap
>
{
private
ImageView
imageView
;
private
Bitmap
image
;
public
DownloadImageTask
(
ImageView
imageView
,
Bitmap
image
)
{
this
.
imageView
=
imageView
;
this
.
image
=
image
;
}
protected
Bitmap
doInBackground
(
String
...
urls
)
{
String
urldisplay
=
urls
[
0
];
try
{
URL
url
=
new
URL
(
urldisplay
);
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
connection
.
setDoInput
(
true
);
connection
.
connect
();
InputStream
input
=
connection
.
getInputStream
();
image
=
BitmapFactory
.
decodeStream
(
input
);
}
catch
(
Exception
e
)
{
image
=
null
;
}
return
image
;
}
@SuppressLint
(
"NewApi"
)
protected
void
onPostExecute
(
Bitmap
result
)
{
if
(
result
!=
null
)
{
imageView
.
setImageBitmap
(
result
);
}
}
}
}
app/src/main/java/fr/utc/simde/payutc/articles/GridAdapter.java
deleted
100644 → 0
View file @
efcf3bb3
package
fr.utc.simde.payutc.articles
;
import
android.app.Activity
;
import
android.media.Image
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.RelativeLayout
;
import
android.widget.TextView
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
fr.utc.simde.payutc.R
;
/**
* Created by Samy on 29/10/2017.
*/
public
class
GridAdapter
extends
ArticlesAdapter
{
private
static
final
String
LOG_TAG
=
"_GridAdapter"
;
private
int
size
;
public
GridAdapter
(
final
Activity
activity
,
final
ArrayNode
articleList
,
final
int
nbrColumns
,
final
Boolean
printCotisant
,
final
Boolean
print18
)
throws
Exception
{
super
(
activity
,
articleList
,
printCotisant
,
print18
);
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
;
}
}
@Override
public
View
getView
(
int
position
,
View
view
,
ViewGroup
viewGroup
)
{
JsonNode
article
=
this
.
articleList
.
get
(
position
);
if
(
this
.
viewList
[
position
]
==
null
)
{
LayoutInflater
layoutInflater
=
LayoutInflater
.
from
(
this
.
activity
);
this
.
viewList
[
position
]
=
layoutInflater
.
inflate
(
R
.
layout
.
fragment_article_grid
,
null
);
ImageView
imageView
=
this
.
viewList
[
position
].
findViewById
(
R
.
id
.
image_article
);
RelativeLayout
.
LayoutParams
parms
=
new
RelativeLayout
.
LayoutParams
(
this
.
size
,
this
.
size
);
imageView
.
setLayoutParams
(
parms
);
if
(
article
==
null
||
article
.
size
()
==
0
)
this
.
viewList
[
position
].
setVisibility
(
View
.
INVISIBLE
);
else
{
this
.
clickViewList
[
position
]
=
this
.
viewList
[
position
].
findViewById
(
R
.
id
.
text_nbr_clicks
);
TextView
textView
=
this
.
viewList
[
position
].
findViewById
(
R
.
id
.
text_article
);
textView
.
setText
(
article
.
get
(
"name"
).
textValue
());
ImageView
imageCotisant
=
this
.
viewList
[
position
].
findViewById
(
R
.
id
.
image_cotisant
);
ImageView
image18
=
this
.
viewList
[
position
].
findViewById
(
R
.
id
.
image_18
);
LinearLayout
.
LayoutParams
imageParms
=
new
LinearLayout
.
LayoutParams
(
45
,
45
);
imageParms
.
setMargins
(
0
,
this
.
size
-
45
,
0
,
0
);
imageCotisant
.
setLayoutParams
(
imageParms
);
image18
.
setLayoutParams
(
imageParms
);
setInfos
(
article
,
imageCotisant
,
image18
);
setImage
(
imageView
,
article
.
get
(
"image_url"
).
textValue
(),
position
);
setClickView
(
position
);
}
}
return
this
.
viewList
[
position
];
}
}
app/src/main/java/fr/utc/simde/payutc/articles/GroupAdapter.java
deleted
100644 → 0
View file @
efcf3bb3
package
fr.utc.simde.payutc.articles
;
import
android.annotation.SuppressLint
;
import
android.app.Activity
;
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.CheckBox
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.RelativeLayout
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.List
;
import
fr.utc.simde.payutc.ArticleCategoryActivity
;
import
fr.utc.simde.payutc.R
;
import
fr.utc.simde.payutc.tools.HTTPRequest
;
/**
* Created by Samy on 29/10/2017.
*/
public
class
GroupAdapter
extends
BaseAdapter
{
private
static
final
String
LOG_TAG
=
"_GroupAdapter"
;
protected
Activity
activity
;
protected
JsonNode
groupList
;
protected
CheckBox
[]
checkBoxList
;
public
GroupAdapter
(
final
Activity
activity
,
final
JsonNode
groupList
)
throws
Exception
{
this
.
activity
=
activity
;
this
.
groupList
=
groupList
;
this
.
checkBoxList
=
new
CheckBox
[
groupList
.
size
()];
}
@Override
public
View
getView
(
int
position
,
View
view
,
ViewGroup
viewGroup
)
{
JsonNode
group
=
this
.
groupList
.
get
(
position
);
if
(
view
==
null
)
{
view
=
new
LinearLayout
(
this
.
activity
);
CheckBox
checkBox
=
new
CheckBox
(
this
.
activity
);
checkBox
.
setText
(
group
.
get
(
"name"
).
textValue
());
((
LinearLayout
)
view
).
addView
(
checkBox
);
if
(
this
.
checkBoxList
[
position
]
==
null
)
this
.
checkBoxList
[
position
]
=
checkBox
;
}
return
view
;
}
@Override
public
int
getCount
()
{
return
this
.
groupList
.
size
();
}
@Override
public
Object
getItem
(
int
position
)
{
return
0
;
}
@Override
public
long
getItemId
(
int
position
)
{
return
position
;
}
public
JsonNode
getList
()
{
ObjectNode
groupList
=
new
ObjectMapper
().
createObjectNode
();
Integer
i
=
0
;
for
(
CheckBox
checkBox
:
this
.
checkBoxList
)
{
if
(
checkBox
.
isChecked
())
groupList
.
put
(
Integer
.
toString
(
this
.
groupList
.
get
(
i
).
get
(
"id"
).
intValue
()),
this
.
groupList
.
get
(
i
).
get
(
"name"
).
textValue
());
i
++;
}
return
groupList
;
}
}
app/src/main/java/fr/utc/simde/payutc/articles/GroupFragment.java
deleted
100644 → 0
View file @
efcf3bb3
package
fr.utc.simde.payutc.articles
;
import
android.app.Activity
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.widget.AdapterView
;
import
android.widget.GridView
;
import
android.widget.ListView
;
import
android.widget.TabHost
;
import
android.widget.Toast
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
java.util.List
;
import
fr.utc.simde.payutc.ArticleCategoryActivity
;
import
fr.utc.simde.payutc.BaseActivity
;
import
fr.utc.simde.payutc.R
;
import
fr.utc.simde.payutc.tools.Config
;
import
fr.utc.simde.payutc.tools.Panier
;
/**
* Created by Samy on 27/10/2017.
*/
public
class
GroupFragment
implements
TabHost
.
TabContentFactory
{
private
static
final
String
LOG_TAG
=
"_ArticleGroupFragment"
;
private
int
nbrColumns
;
private
LayoutInflater
layoutInflater
;
private
View
view
;
private
GridView
gridView
;
private
ListView
listView
;
private
ArticlesAdapter
articlesAdapter
;
private
Panier
panier
;
private
Config
config
;
public
GroupFragment
(
final
Activity
activity
,
final
ArrayNode
articleList
,
final
Panier
panier
,
final
Config
config
)
throws
Exception
{
new
GroupFragment
(
activity
,
articleList
,
panier
,
config
,
3
);
}
public
GroupFragment
(
final
Activity
activity
,
final
ArrayNode
articleList
,
final
Panier
panier
,
final
Config
config
,
final
int
gridColumns
)
throws
Exception
{
this
.
layoutInflater
=
LayoutInflater
.
from
(
activity
);
this
.
panier
=
panier
;
this
.
config
=
config
;
if
(
config
.
getInGrid
())
{
this
.
view
=
this
.
layoutInflater
.
inflate
(
R
.
layout
.
fragment_article_group_grid
,
null
);
this
.
gridView
=
this
.
view
.
findViewById
(
R
.
id
.
grid_articles
);
setGridLayout
(
gridColumns
);
createArticleGrid
(
activity
,
articleList
);
}
else
{
this
.
view
=
this
.
layoutInflater
.
inflate
(
R
.
layout
.
fragment_article_group_list
,
null
);
this
.
listView
=
this
.
view
.
findViewById
(
R
.
id
.
list_articles
);
createArticleList
(
activity
,
articleList
);
}
}
public
void
setGridLayout
(
final
int
nbrColumns
)
{
this
.
nbrColumns
=
nbrColumns
;
this
.
gridView
.
setNumColumns
(
nbrColumns
);
}
public
void
createArticleGrid
(
final
Activity
activity
,
final
ArrayNode
articleList
)
throws
Exception
{
this
.
articlesAdapter
=
new
GridAdapter
(
activity
,
articleList
,
this
.
nbrColumns
,
this
.
config
.
getPrintCotisant
(),
this
.
config
.
getPrint18
());
this
.
gridView
.
setOnItemClickListener
(
new
AdapterView
.
OnItemClickListener
()
{
@Override
public
void
onItemClick
(
AdapterView
parent
,
View
view
,
int
position
,
long
id
)
{
JsonNode
article
=
((
JsonNode
)
articlesAdapter
.
getArticle
(
position
));
articlesAdapter
.
onClick
(
position
);
panier
.
addArticle
(
article
.
get
(
"id"
).
intValue
(),
article
.
get
(
"price"
).
intValue
());
}
});
this
.
gridView
.
setOnItemLongClickListener
(
new
AdapterView
.
OnItemLongClickListener
()
{
@Override
public
boolean
onItemLongClick
(
AdapterView
<?>
adapterView
,
View
view
,
int
position
,
long
id
)
{
articlesAdapter
.
toast
(
position
,
Toast
.
LENGTH_LONG
);
return
true
;
}
});
this
.
gridView
.
setAdapter
(
this
.
articlesAdapter
);
}
public
void
createArticleList
(
final
Activity
activity
,
final
ArrayNode
articleList
)
throws
Exception
{
this
.
articlesAdapter
=
new
ListAdapater
(
activity
,
articleList
,
this
.
config
.
getPrintCotisant
(),
this
.
config
.
getPrint18
());
this
.
listView
.
setOnItemClickListener
(
new
AdapterView
.
OnItemClickListener
()
{
@Override
public
void
onItemClick
(
AdapterView
parent
,
View
view
,
int
position
,
long
id
)
{
JsonNode
article
=
((
JsonNode
)
articlesAdapter
.
getArticle
(
position
));
articlesAdapter
.
onClick
(
position
);
panier
.
addArticle
(
article
.
get
(
"id"
).
intValue
(),
article
.
get
(
"price"
).
intValue
());
}
});
this
.