Skip to content
Snippets Groups Projects
Commit 8c8e7f18 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

ui: don't show disabled accounts in quick list

Tuleap: #468
Change-Id: I7fb15a433047df05d559aecee5e7ed3e16694898
parent 78fbd610
Branches
Tags
No related merge requests found
...@@ -21,12 +21,13 @@ ...@@ -21,12 +21,13 @@
package cx.ring.adapters; package cx.ring.adapters;
import java.io.File; import java.util.ArrayList;
import java.util.List; import java.util.List;
import cx.ring.R; import cx.ring.R;
import android.content.Context; import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
...@@ -40,15 +41,15 @@ public class AccountSelectionAdapter extends BaseAdapter { ...@@ -40,15 +41,15 @@ public class AccountSelectionAdapter extends BaseAdapter {
private static final String TAG = AccountSelectionAdapter.class.getSimpleName(); private static final String TAG = AccountSelectionAdapter.class.getSimpleName();
private List<Account> accounts; private final List<Account> all_accounts = new ArrayList<>();
private Context mContext; private final List<Account> accounts = new ArrayList<>();
private final Context mContext;
private int selectedAccount = -1; private int selectedAccount = -1;
private static final String DEFAULT_ACCOUNT_ID = "IP2IP";
public AccountSelectionAdapter(Context cont, List<Account> newList) { public AccountSelectionAdapter(Context cont, List<Account> newList) {
super(); super();
accounts = newList;
mContext = cont; mContext = cont;
setAccounts(newList);
} }
@Override @Override
...@@ -83,7 +84,7 @@ public class AccountSelectionAdapter extends BaseAdapter { ...@@ -83,7 +84,7 @@ public class AccountSelectionAdapter extends BaseAdapter {
} else { } else {
entryView = (AccountView) rowView.getTag(); entryView = (AccountView) rowView.getTag();
} }
entryView.error.setColorFilter(mContext.getResources().getColor(R.color.error_red)); entryView.error.setColorFilter(ContextCompat.getColor(mContext, R.color.error_red));
/* /*
entryView.alias.setText(accounts.get(pos).getAlias()); entryView.alias.setText(accounts.get(pos).getAlias());
...@@ -114,7 +115,7 @@ public class AccountSelectionAdapter extends BaseAdapter { ...@@ -114,7 +115,7 @@ public class AccountSelectionAdapter extends BaseAdapter {
} else { } else {
entryView = (AccountView) rowView.getTag(); entryView = (AccountView) rowView.getTag();
} }
entryView.error.setColorFilter(mContext.getResources().getColor(R.color.error_red)); entryView.error.setColorFilter(ContextCompat.getColor(mContext, R.color.error_red));
updateAccountView(entryView, accounts.get(pos)); updateAccountView(entryView, accounts.get(pos));
return rowView; return rowView;
...@@ -158,51 +159,29 @@ public class AccountSelectionAdapter extends BaseAdapter { ...@@ -158,51 +159,29 @@ public class AccountSelectionAdapter extends BaseAdapter {
return accounts.get(selectedAccount); return accounts.get(selectedAccount);
} }
public void removeAll() {
accounts.clear();
notifyDataSetChanged();
}
public void addAll(List<Account> results) {
accounts.addAll(results);
notifyDataSetChanged();
}
public void replaceAll(List<Account> results) { public void replaceAll(List<Account> results) {
accounts.clear(); setAccounts(results);
accounts.addAll(results);
notifyDataSetChanged(); notifyDataSetChanged();
} }
/** private void setAccounts(List<Account> results) {
* Modify state of specific account all_accounts.clear();
*/ accounts.clear();
public void updateAccount(String accoundID, String state, int code) { all_accounts.addAll(results);
Log.i(TAG, "updateAccount "); for (Account acc : results)
if (acc.isEnabled())
for (Account a : accounts) { accounts.add(acc);
if (a.getAccountID().contentEquals(accoundID)) {
a.setRegistrationState(state, code);
Log.i(TAG, "updateAccount " + accoundID + " " + code);
notifyDataSetChanged();
return;
}
}
} }
public String getAccountOrder() { public List<String> getAccountOrder() {
String result = DEFAULT_ACCOUNT_ID + File.separator; List<String> result = new ArrayList<>(accounts.size());
String selectedID = accounts.get(selectedAccount).getAccountID(); String selectedID = accounts.get(selectedAccount).getAccountID();
result += selectedID + File.separator; result.add(selectedID);
for (Account a : all_accounts) {
for (Account a : accounts) { if (a.getAccountID().contentEquals(selectedID))
if (a.getAccountID().contentEquals(selectedID)) {
continue; continue;
result.add(a.getAccountID());
} }
result += a.getAccountID() + File.separator;
}
return result; return result;
} }
......
...@@ -55,7 +55,6 @@ import java.util.List; ...@@ -55,7 +55,6 @@ import java.util.List;
public class AccountsManagementFragment extends Fragment { public class AccountsManagementFragment extends Fragment {
static final String TAG = AccountsManagementFragment.class.getSimpleName(); static final String TAG = AccountsManagementFragment.class.getSimpleName();
private static final String DEFAULT_ACCOUNT_ID = "IP2IP";
public static final int ACCOUNT_CREATE_REQUEST = 1; public static final int ACCOUNT_CREATE_REQUEST = 1;
public static final int ACCOUNT_EDIT_REQUEST = 2; public static final int ACCOUNT_EDIT_REQUEST = 2;
private AccountsAdapter mAccountsAdapter; private AccountsAdapter mAccountsAdapter;
...@@ -70,17 +69,12 @@ public class AccountsManagementFragment extends Fragment { ...@@ -70,17 +69,12 @@ public class AccountsManagementFragment extends Fragment {
Account item = mAccountsAdapter.getItem(from); Account item = mAccountsAdapter.getItem(from);
mAccountsAdapter.remove(item); mAccountsAdapter.remove(item);
mAccountsAdapter.insert(item, to); mAccountsAdapter.insert(item, to);
try { mCallbacks.getService().setAccountOrder(mAccountsAdapter.getAccountOrder());
mCallbacks.getService().getRemoteService().setAccountOrder(mAccountsAdapter.generateAccountOrder());
} catch (RemoteException e) {
e.printStackTrace();
}
} }
} }
}; };
private LocalService.Callbacks mCallbacks = LocalService.DUMMY_CALLBACKS; private LocalService.Callbacks mCallbacks = LocalService.DUMMY_CALLBACKS;
//private Account ip2ip;
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
...@@ -351,12 +345,11 @@ public class AccountsManagementFragment extends Fragment { ...@@ -351,12 +345,11 @@ public class AccountsManagementFragment extends Fragment {
notifyDataSetChanged(); notifyDataSetChanged();
} }
private String generateAccountOrder() { private List<String> getAccountOrder() {
String result = DEFAULT_ACCOUNT_ID + File.separator; ArrayList<String> order = new ArrayList<>(accounts.size());
for (Account a : accounts) { for (Account acc : accounts)
result += a.getAccountID() + File.separator; order.add(acc.getAccountID());
} return order;
return result;
} }
} }
......
...@@ -81,7 +81,6 @@ public class GeneralAccountFragment extends PreferenceFragment { ...@@ -81,7 +81,6 @@ public class GeneralAccountFragment extends PreferenceFragment {
private void setPreferenceDetails(AccountDetail details) { private void setPreferenceDetails(AccountDetail details) {
for (AccountDetail.PreferenceEntry p : details.getDetailValues()) { for (AccountDetail.PreferenceEntry p : details.getDetailValues()) {
//Log.i(TAG, "setPreferenceDetails: pref " + p.mKey + " value " + p.mValue);
Preference pref = findPreference(p.mKey); Preference pref = findPreference(p.mKey);
if (pref != null) { if (pref != null) {
if (!p.isTwoState) { if (!p.isTwoState) {
...@@ -96,11 +95,8 @@ public class GeneralAccountFragment extends PreferenceFragment { ...@@ -96,11 +95,8 @@ public class GeneralAccountFragment extends PreferenceFragment {
pref.setSummary(p.mValue); pref.setSummary(p.mValue);
} }
} else { } else {
Log.i(TAG, "pref:"+p.mKey);
((TwoStatePreference) pref).setChecked(p.isChecked()); ((TwoStatePreference) pref).setChecked(p.isChecked());
} }
} else {
Log.w(TAG, "pref not found");
} }
} }
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (C) 2004-2016 Savoir-faire Linux Inc. * Copyright (C) 2004-2016 Savoir-faire Linux Inc.
* *
* Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
* Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -27,7 +28,6 @@ import android.content.Intent; ...@@ -27,7 +28,6 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Bundle; import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
...@@ -56,7 +56,7 @@ public class MenuFragment extends Fragment { ...@@ -56,7 +56,7 @@ public class MenuFragment extends Fragment {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static final String TAG = MenuFragment.class.getSimpleName(); private static final String TAG = MenuFragment.class.getSimpleName();
AccountSelectionAdapter mAccountAdapter; private AccountSelectionAdapter mAccountAdapter;
private Spinner spinnerAccounts; private Spinner spinnerAccounts;
private ImageButton shareBtn; private ImageButton shareBtn;
private Button newAccountBtn; private Button newAccountBtn;
...@@ -64,16 +64,6 @@ public class MenuFragment extends Fragment { ...@@ -64,16 +64,6 @@ public class MenuFragment extends Fragment {
private LocalService.Callbacks mCallbacks = LocalService.DUMMY_CALLBACKS; private LocalService.Callbacks mCallbacks = LocalService.DUMMY_CALLBACKS;
public Account retrieveAccountById(String accountID) {
Account toReturn;
toReturn = mAccountAdapter.getAccount(accountID);
if(toReturn == null || !toReturn.isRegistered())
return getSelectedAccount();
return toReturn;
}
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
...@@ -98,7 +88,6 @@ public class MenuFragment extends Fragment { ...@@ -98,7 +88,6 @@ public class MenuFragment extends Fragment {
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
//getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
} }
private final BroadcastReceiver mReceiver = new BroadcastReceiver() { private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
...@@ -167,12 +156,7 @@ public class MenuFragment extends Fragment { ...@@ -167,12 +156,7 @@ public class MenuFragment extends Fragment {
Bitmap qrBitmap = encodeStringAsQrBitmap(share_uri, qrImage.getWidth()); Bitmap qrBitmap = encodeStringAsQrBitmap(share_uri, qrImage.getWidth());
qrImage.setImageBitmap(qrBitmap); qrImage.setImageBitmap(qrBitmap);
//view.findViewById(R.id.account_selected).setVisibility(View.GONE); mCallbacks.getService().setAccountOrder(mAccountAdapter.getAccountOrder());
try {
mCallbacks.getRemoteService().setAccountOrder(mAccountAdapter.getAccountOrder());
} catch (RemoteException e) {
e.printStackTrace();
}
} }
@Override @Override
...@@ -202,8 +186,6 @@ public class MenuFragment extends Fragment { ...@@ -202,8 +186,6 @@ public class MenuFragment extends Fragment {
} }
public void updateAllAccounts() { public void updateAllAccounts() {
/*if (getActivity() != null)
getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);*/
if (mAccountAdapter != null && mCallbacks.getService() != null) { if (mAccountAdapter != null && mCallbacks.getService() != null) {
List<Account> accs = mCallbacks.getService().getAccounts(); List<Account> accs = mCallbacks.getService().getAccounts();
if (accs.isEmpty()) { if (accs.isEmpty()) {
...@@ -226,6 +208,7 @@ public class MenuFragment extends Fragment { ...@@ -226,6 +208,7 @@ public class MenuFragment extends Fragment {
qr_image_matrix = qr_writer.encode(input, BarcodeFormat.QR_CODE, qrWindowPixels , qrWindowPixels); qr_image_matrix = qr_writer.encode(input, BarcodeFormat.QR_CODE, qrWindowPixels , qrWindowPixels);
} catch (WriterException e) { } catch (WriterException e) {
e.printStackTrace(); e.printStackTrace();
return null;
} }
int qrImageWidth = qr_image_matrix.getWidth(); int qrImageWidth = qr_image_matrix.getWidth();
......
...@@ -724,7 +724,7 @@ public class DRingService extends Service { ...@@ -724,7 +724,7 @@ public class DRingService extends Service {
getExecutor().execute(new SipRunnable() { getExecutor().execute(new SipRunnable() {
@Override @Override
protected void doRun() throws SameThreadException { protected void doRun() throws SameThreadException {
Log.i(TAG, "DRingService.setAccountsOrder() thread running..."); Log.i(TAG, "DRingService.setAccountsOrder() " + order + " thread running...");
Ringservice.setAccountsOrder(order); Ringservice.setAccountsOrder(order);
} }
}); });
......
...@@ -62,6 +62,7 @@ import android.util.LongSparseArray; ...@@ -62,6 +62,7 @@ import android.util.LongSparseArray;
import android.util.LruCache; import android.util.LruCache;
import android.util.Pair; import android.util.Pair;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
...@@ -358,6 +359,8 @@ public class LocalService extends Service implements SharedPreferences.OnSharedP ...@@ -358,6 +359,8 @@ public class LocalService extends Service implements SharedPreferences.OnSharedP
boolean haveSipAccount = false; boolean haveSipAccount = false;
boolean haveRingAccount = false; boolean haveRingAccount = false;
for (Account acc : accounts) { for (Account acc : accounts) {
if (!acc.isEnabled())
continue;
if (acc.isSip()) if (acc.isSip())
haveSipAccount = true; haveSipAccount = true;
else if (acc.isRing()) else if (acc.isRing())
...@@ -511,6 +514,25 @@ public class LocalService extends Service implements SharedPreferences.OnSharedP ...@@ -511,6 +514,25 @@ public class LocalService extends Service implements SharedPreferences.OnSharedP
return acc; return acc;
return null; return null;
} }
public void setAccountOrder(List<String> accountOrder) {
ArrayList<Account> newlist = new ArrayList<>(accounts.size());
String order = "";
for (String acc_id : accountOrder) {
Account acc = getAccount(acc_id);
if (acc != null)
newlist.add(acc);
order += acc_id + File.separator;
}
accounts = newlist;
try {
order += AccountsLoader.ACCOUNT_IP2IP;
mService.setAccountOrder(order);
} catch (RemoteException e) {
e.printStackTrace();
}
sendBroadcast(new Intent(ACTION_ACCOUNT_UPDATE));
}
public ArrayList<Conversation> getConversations() { public ArrayList<Conversation> getConversations() {
ArrayList<Conversation> convs = new ArrayList<>(conversations.values()); ArrayList<Conversation> convs = new ArrayList<>(conversations.values());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment