mirror of
				https://github.com/nerzhul/ownCloud-SMS-App.git
				synced 2025-10-31 02:17:53 +00:00 
			
		
		
		
	Code cleanups
This commit is contained in:
		
							parent
							
								
									e46a7bccf2
								
							
						
					
					
						commit
						e2c65cf867
					
				| @ -44,6 +44,26 @@ public class AndroidSmsFetcher { | ||||
| 		bufferMailboxMessages(result, MailboxID.DRAFTS); | ||||
| 	} | ||||
| 
 | ||||
| 	private void readMailBox(Cursor c, JSONArray result, MailboxID mbID) { | ||||
| 		do { | ||||
| 			JSONObject entry = new JSONObject(); | ||||
| 
 | ||||
| 			try { | ||||
| 				for (int idx = 0; idx < c.getColumnCount(); idx++) { | ||||
| 					handleProviderColumn(c, idx, entry); | ||||
| 				} | ||||
| 
 | ||||
| 				// Mailbox ID is required by server | ||||
| 				entry.put("mbox", mbID.ordinal()); | ||||
| 				result.put(entry); | ||||
| 
 | ||||
| 			} catch (JSONException e) { | ||||
| 				Log.e(AndroidSmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e); | ||||
| 			} | ||||
| 		} | ||||
| 		while (c.moveToNext()); | ||||
| 	} | ||||
| 
 | ||||
