mirror of
				https://github.com/nerzhul/ownCloud-SMS-App.git
				synced 2025-10-28 00:49:00 +00:00 
			
		
		
		
	Abort sync process earlier when no account is available
This commit is contained in:
		
							parent
							
								
									f7dcb8e51c
								
							
						
					
					
						commit
						cc14488a88
					
				| @ -19,10 +19,14 @@ package fr.unix_experience.owncloud_sms.broadcast_receivers; | ||||
| 
 | ||||
| import org.json.JSONArray; | ||||
| 
 | ||||
| import android.accounts.Account; | ||||
| import android.accounts.AccountManager; | ||||
| import android.content.BroadcastReceiver; | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.util.Log; | ||||
| 
 | ||||
| import fr.unix_experience.owncloud_sms.R; | ||||
| import fr.unix_experience.owncloud_sms.engine.ASyncSMSSync; | ||||
| import fr.unix_experience.owncloud_sms.engine.ConnectivityMonitor; | ||||
| import fr.unix_experience.owncloud_sms.engine.SmsFetcher; | ||||
| @ -32,6 +36,13 @@ public class ConnectivityChanged extends BroadcastReceiver implements ASyncSMSSy | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void onReceive(final Context context, final Intent intent) { | ||||
| 		// No account: abort | ||||
| 		final Account[] myAccountList = AccountManager.get(context). | ||||
| 				getAccountsByType(context.getString(R.string.account_type)); | ||||
| 		if (myAccountList.length == 0) { | ||||
| 			return; | ||||
| 		} | ||||
| 
 | ||||
| 		final ConnectivityMonitor cMon = new ConnectivityMonitor(context); | ||||
| 
 | ||||
| 		final OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(context); | ||||
| @ -55,6 +66,7 @@ public class ConnectivityChanged extends BroadcastReceiver implements ASyncSMSSy | ||||
| 	} | ||||
| 
 | ||||
| 	private void checkMessagesAndSend(final Context context) { | ||||
| 
 | ||||
| 		// Get last message synced from preferences | ||||
| 		final Long lastMessageSynced = (new OCSMSSharedPrefs(context)).getLastMessageDate(); | ||||
| 		Log.d(TAG,"Synced Last:" + lastMessageSynced); | ||||
|  | ||||
| @ -38,12 +38,12 @@ public interface ASyncSMSSync { | ||||
| 
 | ||||
| 		@Override | ||||
| 		protected Void doInBackground(final Void... params) { | ||||
| 			final OCSMSNotificationManager nMgr = new OCSMSNotificationManager(_context); | ||||
| 
 | ||||
| 			// Get ownCloud SMS account list | ||||
| 			final AccountManager _accountMgr = AccountManager.get(_context); | ||||
| 
 | ||||
| 			final Account[] myAccountList = _accountMgr.getAccountsByType(_context.getString(R.string.account_type)); | ||||
| 
 | ||||
| 			// Notify that we are syncing SMS | ||||
| 			final OCSMSNotificationManager nMgr = new OCSMSNotificationManager(_context); | ||||
| 			for (final Account element : myAccountList) { | ||||
| 				final Uri serverURI = Uri.parse(_accountMgr.getUserData(element, "ocURI")); | ||||
| 
 | ||||
|  | ||||
| @ -19,11 +19,15 @@ package fr.unix_experience.owncloud_sms.observers; | ||||
| 
 | ||||
| import org.json.JSONArray; | ||||
| 
 | ||||
| import fr.unix_experience.owncloud_sms.R; | ||||
| import fr.unix_experience.owncloud_sms.engine.ASyncSMSSync; | ||||
| import fr.unix_experience.owncloud_sms.engine.ConnectivityMonitor; | ||||
| import fr.unix_experience.owncloud_sms.engine.OCSMSOwnCloudClient; | ||||
| import fr.unix_experience.owncloud_sms.engine.SmsFetcher; | ||||
| import fr.unix_experience.owncloud_sms.enums.MailboxID; | ||||
| 
 | ||||
| import android.accounts.Account; | ||||
| import android.accounts.AccountManager; | ||||
| import android.content.Context; | ||||
| import android.database.ContentObserver; | ||||
| import android.os.Handler; | ||||
| @ -43,6 +47,13 @@ public class SmsObserver extends ContentObserver implements ASyncSMSSync { | ||||
| 	public void onChange(boolean selfChange) { | ||||
| 		super.onChange(selfChange); | ||||
| 		Log.d(TAG, "onChange SmsObserver"); | ||||
| 
 | ||||
| 		// No account, abort | ||||
| 		final Account[] myAccountList = AccountManager.get(_context). | ||||
| 				getAccountsByType(_context.getString(R.string.account_type)); | ||||
| 		if (myAccountList.length == 0) { | ||||
| 			return; | ||||
| 		} | ||||
| 	 | ||||
| 		SmsFetcher fetcher = new SmsFetcher(_context); | ||||
| 		JSONArray smsList = fetcher.getLastMessage(MailboxID.ALL); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user