//TODO: allows me to add to output. Find a better way to do this. //rewriteFile: add the text to the json file. False during the initial read of the json file. public void AddTextToTexts(TextMessage text, bool rewriteFile) { if (rewriteFile) { JSONArray array = (JSONArray)savedTexts ["texts"]; for (int i = textsLength; i > 0; i --) //move all contacts up an index in the array { array[i]["sender"] = array[i-1]["sender"]; Debug.Log ("recipient: '" + array[i-1]["recipient"] + "'"); array[i]["recipient"] = array[i-1]["recipient"]; array[i]["message"] = array[i-1]["message"]; array[i]["timestamp"] = array[i-1]["timestamp"]; array[i]["isRead"] = array[i-1]["isRead"]; array[i]["isTraceable"] = array[i-1]["isTraceable"]; } array[0]["sender"] = text.GetSender(); //add the new text at the top array[0]["recipient"] = text.GetRecipient(); array[0]["message"] = text.GetMessage(); array[0]["timestamp"] = ""+text.GetTimestamp(); array[0]["isRead"] = ""+text.HasBeenRead(); array[0]["isTraceable"] = ""+text.IsTraceable(); savedTexts ["texts"] = array; SaveJson(); } texts.Insert (0, text); textsLength += 1; }
//TODO: make texts scroll-able //display the sender (inbox)/recipient (output), date time, and content of message void SetViewToTextMessage(TextMessage txt) { //update the json file that this text has been read if (!txt.HasBeenRead()) { Debug.Log ("-\n-\n"); JSONArray array = (JSONArray)savedTexts["texts"]; for (int i = 0; i < array.Count; i++) { //setting to strings, because otherwise a "==" comparision always returns false, even when it should return true string sender = array[i]["sender"]; string timestamp = array[i]["timestamp"]; string message = array[i]["message"]; if (sender == txt.GetSender() && timestamp == (""+txt.GetTimestamp()) && message == txt.GetMessage()) { array[i]["isRead"] = "True"; break; } } savedTexts["texts"] = array; SaveJson(); txt.SetHasBeenRead(true); } //need to check for unread texts here, in case the user presses the "red" button, to go back to the main menu. //this would bypass going back to the lists of texts which previously checked for unread texts if (ps.hasUnreadTexts && collectionType == CollectionType.Inbox) { bool newHasUnreadTexts = false; for (int i = 0; i < textsLength; i++) { if (!texts[i].HasBeenRead()) { newHasUnreadTexts = true; break; } } ps.hasUnreadTexts = newHasUnreadTexts; } ps.HandleHasUnreadMessages (); PhoneState.SetState(PhoneState.State.TextMessageDisplay); string str = ""; if (collectionType == CollectionType.Inbox) { //PhoneState.SetState(PhoneState.State.TextMessageInboxDisplay); string senderNumber = txt.GetSender(); str = "From: " + GetContactFromNumber(senderNumber, txt.IsTraceable()) + "\n"; } else { //PhoneState.SetState(PhoneState.State.TextMessageOutboxDisplay); string recipNumber = txt.GetRecipient(); str = "To: " + GetContactFromNumber(recipNumber, true) + "\n"; } str += "Time: " + GetDateTimeFromTimestamp(txt.GetTimestamp()) +"\n"; str += txt.GetMessage (); cs.SetScreenText(str); cs.SetHeadingText("Message"); cs.SetNavLeftText ("Back"); cs.SetNavRightText ("Options"); }