Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 1 | package org.sflphone.loaders; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.HashMap; |
| 5 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 6 | import org.sflphone.model.Account; |
| 7 | import org.sflphone.service.ISipService; |
| 8 | |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 9 | import android.content.AsyncTaskLoader; |
| 10 | import android.content.Context; |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 11 | import android.os.Bundle; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 12 | import android.os.RemoteException; |
| 13 | import android.util.Log; |
| 14 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 15 | public class AccountsLoader extends AsyncTaskLoader<Bundle> { |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 16 | |
| 17 | private static final String TAG = AccountsLoader.class.getSimpleName(); |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 18 | public static final String ACCOUNTS = "accounts"; |
| 19 | public static final String ACCOUNT_IP2IP = "IP2IP"; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 20 | ISipService service; |
| 21 | |
| 22 | public AccountsLoader(Context context, ISipService ref) { |
| 23 | super(context); |
| 24 | service = ref; |
| 25 | } |
| 26 | |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 27 | @SuppressWarnings("unchecked") // Hashmap runtime cast |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 28 | @Override |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 29 | public Bundle loadInBackground() { |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 30 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 31 | ArrayList<Account> accounts = new ArrayList<Account>(); |
| 32 | Account IP2IP = null; |
| 33 | |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 34 | try { |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 35 | ArrayList<String> accountIDs = (ArrayList<String>) service.getAccountList(); |
| 36 | HashMap<String, String> details; |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 37 | for (String id : accountIDs) { |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 38 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 39 | if (id.contentEquals(ACCOUNT_IP2IP)) { |
| 40 | details = (HashMap<String, String>) service.getAccountDetails(id); |
| 41 | IP2IP = new Account(ACCOUNT_IP2IP, details); |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 42 | continue; |
| 43 | } |
| 44 | details = (HashMap<String, String>) service.getAccountDetails(id); |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 45 | Account tmp = new Account(id, details); |
| 46 | |
| 47 | accounts.add(tmp); |
| 48 | |
| 49 | Log.i(TAG, "account:"+tmp.getAlias()+" "+tmp.isEnabled()); |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 50 | |
| 51 | } |
| 52 | } catch (RemoteException e) { |
| 53 | Log.e(TAG, e.toString()); |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 54 | } catch (NullPointerException e1) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 55 | Log.e(TAG, e1.toString()); |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 56 | } |
| 57 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 58 | Bundle result = new Bundle(); |
| 59 | result.putParcelableArrayList(ACCOUNTS, accounts); |
| 60 | result.putParcelable(ACCOUNT_IP2IP, IP2IP); |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 61 | return result; |
| 62 | } |
| 63 | |
| 64 | } |