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
9895576a
Commit
9895576a
authored
Jan 12, 2018
by
Nastuzzi Samy
Browse files
FeteDesPartiels API update
Can read FeteDesPartiels info
parent
1b85d4b8
Changes
6
Hide whitespace changes
Inline
Side-by-side
.idea/modules.xml
View file @
9895576a
...
...
@@ -4,6 +4,7 @@
<modules>
<module
fileurl=
"file://$PROJECT_DIR$/PayUTC.iml"
filepath=
"$PROJECT_DIR$/PayUTC.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/app/app.iml"
filepath=
"$PROJECT_DIR$/app/app.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/jessy.iml"
filepath=
"$PROJECT_DIR$/jessy.iml"
/>
</modules>
</component>
</project>
\ No newline at end of file
app/src/main/java/fr/utc/simde/jessy/ArticleGroupActivity.java
View file @
9895576a
...
...
@@ -177,14 +177,14 @@ public abstract class ArticleGroupActivity extends BaseActivity {
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
ArticleGroupActivity
.
this
);
alertDialogBuilder
.
setTitle
(
R
.
string
.
configuration
)
.
setView
(
popupView
)
.
setCancelable
(
false
)
.
setNegativeButton
(
R
.
string
.
cancel
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialogInterface
,
int
id
)
{
config
.
setCanCancel
(
true
);
}
});
.
setTitle
(
R
.
string
.
configuration
)
.
setView
(
popupView
)
.
setCancelable
(
false
)
.
setNegativeButton
(
R
.
string
.
cancel
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialogInterface
,
int
id
)
{
config
.
setCanCancel
(
true
);
}
});
dialog
.
createDialog
(
alertDialogBuilder
);
}
...
...
app/src/main/java/fr/utc/simde/jessy/QRCodeReaderActivity.java
View file @
9895576a
...
...
@@ -11,8 +11,12 @@ import android.support.v7.app.AlertDialog;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.widget.AdapterView
;
import
android.widget.EditText
;
import
android.widget.LinearLayout
;
import
android.widget.ListView
;
import
android.widget.RadioButton
;
import
android.widget.Switch
;
import
android.widget.TextView
;
import
android.widget.Toast
;
...
...
@@ -27,6 +31,8 @@ import java.util.ArrayList;
import
java.util.List
;
import
fr.utc.simde.jessy.adapters.ListAdapater
;
import
fr.utc.simde.jessy.adapters.LocationsAdapter
;
import
fr.utc.simde.jessy.responses.APIResponse
;
import
fr.utc.simde.jessy.responses.ArticleResponse
;
import
fr.utc.simde.jessy.responses.BottomatikResponse
;
import
fr.utc.simde.jessy.responses.ReservationResponse
;
...
...
@@ -34,6 +40,7 @@ import fr.utc.simde.jessy.responses.GingerResponse;
import
fr.utc.simde.jessy.responses.QRCodeResponse
;
import
fr.utc.simde.jessy.tools.API
;
import
fr.utc.simde.jessy.tools.ExtendedScannerView
;
import
fr.utc.simde.jessy.tools.HTTPRequest
;
import
me.dm7.barcodescanner.core.IViewFinder
;
import
me.dm7.barcodescanner.zxing.ZXingScannerView
;
...
...
@@ -50,6 +57,10 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
protected
SharedPreferences
sharedPreferences
;
protected
String
badgeId
;
protected
Runnable
onIdentification
;
protected
List
<
String
>
apiName
;
protected
List
<
String
>
apiUrl
;
protected
List
<
Boolean
>
apiNeedKey
;
...
...
@@ -59,37 +70,41 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
@Override
public
void
onCreate
(
final
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
this
.
sharedPreferences
=
getSharedPreferences
(
"payutc"
,
Activity
.
MODE_PRIVATE
);
this
.
apiName
=
new
ArrayList
<
String
>()
{{
add
(
"bottomatik"
);
add
(
"comedmus"
);
add
(
"reservations"
);
add
(
"fetedespartiels"
);
}};
this
.
apiUrl
=
new
ArrayList
<
String
>()
{{
add
(
"https://picasso.bottomatik.com/bot/transactions/"
);
add
(
"https://www.lacomutc.fr/qr/"
+
sharedPreferences
.
getString
(
"key_"
+
apiName
.
get
(
1
),
"no_key"
)
+
"/"
);
add
(
"https://assos.utc.fr/simde/reservations/"
);
add
(
"http://assos.utc.fr/fetedespartiels/api/"
);
}};
this
.
apiNeedKey
=
new
ArrayList
<
Boolean
>()
{{
add
(
true
);
add
(
false
);
add
(
true
);
add
(
true
);
}};
this
.
apiNeedGinger
=
new
ArrayList
<
Boolean
>()
{{
add
(
true
);
add
(
false
);
add
(
true
);
add
(
true
);
}};
this
.
apiResponseClass
=
new
ArrayList
<
Class
>()
{{
add
(
BottomatikResponse
.
class
);
add
(
ReservationResponse
.
class
);
add
(
ReservationResponse
.
class
);
add
(
APIResponse
.
class
);
}};
this
.
scannerView
=
new
ZXingScannerView
(
QRCodeReaderActivity
.
this
)
{
...
...
@@ -98,10 +113,37 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
return
new
ExtendedScannerView
(
context
);
}
};
setContentView
(
this
.
scannerView
);
scannerView
.
setResultHandler
(
QRCodeReaderActivity
.
this
);
this
.
scannerView
.
setResultHandler
(
QRCodeReaderActivity
.
this
);
this
.
scannerView
.
startCamera
(
CAMERA_FACING_BACK
);
this
.
scannerView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
final
LayoutInflater
layoutInflater
=
LayoutInflater
.
from
(
QRCodeReaderActivity
.
this
);
final
View
popupView
=
layoutInflater
.
inflate
(
R
.
layout
.
dialog_tag
,
null
);
final
EditText
inputInfo
=
popupView
.
findViewById
(
R
.
id
.
input_info
);
final
RadioButton
buttonTag
=
popupView
.
findViewById
(
R
.
id
.
radio_tag
);
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
QRCodeReaderActivity
.
this
);
alertDialogBuilder
.
setTitle
(
R
.
string
.
getting_informations_from
)
.
setView
(
popupView
)
.
setPositiveButton
(
R
.
string
.
ok
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialogInterface
,
int
i
)
{
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
handleAPI
(
inputInfo
.
getText
().
toString
(),
3
,
null
,
buttonTag
.
isChecked
());
}
}).
start
();
}
})
.
setCancelable
(
true
);
}
});
setContentView
(
this
.
scannerView
);
}
@Override
...
...
@@ -114,42 +156,49 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
@Override
public
void
onIdentification
(
final
String
badgeId
)
{
this
.
scannerView
.
stopCamera
();
if
(
this
.
onIdentification
==
null
)
{
this
.
scannerView
.
stopCamera
();
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
());
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
();
}
});
}
});
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
;
return
;
}
}
}
handleAPI
(
gingerResponse
.
getLogin
(),
apiIndex
,
gingerResponse
,
false
);
}
}.
start
();
handleAPI
(
gingerResponse
.
getLogin
(),
apiIndex
,
gingerResponse
,
false
);
}
}.
start
();
}
else
{
this
.
badgeId
=
badgeId
;
this
.
onIdentification
.
run
();
this
.
onIdentification
=
null
;
}
}
protected
void
resumeReading
()
{
...
...
@@ -204,19 +253,21 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
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
();
}
});
}
});
if
(
ginger
.
getRequest
().
getResponseCode
()
!=
404
)
{
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
;
return
;
}
}
}
...
...
@@ -233,7 +284,7 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
}
});
API
api
=
new
API
(
QRCodeReaderActivity
.
this
,
apiName
.
get
(
apiIndex
),
apiUrl
.
get
(
apiIndex
));
final
API
api
=
new
API
(
QRCodeReaderActivity
.
this
,
apiName
.
get
(
apiIndex
),
apiUrl
.
get
(
apiIndex
));
if
(
apiNeedKey
.
get
(
apiIndex
))
api
.
setKey
(
sharedPreferences
.
getString
(
"key_"
+
apiName
.
get
(
apiIndex
),
""
));
...
...
@@ -254,17 +305,70 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
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
()
{
if
(
api
.
getRequest
().
getResponseCode
()
==
410
)
{
try
{
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"
))
throw
new
Exception
(
api
.
getRequest
().
getJSONResponse
().
get
(
"message"
).
textValue
());
}
catch
(
final
Exception
e1
)
{
Log
.
e
(
LOG_TAG
,
e
.
getMessage
());
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
resumeReading
();
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
;
}
});
final
APIResponse
finalApiResponse
=
(
APIResponse
)
apiResponse
;
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
QRCodeReaderActivity
.
this
);
alertDialogBuilder
.
setTitle
(
getString
(
R
.
string
.
reservation_number
)
+
finalApiResponse
.
getId
())
.
setMessage
(
getString
(
R
.
string
.
ticket_validated
))
.
setCancelable
(
false
)
.
setPositiveButton
(
R
.
string
.
ok
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
resumeReading
();
}
})
.
setNeutralButton
(
R
.
string
.
more
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
seeInfo
(
api
,
(
APIResponse
)
finalApiResponse
,
gingerResponse
);
}
});
dialog
.
createDialog
(
alertDialogBuilder
);
((
Vibrator
)
getSystemService
(
QRCodeReaderActivity
.
VIBRATOR_SERVICE
)).
vibrate
(
500
);
}
});
}
else
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
;
}
...
...
@@ -278,6 +382,9 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
case
2
:
checkReservation
(
api
,
(
ReservationResponse
)
apiResponse
,
gingerResponse
);
break
;
case
3
:
seeInfo
(
api
,
(
APIResponse
)
apiResponse
,
gingerResponse
);
break
;
}
}
...
...
@@ -668,5 +775,135 @@ public class QRCodeReaderActivity extends BaseActivity implements ZXingScannerVi
dialog
.
createDialog
(
alertDialogBuilder
);
}
protected
void
seeInfo
(
final
API
api
,
final
APIResponse
apiResponse
,
final
GingerResponse
gingerResponse
)
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
final
View
keyView
=
getLayoutInflater
().
inflate
(
R
.
layout
.
dialog_api_info
,
null
);
final
TextView
nameText
=
keyView
.
findViewById
(
R
.
id
.
text_name
);
final
TextView
typeText
=
keyView
.
findViewById
(
R
.
id
.
text_price
);
final
TextView
adultText
=
keyView
.
findViewById
(
R
.
id
.
text_adult
);
final
TextView
contributerText
=
keyView
.
findViewById
(
R
.
id
.
text_cotisant
);
nameText
.
setText
(
apiResponse
.
getUsername
());
typeText
.
setText
(
apiResponse
.
getType
());
if
(
gingerResponse
==
null
)
((
LinearLayout
)
keyView
.
findViewById
(
R
.
id
.
more_info
)).
setVisibility
(
View
.
GONE
);
else
{
if
(
gingerResponse
.
getIs_adulte
())
adultText
.
setText
(
getString
(
R
.
string
.
yes
));
else
{
adultText
.
setText
(
getString
(
R
.
string
.
no
));
adultText
.
setTextColor
(
Color
.
RED
);
}
if
(
gingerResponse
.
getIs_adulte
())
contributerText
.
setText
(
getString
(
R
.
string
.
yes
));
else
{
contributerText
.
setText
(
getString
(
R
.
string
.
no
));
contributerText
.
setTextColor
(
Color
.
RED
);
}
}
final
AlertDialog
.
Builder
alertDialogBuilder
=
new
AlertDialog
.
Builder
(
QRCodeReaderActivity
.
this
);
alertDialogBuilder
.
setTitle
(
getString
(
R
.
string
.
reservation_number
)
+
apiResponse
.
getId
())
.
setView
(
keyView
)
.
setCancelable
(
false
)
.
setPositiveButton
(
R
.
string
.
validate
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
final
DialogInterface
dialogInterface
,
int
id
)
{
dialog
.
startLoading
(
QRCodeReaderActivity
.
this
,
getResources
().
getString
(
R
.
string
.
paiement
),
getResources
().
getString
(
R
.
string
.
ticket_in_validation
));
new
Thread
()
{
@Override
public
void
run
()
{
try
{
api
.
validate
(
apiResponse
.
getId
());
Thread
.
sleep
(
100
);
/*
if (api.getRequest().getJSONResponse().has("command")) {
onIdentification = new Runnable() {
@Override
public void run() {
dialog.changeLoading("Création du compte");
new Thread() {
@Override
public void run() {
try {
HTTPRequest httpRequest = new HTTPRequest("http://assos.utc.fr/simde/ginger/" + api.getRequest().getJSONResponse().get("isAdult").intValue() + "/" + badgeId + "?app_key=bebesamy");
httpRequest.get();
Thread.sleep(100);
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.stopLoading();
Toast.makeText(QRCodeReaderActivity.this, getString(R.string.ticket_validated), Toast.LENGTH_LONG).show();
resumeReading();
}
});
} catch (final Exception e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.e(LOG_TAG, "error: " + e.getMessage());
dialog.errorDialog(QRCodeReaderActivity.this, getString(R.string.qrcode_reading), e.getMessage());
resumeReading();
}
});
}
}
}.start();
}
};
runOnUiThread(new Runnable() {
@Override
public void run() {
dialog.changeLoading("Il est nécessaire de badger une nouvelle carte !");
}
});
} else {*/
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dialog
.
stopLoading
();
Toast
.
makeText
(
QRCodeReaderActivity
.
this
,
getString
(
R
.
string
.
ticket_validated
),
Toast
.
LENGTH_LONG
).
show
();
resumeReading
();
}
});
//}
}
catch
(
final
Exception
e
)
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
Log
.
e
(
LOG_TAG
,
"error: "
+
e
.
getMessage
());
dialog
.
errorDialog
(
QRCodeReaderActivity
.
this
,
getString
(
R
.
string
.
qrcode_reading
),
e
.
getMessage
());
resumeReading
();
}
});
}
}
}.
start
();
}
})
.
setNegativeButton
(
R
.
string
.
ok
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
resumeReading
();
}
});
dialog
.
createDialog
(
alertDialogBuilder
);
}
});
}
}
app/src/main/res/layout/dialog_api_info.xml
0 → 100644
View file @
9895576a
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"25dp"
android:layout_marginRight=
"25dp"
android:orientation=
"horizontal"
>
<TextView
android:layout_width=
"100dp"
android:textColor=
"#000000"
android:layout_height=
"wrap_content"
android:text=
"@string/lastname"
/>
<TextView
android:id=
"@+id/text_name"
android:textColor=
"#000000"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"25dp"
android:layout_marginRight=
"25dp"
android:orientation=
"horizontal"
>
<TextView
android:layout_width=
"100dp"
android:textColor=
"#000000"
android:layout_height=
"wrap_content"
android:text=
"@string/type"
/>
<TextView
android:id=
"@+id/text_price"
android:textColor=
"#000000"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
<LinearLayout
android:id=
"@+id/more_info"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"25dp"
android:layout_marginRight=
"25dp"
android:orientation=
"horizontal"
>
<TextView
android:layout_width=
"100dp"
android:textColor=
"#000000"
android:layout_height=
"wrap_content"
android:text=
"@string/adult"
/>
<TextView
android:id=
"@+id/text_adult"
android:textColor=
"#000000"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"25dp"
android:layout_marginRight=
"25dp"
android:orientation=
"horizontal"
>
<TextView
android:layout_width=
"100dp"
android:textColor=
"#000000"
android:layout_height=
"wrap_content"
android:text=
"@string/cotisant"
/>