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
60e86bd2
Commit
60e86bd2
authored
Oct 27, 2017
by
Nastuzzi Samy
Browse files
Cleaning
Move loading in Dialog class Better JSON management
parent
f103c9be
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/fr/utc/simde/payutc/FoundationListActivity.java
View file @
60e86bd2
...
...
@@ -4,6 +4,9 @@ import android.app.ProgressDialog;
import
android.os.Bundle
;
import
android.util.Log
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
fr.utc.simde.payutc.tools.HTTPRequest
;
/**
...
...
@@ -18,8 +21,7 @@ public class FoundationListActivity extends BaseActivity {
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_foundation_list
);
final
ProgressDialog
loading
=
ProgressDialog
.
show
(
FoundationListActivity
.
this
,
getString
(
R
.
string
.
nemopay_connection
),
getString
(
R
.
string
.
nemopay_authentification
),
true
);
loading
.
setCancelable
(
false
);
dialog
.
startLoading
(
FoundationListActivity
.
this
,
getString
(
R
.
string
.
nemopay_connection
),
getString
(
R
.
string
.
nemopay_authentification
));
new
Thread
()
{
@Override
public
void
run
()
{
...
...
@@ -34,11 +36,13 @@ public class FoundationListActivity extends BaseActivity {
@Override
public
void
run
()
{
HTTPRequest
request
=
nemopaySession
.
getRequest
();
loading
.
dismiss
();
dialog
.
stopLoading
();
try
{
if
(
request
.
getResponseCode
()
==
200
&&
request
.
isJsonResponse
())
return
;
// setFoundationList(request.getJsonResponse();
Log
.
d
(
LOG_TAG
,
"Liste acquise"
);
// setFoundationList(request.getJsonResponse();
else
dialog
.
errorDialog
(
getString
(
R
.
string
.
information_collection
),
getString
(
R
.
string
.
foundation_error_get_list
));
}
catch
(
Exception
e
)
{
...
...
app/src/main/java/fr/utc/simde/payutc/MainActivity.java
View file @
60e86bd2
...
...
@@ -97,8 +97,7 @@ public class MainActivity extends BaseActivity {
return
;
}
final
ProgressDialog
loading
=
ProgressDialog
.
show
(
MainActivity
.
this
,
getString
(
R
.
string
.
nemopay_connection
),
getString
(
R
.
string
.
nemopay_authentification
),
true
);
loading
.
setCancelable
(
false
);
dialog
.
startLoading
(
MainActivity
.
this
,
getString
(
R
.
string
.
nemopay_connection
),
getString
(
R
.
string
.
nemopay_authentification
));
new
Thread
()
{
@Override
public
void
run
()
{
...
...
@@ -112,7 +111,7 @@ public class MainActivity extends BaseActivity {
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
loading
.
dismiss
();
dialog
.
stopLoading
();
if
(
nemopaySession
.
isRegistered
())
{
SharedPreferences
.
Editor
editor
=
sharedPreferences
.
edit
();
...
...
@@ -134,10 +133,7 @@ public class MainActivity extends BaseActivity {
}
protected
void
connectWithCAS
(
final
String
username
,
final
String
password
)
throws
InterruptedException
{
dialog
.
dismiss
();
final
ProgressDialog
loading
=
ProgressDialog
.
show
(
MainActivity
.
this
,
getString
(
R
.
string
.
cas_connection
),
getString
(
R
.
string
.
cas_in_url
),
true
);
loading
.
setCancelable
(
false
);
dialog
.
startLoading
(
MainActivity
.
this
,
getString
(
R
.
string
.
cas_connection
),
getString
(
R
.
string
.
cas_in_url
));
new
Thread
()
{
@Override
public
void
run
()
{
...
...
@@ -159,11 +155,11 @@ public class MainActivity extends BaseActivity {
@Override
public
void
run
()
{
if
(
casConnexion
.
getUrl
().
equals
(
""
))
{
loading
.
dismiss
();
dialog
.
stopLoading
();
dialog
.
errorDialog
(
getString
(
R
.
string
.
cas_connection
),
getString
(
R
.
string
.
cas_error_url
));
}
else
loading
.
setMessage
(
getString
(
R
.
string
.
cas_in_connection
));
dialog
.
changeLoading
(
getString
(
R
.
string
.
cas_in_connection
));
}
});
...
...
@@ -181,9 +177,9 @@ public class MainActivity extends BaseActivity {
@Override
public
void
run
()
{
if
(
casConnexion
.
isConnected
())
loading
.
setMessage
(
getString
(
R
.
string
.
cas_in_service_adding
));
dialog
.
changeLoading
(
getString
(
R
.
string
.
cas_in_service_adding
));
else
{
loading
.
dismiss
();
dialog
.
stopLoading
();
dialog
.
errorDialog
(
getString
(
R
.
string
.
cas_connection
),
getString
(
R
.
string
.
cas_error_connection
));
}
}
...
...
@@ -202,11 +198,10 @@ public class MainActivity extends BaseActivity {
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
casConnexion
.
isServiceAdded
())
loading
.
setMessage
(
getString
(
R
.
string
.
nemopay_connection
));
dialog
.
changeLoading
(
getString
(
R
.
string
.
nemopay_connection
));
else
{
loading
.
dismiss
();
dialog
.
stopLoading
();
dialog
.
errorDialog
(
getString
(
R
.
string
.
cas_connection
),
getString
(
R
.
string
.
cas_error_service_adding
));
}
}
...
...
@@ -225,7 +220,7 @@ public class MainActivity extends BaseActivity {
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
loading
.
dismiss
();
dialog
.
stopLoading
();
if
(!
nemopaySession
.
isConnected
())
dialog
.
errorDialog
(
getString
(
R
.
string
.
cas_connection
),
getString
(
R
.
string
.
cas_error_service_linking
));
...
...
@@ -240,13 +235,10 @@ public class MainActivity extends BaseActivity {
}
protected
void
connectWithBadge
(
final
String
idBadge
,
final
String
pin
)
{
dialog
.
dismiss
();
if
(!
nemopaySession
.
isRegistered
()
||
nemopaySession
.
isConnected
())
return
;
final
ProgressDialog
loading
=
ProgressDialog
.
show
(
MainActivity
.
this
,
getString
(
R
.
string
.
badge_dialog
),
getString
(
R
.
string
.
badge_recognization
),
true
);
loading
.
setCancelable
(
false
);
dialog
.
startLoading
(
MainActivity
.
this
,
getString
(
R
.
string
.
badge_dialog
),
getString
(
R
.
string
.
badge_recognization
));
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
...
...
@@ -260,7 +252,7 @@ public class MainActivity extends BaseActivity {
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
loading
.
dismiss
();
dialog
.
stopLoading
();
try
{
if
(
nemopaySession
.
isConnected
())
...
...
app/src/main/java/fr/utc/simde/payutc/tools/Dialog.java
View file @
60e86bd2
package
fr.utc.simde.payutc.tools
;
import
android.app.Activity
;
import
android.app.ProgressDialog
;
import
android.content.Context
;
import
android.support.v7.app.AlertDialog
;
import
android.view.inputmethod.InputMethodManager
;
...
...
@@ -17,6 +18,7 @@ public class Dialog {
private
static
Activity
activity
;
private
static
AlertDialog
alertDialog
;
private
static
AlertDialog
.
Builder
alertDialogBuilder
;
private
static
ProgressDialog
loading
;
public
Dialog
(
final
Activity
activity
)
{
this
.
activity
=
activity
;
...
...
@@ -26,10 +28,14 @@ public class Dialog {
if
(
this
.
alertDialog
!=
null
)
this
.
alertDialog
.
dismiss
();
if
(
this
.
loading
!=
null
)
this
.
loading
.
dismiss
();
this
.
alertDialog
=
null
;
this
.
loading
=
null
;
}
public
Boolean
isShowing
()
{
return
this
.
alertDialog
!=
null
&&
this
.
alertDialog
.
isShowing
();
}
public
Boolean
isShowing
()
{
return
(
this
.
alertDialog
!=
null
&&
this
.
alertDialog
.
isShowing
()
)
||
(
this
.
loading
!=
null
&&
this
.
loading
.
isShowing
())
;
}
public
void
createDialog
()
{
createDialog
((
EditText
)
null
);
}
public
void
createDialog
(
AlertDialog
.
Builder
alertDialogBuilder
)
{
createDialog
(
alertDialogBuilder
,
null
);
}
...
...
@@ -77,4 +83,17 @@ public class Dialog {
createDialog
();
}
public
void
startLoading
(
Activity
activity
,
final
String
title
,
final
String
message
)
{
dismiss
();
this
.
loading
=
ProgressDialog
.
show
(
activity
,
title
,
message
,
true
,
false
);
}
public
void
changeLoading
(
final
String
message
)
{
this
.
loading
.
setMessage
(
message
);
}
public
void
stopLoading
()
{
this
.
loading
.
dismiss
();
this
.
loading
=
null
;
}
}
app/src/main/java/fr/utc/simde/payutc/tools/HTTPRequest.java
View file @
60e86bd2
...
...
@@ -6,6 +6,7 @@ package fr.utc.simde.payutc.tools;
import
android.util.Log
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
...
...
@@ -171,20 +172,24 @@ public class HTTPRequest {
this
.
response
=
builder
.
toString
();
}
public
JSONObject
getJsonResponse
()
throws
IOException
,
JSONException
{
return
new
JSONObject
(
response
);
}
public
String
getResponse
()
throws
IOException
{
return
response
;
}
public
Boolean
isJsonResponse
()
{
if
(
request
==
null
)
return
null
;
return
request
.
getContentType
()
==
"application/json"
;
}
public
JSONObject
getJsonResponse
()
throws
IOException
,
JSONException
{
try
{
new
JSONObject
(
response
);
return
new
JSONObject
(
response
);
}
catch
(
Exception
e
)
{
return
fal
se
;
return
new
JSONArray
(
respon
se
)
;
}
return
true
;
}
public
String
getResponse
()
throws
IOException
{
return
response
;
}
protected
String
args2String
(
Map
<
String
,
String
>
args
)
throws
UnsupportedEncodingException
{
return
args2String
(
args
,
false
);
}
protected
String
args2String
(
Map
<
String
,
String
>
args
,
Boolean
isGet
)
throws
UnsupportedEncodingException
{
String
data
=
""
;
...
...
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