1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2025-06-22 15:26:24 +00:00

Prepare ASyncContactLoad task.

This commit is contained in:
Loic Blot 2015-05-23 19:28:56 +02:00
parent 9c60469658
commit 3b7351db79
2 changed files with 41 additions and 25 deletions

View File

@ -3,13 +3,11 @@ package fr.unix_experience.owncloud_sms.activities.remote_account;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.ListActivity;
import android.net.Uri;
import android.os.Bundle;
import fr.unix_experience.owncloud_sms.R;
import fr.unix_experience.owncloud_sms.engine.OCSMSOwnCloudClient;
import fr.unix_experience.owncloud_sms.exceptions.OCSyncException;
import fr.unix_experience.owncloud_sms.engine.ASyncContactLoad;
public class ContactListActivity extends ListActivity {
public class ContactListActivity extends ListActivity implements ASyncContactLoad {
static AccountManager _accountMgr;
@ -30,7 +28,7 @@ public class ContactListActivity extends ListActivity {
for (final Account element : myAccountList) {
if (element.name.equals(accountName)) {
new ContactLoadTask().execute(); loadContacts(element);
new ContactLoadTask(element, getBaseContext()).execute();
return;
}
}
@ -38,26 +36,6 @@ public class ContactListActivity extends ListActivity {
// This function fetch contacts from the ownCloud instance and generate the list activity
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
}
}
}

View File

@ -1,11 +1,49 @@
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 fr.unix_experience.owncloud_sms.exceptions.OCSyncException;
public interface ASyncContactLoad {
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
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;
}