1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2025-06-27 09:46:23 +00:00

Coding style + removal some class copy

This commit is contained in:
Loic Blot 2015-11-17 21:04:02 +01:00
parent ac239f1f71
commit 22f0790f2e
6 changed files with 53 additions and 51 deletions

View File

@ -166,10 +166,10 @@ public class MainActivity extends Activity {
if (cMon.isValid()) { if (cMon.isValid()) {
// Now fetch messages since last stored date // Now fetch messages since last stored date
JSONArray smsList = new SmsFetcher(ctx) JSONArray smsList = new JSONArray();
.bufferMessagesSinceDate((long) 0); new SmsFetcher(ctx).bufferMessagesSinceDate(smsList, (long) 0);
if (smsList != null) { if (smsList.length() > 0) {
OCSMSNotificationManager nMgr = new OCSMSNotificationManager(ctx); OCSMSNotificationManager nMgr = new OCSMSNotificationManager(ctx);
nMgr.setSyncProcessMsg(); nMgr.setSyncProcessMsg();
new SyncTask(getApplicationContext(), smsList).execute(); new SyncTask(getApplicationContext(), smsList).execute();

View File

@ -119,10 +119,11 @@ public class ContactListActivity extends Activity implements ASyncContactLoad {
null, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{contactId}, null); new String[]{contactId}, null);
while ((phones != null) && phones.moveToNext()) { while ((phones != null) && phones.moveToNext()) {
String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)) r.add(phones.getString(phones.getColumnIndex(
.replaceAll(" ", ""); ContactsContract.CommonDataKinds.Phone.NUMBER))
r.add(phoneNumber); .replaceAll(" ", ""));
} }
if (phones != null) { if (phones != null) {

View File

@ -74,12 +74,13 @@ public class ConnectivityChanged extends BroadcastReceiver implements ASyncSMSSy
Log.d(ConnectivityChanged.TAG,"Synced Last:" + lastMessageSynced); Log.d(ConnectivityChanged.TAG,"Synced Last:" + lastMessageSynced);
// Now fetch messages since last stored date // Now fetch messages since last stored date
JSONArray smsList = new SmsFetcher(context).bufferMessagesSinceDate(lastMessageSynced); JSONArray smsList = new JSONArray();
new SmsFetcher(context).bufferMessagesSinceDate(smsList, lastMessageSynced);
AtomicReference<ConnectivityMonitor> cMon = new AtomicReference<>(new ConnectivityMonitor(context)); AtomicReference<ConnectivityMonitor> cMon = new AtomicReference<>(new ConnectivityMonitor(context));
// Synchronize if network is valid and there are SMS // Synchronize if network is valid and there are SMS
if (cMon.get().isValid() && (smsList != null)) { if (cMon.get().isValid() && (smsList.length() > 0)) {
new SyncTask(context, smsList).execute(); new SyncTask(context, smsList).execute();
} }
} }

View File

@ -85,9 +85,10 @@ public interface ASyncContactLoad {
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null); null, null, null, null);
if (((cur != null) ? cur.getCount() : 0) > 0) { if (((cur != null) ? cur.getCount() : 0) > 0) {
String id, name;
while ((cur != null) && cur.moveToNext()) { while ((cur != null) && cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer.parseInt(cur.getString( if (Integer.parseInt(cur.getString(
cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) { cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {

View File

@ -152,7 +152,8 @@ public class OCSMSOwnCloudClient {
fetcher.setExistingSentMessages(sentSmsList); fetcher.setExistingSentMessages(sentSmsList);
fetcher.setExistingDraftsMessages(draftsSmsList); fetcher.setExistingDraftsMessages(draftsSmsList);
smsList = fetcher.fetchAllMessages(); smsList = new JSONArray();
fetcher.fetchAllMessages(smsList);
// Get maximum message date present in smsList to keep a step when connectivity changes // Get maximum message date present in smsList to keep a step when connectivity changes
lastMsgDate = fetcher.getLastMessageDate(); lastMsgDate = fetcher.getLastMessageDate();

View File

@ -38,15 +38,13 @@ public class SmsFetcher {
_existingDraftsMessages = null; _existingDraftsMessages = null;
} }
public JSONArray fetchAllMessages() { public void fetchAllMessages(JSONArray result) {
_jsonDataDump = new JSONArray(); bufferMailboxMessages(result, MailboxID.INBOX);
bufferMailboxMessages(MailboxID.INBOX); bufferMailboxMessages(result, MailboxID.SENT);
bufferMailboxMessages(MailboxID.SENT); bufferMailboxMessages(result, MailboxID.DRAFTS);
bufferMailboxMessages(MailboxID.DRAFTS);
return _jsonDataDump;
} }
private void bufferMailboxMessages(MailboxID mbID) { private void bufferMailboxMessages(JSONArray result, MailboxID mbID) {
String mbURI = mapMailboxIDToURI(mbID); String mbURI = mapMailboxIDToURI(mbID);
if ((_context == null) || (mbURI == null)) { if ((_context == null) || (mbURI == null)) {
@ -71,8 +69,9 @@ public class SmsFetcher {
JSONObject entry = new JSONObject(); JSONObject entry = new JSONObject();
try { try {
String colName;
for(int idx=0;idx<c.getColumnCount();idx++) { for(int idx=0;idx<c.getColumnCount();idx++) {
String colName = c.getColumnName(idx); colName = c.getColumnName(idx);
// Id column is must be an integer // Id column is must be an integer
switch (colName) { switch (colName) {
@ -101,7 +100,7 @@ public class SmsFetcher {
// Mailbox ID is required by server // Mailbox ID is required by server
entry.put("mbox", mbID.ordinal()); entry.put("mbox", mbID.ordinal());
_jsonDataDump.put(entry); result.put(entry);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(SmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e); Log.e(SmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e);
@ -136,8 +135,9 @@ public class SmsFetcher {
try { try {
Integer mboxId = -1; Integer mboxId = -1;
String colName;
for(int idx = 0;idx < c.getColumnCount(); idx++) { for(int idx = 0;idx < c.getColumnCount(); idx++) {
String colName = c.getColumnName(idx); colName = c.getColumnName(idx);
// Id column is must be an integer // Id column is must be an integer
switch (colName) { switch (colName) {
@ -178,16 +178,14 @@ public class SmsFetcher {
} }
// Used by ConnectivityChanged Event // Used by ConnectivityChanged Event
public JSONArray bufferMessagesSinceDate(Long sinceDate) { public void bufferMessagesSinceDate(JSONArray result, Long sinceDate) {
_jsonDataDump = new JSONArray(); bufferMessagesSinceDate(result, MailboxID.INBOX, sinceDate);
bufferMessagesSinceDate(MailboxID.INBOX, sinceDate); bufferMessagesSinceDate(result, MailboxID.SENT, sinceDate);
bufferMessagesSinceDate(MailboxID.SENT, sinceDate); bufferMessagesSinceDate(result, MailboxID.DRAFTS, sinceDate);
bufferMessagesSinceDate(MailboxID.DRAFTS, sinceDate);
return _jsonDataDump;
} }
// Used by ConnectivityChanged Event // Used by ConnectivityChanged Event
public void bufferMessagesSinceDate(MailboxID mbID, Long sinceDate) { public void bufferMessagesSinceDate(JSONArray result, MailboxID mbID, Long sinceDate) {
String mbURI = mapMailboxIDToURI(mbID); String mbURI = mapMailboxIDToURI(mbID);
if ((_context == null) || (mbURI == null)) { if ((_context == null) || (mbURI == null)) {
@ -203,8 +201,9 @@ public class SmsFetcher {
JSONObject entry = new JSONObject(); JSONObject entry = new JSONObject();
try { try {
String colName;
for (int idx = 0; idx < c.getColumnCount(); idx++) { for (int idx = 0; idx < c.getColumnCount(); idx++) {
String colName = c.getColumnName(idx); colName = c.getColumnName(idx);
// Id column is must be an integer // Id column is must be an integer
switch (colName) { switch (colName) {
@ -233,7 +232,7 @@ public class SmsFetcher {
// Mailbox ID is required by server // Mailbox ID is required by server
entry.put("mbox", mbID.ordinal()); entry.put("mbox", mbID.ordinal());
_jsonDataDump.put(entry); result.put(entry);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(SmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e); Log.e(SmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e);
@ -273,11 +272,12 @@ public class SmsFetcher {
existingMessages = _existingDraftsMessages; existingMessages = _existingDraftsMessages;
} else if (_mbID == MailboxID.SENT) { } else if (_mbID == MailboxID.SENT) {
existingMessages = _existingSentMessages; existingMessages = _existingSentMessages;
} else {
return "";
} }
// Note: The default case isn't possible, we check the mailbox before
// Note: The default case isn't possible, we check the mailbox before
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (existingMessages != null) {
int len = existingMessages.length(); int len = existingMessages.length();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
try { try {
@ -289,7 +289,6 @@ public class SmsFetcher {
} }
} }
}
return sb.toString(); return sb.toString();
} }
@ -311,7 +310,6 @@ public class SmsFetcher {
} }
private final Context _context; private final Context _context;
private JSONArray _jsonDataDump;
private JSONArray _existingInboxMessages; private JSONArray _existingInboxMessages;
private JSONArray _existingSentMessages; private JSONArray _existingSentMessages;
private JSONArray _existingDraftsMessages; private JSONArray _existingDraftsMessages;