| 	private void bufferMailboxMessages(JSONArray result, MailboxID mbID) { | ||||
| 		if ((_context == null)) { | ||||
| 			return; | ||||
| @ -64,23 +84,7 @@ public class AndroidSmsFetcher { | ||||
| 		} | ||||
| 
 | ||||
| 		// Reading mailbox | ||||
| 		do { | ||||
| 			JSONObject entry = new JSONObject(); | ||||
| 
 | ||||
| 			try { | ||||
| 				for (int idx = 0; idx < c.getColumnCount(); idx++) { | ||||
| 					handleProviderColumn(c, idx, entry); | ||||
| 				} | ||||
| 
 | ||||
| 				// Mailbox ID is required by server | ||||
| 				entry.put("mbox", mbID.ordinal()); | ||||
| 				result.put(entry); | ||||
| 
 | ||||
| 			} catch (JSONException e) { | ||||
| 				Log.e(AndroidSmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e); | ||||
| 			} | ||||
| 		} | ||||
| 		while (c.moveToNext()); | ||||
| 		readMailBox(c, result, mbID); | ||||
| 
 | ||||
| 		Log.i(AndroidSmsFetcher.TAG, c.getCount() + " messages read from " + mbID.getURI()); | ||||
| 		c.close(); | ||||
| @ -150,22 +154,8 @@ public class AndroidSmsFetcher { | ||||
| 			return; | ||||
| 		} | ||||
| 
 | ||||
| 		do { | ||||
| 			JSONObject entry = new JSONObject(); | ||||
| 
 | ||||
| 			try { | ||||
| 				for (int idx = 0; idx < c.getColumnCount(); idx++) { | ||||
| 					handleProviderColumn(c, idx, entry); | ||||
| 				} | ||||
| 
 | ||||
| 				// Mailbox ID is required by server | ||||
| 				entry.put("mbox", mbID.ordinal()); | ||||
| 				result.put(entry); | ||||
| 			} catch (JSONException e) { | ||||
| 				Log.e(AndroidSmsFetcher.TAG, "JSON Exception when reading SMS Mailbox", e); | ||||
| 			} | ||||
| 		} | ||||
| 		while (c.moveToNext()); | ||||
| 		// Read Mailbox | ||||
| 		readMailBox(c, result, mbID); | ||||
| 
 | ||||
| 		Log.i(AndroidSmsFetcher.TAG, c.getCount() + " messages read from " + mbID.getURI()); | ||||
| 		c.close(); | ||||
|  | ||||
| @ -293,7 +293,7 @@ public class OCSMSOwnCloudClient { | ||||
| 
 | ||||
| 				// Force loop exit | ||||
| 				tryNb = OCSMSOwnCloudClient.maximumHttpReqTries; | ||||
| 			} catch (ConnectException e) { | ||||
| 			} catch (ConnectException | HttpException e) { | ||||
| 				Log.e(OCSMSOwnCloudClient.TAG, "Unable to perform a connection to ownCloud instance", e); | ||||
| 
 | ||||
| 				// If it's the last try | ||||
| @ -301,14 +301,6 @@ public class OCSMSOwnCloudClient { | ||||
| 					req.releaseConnection(); | ||||
| 					throw new OCSyncException(R.string.err_sync_http_request_connect, OCSyncErrorType.IO); | ||||
| 				} | ||||
| 			} catch (HttpException e) { | ||||
| 				Log.e(OCSMSOwnCloudClient.TAG, "Unable to perform a connection to ownCloud instance", e); | ||||
| 
 | ||||
| 				// If it's the last try | ||||
| 				if (tryNb == OCSMSOwnCloudClient.maximumHttpReqTries) { | ||||
| 					req.releaseConnection(); | ||||
| 					throw new OCSyncException(R.string.err_sync_http_request_httpexception, OCSyncErrorType.IO); | ||||
| 				} | ||||
| 			} catch (IOException e) { | ||||
| 				Log.e(OCSMSOwnCloudClient.TAG, "Unable to perform a connection to ownCloud instance", e); | ||||
| 
 | ||||
| @ -321,13 +313,7 @@ public class OCSMSOwnCloudClient { | ||||
| 		} | ||||
| 
 | ||||
| 		if (status == 200) { | ||||
| 			String response; | ||||
| 			try { | ||||
| 				response = req.getResponseBodyAsString(); | ||||
| 			} catch (IOException e) { | ||||
| 				Log.e(OCSMSOwnCloudClient.TAG, "Unable to parse server response", e); | ||||
| 				throw new OCSyncException(R.string.err_sync_http_request_resp, OCSyncErrorType.IO); | ||||
| 			} | ||||
| 			String response = getResponseBody(req); | ||||
| 
 | ||||
| 			// Parse the response | ||||
| 			try { | ||||
| @ -350,15 +336,9 @@ public class OCSMSOwnCloudClient { | ||||
| 			throw new OCSyncException(R.string.err_sync_auth_failed, OCSyncErrorType.AUTH); | ||||
| 		} else { | ||||
| 			// Unk error | ||||
| 			String response; | ||||
| 			try { | ||||
| 				response = req.getResponseBodyAsString(); | ||||
| 			} catch (IOException e) { | ||||
| 				Log.e(OCSMSOwnCloudClient.TAG, "Unable to parse server response", e); | ||||
| 				throw new OCSyncException(R.string.err_sync_http_request_resp, OCSyncErrorType.PARSE); | ||||
| 			} | ||||
| 
 | ||||
| 			String response = getResponseBody(req); | ||||
| 			Log.e(OCSMSOwnCloudClient.TAG, "Server set unhandled HTTP return code " + status); | ||||
| 
 | ||||
| 			if (response != null) { | ||||
| 				Log.e(OCSMSOwnCloudClient.TAG, "Status code: " + status + ". Response message: " + response); | ||||
| 			} else { | ||||
| @ -368,7 +348,16 @@ public class OCSMSOwnCloudClient { | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
|     private static final int maximumHttpReqTries = 3; | ||||
| 	private String getResponseBody(HttpMethod req) throws OCSyncException { | ||||
| 		try { | ||||
| 			return req.getResponseBodyAsString(); | ||||
| 		} catch (IOException e) { | ||||
| 			Log.e(OCSMSOwnCloudClient.TAG, "Unable to parse server response", e); | ||||
| 			throw new OCSyncException(R.string.err_sync_http_request_resp, OCSyncErrorType.IO); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	private static final int maximumHttpReqTries = 3; | ||||
| 
 | ||||
| 	private final OCHttpClient _http; | ||||
| 	private final Context _context; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user