1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2025-06-19 13:56:28 +00:00

Prepare ListView loading

This commit is contained in:
Loic Blot 2015-05-15 12:31:41 +02:00
parent 9d2d76a606
commit 8e4c07f924

View File

@ -3,11 +3,16 @@ package fr.unix_experience.owncloud_sms.activities.restore_sms;
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;
public class ContactListActivity extends ListActivity {
static AccountManager _accountMgr;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -19,9 +24,10 @@ public class ContactListActivity extends ListActivity {
// accountName cannot be null, devel error
assert accountName != null;
final AccountManager _accountMgr = AccountManager.get(getBaseContext());
_accountMgr = AccountManager.get(getBaseContext());
final Account[] myAccountList =
_accountMgr.getAccountsByType(getString(R.string.account_type));
for (final Account element : myAccountList) {
if (element.name.equals(accountName)) {
loadContacts(element);
@ -32,6 +38,26 @@ 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
}
}
}