mirror of
				https://github.com/nerzhul/ownCloud-SMS-App.git
				synced 2025-10-31 02:17:53 +00:00 
			
		
		
		
	Prepare ASyncContactLoad task.
This commit is contained in:
		
							parent
							
								
									9c60469658
								
							
						
					
					
						commit
						3b7351db79
					
				| @ -3,13 +3,11 @@ package fr.unix_experience.owncloud_sms.activities.remote_account; | |||||||
| import android.accounts.Account; | import android.accounts.Account; | ||||||
| import android.accounts.AccountManager; | import android.accounts.AccountManager; | ||||||
| import android.app.ListActivity; | import android.app.ListActivity; | ||||||
| import android.net.Uri; |  | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
| import fr.unix_experience.owncloud_sms.R; | import fr.unix_experience.owncloud_sms.R; | ||||||
| import fr.unix_experience.owncloud_sms.engine.OCSMSOwnCloudClient; | import fr.unix_experience.owncloud_sms.engine.ASyncContactLoad; | ||||||
| import fr.unix_experience.owncloud_sms.exceptions.OCSyncException; |  | ||||||
| 
 | 
 | ||||||
| public class ContactListActivity extends ListActivity { | public class ContactListActivity extends ListActivity implements ASyncContactLoad { | ||||||
| 
 | 
 | ||||||
| 	static AccountManager _accountMgr; | 	static AccountManager _accountMgr; | ||||||
| 
 | 
 | ||||||
| @ -30,7 +28,7 @@ public class ContactListActivity extends ListActivity { | |||||||
| 
 | 
 | ||||||
| 		for (final Account element : myAccountList) { | 		for (final Account element : myAccountList) { | ||||||
| 			if (element.name.equals(accountName)) { | 			if (element.name.equals(accountName)) { | ||||||
| 				new ContactLoadTask().execute(); loadContacts(element); | 				new ContactLoadTask(element, getBaseContext()).execute(); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @ -38,26 +36,6 @@ public class ContactListActivity extends ListActivity { | |||||||
| 
 | 
 | ||||||
| 	// This function fetch contacts from the ownCloud instance and generate the list activity | 	// This function fetch contacts from the ownCloud instance and generate the list activity | ||||||
| 	private void loadContacts(final Account account) { | 	private void loadContacts(final Account account) { | ||||||
| 		// Create client |  | ||||||
| 		final String ocURI = _accountMgr.getUserData(account, "ocURI"); |  | ||||||
| 		if (ocURI == null) { |  | ||||||
| 			// @TODO: Handle the problem |  | ||||||
| 			return; |  | ||||||
| 		} |  | ||||||
| 
 | 
 | ||||||
| 		final Uri serverURI = Uri.parse(ocURI); |  | ||||||
| 
 |  | ||||||
| 		final OCSMSOwnCloudClient _client = new OCSMSOwnCloudClient(getBaseContext(), |  | ||||||
| 				serverURI, _accountMgr.getUserData(account, "ocLogin"), |  | ||||||
| 				_accountMgr.getPassword(account)); |  | ||||||
| 
 |  | ||||||
| 		try { |  | ||||||
| 			if (_client.getServerAPIVersion() < 2) { |  | ||||||
| 				// @TODO: handle error |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 		} catch (final OCSyncException e) { |  | ||||||
| 			// @TODO: handle error |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,11 +1,49 @@ | |||||||
| package fr.unix_experience.owncloud_sms.engine; | package fr.unix_experience.owncloud_sms.engine; | ||||||
| 
 | 
 | ||||||
|  | import android.accounts.Account; | ||||||
|  | import android.accounts.AccountManager; | ||||||
|  | import android.content.Context; | ||||||
|  | import android.net.Uri; | ||||||
| import android.os.AsyncTask; | import android.os.AsyncTask; | ||||||
|  | import fr.unix_experience.owncloud_sms.exceptions.OCSyncException; | ||||||
| 
 | 
 | ||||||
| public interface ASyncContactLoad { | public interface ASyncContactLoad { | ||||||
| 	class ContactLoadTask extends AsyncTask<Void, Void, Void> { | 	class ContactLoadTask extends AsyncTask<Void, Void, Void> { | ||||||
|  | 		private static AccountManager _accountMgr = null; | ||||||
|  | 		private static Account _account; | ||||||
|  | 		private final Context _context; | ||||||
|  | 
 | ||||||
|  | 		public ContactLoadTask(final Account account, final Context context) { | ||||||
|  | 			if (_accountMgr == null) { | ||||||
|  | 				_accountMgr = AccountManager.get(context); | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 			_account = account; | ||||||
|  | 			_context = context; | ||||||
|  | 		} | ||||||
| 		@Override | 		@Override | ||||||
| 		protected Void doInBackground(final Void... params) { | 		protected Void doInBackground(final Void... params) { | ||||||
|  | 			// Create client | ||||||
|  | 			final String ocURI = _accountMgr.getUserData(_account, "ocURI"); | ||||||
|  | 			if (ocURI == null) { | ||||||
|  | 				// @TODO: Handle the problem | ||||||
|  | 				return null; | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 			final Uri serverURI = Uri.parse(ocURI); | ||||||
|  | 
 | ||||||
|  | 			final OCSMSOwnCloudClient _client = new OCSMSOwnCloudClient(_context, | ||||||
|  | 					serverURI, _accountMgr.getUserData(_account, "ocLogin"), | ||||||
|  | 					_accountMgr.getPassword(_account)); | ||||||
|  | 
 | ||||||
|  | 			try { | ||||||
|  | 				if (_client.getServerAPIVersion() < 2) { | ||||||
|  | 					// @TODO: handle error | ||||||
|  | 				} | ||||||
|  | 				_client.getServerPhoneNumbers(); | ||||||
|  | 			} catch (final OCSyncException e) { | ||||||
|  | 				// @TODO: handle error | ||||||
|  | 			} | ||||||
| 			return null; | 			return null; | ||||||
| 
 | 
 | ||||||
| 		} | 		} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user