Added checks on network status to data sharing status area

This commit is contained in:
Graham Jones
2022-02-01 22:40:05 +00:00
parent d2874cc031
commit 87088c63b9
4 changed files with 55 additions and 31 deletions

View File

@@ -574,12 +574,32 @@ public class MainActivity extends AppCompatActivity {
if (mConnection.mSdServer.mLogData) {
if (mConnection.mSdServer.mLogDataRemote) {
if (mConnection.mSdServer.mLm.mWac.isLoggedIn()) {
if (!mConnection.mSdServer.mLogDataRemoteMobile) {
Log.v(TAG,"mLogDataRemoteMobile="+mConnection.mSdServer.mLogDataRemoteMobile);
Log.v(TAG,"mUtil.isMobileDataActive="+mUtil.isMobileDataActive());
if (mUtil.isMobileDataActive()) {
tv = (TextView) findViewById(R.id.remoteDbTv);
tv.setText(getString(R.string.data_sharing_status)
+ ": "
+ getString(R.string.not_updating_mobile));
tv.setBackgroundColor(warnColour);
tv.setTextColor(warnTextColour);
} else {
tv = (TextView) findViewById(R.id.remoteDbTv);
tv.setText(getString(R.string.data_sharing_status)
+ ": "
+ getString(R.string.data_sharing_setup_ok));
tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
}
} else {
tv = (TextView) findViewById(R.id.remoteDbTv);
tv.setText(getString(R.string.data_sharing_status)
+ ": "
+ getString(R.string.data_sharing_setup_ok));
tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
}
} else {
tv = (TextView) findViewById(R.id.remoteDbTv);
tv.setText(getString(R.string.data_sharing_status)

View File

@@ -136,7 +136,7 @@ public class SdServer extends Service implements SdDataReceiver {
private boolean mLogAlarms = true;
public boolean mLogData = false;
public boolean mLogDataRemote = false;
private boolean mLogDataRemoteMobile = false;
public boolean mLogDataRemoteMobile = false;
private String mAuthToken = null;
private long mEventDuration = 120; // event duration in seconds - uploads datapoints that cover this time range centred on the event time.
public long mDataRetentionPeriod = 1; // Prunes the local db so it only retains data younger than this duration (in days)

View File

@@ -52,6 +52,7 @@ public class WebApiConnection {
/**
* Attempt to authenticate with the web API using user name uname and password passwd. Calls function callback with either
* the authentication token on success or null on failure.
*
* @param uname - user name
* @param passwd - password
* @param callback - call back function callback(String retVal)
@@ -270,6 +271,7 @@ public class WebApiConnection {
/**
* Retrieve all events accessible to the logged in user, and pass them to the callback function as a JSONObject
*
* @param callback
* @return true on success or false on failure to initiate the request.
*/
@@ -304,6 +306,7 @@ public class WebApiConnection {
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//if ((error != null) && (error.networkResponse != null) && (error.networkResponse.data != null)) {
if (error != null) {
String responseBody = new String(error.networkResponse.data);
Log.e(TAG, "getEvents(): Error: " + error.toString() + ", message:" + error.getMessage() + ", Response Code:" + error.networkResponse.statusCode + ", Response: " + responseBody);
@@ -349,7 +352,8 @@ public class WebApiConnection {
int reqMethod;
String urlStr;
if (eventId != -1) {
Log.v(TAG,"updateEvent() - found eventId "+eventId+", Updating event record");urlStr = mUrlBase + "/api/events/"+eventId+"/";
Log.v(TAG, "updateEvent() - found eventId " + eventId + ", Updating event record");
urlStr = mUrlBase + "/api/events/" + eventId + "/";
Log.v(TAG, "urlStr=" + urlStr);
reqMethod = Request.Method.PUT;
} else {
@@ -423,8 +427,6 @@ public class WebApiConnection {
}
public boolean createDatapoint(JSONObject dataObj, int eventId, Consumer<String> callback) {
Log.v(TAG, "createDatapoint()");
// Create a new event in the remote database, based on the provided parameters.
@@ -513,6 +515,7 @@ public class WebApiConnection {
* Calls the specified callback function, passing a JSONObject as a parameter when the data has been received and parsed.
* Note it uses a Consumer callback function to avoid having to create another interface
* - see https://medium.com/@pra4mesh/callback-function-in-java-20fa48b27797
*
* @return true if request sent successfully or else false.
*/
public boolean getEventTypes(Consumer<JSONObject> callback) {

View File

@@ -338,4 +338,5 @@
<string name="data_sharing_setup_ok">Data Sharing Setup OK</string>
<string name="please_confirm_seizure_events">Please Check your Shared Seizure Events</string>
<string name="data_sharing_log_in">Data Sharing Log-In</string>
<string name="not_updating_mobile">Not Updating using Mobile Internet</string>
</resources>