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
b38dc7ba
Commit
b38dc7ba
authored
Nov 10, 2017
by
Nastuzzi Samy
Browse files
ReadCard info
Read info from a card
parent
7a7a4a14
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/fr/utc/simde/payutc/FoundationsOptionsActivity.java
View file @
b38dc7ba
package
fr.utc.simde.payutc
;
import
android.app.ProgressDialog
;
import
android.content.DialogInterface
;
import
android.os.Bundle
;
import
android.support.v7.app.AlertDialog
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.AdapterView
;
import
android.widget.ArrayAdapter
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.LinearLayout
;
import
android.widget.ListView
;
import
android.widget.TabHost
;
...
...
@@ -16,7 +19,10 @@ import com.fasterxml.jackson.databind.JsonNode;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Locale
;
import
fr.utc.simde.payutc.adapters.FoundationsAdapter
;
import
fr.utc.simde.payutc.adapters.ListAdapater
;
...
...
@@ -92,6 +98,62 @@ public class FoundationsOptionsActivity extends BaseActivity {
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
final
int
position
,
long
id
)
{
if
(
position
==
2
)
startReadCardInfoActivity
(
FoundationsOptionsActivity
.
this
);
else
if
(
position
==
6
)
keyNemopayDialog
();
else
if
(
position
==
7
)
keyGingerDialog
();
else
dialog
.
infoDialog
(
FoundationsOptionsActivity
.
this
,
"Non encore fait"
,
"A faire"
);
}
});
}
protected
void
keyNemopayDialog
()
{
hasRights
(
getString
(
R
.
string
.
nemopay
),
new
String
[]{},
new
Runnable
(){
@Override
public
void
run
()
{
final
View
keyView
=
getLayoutInflater
().
inflate
(
R
.
layout
.
dialog_key_force
,
null
);
final
EditText
keyInput
=
keyView
.
findViewById
(
R
.
id
.
input_key
);
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
FoundationsOptionsActivity
.
this
);
alertDialogBuilder
.
setTitle
(
getString
(
R
.
string
.
key_registration
)
+
" "
+
getString
(
R
.
string
.
nemopay
))
.
setView
(
keyView
)
.
setCancelable
(
false
)
.
setPositiveButton
(
R
.
string
.
register
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialogInterface
,
int
id
)
{
if
(!
keyInput
.
getText
().
toString
().
equals
(
""
))
setNemopayKey
(
keyInput
.
getText
().
toString
());
}
})
.
setNegativeButton
(
R
.
string
.
cancel
,
null
);
dialog
.
createDialog
(
alertDialogBuilder
,
keyInput
);
}
});
}
protected
void
keyGingerDialog
()
{
hasRights
(
getString
(
R
.
string
.
ginger
),
new
String
[]{},
new
Runnable
(){
@Override
public
void
run
()
{
final
View
keyView
=
getLayoutInflater
().
inflate
(
R
.
layout
.
dialog_key_force
,
null
);
final
EditText
keyInput
=
keyView
.
findViewById
(
R
.
id
.
input_key
);
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
FoundationsOptionsActivity
.
this
);
alertDialogBuilder
.
setTitle
(
getString
(
R
.
string
.
key_registration
)
+
" "
+
getString
(
R
.
string
.
ginger
))
.
setView
(
keyView
)
.
setCancelable
(
false
)
.
setPositiveButton
(
R
.
string
.
register
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialogInterface
,
int
id
)
{
if
(!
keyInput
.
getText
().
toString
().
equals
(
""
))
setGingerKey
(
keyInput
.
getText
().
toString
());
}
})
.
setNegativeButton
(
R
.
string
.
cancel
,
null
);
dialog
.
createDialog
(
alertDialogBuilder
,
keyInput
);
}
});
}
...
...
app/src/main/java/fr/utc/simde/payutc/ReadCardInfoActivity.java
View file @
b38dc7ba
...
...
@@ -2,6 +2,7 @@ package fr.utc.simde.payutc;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.graphics.Color
;
import
android.os.Bundle
;
import
android.support.v7.app.AlertDialog
;
import
android.util.Log
;
...
...
@@ -39,6 +40,17 @@ public class ReadCardInfoActivity extends BaseActivity {
TextView
textTag
;
TextView
textShortTag
;
TextView
textUsernameGinger
;
TextView
textFirstnameGinger
;
TextView
textLastnameGinger
;
TextView
textTypeGinger
;
TextView
textEmailGinger
;
TextView
textAdultGinger
;
TextView
textCotisantGinger
;
String
username
;
Boolean
canRead
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -55,11 +67,30 @@ public class ReadCardInfoActivity extends BaseActivity {
this
.
textTag
=
findViewById
(
R
.
id
.
text_tag
);
this
.
textShortTag
=
findViewById
(
R
.
id
.
text_short_tag
);
dialog
.
startLoading
(
ReadCardInfoActivity
.
this
,
getString
(
R
.
string
.
information_collection
),
getString
(
R
.
string
.
badge_waiting
));
this
.
textUsernameGinger
=
findViewById
(
R
.
id
.
text_username_ginger
);
this
.
textFirstnameGinger
=
findViewById
(
R
.
id
.
text_firstname_ginger
);
this
.
textLastnameGinger
=
findViewById
(
R
.
id
.
text_lastname_ginger
);
this
.
textEmailGinger
=
findViewById
(
R
.
id
.
text_email_ginger
);
this
.
textTypeGinger
=
findViewById
(
R
.
id
.
text_type_ginger
);
this
.
textAdultGinger
=
findViewById
(
R
.
id
.
text_adult_ginger
);
this
.
textCotisantGinger
=
findViewById
(
R
.
id
.
text_cotisant_ginger
);
findViewById
(
R
.
id
.
read_new_card
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
readNewCard
();
}
});
readNewCard
();
}
@Override
protected
void
onIdentification
(
final
String
badgeId
)
{
if
(!
canRead
)
return
;
this
.
canRead
=
false
;
dialog
.
startLoading
(
ReadCardInfoActivity
.
this
,
getResources
().
getString
(
R
.
string
.
information_collection
),
getResources
().
getString
(
R
.
string
.
buyer_info_collecting
));
new
Thread
()
{
...
...
@@ -74,6 +105,8 @@ public class ReadCardInfoActivity extends BaseActivity {
if
(!
buyerInfo
.
has
(
"lastname"
)
||
!
buyerInfo
.
has
(
"username"
)
||
!
buyerInfo
.
has
(
"firstname"
)
||
!
buyerInfo
.
has
(
"solde"
)
||
!
buyerInfo
.
has
(
"last_purchases"
)
||
!
buyerInfo
.
get
(
"last_purchases"
).
isArray
())
throw
new
Exception
(
"Unexpected JSON"
);
username
=
nemopaySession
.
getRequest
().
getJSONResponse
().
get
(
"username"
).
textValue
();
}
catch
(
final
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
...
...
@@ -107,7 +140,7 @@ public class ReadCardInfoActivity extends BaseActivity {
});
try
{
nemopaySession
.
foundUser
(
nemopaySession
.
getRequest
().
getJSONResponse
().
get
(
"username"
).
textValue
()
);
nemopaySession
.
foundUser
(
username
);
Thread
.
sleep
(
100
);
}
catch
(
final
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
...
...
@@ -149,17 +182,23 @@ public class ReadCardInfoActivity extends BaseActivity {
nemopaySession
.
getUser
(
usersFounded
.
get
(
0
).
get
(
"id"
).
intValue
());
Thread
.
sleep
(
100
);
ginger
.
getInfo
(
username
);
Thread
.
sleep
(
100
);
// Toute une série de vérifications avant de lancer l'activité
final
JsonNode
userInfo
=
nemopaySession
.
getRequest
().
getJSONResponse
();
final
JsonNode
gingerInfo
=
new
ObjectMapper
().
readTree
(
ginger
.
getRequest
().
getResponse
());
// La réponse n'est pas considérée comme une réponse json.. (l'en-tête ne renvoie pas une application/json)
if
(!
userInfo
.
has
(
"user"
)
||
!
userInfo
.
has
(
"tag"
))
throw
new
Exception
(
"Unexpected JSON"
);
throw
new
Exception
(
"Unexpected Nemopay JSON"
);
if
(!
gingerInfo
.
has
(
"login"
)
||
!
gingerInfo
.
has
(
"nom"
)
||
!
gingerInfo
.
has
(
"prenom"
)
||
!
gingerInfo
.
has
(
"mail"
)
||
!
gingerInfo
.
has
(
"type"
)
||
!
gingerInfo
.
has
(
"is_adulte"
)
||
!
gingerInfo
.
has
(
"is_cotisant"
))
throw
new
Exception
(
"Unexpected Ginger JSON"
);
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
setUserInfo
(
userInfo
.
get
(
"user"
),
userInfo
.
get
(
"tag"
));
setUserInfo
(
userInfo
.
get
(
"user"
),
userInfo
.
get
(
"tag"
)
,
gingerInfo
);
dialog
.
stopLoading
();
}
});
...
...
@@ -174,6 +213,13 @@ public class ReadCardInfoActivity extends BaseActivity {
dialog
.
errorDialog
(
ReadCardInfoActivity
.
this
,
getString
(
R
.
string
.
information_collection
),
getString
(
R
.
string
.
user_error_collecting
));
}
});
else
if
(
ginger
.
getRequest
().
getResponseCode
()
==
404
)
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
errorDialog
(
ReadCardInfoActivity
.
this
,
getString
(
R
.
string
.
information_collection
),
getString
(
R
.
string
.
user_not_recognized
));
}
});
else
throw
new
Exception
(
""
);
}
catch
(
Exception
e1
)
{
...
...
@@ -191,19 +237,31 @@ public class ReadCardInfoActivity extends BaseActivity {
}.
start
();
}
void
setUserInfo
(
JsonNode
userInfo
,
JsonNode
tagInfo
)
{
void
setUserInfo
(
JsonNode
userInfo
,
JsonNode
tagInfo
,
JsonNode
gingerInfo
)
{
try
{
this
.
textUserId
.
setText
(
Integer
.
toString
(
userInfo
.
get
(
"id"
).
intValue
()));
this
.
textUsername
.
setText
(
userInfo
.
get
(
"username"
).
textValue
());
this
.
textFirstname
.
setText
(
userInfo
.
get
(
"first_name"
).
textValue
());
this
.
textLastname
.
setText
(
userInfo
.
get
(
"last_name"
).
textValue
());
this
.
textEmail
.
setText
(
userInfo
.
get
(
"email"
).
textValue
());
this
.
textAdult
.
setText
(
userInfo
.
get
(
"adult"
).
booleanValue
()
?
getString
(
R
.
string
.
yes
)
:
getString
(
R
.
string
.
no
));
this
.
textCotisant
.
setText
(
userInfo
.
get
(
"cotisant"
).
booleanValue
()
?
getString
(
R
.
string
.
yes
)
:
getString
(
R
.
string
.
no
));
this
.
textAdult
.
setText
(
userInfo
.
get
(
"adult"
).
booleanValue
()
?
getString
(
R
.
string
.
yes
)
:
getString
(
R
.
string
.
no
));
this
.
textAdult
.
setTextColor
(
userInfo
.
get
(
"adult"
).
booleanValue
()
?
Color
.
BLUE
:
Color
.
RED
);
this
.
textCotisant
.
setText
(
userInfo
.
get
(
"cotisant"
).
booleanValue
()
?
getString
(
R
.
string
.
yes
)
:
getString
(
R
.
string
.
no
));
this
.
textCotisant
.
setTextColor
(
userInfo
.
get
(
"cotisant"
).
booleanValue
()
?
Color
.
BLUE
:
Color
.
RED
);
this
.
textTagId
.
setText
(
Integer
.
toString
(
tagInfo
.
get
(
"id"
).
intValue
()));
this
.
textTag
.
setText
(
tagInfo
.
get
(
"tag"
).
textValue
());
this
.
textShortTag
.
setText
(
tagInfo
.
get
(
"short_tag"
).
textValue
()
==
null
?
getString
(
R
.
string
.
none
)
:
tagInfo
.
get
(
"short_tag"
).
textValue
());
this
.
textUsernameGinger
.
setText
(
gingerInfo
.
get
(
"login"
).
textValue
());
this
.
textFirstnameGinger
.
setText
(
gingerInfo
.
get
(
"prenom"
).
textValue
());
this
.
textLastnameGinger
.
setText
(
gingerInfo
.
get
(
"nom"
).
textValue
());
this
.
textEmailGinger
.
setText
(
gingerInfo
.
get
(
"mail"
).
textValue
());
this
.
textTypeGinger
.
setText
(
gingerInfo
.
get
(
"type"
).
textValue
());
this
.
textAdultGinger
.
setText
(
gingerInfo
.
get
(
"is_adulte"
).
booleanValue
()
?
getString
(
R
.
string
.
yes
)
:
getString
(
R
.
string
.
no
));
this
.
textAdultGinger
.
setTextColor
(
gingerInfo
.
get
(
"is_adulte"
).
booleanValue
()
?
Color
.
BLUE
:
Color
.
RED
);
this
.
textCotisantGinger
.
setText
(
gingerInfo
.
get
(
"is_cotisant"
).
booleanValue
()
?
getString
(
R
.
string
.
yes
)
:
getString
(
R
.
string
.
no
));
this
.
textCotisantGinger
.
setTextColor
(
gingerInfo
.
get
(
"is_cotisant"
).
booleanValue
()
?
Color
.
BLUE
:
Color
.
RED
);
}
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
()
{
...
...
@@ -214,4 +272,14 @@ public class ReadCardInfoActivity extends BaseActivity {
});
}
}
protected
void
readNewCard
()
{
dialog
.
infoDialog
(
ReadCardInfoActivity
.
this
,
getString
(
R
.
string
.
information_collection
),
getString
(
R
.
string
.
badge_waiting
),
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialogInterface
,
int
id
)
{
canRead
=
false
;
}
});
this
.
canRead
=
true
;
}
}
app/src/main/res/layout/activity_read_card_info.xml
View file @
b38dc7ba
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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