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
78e437dc
Commit
78e437dc
authored
Nov 05, 2017
by
Nastuzzi Samy
Browse files
Merge branch 'release/keybaords' into develop
parents
f7018e5c
2c75015e
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
app/src/main/AndroidManifest.xml
View file @
78e437dc
...
...
@@ -29,6 +29,9 @@
<activity
android:name=
".FoundationListActivity"
android:configChanges=
"orientation"
android:screenOrientation=
"portrait"
/>
<activity
android:name=
".ArticleKeyboardActivity"
android:configChanges=
"orientation"
android:screenOrientation=
"portrait"
/>
<activity
android:name=
".ArticleCategoryActivity"
android:configChanges=
"orientation"
android:screenOrientation=
"portrait"
/>
...
...
app/src/main/java/fr/utc/simde/payutc/ArticleCategoryActivity.java
View file @
78e437dc
This diff is collapsed.
Click to expand it.
app/src/main/java/fr/utc/simde/payutc/ArticleGroupActivity.java
0 → 100644
View file @
78e437dc
package
fr.utc.simde.payutc
;
import
android.content.DialogInterface
;
import
android.os.Bundle
;
import
android.os.Vibrator
;
import
android.support.v7.app.AlertDialog
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.ImageButton
;
import
android.widget.ListView
;
import
android.widget.RadioButton
;
import
android.widget.Switch
;
import
android.widget.TabHost
;
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
java.util.ArrayList
;
import
java.util.List
;
import
fr.utc.simde.payutc.articles.GroupAdapter
;
import
fr.utc.simde.payutc.articles.GroupFragment
;
import
fr.utc.simde.payutc.tools.HTTPRequest
;
import
fr.utc.simde.payutc.tools.Panier
;
/**
* Created by Samy on 27/10/2017.
*/
public
abstract
class
ArticleGroupActivity
extends
BaseActivity
{
private
static
final
String
LOG_TAG
=
"_ArticleGroupActivity"
;
protected
ImageButton
paramButton
;
protected
ImageButton
deleteButton
;
protected
TabHost
tabHost
;
protected
Panier
panier
;
protected
List
<
GroupFragment
>
groupFragmentList
;
protected
int
nbrGroups
;
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_article_group
);
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
.
groupFragmentList
=
new
ArrayList
<
GroupFragment
>();
this
.
nbrGroups
=
0
;
try
{
createGroups
(
new
ObjectMapper
().
readTree
(
getIntent
().
getExtras
().
getString
(
"groupList"
)),
new
ObjectMapper
().
readTree
(
getIntent
().
getExtras
().
getString
(
"articleList"
)));
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
dialog
.
errorDialog
(
this
,
getResources
().
getString
(
R
.
string
.
information_collection
),
getResources
().
getString
(
R
.
string
.
error_view
),
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialogInterface
,
int
id
)
{
finish
();
}
});
}
if
(
this
.
nbrGroups
==
0
)
{
dialog
.
errorDialog
(
this
,
getResources
().
getString
(
R
.
string
.
information_collection
),
getResources
().
getString
(
R
.
string
.
article_error_0_categorie_not_0
),
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialogInterface
,
int
id
)
{
finish
();
}
});
}
this
.
paramButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
if
(
config
.
getFoundationId
()
==
-
1
)
{
final
View
popupView
=
LayoutInflater
.
from
(
ArticleGroupActivity
.
this
).
inflate
(
R
.
layout
.
dialog_config
,
null
,
false
);
final
RadioButton
radioKeyboard
=
popupView
.
findViewById
(
R
.
id
.
radio_keyboard
);
final
RadioButton
radioCategory
=
popupView
.
findViewById
(
R
.
id
.
radio_category
);
final
RadioButton
radioGrid
=
popupView
.
findViewById
(
R
.
id
.
radio_grid
);
final
RadioButton
radioList
=
popupView
.
findViewById
(
R
.
id
.
radio_list
);
final
Switch
switchCotisant
=
popupView
.
findViewById
(
R
.
id
.
swtich_cotisant
);
final
Switch
swtich18
=
popupView
.
findViewById
(
R
.
id
.
swtich_18
);
final
Button
configButton
=
popupView
.
findViewById
(
R
.
id
.
button_config
);
if
(
config
.
getInKeyboard
())
radioKeyboard
.
setChecked
(
true
);
else
radioCategory
.
setChecked
(
true
);
if
(
config
.
getInGrid
())
radioGrid
.
setChecked
(
true
);
else
radioList
.
setChecked
(
true
);
switchCotisant
.
setChecked
(
config
.
getPrintCotisant
());
swtich18
.
setChecked
(
config
.
getPrint18
());
configButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
final
View
view
)
{
configApp
();
}
});
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
ArticleGroupActivity
.
this
);
alertDialogBuilder
.
setTitle
(
R
.
string
.
configuration
)
.
setView
(
popupView
)
.
setCancelable
(
false
)
.
setPositiveButton
(
R
.
string
.
reload
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialogInterface
,
int
id
)
{
config
.
setInKeyboard
(
radioKeyboard
.
isChecked
());
config
.
setInGrid
(
radioGrid
.
isChecked
());
config
.
setPrintCotisant
(
switchCotisant
.
isChecked
());
config
.
setPrint18
(
swtich18
.
isChecked
());
startArticleGroupActivity
(
ArticleGroupActivity
.
this
);
}
})
.
setNegativeButton
(
R
.
string
.
cancel
,
null
);
dialog
.
createDialog
(
alertDialogBuilder
);
}
else
{
final
View
popupView
=
LayoutInflater
.
from
(
ArticleGroupActivity
.
this
).
inflate
(
R
.
layout
.
dialog_config_restore
,
null
,
false
);
final
Switch
switchCotisant
=
popupView
.
findViewById
(
R
.
id
.
swtich_cotisant
);
final
Switch
swtich18
=
popupView
.
findViewById
(
R
.
id
.
swtich_18
);
final
Button
configButton
=
popupView
.
findViewById
(
R
.
id
.
button_config
);
switchCotisant
.
setChecked
(
config
.
getPrintCotisant
());
swtich18
.
setChecked
(
config
.
getPrint18
());
configButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
config
.
setFoundation
(-
1
,
""
);
config
.
setGroupList
(
new
ObjectMapper
().
createObjectNode
());
config
.
setCanCancel
(
true
);
startMainActivity
(
ArticleGroupActivity
.
this
);
}
});
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
ArticleGroupActivity
.
this
);
alertDialogBuilder
.
setTitle
(
R
.
string
.
configuration
)
.
setView
(
popupView
)
.
setCancelable
(
false
)
.
setPositiveButton
(
R
.
string
.
applicate
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialogInterface
,
int
id
)
{
config
.
setPrintCotisant
(
switchCotisant
.
isChecked
());
config
.
setPrint18
(
swtich18
.
isChecked
());
startArticleGroupActivity
(
ArticleGroupActivity
.
this
);
}
})
.
setNegativeButton
(
R
.
string
.
cancel
,
null
);
dialog
.
createDialog
(
alertDialogBuilder
);
}
}
});
this
.
deleteButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
clearPanier
();
}
});
}
@Override
public
void
onRestart
()
{
super
.
onRestart
();
startArticleGroupActivity
(
ArticleGroupActivity
.
this
);
}
@Override
protected
void
onIdentification
(
final
String
badgeId
)
{
if
(
dialog
.
isShowing
())
return
;
if
(
this
.
panier
.
isEmpty
())
startBuyerInfoActivity
(
ArticleGroupActivity
.
this
,
badgeId
);
else
pay
(
badgeId
);
}
protected
abstract
void
createGroups
(
final
JsonNode
groupList
,
final
JsonNode
articleList
)
throws
Exception
;
protected
void
configApp
()
{
dialog
.
startLoading
(
ArticleGroupActivity
.
this
,
getResources
().
getString
(
R
.
string
.
information_collection
),
getString
(
config
.
getInKeyboard
()
?
R
.
string
.
keyboard_list_collecting
:
R
.
string
.
category_list_collecting
));
new
Thread
()
{
@Override
public
void
run
()
{
try
{
if
(
config
.
getInKeyboard
())
nemopaySession
.
getKeyboards
();
else
nemopaySession
.
getCategories
();
Thread
.
sleep
(
100
);
final
HTTPRequest
request
=
nemopaySession
.
getRequest
();
final
JsonNode
groupList
=
request
.
getJSONResponse
();
if
(!
groupList
.
isArray
())
throw
new
Exception
(
"Malformed JSON"
);
if
(
groupList
==
null
||
groupList
.
size
()
==
0
)
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
stopLoading
();
dialog
.
errorDialog
(
ArticleGroupActivity
.
this
,
getString
(
R
.
string
.
information_collection
),
nemopaySession
.
getFoundationName
()
+
" "
+
getString
(
config
.
getInKeyboard
()
?
R
.
string
.
keyboard_error_0
:
R
.
string
.
category_error_0
));
}
});
return
;
}
for
(
final
JsonNode
group
:
groupList
)
{
if
(!
group
.
has
(
"id"
)
||
!
group
.
has
(
"name"
))
throw
new
Exception
(
"Unexpected JSON"
);
}
}
catch
(
final
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
fatal
(
ArticleGroupActivity
.
this
,
getString
(
config
.
getInKeyboard
()
?
R
.
string
.
keyboard_list_collecting
:
R
.
string
.
category_list_collecting
),
e
.
getMessage
());
}
});
}
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
stopLoading
();
LayoutInflater
layoutInflater
=
LayoutInflater
.
from
(
ArticleGroupActivity
.
this
);
View
popupView
=
layoutInflater
.
inflate
(
R
.
layout
.
dialog_group
,
null
);
ListView
listView
=
popupView
.
findViewById
(
R
.
id
.
list_groups
);
final
Switch
canCancelSwitch
=
popupView
.
findViewById
(
R
.
id
.
swtich_cancel
);
canCancelSwitch
.
setChecked
(
config
.
getCanCancel
());
if
(
config
.
getInKeyboard
())
((
TextView
)
popupView
.
findViewById
(
R
.
id
.
text_to_print
)).
setText
(
R
.
string
.
keyboard_list
);
JsonNode
groupList
;
GroupAdapter
groupAdapter
=
null
;
try
{
groupList
=
nemopaySession
.
getRequest
().
getJSONResponse
();
groupAdapter
=
new
GroupAdapter
(
ArticleGroupActivity
.
this
,
groupList
);
listView
.
setAdapter
(
groupAdapter
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
fatal
(
ArticleGroupActivity
.
this
,
getString
(
config
.
getInKeyboard
()
?
R
.
string
.
keyboard_list_collecting
:
R
.
string
.
category_list_collecting
),
e
.
getMessage
());
}
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
ArticleGroupActivity
.
this
);
final
GroupAdapter
finalGroupAdapter
=
groupAdapter
;
alertDialogBuilder
.
setTitle
(
R
.
string
.
configuration
)
.
setView
(
popupView
)
.
setCancelable
(
false
)
.
setPositiveButton
(
R
.
string
.
applicate
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialogInterface
,
int
id
)
{
config
.
setCanCancel
(
canCancelSwitch
.
isChecked
());
JsonNode
groupList
=
finalGroupAdapter
.
getList
();
if
(
groupList
==
null
||
groupList
.
size
()
==
0
)
{
Toast
.
makeText
(
ArticleGroupActivity
.
this
,
getString
(
config
.
getInKeyboard
()
?
R
.
string
.
keyboard_0_selected
:
R
.
string
.
category_0_selected
),
Toast
.
LENGTH_LONG
).
show
();
configApp
();
}
else
{
config
.
setFoundation
(
nemopaySession
.
getFoundationId
(),
nemopaySession
.
getFoundationName
());
config
.
setGroupList
(
finalGroupAdapter
.
getList
());
startMainActivity
(
ArticleGroupActivity
.
this
);
}
}
})
.
setNegativeButton
(
R
.
string
.
cancel
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialogInterface
,
int
id
)
{
config
.
setCanCancel
(
true
);
}
});
dialog
.
createDialog
(
alertDialogBuilder
);
}
});
}
}.
start
();
}
public
void
clearPanier
()
{
for
(
GroupFragment
groupFragment
:
groupFragmentList
)
groupFragment
.
clear
();
panier
.
clear
();
}
public
void
setBackgroundColor
(
int
color
)
{
this
.
tabHost
.
setBackgroundColor
(
color
);
new
Thread
(){
@Override
public
void
run
()
{
try
{
Thread
.
sleep
(
2500
);
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
tabHost
.
setBackgroundColor
(
getResources
().
getColor
(
R
.
color
.
white
));
}
});
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
}
}
}.
start
();
}
protected
void
pay
(
final
String
badgeId
)
{
dialog
.
startLoading
(
this
,
getResources
().
getString
(
R
.
string
.
paiement
),
getResources
().
getString
(
R
.
string
.
transaction_in_progress
));
new
Thread
()
{
@Override
public
void
run
()
{
try
{
nemopaySession
.
setTransaction
(
badgeId
,
panier
.
getArticleList
());
Thread
.
sleep
(
100
);
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
stopLoading
();
Toast
.
makeText
(
ArticleGroupActivity
.
this
,
"Paiement effectué"
,
Toast
.
LENGTH_LONG
).
show
();
setBackgroundColor
(
getResources
().
getColor
(
R
.
color
.
success
));
((
Vibrator
)
getSystemService
(
ArticleCategoryActivity
.
VIBRATOR_SERVICE
)).
vibrate
(
250
);
clearPanier
();
}
});
}
catch
(
final
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
try
{
final
JsonNode
response
=
nemopaySession
.
getRequest
().
getJSONResponse
();
if
(
response
.
has
(
"error"
)
&&
response
.
get
(
"error"
).
has
(
"message"
))
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
stopLoading
();
dialog
.
errorDialog
(
ArticleGroupActivity
.
this
,
getString
(
R
.
string
.
paiement
),
response
.
get
(
"error"
).
get
(
"message"
).
textValue
());
setBackgroundColor
(
getResources
().
getColor
(
R
.
color
.
error
));
((
Vibrator
)
getSystemService
(
ArticleCategoryActivity
.
VIBRATOR_SERVICE
)).
vibrate
(
500
);
}
});
}
else
throw
new
Exception
(
""
);
}
catch
(
Exception
e1
)
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
stopLoading
();
dialog
.
errorDialog
(
ArticleGroupActivity
.
this
,
getString
(
R
.
string
.
paiement
),
e
.
getMessage
());
setBackgroundColor
(
getResources
().
getColor
(
R
.
color
.
error
));
((
Vibrator
)
getSystemService
(
ArticleCategoryActivity
.
VIBRATOR_SERVICE
)).
vibrate
(
500
);
}
});
}
}
}
}.
start
();
}
protected
void
createNewGroup
(
final
String
name
,
final
ArrayNode
articleList
)
throws
Exception
{
createNewGroup
(
name
,
articleList
,
3
);
}
protected
void
createNewGroup
(
final
String
name
,
final
ArrayNode
articleList
,
int
gridColumns
)
throws
Exception
{
GroupFragment
articleGroupFragment
=
new
GroupFragment
(
ArticleGroupActivity
.
this
,
articleList
,
this
.
panier
,
this
.
config
,
gridColumns
);
TabHost
.
TabSpec
newTabSpec
=
this
.
tabHost
.
newTabSpec
(
name
);
newTabSpec
.
setIndicator
(
name
);
newTabSpec
.
setContent
(
articleGroupFragment
);
this
.
groupFragmentList
.
add
(
articleGroupFragment
);
this
.
tabHost
.
addTab
(
newTabSpec
);
nbrGroups
++;
}
}
app/src/main/java/fr/utc/simde/payutc/ArticleKeyboardActivity.java
0 → 100644
View file @
78e437dc
package
fr.utc.simde.payutc
;
import
android.os.Bundle
;
import
android.util.Log
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
fr.utc.simde.payutc.ArticleGroupActivity
;
/**
* Created by Samy on 27/10/2017.
*/
public
class
ArticleKeyboardActivity
extends
ArticleGroupActivity
{
private
static
final
String
LOG_TAG
=
"_ArticleKeyboardActivit"
;
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
}
protected
void
createGroups
(
final
JsonNode
keyboardList
,
final
JsonNode
articleList
)
throws
Exception
{
final
int
foundationId
=
nemopaySession
.
getFoundationId
();
final
JsonNode
authorizedList
=
config
.
getGroupList
();
for
(
final
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"
)
||
article
.
get
(
"fundation_id"
).
intValue
()
!=
foundationId
)
throw
new
Exception
(
"Unexpected JSON"
);
}
for
(
JsonNode
keyboard
:
keyboardList
)
{
ArrayNode
articlesForThisKeyboard
=
new
ObjectMapper
().
createArrayNode
();
if
(!
keyboard
.
has
(
"id"
)
||
!
keyboard
.
has
(
"name"
)
||
!
keyboard
.
has
(
"fun_id"
)
||
keyboard
.
get
(
"fun_id"
).
intValue
()
!=
foundationId
||
!
keyboard
.
has
(
"data"
)
||
!
keyboard
.
get
(
"data"
).
has
(
"items"
)
||
!
keyboard
.
get
(
"data"
).
get
(
"items"
).
isArray
()
||
!
keyboard
.
get
(
"data"
).
has
(
"nbColumns"
))
throw
new
Exception
(
"Unexpected JSON"
);
if
(
config
.
getFoundationId
()
!=
-
1
)
if
(!
authorizedList
.
has
(
Integer
.
toString
(
keyboard
.
get
(
"id"
).
intValue
())))
continue
;
else
if
(
keyboard
.
get
(
"data"
).
get
(
"items"
).
size
()
==
0
)
continue
;
for
(
JsonNode
article
:
keyboard
.
get
(
"data"
).
get
(
"items"
))
{
if
(
article
.
has
(
"itm_id"
))
{
boolean
in
=
false
;
for
(
JsonNode
articleInList
:
articleList
)
{
if
(
articleInList
.
get
(
"id"
).
intValue
()
==
article
.
get
(
"itm_id"
).
intValue
())
{
articlesForThisKeyboard
.
add
(
articleInList
);
in
=
true
;
break
;
}
}
if
(!
in
)
articlesForThisKeyboard
.
add
(
new
ObjectMapper
().
createObjectNode
());
}
else
if
(
config
.
getInGrid
())
articlesForThisKeyboard
.
add
(
new
ObjectMapper
().
createObjectNode
());
}
createNewGroup
(
keyboard
.
get
(
"name"
).
textValue
(),
articlesForThisKeyboard
,
keyboard
.
get
(
"data"
).
get
(
"nbColumns"
).
isInt
()
?
keyboard
.
get
(
"data"
).
get
(
"nbColumns"
).
intValue
()
:
Integer
.
valueOf
(
keyboard
.
get
(
"data"
).
get
(
"nbColumns"
).
textValue
()));
}
}
}
app/src/main/java/fr/utc/simde/payutc/BaseActivity.java
View file @
78e437dc
...
...
@@ -74,7 +74,7 @@ public abstract class BaseActivity extends NFCActivity {
protected
void
startFoundationListActivity
(
final
Activity
activity
)
{
if
(
config
.
getFoundationId
()
!=
-
1
)
{
start
Category
Article
s
Activity
(
activity
);
startArticle
Group
Activity
(
activity
);
return
;
}
...
...
@@ -150,50 +150,48 @@ public abstract class BaseActivity extends NFCActivity {
}.
start
();
}
protected
void
start
Category
Article
s
Activity
(
final
Activity
activity
)
{
dialog
.
startLoading
(
activity
,
activity
.
getResources
().
getString
(
R
.
string
.
information_collection
),
activity
.
getResources
().
getString
(
R
.
string
.
category_list_collecting
));
final
Intent
intent
=
new
Intent
(
activity
,
ArticleCategoryActivity
.
class
);
protected
void
startArticle
Group
Activity
(
final
Activity
activity
)
{
dialog
.
startLoading
(
activity
,
activity
.
getResources
().
getString
(
R
.
string
.
information_collection
),
activity
.
getResources
().
getString
(
config
.
getInKeyboard
()
?
R
.
string
.
keyboard_list_collecting
:
R
.
string
.
category_list_collecting
));
final
Intent
intent
=
new
Intent
(
activity
,
config
.
getInKeyboard
()
?
ArticleKeyboardActivity
.
class
:
ArticleCategoryActivity
.
class
);
new
Thread
()
{
@Override
public
void
run
()
{
try
{
int
responseCode
=
nemopaySession
.
getCategories
();
if
(
config
.
getInKeyboard
())
nemopaySession
.
getKeyboards
();
else
nemopaySession
.
getCategories
();
Thread
.
sleep
(
100
);
// Toute une série de vérifications avant de lancer l'activité
final
HTTPRequest
request
=
nemopaySession
.
getRequest
();
final
JsonNode
category
List
=
request
.
getJSONResponse
();
final
JsonNode
group
List
=
request
.
getJSONResponse
();
if
(!
request
.
isJSONResponse
()
||
!
category
List
.
isArray
())
if
(!
group
List
.
isArray
())
throw
new
Exception
(
"Malformed JSON"
);
if
(
category
List
.
size
()
==
0
)
{
if
(
group
List
.
size
()
==
0
)
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
stopLoading
();
dialog
.
errorDialog
(
activity
,
getString
(
R
.
string
.
information_collection
),
nemopaySession
.
getFoundationName
()
+
" "
+
getString
(
R
.
string
.
category_error_0
));
dialog
.
errorDialog
(
activity
,
getString
(
R
.
string
.
information_collection
),
nemopaySession
.
getFoundationName
()
+
" "
+
getString
(
config
.
getInKeyboard
()
?
R
.
string
.
keyboard_error_0
:
R
.
string
.
category_error_0
));
}
});
return
;
}
for
(
final
JsonNode
category
:
categoryList
)
{
if
(!
category
.
has
(
"id"
)
||
!
category
.
has
(
"name"
)
||
!
category
.
has
(
"fundation_id"
)
||
category
.
get
(
"fundation_id"
).
intValue
()
!=
nemopaySession
.
getFoundationId
())
throw
new
Exception
(
"Unexpected JSON"
);
}
intent
.
putExtra
(
"categoryList"
,
request
.
getResponse
());
intent
.
putExtra
(
"groupList"
,
request
.
getResponse
());
}
catch
(
final
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
fatal
(
activity
,
getString
(
R
.
string
.
category_list_collecting
),
e
.
getMessage
());
fatal
(
activity
,
getString
(
config
.
getInKeyboard
()
?
R
.
string
.
keyboard_list_collecting
:
R
.
string
.
category_list_collecting
),
e
.
getMessage
());
}