mirror of
				https://github.com/nerzhul/ownCloud-SMS-App.git
				synced 2025-10-31 02:17:53 +00:00 
			
		
		
		
	Add SmsEntry object to remove a JsonObject unoptimized storage object
This commit is contained in:
		
							parent
							
								
									ebfd1ccfbf
								
							
						
					
					
						commit
						0407f719ef
					
				| @ -23,7 +23,6 @@ import android.util.Log; | ||||
| 
 | ||||
| import org.json.JSONArray; | ||||
| import org.json.JSONException; | ||||
| import org.json.JSONObject; | ||||
| 
 | ||||
| import fr.unix_experience.owncloud_sms.enums.MailboxID; | ||||
| import fr.unix_experience.owncloud_sms.jni.SmsBuffer; | ||||
| @ -47,7 +46,7 @@ public class AndroidSmsFetcher { | ||||
| 
 | ||||
| 	private void readMailBox(Cursor c, SmsBuffer smsBuffer, MailboxID mbID) { | ||||
| 		do { | ||||
| 			JSONObject entry = new JSONObject(); | ||||
| 			SmsEntry entry = new SmsEntry(); | ||||
| 
 | ||||
| 			try { | ||||
| 				for (int idx = 0; idx < c.getColumnCount(); idx++) { | ||||
| @ -55,7 +54,7 @@ public class AndroidSmsFetcher { | ||||
| 				} | ||||
| 
 | ||||
| 				// Mailbox ID is required by server | ||||
| 				entry.put("mbox", mbID.ordinal()); | ||||
| 				entry.mailboxId = mbID.ordinal(); | ||||
| 				smsBuffer.push(mbID, entry); | ||||
| 
 | ||||
| 			} catch (JSONException e) { | ||||
| @ -104,7 +103,7 @@ public class AndroidSmsFetcher { | ||||
| 		} | ||||
| 
 | ||||
| 		// We create a list of strings to store results | ||||
| 		JSONObject entry = new JSONObject(); | ||||
| 		SmsEntry entry = new SmsEntry(); | ||||
| 		SmsBuffer results = new SmsBuffer(); | ||||
| 
 | ||||
| 		try { | ||||
| @ -121,7 +120,7 @@ public class AndroidSmsFetcher { | ||||
| 			* mboxId is greater than server mboxId by 1 because types | ||||
| 			* aren't indexed in the same mean | ||||
| 			*/ | ||||
| 			entry.put("mbox", (mboxId - 1)); | ||||
| 			entry.mailboxId = mboxId - 1; | ||||
| 			results.push(mbID, entry); | ||||
| 		} catch (JSONException e) { | ||||
| 			Log.e(AndroidSmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e); | ||||
| @ -161,16 +160,16 @@ public class AndroidSmsFetcher { | ||||
| 		c.close(); | ||||
| 	} | ||||
| 
 | ||||
| 	private Integer handleProviderColumn(Cursor c, int idx, JSONObject entry) throws JSONException { | ||||
| 	private Integer handleProviderColumn(Cursor c, int idx, SmsEntry entry) throws JSONException { | ||||
| 		String colName = c.getColumnName(idx); | ||||
| 
 | ||||
| 		// Id column is must be an integer | ||||
| 		switch (colName) { | ||||
| 			case "_id": | ||||
| 				entry.put(colName, c.getInt(idx)); | ||||
| 				entry.id = c.getInt(idx); | ||||
| 				break; | ||||
| 			case "type": | ||||
| 				entry.put(colName, c.getInt(idx)); | ||||
| 				entry.type = c.getInt(idx); | ||||
| 				return c.getInt(idx); | ||||
| 			/* For debug purpose | ||||
|             case "length(address)": | ||||
| @ -178,8 +177,10 @@ public class AndroidSmsFetcher { | ||||
|                 break;*/ | ||||
| 			// Seen and read must be pseudo boolean | ||||
| 			case "read": | ||||
| 				entry.read = (c.getInt(idx) > 0); | ||||
| 				break; | ||||
| 			case "seen": | ||||
| 				entry.put(colName, (c.getInt(idx) > 0) ? "true" : "false"); | ||||
| 				entry.seen = (c.getInt(idx) > 0); | ||||
| 				break; | ||||
| 			case "date": | ||||
| 				// Special case for date, we need to record last without searching | ||||
| @ -187,10 +188,16 @@ public class AndroidSmsFetcher { | ||||
| 				if (tmpDate > _lastMsgDate) { | ||||
| 					_lastMsgDate = tmpDate; | ||||
| 				} | ||||
| 				entry.put(colName, c.getLong(idx)); | ||||
| 				entry.date = c.getLong(idx); | ||||
| 				break; | ||||
| 			case "address": | ||||
| 				entry.address = c.getString(idx); | ||||
| 				break; | ||||
| 			case "body": | ||||
| 				entry.body = c.getString(idx); | ||||
| 				break; | ||||
| 			default: | ||||
| 				entry.put(colName, c.getString(idx)); | ||||
| 				// Unhandled column | ||||
| 				break; | ||||
| 		} | ||||
| 
 | ||||
|  | ||||
| @ -0,0 +1,29 @@ | ||||
| package fr.unix_experience.owncloud_sms.engine; | ||||
| 
 | ||||
| /* | ||||
|  *  Copyright (c) 2014-2016, Loic Blot <loic.blot@unix-experience.fr> | ||||
|  * | ||||
|  *  This program is free software: you can redistribute it and/or modify | ||||
|  *  it under the terms of the GNU Affero General Public License as | ||||
|  *  published by the Free Software Foundation, either version 3 of the | ||||
|  *  License, or (at your option) any later version. | ||||
|  * | ||||
|  *  This program is distributed in the hope that it will be useful, | ||||
|  *  but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  *  GNU Affero General Public License for more details. | ||||
|  * | ||||
|  *  You should have received a copy of the GNU Affero General Public License | ||||
|  *  along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
| 
 | ||||
| public class SmsEntry { | ||||
| 	public int id; | ||||
| 	public int mailboxId; | ||||
| 	public int type; | ||||
| 	public boolean read; | ||||
| 	public boolean seen; | ||||
| 	public long date; | ||||
| 	public String address; | ||||
| 	public String body; | ||||
| } | ||||
| @ -1,8 +1,8 @@ | ||||
| package fr.unix_experience.owncloud_sms.jni; | ||||
| 
 | ||||
| import org.json.JSONException; | ||||
| import org.json.JSONObject; | ||||
| 
 | ||||
| import fr.unix_experience.owncloud_sms.engine.SmsEntry; | ||||
| import fr.unix_experience.owncloud_sms.enums.MailboxID; | ||||
| 
 | ||||
| /** | ||||
| @ -48,15 +48,15 @@ public class SmsBuffer { | ||||
| 	public native void print(); | ||||
| 	public native String asRawJsonString(); | ||||
| 
 | ||||
| 	public void push (MailboxID mbid, JSONObject jsonObject) throws JSONException { | ||||
| 		push(jsonObject.getInt("_id"), | ||||
| 	public void push(MailboxID mbid, SmsEntry smsEntry) throws JSONException { | ||||
| 		push(smsEntry.id, | ||||
| 				mbid.ordinal(), | ||||
| 				jsonObject.getInt("type"), | ||||
| 				jsonObject.getLong("date"), | ||||
| 				jsonObject.getString("address"), | ||||
| 				jsonObject.getString("body"), | ||||
| 				jsonObject.getString("read"), | ||||
| 				jsonObject.getString("seen")); | ||||
| 				smsEntry.type, | ||||
| 				smsEntry.date, | ||||
| 				smsEntry.address, | ||||
| 				smsEntry.body, | ||||
| 				smsEntry.read ? "true" : "false", | ||||
| 				smsEntry.seen ? "true" : "false"); | ||||
| 	} | ||||
| 
 | ||||
| 	public void clear() { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user