Got remote events list working. Edit event still fails to update firebase with odd error about arrays not being supported...but we are not trying to send an array....
This commit is contained in:
@@ -159,10 +159,10 @@ public class EditEventActivity extends AppCompatActivity {
|
|||||||
mWac.getEvent(mEventId, new WebApiConnection.JSONObjectCallback() {
|
mWac.getEvent(mEventId, new WebApiConnection.JSONObjectCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(JSONObject eventObj) {
|
public void accept(JSONObject eventObj) {
|
||||||
Log.v(TAG, "onCreate.getEvent");
|
Log.v(TAG, "initialiseServiceConnection.getEvent");
|
||||||
if (eventObj != null) {
|
if (eventObj != null) {
|
||||||
mEventObj = eventObj;
|
mEventObj = eventObj;
|
||||||
Log.v(TAG, "onCreate.getEvent: eventObj=" + eventObj.toString());
|
Log.v(TAG, "initialiseServiceConnection.getEvent: eventObj=" + eventObj.toString());
|
||||||
updateUi();
|
updateUi();
|
||||||
// FIXME: modify updateUi to use mEventObj
|
// FIXME: modify updateUi to use mEventObj
|
||||||
} else {
|
} else {
|
||||||
@@ -198,9 +198,9 @@ public class EditEventActivity extends AppCompatActivity {
|
|||||||
try {
|
try {
|
||||||
if (mEventObj != null) {
|
if (mEventObj != null) {
|
||||||
tv = (TextView) findViewById(R.id.eventIdTv);
|
tv = (TextView) findViewById(R.id.eventIdTv);
|
||||||
tv.setText(String.valueOf(mEventObj.getLong("id")));
|
tv.setText(mEventId);
|
||||||
tv = (TextView) findViewById(R.id.eventAlarmStateTv);
|
tv = (TextView) findViewById(R.id.eventAlarmStateTv);
|
||||||
tv.setText(mEventObj.getString("alarmStateStr"));
|
tv.setText(mEventObj.getString("osdAlarmState"));
|
||||||
tv = (TextView) findViewById(R.id.eventNotsTv);
|
tv = (TextView) findViewById(R.id.eventNotsTv);
|
||||||
tv.setText(mEventObj.getString("desc"));
|
tv.setText(mEventObj.getString("desc"));
|
||||||
|
|
||||||
@@ -208,10 +208,11 @@ public class EditEventActivity extends AppCompatActivity {
|
|||||||
tv = (TextView) findViewById(R.id.eventDateTv);
|
tv = (TextView) findViewById(R.id.eventDateTv);
|
||||||
try {
|
try {
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||||
Date dataTime = dateFormat.parse(mEventObj.getString("dataTime"));
|
//Date dataTime = dateFormat.parse(mEventObj.getString("dataTime"));
|
||||||
|
Date dataTime = new Date(mEventObj.getLong("dataTime"));
|
||||||
dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
tv.setText(dateFormat.format(dataTime));
|
tv.setText(dateFormat.format(dataTime));
|
||||||
} catch (ParseException e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG,"updateUI: Error Parsing dataDate "+e.getLocalizedMessage());
|
Log.e(TAG,"updateUI: Error Parsing dataDate "+e.getLocalizedMessage());
|
||||||
tv.setText("---");
|
tv.setText("---");
|
||||||
}
|
}
|
||||||
@@ -283,12 +284,12 @@ public class EditEventActivity extends AppCompatActivity {
|
|||||||
TextView tv = (TextView)findViewById(R.id.eventNotsTv);
|
TextView tv = (TextView)findViewById(R.id.eventNotsTv);
|
||||||
try {
|
try {
|
||||||
mEventObj.put("desc",tv.getText());
|
mEventObj.put("desc",tv.getText());
|
||||||
|
mEventObj.put("id",mEventId); // Add event Id to event object manually because firestore does not include it by default.
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(TAG,"Error writing mEventObj: "+e.getMessage());
|
Log.e(TAG,"Error writing mEventObj: "+e.getMessage());
|
||||||
}
|
}
|
||||||
Log.v(TAG, "onOK() - eventObj="+mEventObj.toString());
|
Log.v(TAG, "onOK() - eventObj="+mEventObj.toString());
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mWac.updateEvent(mEventObj, new WebApiConnection.JSONObjectCallback() {
|
mWac.updateEvent(mEventObj, new WebApiConnection.JSONObjectCallback() {
|
||||||
@Override
|
@Override
|
||||||
@@ -307,7 +308,7 @@ public class EditEventActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG,"ERROR:"+e.getMessage());
|
Log.e(TAG,"onOK() - ERROR: "+e.getMessage()+" : " +e.toString());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
mUtil.showToast("Error Updating Event");
|
mUtil.showToast("Error Updating Event");
|
||||||
updateUi();
|
updateUi();
|
||||||
|
|||||||
@@ -792,14 +792,14 @@ public class LogManager {
|
|||||||
mCurrentEventLocalId = eventId;
|
mCurrentEventLocalId = eventId;
|
||||||
mWac.createEvent(eventAlarmStatus, eventDate, "", this::createEventCallback);
|
mWac.createEvent(eventAlarmStatus, eventDate, "", this::createEventCallback);
|
||||||
} else {
|
} else {
|
||||||
Log.v(TAG, "uploadSdData - no data to upload");
|
Log.v(TAG, "uploadSdData - no data to upload "); //(warnings="+warningsVal+")");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Mark the relevant member variables to show we are not currently doing an upload, so a new one can be
|
// Mark the relevant member variables to show we are not cuurrently doing an upload, so a new one can be
|
||||||
// started if necessary.
|
// started if necessary.
|
||||||
public void finishUpload() {
|
public void finishUpload() {
|
||||||
mCurrentEventRemoteId = null;
|
mCurrentEventRemoteId = null;
|
||||||
|
|||||||
@@ -11,9 +11,11 @@ import android.os.Bundle;
|
|||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
|
||||||
import androidx.core.view.MenuCompat;
|
import androidx.core.view.MenuCompat;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -219,14 +221,34 @@ public class LogManagerControlActivity extends AppCompatActivity {
|
|||||||
// A bit of a hack to display in reverse chronological order
|
// A bit of a hack to display in reverse chronological order
|
||||||
for (int i = eventsArray.length() - 1; i >= 0; i--) {
|
for (int i = eventsArray.length() - 1; i >= 0; i--) {
|
||||||
JSONObject eventObj = eventsArray.getJSONObject(i);
|
JSONObject eventObj = eventsArray.getJSONObject(i);
|
||||||
Long id = eventObj.getLong("id");
|
Log.v(TAG, "getRemoteEvents() - " + eventObj.toString());
|
||||||
int osdAlarmState = eventObj.getInt("osdAlarmState");
|
String id = null;
|
||||||
String dataTime = eventObj.getString("dataTime");
|
if (!eventObj.isNull("id")) {
|
||||||
String typeStr = eventObj.getString("type");
|
id = eventObj.getString("id");
|
||||||
String subType = eventObj.getString("subType");
|
}
|
||||||
String desc = eventObj.getString("desc");
|
int osdAlarmState = -1;
|
||||||
|
if (!eventObj.isNull("osdAlarmState")) {
|
||||||
|
osdAlarmState = eventObj.getInt("osdAlarmState");
|
||||||
|
}
|
||||||
|
String dataTime = "null";
|
||||||
|
if (!eventObj.isNull("dataTime")) {
|
||||||
|
dataTime = eventObj.getString("dataTime");
|
||||||
|
Log.v(TAG, "getRemoteEvents() - dataTime=" + dataTime);
|
||||||
|
}
|
||||||
|
String typeStr = "null";
|
||||||
|
if (!eventObj.isNull("type")) {
|
||||||
|
typeStr = eventObj.getString("type");
|
||||||
|
}
|
||||||
|
String subType = "null";
|
||||||
|
if (!eventObj.isNull("subType")) {
|
||||||
|
subType = eventObj.getString("subType");
|
||||||
|
}
|
||||||
|
String desc = "null";
|
||||||
|
if (!eventObj.isNull("desc")) {
|
||||||
|
desc = eventObj.getString("desc");
|
||||||
|
}
|
||||||
HashMap<String, String> eventHashMap = new HashMap<String, String>();
|
HashMap<String, String> eventHashMap = new HashMap<String, String>();
|
||||||
eventHashMap.put("id", String.valueOf(id));
|
eventHashMap.put("id", id);
|
||||||
eventHashMap.put("osdAlarmState", String.valueOf(osdAlarmState));
|
eventHashMap.put("osdAlarmState", String.valueOf(osdAlarmState));
|
||||||
eventHashMap.put("osdAlarmStateStr", mUtil.alarmStatusToString(osdAlarmState));
|
eventHashMap.put("osdAlarmStateStr", mUtil.alarmStatusToString(osdAlarmState));
|
||||||
eventHashMap.put("dataTime", dataTime);
|
eventHashMap.put("dataTime", dataTime);
|
||||||
@@ -249,7 +271,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
|
|
||||||
private void updateUi() {
|
private void updateUi() {
|
||||||
Log.i(TAG,"updateUi()");
|
Log.i(TAG, "updateUi()");
|
||||||
boolean stopUpdating = true;
|
boolean stopUpdating = true;
|
||||||
TextView tv;
|
TextView tv;
|
||||||
Button btn;
|
Button btn;
|
||||||
@@ -291,7 +313,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
|
|||||||
if (mRemoteEventsList != null) {
|
if (mRemoteEventsList != null) {
|
||||||
ListView lv = (ListView) findViewById(R.id.remoteEventsLv);
|
ListView lv = (ListView) findViewById(R.id.remoteEventsLv);
|
||||||
ListAdapter adapter = new RemoteEventsAdapter(LogManagerControlActivity.this, mRemoteEventsList, R.layout.log_entry_layout_remote,
|
ListAdapter adapter = new RemoteEventsAdapter(LogManagerControlActivity.this, mRemoteEventsList, R.layout.log_entry_layout_remote,
|
||||||
new String[]{"id","dataTime", "type", "subType", "osdAlarmStateStr", "desc"},
|
new String[]{"id", "dataTime", "type", "subType", "osdAlarmStateStr", "desc"},
|
||||||
new int[]{R.id.event_id_remote_tv, R.id.event_date_remote_tv, R.id.event_type_remote_tv, R.id.event_subtype_remote_tv,
|
new int[]{R.id.event_id_remote_tv, R.id.event_date_remote_tv, R.id.event_type_remote_tv, R.id.event_subtype_remote_tv,
|
||||||
R.id.event_alarmState_remote_tv, R.id.event_notes_remote_tv});
|
R.id.event_alarmState_remote_tv, R.id.event_notes_remote_tv});
|
||||||
lv.setAdapter(adapter);
|
lv.setAdapter(adapter);
|
||||||
@@ -335,7 +357,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
|
|||||||
boolean checked = ((RadioButton) view).isChecked();
|
boolean checked = ((RadioButton) view).isChecked();
|
||||||
|
|
||||||
// Check which radio button was clicked
|
// Check which radio button was clicked
|
||||||
switch(view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.local_data_rb:
|
case R.id.local_data_rb:
|
||||||
if (checked) {
|
if (checked) {
|
||||||
// Switch to the local data view
|
// Switch to the local data view
|
||||||
@@ -411,7 +433,6 @@ public class LogManagerControlActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
View.OnClickListener onAuth =
|
View.OnClickListener onAuth =
|
||||||
new View.OnClickListener() {
|
new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -504,7 +525,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
|
|||||||
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
|
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
|
||||||
Log.v(TAG, "onRemoteEventList Click() - Position=" + position + ", id=" + id);// Confirmation dialog based on: https://stackoverflow.com/a/12213536/2104584
|
Log.v(TAG, "onRemoteEventList Click() - Position=" + position + ", id=" + id);// Confirmation dialog based on: https://stackoverflow.com/a/12213536/2104584
|
||||||
HashMap<String, String> eventObj = (HashMap<String, String>) adapter.getItemAtPosition(position);
|
HashMap<String, String> eventObj = (HashMap<String, String>) adapter.getItemAtPosition(position);
|
||||||
Long eventId = Long.parseLong(eventObj.get("id"));
|
String eventId = eventObj.get("id");
|
||||||
Log.d(TAG, "onItemClickListener(): eventId=" + eventId + ", eventObj=" + eventObj);
|
Log.d(TAG, "onItemClickListener(): eventId=" + eventId + ", eventObj=" + eventObj);
|
||||||
Intent i = new Intent(getApplicationContext(), EditEventActivity.class);
|
Intent i = new Intent(getApplicationContext(), EditEventActivity.class);
|
||||||
i.putExtra("eventId", eventId);
|
i.putExtra("eventId", eventId);
|
||||||
@@ -588,9 +609,9 @@ public class LogManagerControlActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
View v = super.getView(position, convertView, parent);
|
View v = super.getView(position, convertView, parent);
|
||||||
Map<String, ?> dataItem = (Map<String,?>)getItem(position);
|
Map<String, ?> dataItem = (Map<String, ?>) getItem(position);
|
||||||
Log.v(TAG,"getView() "+dataItem.toString());
|
Log.v(TAG, "getView() " + dataItem.toString());
|
||||||
switch(dataItem.get("type").toString()) {
|
switch (dataItem.get("type").toString()) {
|
||||||
case "null":
|
case "null":
|
||||||
v.setBackgroundColor(Color.parseColor("#ffaaaa"));
|
v.setBackgroundColor(Color.parseColor("#ffaaaa"));
|
||||||
break;
|
break;
|
||||||
@@ -604,19 +625,23 @@ public class LogManagerControlActivity extends AppCompatActivity {
|
|||||||
// Convert date format to something more readable.
|
// Convert date format to something more readable.
|
||||||
TextView tv = (TextView) v.findViewById(R.id.event_date_remote_tv);
|
TextView tv = (TextView) v.findViewById(R.id.event_date_remote_tv);
|
||||||
try {
|
try {
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
//SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||||
Date dataTime = dateFormat.parse(dataItem.get("dataTime").toString());
|
//Date dataTime = dateFormat.parse(dataItem.get("dataTime").toString());
|
||||||
dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
|
Long tstamp = Long.parseLong((String) dataItem.get("dataTime"));
|
||||||
|
Date dataTime = new Date(tstamp);
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
|
||||||
tv.setText(dateFormat.format(dataTime));
|
tv.setText(dateFormat.format(dataTime));
|
||||||
} catch (ParseException e) {
|
} catch (NumberFormatException e) {
|
||||||
Log.e(TAG,"remoteEventsAdapter.getView: Error Parsing dataDate "+e.getLocalizedMessage());
|
Log.e(TAG, "remoteEventsAdapter.getView: Error Parsing dataDate " + e.getLocalizedMessage());
|
||||||
tv.setText("---");
|
tv.setText("---");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return(v);
|
return (v);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -631,7 +631,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
tv.setBackgroundColor(okColour);
|
tv.setBackgroundColor(okColour);
|
||||||
tv.setTextColor(okTextColour);
|
tv.setTextColor(okTextColour);
|
||||||
|
|
||||||
if (!mConnection.mSdServer.mLm.mWac.mServerConnectionOk) {
|
if (!mConnection.mSdServer.mLm.mWac.checkServerConnection()) {
|
||||||
// Problem connecting to server
|
// Problem connecting to server
|
||||||
tv = (TextView) findViewById(R.id.remoteDbTv);
|
tv = (TextView) findViewById(R.id.remoteDbTv);
|
||||||
tv.setText(getString(R.string.data_sharing_status)
|
tv.setText(getString(R.string.data_sharing_status)
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ import java.text.DateFormat;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
@@ -67,16 +69,22 @@ public class WebApiConnection {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mQueue = Volley.newRequestQueue(context);
|
mQueue = Volley.newRequestQueue(context);
|
||||||
mUtil = new OsdUtil(mContext, new Handler());
|
mUtil = new OsdUtil(mContext, new Handler());
|
||||||
// Check if we are already logged in
|
loginToFirebase();
|
||||||
FirebaseAuth auth = FirebaseAuth.getInstance();
|
|
||||||
if (auth != null) {
|
|
||||||
Log.i(TAG, "Firebase Logged in OK");
|
|
||||||
mDb = FirebaseFirestore.getInstance();
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "Firebase not logged in");
|
|
||||||
mDb = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loginToFirebase() {
|
||||||
|
// Check if we are already logged in
|
||||||
|
FirebaseAuth auth = FirebaseAuth.getInstance();
|
||||||
|
mDb = FirebaseFirestore.getInstance();
|
||||||
|
if (auth != null) {
|
||||||
|
if (auth.getCurrentUser() != null) {
|
||||||
|
Log.i(TAG, "Firebase Logged in OK -" + auth.getCurrentUser().getDisplayName());
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Firebase not logged in - no current user");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Firebase not logged in");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
@@ -109,6 +117,12 @@ public class WebApiConnection {
|
|||||||
public boolean createEvent(final int osdAlarmState, final Date eventDate, final String eventDesc, StringCallback callback) {
|
public boolean createEvent(final int osdAlarmState, final Date eventDate, final String eventDesc, StringCallback callback) {
|
||||||
Log.v(TAG, "createEvent()");
|
Log.v(TAG, "createEvent()");
|
||||||
String userId = null;
|
String userId = null;
|
||||||
|
|
||||||
|
if (mDb == null) {
|
||||||
|
Log.w(TAG, "createEvent() - mDb is null - not doing anything");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (FirebaseAuth.getInstance().getCurrentUser() == null) {
|
if (FirebaseAuth.getInstance().getCurrentUser() == null) {
|
||||||
Log.e(TAG, "ERROR: createEvent() - not logged in");
|
Log.e(TAG, "ERROR: createEvent() - not logged in");
|
||||||
return false;
|
return false;
|
||||||
@@ -146,6 +160,10 @@ public class WebApiConnection {
|
|||||||
// calls function callback with a JSONObject representation of the event with id 'eventId'
|
// calls function callback with a JSONObject representation of the event with id 'eventId'
|
||||||
public boolean getEvent(String eventId, JSONObjectCallback callback) {
|
public boolean getEvent(String eventId, JSONObjectCallback callback) {
|
||||||
Log.v(TAG, "getEvent()");
|
Log.v(TAG, "getEvent()");
|
||||||
|
if (mDb == null) {
|
||||||
|
Log.w(TAG, "getEvent() - mDb is null - not doing anything");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
DocumentReference docRef = mDb.collection("Events").document(eventId);
|
DocumentReference docRef = mDb.collection("Events").document(eventId);
|
||||||
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
|
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
|
||||||
@@ -183,7 +201,13 @@ public class WebApiConnection {
|
|||||||
public boolean getEvents(JSONObjectCallback callback) {
|
public boolean getEvents(JSONObjectCallback callback) {
|
||||||
//Long eventId=Long.valueOf(285);
|
//Long eventId=Long.valueOf(285);
|
||||||
Log.v(TAG, "getEvents()");
|
Log.v(TAG, "getEvents()");
|
||||||
mDb.collection("Events")
|
if (mDb == null) {
|
||||||
|
Log.w(TAG, "getEvents() - mDb is null - not doing anything");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
|
||||||
|
mDb.collection("Events") //.where("userId", "==", userId)
|
||||||
|
.whereEqualTo("userId", userId)
|
||||||
.get()
|
.get()
|
||||||
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
|
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -192,14 +216,18 @@ public class WebApiConnection {
|
|||||||
try {
|
try {
|
||||||
JSONObject retObj = new JSONObject();
|
JSONObject retObj = new JSONObject();
|
||||||
JSONArray eventArray = new JSONArray();
|
JSONArray eventArray = new JSONArray();
|
||||||
|
Log.d(TAG, "getEvents() - returned " + task.getResult().size());
|
||||||
for (QueryDocumentSnapshot document : task.getResult()) {
|
for (QueryDocumentSnapshot document : task.getResult()) {
|
||||||
Log.d(TAG, document.getId() + " => " + document.getData());
|
Log.d(TAG, "getEvents() - " + document.getId() + " => " + document.getData());
|
||||||
eventArray.put(new JSONObject(document.getData()));
|
JSONObject eventObj = new JSONObject(document.getData());
|
||||||
|
// Add the event id into the event data because firebase does not include it as part of the document.
|
||||||
|
eventObj.put("id", document.getId());
|
||||||
|
eventArray.put(eventObj);
|
||||||
}
|
}
|
||||||
retObj.put("events", eventArray);
|
retObj.put("events", eventArray);
|
||||||
callback.accept(retObj);
|
callback.accept(retObj);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(TAG, "getEventTypes.onResponse(): Error: " + e.getMessage() + "," + e.toString());
|
Log.e(TAG, "getEvents.onResponse(): Error: " + e.getMessage() + "," + e.toString());
|
||||||
callback.accept(null);
|
callback.accept(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,10 +240,29 @@ public class WebApiConnection {
|
|||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, Object> jsonObjectToMap(JSONObject obj) {
|
||||||
|
try {
|
||||||
|
Map<String, Object> retMap = new HashMap<String, Object>();
|
||||||
|
for (Iterator<String> it = obj.keys(); it.hasNext(); ) {
|
||||||
|
String keyStr = it.next();
|
||||||
|
Log.v(TAG, "jsonObjecToMap()- keyStr=" + keyStr + ", obj=" + obj.get(keyStr));
|
||||||
|
retMap.put(keyStr, obj.get(keyStr));
|
||||||
|
}
|
||||||
|
return (retMap);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(TAG, "jsonObjectToMap() - Error Converting JSONObject" + obj.toString() + ": " + e.toString());
|
||||||
|
return (null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean updateEvent(final JSONObject eventObj, JSONObjectCallback callback) {
|
public boolean updateEvent(final JSONObject eventObj, JSONObjectCallback callback) {
|
||||||
String eventId;
|
String eventId;
|
||||||
Log.v(TAG, "updateEvent()");
|
Log.v(TAG, "updateEvent()");
|
||||||
|
if (mDb == null) {
|
||||||
|
Log.w(TAG, "updateEvent() - mDb is null - not doing anything");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
eventId = eventObj.getString("id");
|
eventId = eventObj.getString("id");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@@ -225,9 +272,12 @@ public class WebApiConnection {
|
|||||||
}
|
}
|
||||||
final String dataStr = eventObj.toString();
|
final String dataStr = eventObj.toString();
|
||||||
Log.v(TAG, "updateEvent - data=" + dataStr);
|
Log.v(TAG, "updateEvent - data=" + dataStr);
|
||||||
|
Map<String, Object> eventMap = jsonObjectToMap(eventObj);
|
||||||
|
Log.v(TAG, "updateEvent - map=" + eventMap.toString());
|
||||||
|
|
||||||
|
try {
|
||||||
DocumentReference docRef = mDb.collection("Events").document(eventId);
|
DocumentReference docRef = mDb.collection("Events").document(eventId);
|
||||||
docRef.update((Map<String, Object>) eventObj)
|
docRef.set(eventMap)
|
||||||
.addOnSuccessListener(new OnSuccessListener<Void>() {
|
.addOnSuccessListener(new OnSuccessListener<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Void aVoid) {
|
public void onSuccess(Void aVoid) {
|
||||||
@@ -248,6 +298,11 @@ public class WebApiConnection {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return (true);
|
return (true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "updateEvent() - ERROR: " + e.toString());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean createDatapoint(JSONObject dataObj, String eventId, StringCallback callback) {
|
public boolean createDatapoint(JSONObject dataObj, String eventId, StringCallback callback) {
|
||||||
@@ -268,7 +323,7 @@ public class WebApiConnection {
|
|||||||
}
|
}
|
||||||
Map<String, Object> datapoint = new HashMap<>();
|
Map<String, Object> datapoint = new HashMap<>();
|
||||||
datapoint.put("dataTime", dataTime);
|
datapoint.put("dataTime", dataTime);
|
||||||
datapoint.put("dataJSON",dataObj.toString());
|
datapoint.put("dataJSON", dataObj.toString());
|
||||||
datapoint.put("userId", userId);
|
datapoint.put("userId", userId);
|
||||||
datapoint.put("eventId", userId);
|
datapoint.put("eventId", userId);
|
||||||
|
|
||||||
@@ -293,7 +348,6 @@ public class WebApiConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the file containing the standard event types from the server.
|
* Retrieve the file containing the standard event types from the server.
|
||||||
* Calls the specified callback function, passing a JSONObject as a parameter when the data has been received and parsed.
|
* Calls the specified callback function, passing a JSONObject as a parameter when the data has been received and parsed.
|
||||||
@@ -302,6 +356,10 @@ public class WebApiConnection {
|
|||||||
*/
|
*/
|
||||||
public boolean getEventTypes(JSONObjectCallback callback) {
|
public boolean getEventTypes(JSONObjectCallback callback) {
|
||||||
Log.v(TAG, "getEventTypes()");
|
Log.v(TAG, "getEventTypes()");
|
||||||
|
if (mDb == null) {
|
||||||
|
Log.w(TAG, "getEventTypes() - mDb is null - not doing anything");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
mDb.collection("EventTypes")
|
mDb.collection("EventTypes")
|
||||||
.get()
|
.get()
|
||||||
@@ -311,12 +369,13 @@ public class WebApiConnection {
|
|||||||
if (task.isSuccessful()) {
|
if (task.isSuccessful()) {
|
||||||
try {
|
try {
|
||||||
JSONObject retObj = new JSONObject();
|
JSONObject retObj = new JSONObject();
|
||||||
JSONArray eventArray = new JSONArray();
|
|
||||||
for (QueryDocumentSnapshot document : task.getResult()) {
|
for (QueryDocumentSnapshot document : task.getResult()) {
|
||||||
Log.d(TAG, document.getId() + " => " + document.getData());
|
Log.d(TAG, "getEventTypes.onComplete(): " + document.getId() + " => " + document.getData());
|
||||||
eventArray.put(new JSONObject(document.getData()));
|
Log.v(TAG, "getEventTypes.onComplete() - subtypes=" + document.getData().get("subTypes"));
|
||||||
|
JSONArray subTypesArray = listToJSONArray((List) document.getData().get("subTypes"));
|
||||||
|
retObj.put(document.getData().get("type").toString(), subTypesArray);
|
||||||
}
|
}
|
||||||
retObj.put("eventTypes", eventArray);
|
Log.d(TAG, "getEventTypes.onComplete() - retObj=" + retObj.toString());
|
||||||
callback.accept(retObj);
|
callback.accept(retObj);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e(TAG, "getEventTypes.onResponse(): Error: " + e.getMessage() + "," + e.toString());
|
Log.e(TAG, "getEventTypes.onResponse(): Error: " + e.getMessage() + "," + e.toString());
|
||||||
@@ -332,6 +391,14 @@ public class WebApiConnection {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JSONArray listToJSONArray(List<Object> list) {
|
||||||
|
JSONArray arr = new JSONArray();
|
||||||
|
for (Object obj : list) {
|
||||||
|
arr.put(obj);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a trivial file from the server to check we have a good server connection.
|
* Retrieve a trivial file from the server to check we have a good server connection.
|
||||||
* sets mServerConnectionOk.
|
* sets mServerConnectionOk.
|
||||||
@@ -341,7 +408,7 @@ public class WebApiConnection {
|
|||||||
public boolean checkServerConnection() {
|
public boolean checkServerConnection() {
|
||||||
//FIXME There must be a Firebase function for this?
|
//FIXME There must be a Firebase function for this?
|
||||||
mServerConnectionOk = true;
|
mServerConnectionOk = true;
|
||||||
return true;
|
return mServerConnectionOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,19 +5,12 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
<TextView
|
|
||||||
android:id="@+id/event_id_remote_tv"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginRight="10dp"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
|
||||||
android:text="eventId" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
@@ -25,8 +18,8 @@
|
|||||||
android:id="@+id/event_date_remote_tv"
|
android:id="@+id/event_date_remote_tv"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textStyle="bold"
|
android:text="date"
|
||||||
android:text="date" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
@@ -37,8 +30,8 @@
|
|||||||
android:id="@+id/event_type_remote_tv"
|
android:id="@+id/event_type_remote_tv"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textStyle="bold"
|
android:text="---"
|
||||||
android:text="---" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@@ -52,24 +45,27 @@
|
|||||||
android:text="---" />
|
android:text="---" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/event_alarmState_remote_tv"
|
android:id="@+id/event_alarmState_remote_tv"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="alarm" />
|
android:text="alarm" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/event_notes_remote_tv"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="notes"
|
android:text="notes"
|
||||||
android:textStyle="italic"
|
android:textStyle="italic" />
|
||||||
android:id="@+id/event_notes_remote_tv" />
|
|
||||||
|
|
||||||
<!-- <TextView
|
<TextView
|
||||||
|
android:id="@+id/event_id_remote_tv"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="dataJSON"
|
android:layout_marginRight="10dp"
|
||||||
android:id="@+id/event_dataJSON" />
|
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||||
-->
|
android:text="eventId" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user