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
f102ce04
Commit
f102ce04
authored
Dec 13, 2017
by
Nastuzzi Samy
Browse files
Add reservation API
Can now manage shotgun reservations
parent
b19d840d
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/fr/utc/simde/jessy/QRCodeReaderActivity.java
View file @
f102ce04
...
@@ -25,10 +25,9 @@ import java.util.ArrayList;
...
@@ -25,10 +25,9 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.List
;
import
fr.utc.simde.jessy.adapters.ListAdapater
;
import
fr.utc.simde.jessy.adapters.ListAdapater
;
import
fr.utc.simde.jessy.responses.APIResponse
;
import
fr.utc.simde.jessy.responses.ArticleResponse
;
import
fr.utc.simde.jessy.responses.ArticleResponse
;
import
fr.utc.simde.jessy.responses.BottomatikResponse
;
import
fr.utc.simde.jessy.responses.BottomatikResponse
;
import
fr.utc.simde.jessy.responses.
Comedmus
Response
;
import
fr.utc.simde.jessy.responses.
Reservation
Response
;
import
fr.utc.simde.jessy.responses.GingerResponse
;
import
fr.utc.simde.jessy.responses.GingerResponse
;
import
fr.utc.simde.jessy.responses.QRCodeResponse
;
import
fr.utc.simde.jessy.responses.QRCodeResponse
;
import
fr.utc.simde.jessy.tools.API
;
import
fr.utc.simde.jessy.tools.API
;
...
@@ -64,27 +63,33 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
...
@@ -64,27 +63,33 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
this
.
apiName
=
new
ArrayList
<
String
>()
{{
this
.
apiName
=
new
ArrayList
<
String
>()
{{
add
(
"bottomatik"
);
add
(
"bottomatik"
);
add
(
"comedmus"
);
add
(
"comedmus"
);
add
(
"reservations"
);
}};
}};
this
.
apiUrl
=
new
ArrayList
<
String
>()
{{
this
.
apiUrl
=
new
ArrayList
<
String
>()
{{
add
(
"https://picasso.bottomatik.com/bot/transactions/"
);
add
(
"https://picasso.bottomatik.com/bot/transactions/"
);
add
(
"https://www.lacomutc.fr/qr/"
+
sharedPreferences
.
getString
(
"key_"
+
apiName
.
get
(
1
),
"no_key"
)
+
"/"
);
add
(
"https://www.lacomutc.fr/qr/"
+
sharedPreferences
.
getString
(
"key_"
+
apiName
.
get
(
1
),
"no_key"
)
+
"/"
);
add
(
"https://assos.utc.fr/simde/reservations/"
);
}};
}};
this
.
apiNeedKey
=
new
ArrayList
<
Boolean
>()
{{
this
.
apiNeedKey
=
new
ArrayList
<
Boolean
>()
{{
add
(
true
);
add
(
true
);
add
(
false
);
add
(
false
);
add
(
true
);
}};
}};
this
.
apiNeedGinger
=
new
ArrayList
<
Boolean
>()
{{
this
.
apiNeedGinger
=
new
ArrayList
<
Boolean
>()
{{
add
(
true
);
add
(
true
);
add
(
false
);
add
(
false
);
add
(
true
);
}};
}};
this
.
apiResponseClass
=
new
ArrayList
<
Class
>()
{{
this
.
apiResponseClass
=
new
ArrayList
<
Class
>()
{{
add
(
BottomatikResponse
.
class
);
add
(
BottomatikResponse
.
class
);
add
(
ComedmusResponse
.
class
);
add
(
ReservationResponse
.
class
);
add
(
ReservationResponse
.
class
);
}};
}};
this
.
scannerView
=
new
ZXingScannerView
(
QRCodeReaderActivity
.
this
)
{
this
.
scannerView
=
new
ZXingScannerView
(
QRCodeReaderActivity
.
this
)
{
@Override
@Override
protected
IViewFinder
createViewFinderView
(
Context
context
)
{
protected
IViewFinder
createViewFinderView
(
Context
context
)
{
...
@@ -108,13 +113,49 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
...
@@ -108,13 +113,49 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
@Override
@Override
public
void
onIdentification
(
final
String
badgeId
)
{
public
void
onIdentification
(
final
String
badgeId
)
{
this
.
scannerView
.
stopCamera
();
this
.
scannerView
.
stopCamera
();
/*
dialog.infoDialog(QRCodeReaderActivity.this, "Badge", badgeId, new DialogInterface.OnClickListener() {
dialog.infoDialog(QRCodeReaderActivity.this, "Badge", badgeId, new DialogInterface.OnClickListener() {
@Override
@Override
public void onClick(DialogInterface dialog, int which) {
public void onClick(DialogInterface dialog, int which) {
resumeReading();
resumeReading();
}
}
});
});
*/
new
Thread
()
{
@Override
public
void
run
()
{
Integer
apiIndex
=
2
;
GingerResponse
gingerResponse
=
null
;
if
(
apiNeedGinger
.
get
(
apiIndex
))
{
try
{
ginger
.
getInfoFromBadge
(
badgeId
);
Thread
.
sleep
(
100
);
gingerResponse
=
new
ObjectMapper
().
readValue
(
ginger
.
getRequest
().
getResponse
(),
GingerResponse
.
class
);
}
catch
(
final
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
e
.
getMessage
());
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
infoDialog
(
QRCodeReaderActivity
.
this
,
getString
(
R
.
string
.
qrcode_reading
),
e
.
getMessage
(),
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
resumeReading
();
}
});
}
});
return
;
}
}
handleAPI
(
gingerResponse
.
getLogin
(),
apiIndex
,
gingerResponse
.
getBadge_uid
(),
false
);
}
}.
start
();
}
}
protected
void
resumeReading
()
{
protected
void
resumeReading
()
{
...
@@ -185,53 +226,65 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
...
@@ -185,53 +226,65 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
}
}
}
}
runOnUiThread
(
new
Runnable
()
{
handleAPI
(
qrCodeResponse
.
getId
(),
apiIndex
,
gingerResponse
==
null
?
null
:
gingerResponse
.
getBadge_uid
(),
true
);
@Override
}
public
void
run
()
{
}.
start
();
dialog
.
changeLoading
(
getString
(
R
.
string
.
getting_informations_from
)
+
" "
+
apiName
.
get
(
apiIndex
));
}
}
});
protected
void
handleAPI
(
final
String
info
,
final
Integer
apiIndex
,
final
String
badgeId
,
final
boolean
byQRCode
)
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
changeLoading
(
getString
(
R
.
string
.
getting_informations_from
)
+
" "
+
apiName
.
get
(
apiIndex
));
}
});
API
api
=
new
API
(
QRCodeReaderActivity
.
this
,
apiName
.
get
(
apiIndex
),
apiUrl
.
get
(
apiIndex
));
API
api
=
new
API
(
QRCodeReaderActivity
.
this
,
apiName
.
get
(
apiIndex
),
apiUrl
.
get
(
apiIndex
));
if
(
apiNeedKey
.
get
(
apiIndex
))
if
(
apiNeedKey
.
get
(
apiIndex
))
api
.
setKey
(
sharedPreferences
.
getString
(
"key_"
+
apiName
.
get
(
apiIndex
),
""
));
api
.
setKey
(
sharedPreferences
.
getString
(
"key_"
+
apiName
.
get
(
apiIndex
),
""
));
Object
apiResponse
;
Object
apiResponse
;
try
{
try
{
api
.
getInfosFromId
(
qrCodeResponse
.
getId
());
if
(
byQRCode
)
Thread
.
sleep
(
100
);
api
.
getInfosFromId
(
info
);
else
api
.
getInfosFromUsername
(
info
);
Thread
.
sleep
(
100
);
apiResponse
=
new
ObjectMapper
().
readValue
(
api
.
getRequest
().
getResponse
(),
apiResponseClass
.
get
(
apiIndex
));
apiResponse
=
new
ObjectMapper
().
readValue
(
api
.
getRequest
().
getResponse
(),
apiResponseClass
.
get
(
apiIndex
));
if
(
api
.
getRequest
().
getJSONResponse
().
has
(
"type"
)
&&
api
.
getRequest
().
getJSONResponse
().
get
(
"type"
).
textValue
().
equals
(
"error"
)
&&
api
.
getRequest
().
getJSONResponse
().
has
(
"message"
))
if
(
api
.
getRequest
().
getJSONResponse
().
has
(
"type"
)
&&
api
.
getRequest
().
getJSONResponse
().
get
(
"type"
).
textValue
().
equals
(
"error"
)
&&
api
.
getRequest
().
getJSONResponse
().
has
(
"message"
))
throw
new
Exception
(
api
.
getRequest
().
getJSONResponse
().
get
(
"message"
).
textValue
());
throw
new
Exception
(
api
.
getRequest
().
getJSONResponse
().
get
(
"message"
).
textValue
());
}
}
catch
(
final
Exception
e
)
{
catch
(
final
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
e
.
getMessage
());
Log
.
e
(
LOG_TAG
,
e
.
getMessage
());
runOnUiThread
(
new
Runnable
()
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
infoDialog
(
QRCodeReaderActivity
.
this
,
getString
(
R
.
string
.
qrcode_reading
),
e
.
getMessage
(),
new
DialogInterface
.
OnClickListener
()
{
@Override
@Override
public
void
run
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
dialog
.
infoDialog
(
QRCodeReaderActivity
.
this
,
getString
(
R
.
string
.
qrcode_reading
),
e
.
getMessage
(),
new
DialogInterface
.
OnClickListener
()
{
resumeReading
();
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
resumeReading
();
}
});
}
}
});
});
return
;
}
}
});
if
(
apiIndex
==
0
)
return
;
payWithBottomatik
(
api
,
(
BottomatikResponse
)
apiResponse
,
gingerResponse
.
getBadge_uid
());
}
else
if
(
apiIndex
==
1
)
{
checkReservation
(
api
,
(
ComedmusResponse
)
apiResponse
);
switch
(
apiIndex
)
{
}
case
0
:
}
payWithBottomatik
(
api
,
(
BottomatikResponse
)
apiResponse
,
badgeId
);
}.
start
();
break
;
case
1
:
case
2
:
checkReservation
(
api
,
(
ReservationResponse
)
apiResponse
);
break
;
}
}
}
public
void
payWithBottomatik
(
final
API
api
,
final
BottomatikResponse
bottomatikResponse
,
final
String
badgeId
)
{
public
void
payWithBottomatik
(
final
API
api
,
final
BottomatikResponse
bottomatikResponse
,
final
String
badgeId
)
{
...
@@ -472,17 +525,17 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
...
@@ -472,17 +525,17 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
}
}
}
}
protected
void
checkReservation
(
final
API
api
,
final
ComedmusResponse
comedmus
Response
)
{
protected
void
checkReservation
(
final
API
api
,
final
ReservationResponse
reservation
Response
)
{
long
currentTimestamp
=
(
System
.
currentTimeMillis
()
/
1000
);
long
currentTimestamp
=
(
System
.
currentTimeMillis
()
/
1000
);
Log
.
d
(
LOG_TAG
,
"Current time: "
+
currentTimestamp
);
Log
.
d
(
LOG_TAG
,
"Current time: "
+
currentTimestamp
);
if
(
currentTimestamp
<
comedmus
Response
.
getCreation_date
())
{
if
(
currentTimestamp
<
reservation
Response
.
getCreation_date
())
{
runOnUiThread
(
new
Runnable
()
{
runOnUiThread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
QRCodeReaderActivity
.
this
);
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
QRCodeReaderActivity
.
this
);
alertDialogBuilder
alertDialogBuilder
.
setTitle
(
getString
(
R
.
string
.
reservation_number
)
+
comedmus
Response
.
getReservation_id
())
.
setTitle
(
getString
(
R
.
string
.
reservation_number
)
+
reservation
Response
.
getReservation_id
())
.
setMessage
(
getString
(
R
.
string
.
ticket_not_created_yet
))
.
setMessage
(
getString
(
R
.
string
.
ticket_not_created_yet
))
.
setCancelable
(
false
)
.
setCancelable
(
false
)
.
setPositiveButton
(
R
.
string
.
ok
,
new
DialogInterface
.
OnClickListener
()
{
.
setPositiveButton
(
R
.
string
.
ok
,
new
DialogInterface
.
OnClickListener
()
{
...
@@ -494,7 +547,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
...
@@ -494,7 +547,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
.
setNeutralButton
(
R
.
string
.
more
,
new
DialogInterface
.
OnClickListener
()
{
.
setNeutralButton
(
R
.
string
.
more
,
new
DialogInterface
.
OnClickListener
()
{
@Override
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
seeReservation
(
api
,
comedmus
Response
);
seeReservation
(
api
,
reservation
Response
);
}
}
});
});
...
@@ -506,13 +559,13 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
...
@@ -506,13 +559,13 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
return
;
return
;
}
}
if
(
currentTimestamp
>
comedmus
Response
.
getExpires_at
())
{
if
(
currentTimestamp
>
reservation
Response
.
getExpires_at
())
{
runOnUiThread
(
new
Runnable
()
{
runOnUiThread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
QRCodeReaderActivity
.
this
);
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
QRCodeReaderActivity
.
this
);
alertDialogBuilder
alertDialogBuilder
.
setTitle
(
getString
(
R
.
string
.
reservation_number
)
+
comedmus
Response
.
getReservation_id
())
.
setTitle
(
getString
(
R
.
string
.
reservation_number
)
+
reservation
Response
.
getReservation_id
())
.
setMessage
(
getString
(
R
.
string
.
ticket_expired
))
.
setMessage
(
getString
(
R
.
string
.
ticket_expired
))
.
setCancelable
(
false
)
.
setCancelable
(
false
)
.
setPositiveButton
(
R
.
string
.
ok
,
new
DialogInterface
.
OnClickListener
()
{
.
setPositiveButton
(
R
.
string
.
ok
,
new
DialogInterface
.
OnClickListener
()
{
...
@@ -524,7 +577,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
...
@@ -524,7 +577,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
.
setNeutralButton
(
R
.
string
.
more
,
new
DialogInterface
.
OnClickListener
()
{
.
setNeutralButton
(
R
.
string
.
more
,
new
DialogInterface
.
OnClickListener
()
{
@Override
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
seeReservation
(
api
,
comedmus
Response
);
seeReservation
(
api
,
reservation
Response
);
}
}
});
});
...
@@ -539,24 +592,24 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
...
@@ -539,24 +592,24 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
runOnUiThread
(
new
Runnable
()
{
runOnUiThread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
seeReservation
(
api
,
comedmus
Response
);
seeReservation
(
api
,
reservation
Response
);
}
}
});
});
}
}
protected
void
seeReservation
(
final
API
api
,
final
ComedmusResponse
comedmus
Response
)
{
protected
void
seeReservation
(
final
API
api
,
final
ReservationResponse
reservation
Response
)
{
final
View
keyView
=
getLayoutInflater
().
inflate
(
R
.
layout
.
dialog_reservation_info
,
null
);
final
View
keyView
=
getLayoutInflater
().
inflate
(
R
.
layout
.
dialog_reservation_info
,
null
);
final
TextView
nameText
=
keyView
.
findViewById
(
R
.
id
.
text_name
);
final
TextView
nameText
=
keyView
.
findViewById
(
R
.
id
.
text_name
);
final
TextView
seanceText
=
keyView
.
findViewById
(
R
.
id
.
text_seance
);
final
TextView
seanceText
=
keyView
.
findViewById
(
R
.
id
.
text_seance
);
final
TextView
priceText
=
keyView
.
findViewById
(
R
.
id
.
text_price
);
final
TextView
priceText
=
keyView
.
findViewById
(
R
.
id
.
text_price
);
nameText
.
setText
(
comedmus
Response
.
getUsername
());
nameText
.
setText
(
reservation
Response
.
getUsername
());
seanceText
.
setText
(
comedmus
Response
.
getSeance
());
seanceText
.
setText
(
reservation
Response
.
getSeance
());
priceText
.
setText
(
comedmus
Response
.
getType
());
priceText
.
setText
(
reservation
Response
.
getType
());
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
QRCodeReaderActivity
.
this
);
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
QRCodeReaderActivity
.
this
);
alertDialogBuilder
alertDialogBuilder
.
setTitle
(
getString
(
R
.
string
.
reservation_number
)
+
comedmus
Response
.
getReservation_id
())
.
setTitle
(
getString
(
R
.
string
.
reservation_number
)
+
reservation
Response
.
getReservation_id
())
.
setView
(
keyView
)
.
setView
(
keyView
)
.
setCancelable
(
false
)
.
setCancelable
(
false
)
.
setPositiveButton
(
R
.
string
.
register
,
new
DialogInterface
.
OnClickListener
()
{
.
setPositiveButton
(
R
.
string
.
register
,
new
DialogInterface
.
OnClickListener
()
{
...
@@ -565,7 +618,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
...
@@ -565,7 +618,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
@Override
@Override
public
void
run
()
{
public
void
run
()
{
try
{
try
{
api
.
validate
(
comedmus
Response
.
getId
());
api
.
validate
(
reservation
Response
.
getId
());
Thread
.
sleep
(
100
);
Thread
.
sleep
(
100
);
runOnUiThread
(
new
Runnable
()
{
runOnUiThread
(
new
Runnable
()
{
...
...
app/src/main/java/fr/utc/simde/jessy/responses/QRCodeResponse.java
View file @
f102ce04
...
@@ -12,6 +12,10 @@ public class QRCodeResponse {
...
@@ -12,6 +12,10 @@ public class QRCodeResponse {
protected
String
id
;
protected
String
id
;
protected
String
system
;
protected
String
system
;
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
void
setSystem
(
String
system
)
{
this
.
system
=
system
;
}
public
String
getUsername
()
{
return
this
.
username
;
}
public
String
getUsername
()
{
return
this
.
username
;
}
public
String
getId
()
{
return
this
.
id
;
}
public
String
getId
()
{
return
this
.
id
;
}
public
String
getSystem
()
{
return
this
.
system
;
}
public
String
getSystem
()
{
return
this
.
system
;
}
...
...
app/src/main/java/fr/utc/simde/jessy/responses/
Comedmus
Response.java
→
app/src/main/java/fr/utc/simde/jessy/responses/
Reservation
Response.java
View file @
f102ce04
...
@@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
...
@@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
* Created by Samy on 10/11/2017.
* Created by Samy on 10/11/2017.
*/
*/
public
class
Comedmus
Response
extends
APIResponse
{
public
class
Reservation
Response
extends
APIResponse
{
protected
Integer
reservation_id
;
protected
Integer
reservation_id
;
protected
String
seance
;
protected
String
seance
;
...
...
app/src/main/res/layout/dialog_reservation_info.xml
View file @
f102ce04
...
@@ -55,7 +55,7 @@
...
@@ -55,7 +55,7 @@
android:layout_width=
"100dp"
android:layout_width=
"100dp"
android:textColor=
"#000000"
android:textColor=
"#000000"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/
pric
e"
/>
android:text=
"@string/
typ
e"
/>
<TextView
<TextView
android:id=
"@+id/text_price"
android:id=
"@+id/text_price"
...
...
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