1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2025-06-25 00:36:39 +00:00

Add SmsEntry object to remove a JsonObject unoptimized storage object

This commit is contained in:
Loic Blot 2017-09-04 22:27:36 +02:00
parent ebfd1ccfbf
commit 0407f719ef
No known key found for this signature in database
GPG Key ID: EFAA458E8C153987
3 changed files with 56 additions and 20 deletions

View File

@ -23,7 +23,6 @@ import android.util.Log;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject;
import fr.unix_experience.owncloud_sms.enums.MailboxID; import fr.unix_experience.owncloud_sms.enums.MailboxID;
import fr.unix_experience.owncloud_sms.jni.SmsBuffer; import fr.unix_experience.owncloud_sms.jni.SmsBuffer;
@ -47,7 +46,7 @@ public class AndroidSmsFetcher {
private void readMailBox(Cursor c, SmsBuffer smsBuffer, MailboxID mbID) { private void readMailBox(Cursor c, SmsBuffer smsBuffer, MailboxID mbID) {
do { do {
JSONObject entry = new JSONObject(); SmsEntry entry = new SmsEntry();
try { try {
for (int idx = 0; idx < c.getColumnCount(); idx++) { for (int idx = 0; idx < c.getColumnCount(); idx++) {
@ -55,7 +54,7 @@ public class AndroidSmsFetcher {
} }
// Mailbox ID is required by server // Mailbox ID is required by server
entry.put("mbox", mbID.ordinal()); entry.mailboxId = mbID.ordinal();
smsBuffer.push(mbID, entry); smsBuffer.push(mbID, entry);
} catch (JSONException e) { } catch (JSONException e) {
@ -104,7 +103,7 @@ public class AndroidSmsFetcher {
} }
// We create a list of strings to store results // We create a list of strings to store results
JSONObject entry = new JSONObject(); SmsEntry entry = new SmsEntry();
SmsBuffer results = new SmsBuffer(); SmsBuffer results = new SmsBuffer();
try { try {
@ -121,7 +120,7 @@ public class AndroidSmsFetcher {
* mboxId is greater than server mboxId by 1 because types * mboxId is greater than server mboxId by 1 because types
* aren't indexed in the same mean * aren't indexed in the same mean
*/ */
entry.put("mbox", (mboxId - 1)); entry.mailboxId = mboxId - 1;
results.push(mbID, entry); results.push(mbID, entry);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(AndroidSmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e); Log.e(AndroidSmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e);
@ -161,16 +160,16 @@ public class AndroidSmsFetcher {
c.close(); 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); String colName = c.getColumnName(idx);
// Id column is must be an integer // Id column is must be an integer
switch (colName) { switch (colName) {
case "_id": case "_id":
entry.put(colName, c.getInt(idx)); entry.id = c.getInt(idx);
break; break;
case "type": case "type":
entry.put(colName, c.getInt(idx)); entry.type = c.getInt(idx);
return c.getInt(idx); return c.getInt(idx);
/* For debug purpose /* For debug purpose
case "length(address)": case "length(address)":
@ -178,8 +177,10 @@ public class AndroidSmsFetcher {
break;*/ break;*/
// Seen and read must be pseudo boolean // Seen and read must be pseudo boolean
case "read": case "read":
entry.read = (c.getInt(idx) > 0);
break;
case "seen": case "seen":
entry.put(colName, (c.getInt(idx) > 0) ? "true" : "false"); entry.seen = (c.getInt(idx) > 0);
break; break;
case "date": case "date":
// Special case for date, we need to record last without searching // Special case for date, we need to record last without searching
@ -187,10 +188,16 @@ public class AndroidSmsFetcher {
if (tmpDate > _lastMsgDate) { if (tmpDate > _lastMsgDate) {
_lastMsgDate = tmpDate; _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; break;
default: default:
entry.put(colName, c.getString(idx)); // Unhandled column
break; break;
} }

View File

@ -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;
}

View File

@ -1,8 +1,8 @@
package fr.unix_experience.owncloud_sms.jni; package fr.unix_experience.owncloud_sms.jni;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject;
import fr.unix_experience.owncloud_sms.engine.SmsEntry;
import fr.unix_experience.owncloud_sms.enums.MailboxID; import fr.unix_experience.owncloud_sms.enums.MailboxID;
/** /**
@ -48,15 +48,15 @@ public class SmsBuffer {
public native void print(); public native void print();
public native String asRawJsonString(); public native String asRawJsonString();
public void push (MailboxID mbid, JSONObject jsonObject) throws JSONException { public void push(MailboxID mbid, SmsEntry smsEntry) throws JSONException {
push(jsonObject.getInt("_id"), push(smsEntry.id,
mbid.ordinal(), mbid.ordinal(),
jsonObject.getInt("type"), smsEntry.type,
jsonObject.getLong("date"), smsEntry.date,
jsonObject.getString("address"), smsEntry.address,
jsonObject.getString("body"), smsEntry.body,
jsonObject.getString("read"), smsEntry.read ? "true" : "false",
jsonObject.getString("seen")); smsEntry.seen ? "true" : "false");
} }
public void clear() { public void clear() {