Replaced size == 0 by isEmpty when possible

This commit is contained in:
Sylvain Berfini 2019-06-21 13:48:38 +02:00
parent b1c8219c7b
commit 245452279a
10 changed files with 21 additions and 25 deletions

View file

@ -522,7 +522,7 @@ public class LinphoneManager implements SensorEventListener {
if (mCore.limeX3DhAvailable()) { if (mCore.limeX3DhAvailable()) {
String url = mCore.getLimeX3DhServerUrl(); String url = mCore.getLimeX3DhServerUrl();
if (url == null || url.length() == 0) { if (url == null || url.isEmpty()) {
url = getString(R.string.default_lime_x3dh_server_url); url = getString(R.string.default_lime_x3dh_server_url);
Log.i("[Manager] Setting LIME X3Dh server url to default value: " + url); Log.i("[Manager] Setting LIME X3Dh server url to default value: " + url);
mCore.setLimeX3DhServerUrl(url); mCore.setLimeX3DhServerUrl(url);

View file

@ -716,7 +716,7 @@ public class ChatMessagesFragment extends Fragment
Core core = LinphoneManager.getCore(); Core core = LinphoneManager.getCore();
if (mRemoteSipAddress == null if (mRemoteSipAddress == null
|| mRemoteSipUri == null || mRemoteSipUri == null
|| mRemoteSipUri.length() == 0 || mRemoteSipUri.isEmpty()
|| core == null) { || core == null) {
// TODO error // TODO error
return; return;
@ -768,7 +768,7 @@ public class ChatMessagesFragment extends Fragment
}); });
} }
if (mParticipants.size() == 0) { if (mParticipants.isEmpty()) {
// Contact not found // Contact not found
String displayName = LinphoneUtils.getAddressDisplayName(mRemoteParticipantAddress); String displayName = LinphoneUtils.getAddressDisplayName(mRemoteParticipantAddress);
mRoomLabel.setText(displayName); mRoomLabel.setText(displayName);
@ -1229,7 +1229,7 @@ public class ChatMessagesFragment extends Fragment
} }
mRemoteComposing.setVisibility(View.VISIBLE); mRemoteComposing.setVisibility(View.VISIBLE);
if (composing.size() == 0) { if (composing.isEmpty()) {
mRemoteComposing.setVisibility(View.GONE); mRemoteComposing.setVisibility(View.GONE);
} else if (composing.size() == 1) { } else if (composing.size() == 1) {
mRemoteComposing.setText( mRemoteComposing.setText(

View file

@ -485,7 +485,7 @@ public class ChatRoomCreationFragment extends Fragment
} }
private void updateLayout() { private void updateLayout() {
if (mParticipants.size() != 0) { if (!mParticipants.isEmpty()) {
mSearchAdapter.setContactsSelectedList(mParticipants); mSearchAdapter.setContactsSelectedList(mParticipants);
updateList(); updateList();
updateListSelected(); updateListSelected();

View file

@ -199,7 +199,7 @@ class DevicesAdapter extends BaseExpandableListAdapter {
@Override @Override
public int getGroupCount() { public int getGroupCount() {
if (mParticipants.size() == 0) return 0; if (mParticipants.isEmpty()) return 0;
return mOnlyDisplayChildsAsGroups return mOnlyDisplayChildsAsGroups
? mParticipants.get(0).getDevices().length ? mParticipants.get(0).getDevices().length
: mParticipants.size(); : mParticipants.size();
@ -207,7 +207,7 @@ class DevicesAdapter extends BaseExpandableListAdapter {
@Override @Override
public int getChildrenCount(int groupPosition) { public int getChildrenCount(int groupPosition) {
if (mParticipants.size() == 0) return 0; if (mParticipants.isEmpty()) return 0;
return mOnlyDisplayChildsAsGroups return mOnlyDisplayChildsAsGroups
? 0 ? 0
: mParticipants.get(groupPosition).getDevices().length; : mParticipants.get(groupPosition).getDevices().length;
@ -215,7 +215,7 @@ class DevicesAdapter extends BaseExpandableListAdapter {
@Override @Override
public Object getGroup(int groupPosition) { public Object getGroup(int groupPosition) {
if (mParticipants.size() == 0) return null; if (mParticipants.isEmpty()) return null;
return mOnlyDisplayChildsAsGroups return mOnlyDisplayChildsAsGroups
? mParticipants.get(0).getDevices()[groupPosition] ? mParticipants.get(0).getDevices()[groupPosition]
: mParticipants.get(groupPosition); : mParticipants.get(groupPosition);
@ -223,7 +223,7 @@ class DevicesAdapter extends BaseExpandableListAdapter {
@Override @Override
public Object getChild(int groupPosition, int childPosition) { public Object getChild(int groupPosition, int childPosition) {
if (mParticipants.size() == 0) return null; if (mParticipants.isEmpty()) return null;
return mParticipants.get(groupPosition).getDevices()[childPosition]; return mParticipants.get(groupPosition).getDevices()[childPosition];
} }

View file

@ -37,6 +37,7 @@ import org.linphone.core.ChatRoomCapabilities;
import org.linphone.core.tools.Log; import org.linphone.core.tools.Log;
import org.linphone.settings.LinphonePreferences; import org.linphone.settings.LinphonePreferences;
import org.linphone.utils.LinphoneShortcutManager; import org.linphone.utils.LinphoneShortcutManager;
import org.linphone.utils.LinphoneUtils;
@TargetApi(25) @TargetApi(25)
class ApiTwentyFivePlus { class ApiTwentyFivePlus {
@ -50,13 +51,8 @@ class ApiTwentyFivePlus {
ArrayList<ShortcutInfo> shortcuts = new ArrayList<>(); ArrayList<ShortcutInfo> shortcuts = new ArrayList<>();
ChatRoom[] rooms = LinphoneManager.getCore().getChatRooms(); ChatRoom[] rooms = LinphoneManager.getCore().getChatRooms();
ArrayList<ChatRoom> notEmptyOneToOneRooms = new ArrayList<>(); ArrayList<ChatRoom> notEmptyOneToOneRooms =
for (ChatRoom room : rooms) { LinphoneUtils.removeEmptyOneToOneChatRooms(rooms);
if (room.hasCapability(ChatRoomCapabilities.OneToOne.toInt())
&& room.getHistorySize() > 0) {
notEmptyOneToOneRooms.add(room);
}
}
Collections.sort( Collections.sort(
notEmptyOneToOneRooms, notEmptyOneToOneRooms,
new Comparator<ChatRoom>() { new Comparator<ChatRoom>() {

View file

@ -144,10 +144,10 @@ public class ContactsFragment extends Fragment
} }
} else { } else {
if (!mOnlyDisplayLinphoneContacts if (!mOnlyDisplayLinphoneContacts
&& ContactsManager.getInstance().getContacts().size() == 0) { && ContactsManager.getInstance().getContacts().isEmpty()) {
mNoContact.setVisibility(View.VISIBLE); mNoContact.setVisibility(View.VISIBLE);
} else if (mOnlyDisplayLinphoneContacts } else if (mOnlyDisplayLinphoneContacts
&& ContactsManager.getInstance().getSIPContacts().size() == 0) { && ContactsManager.getInstance().getSIPContacts().isEmpty()) {
mNoSipContact.setVisibility(View.VISIBLE); mNoSipContact.setVisibility(View.VISIBLE);
} }
} }
@ -268,7 +268,7 @@ public class ContactsFragment extends Fragment
private void searchContacts(String search) { private void searchContacts(String search) {
boolean isEditionEnabled = false; boolean isEditionEnabled = false;
if (search == null || search.length() == 0) { if (search == null || search.isEmpty()) {
changeContactsAdapter(); changeContactsAdapter();
return; return;
} }

View file

@ -264,7 +264,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
} }
} }
if (mContext != null && getContacts().size() == 0 && hasReadContactsAccess()) { if (mContext != null && getContacts().isEmpty() && hasReadContactsAccess()) {
fetchContactsAsync(); fetchContactsAsync();
} }
} }

View file

@ -125,7 +125,7 @@ public class LinphoneContact extends AndroidContact
} }
public void setFirstNameAndLastName(String fn, String ln, boolean commitChanges) { public void setFirstNameAndLastName(String fn, String ln, boolean commitChanges) {
if (fn != null && fn.length() == 0 && ln != null && ln.length() == 0) return; if (fn != null && fn.isEmpty() && ln != null && ln.isEmpty()) return;
if (fn != null && fn.equals(mFirstName) && ln != null && ln.equals(mLastName)) return; if (fn != null && fn.equals(mFirstName) && ln != null && ln.equals(mLastName)) return;
if (commitChanges) { if (commitChanges) {

View file

@ -108,7 +108,7 @@ public class InAppPurchaseActivity extends Activity
public List<Purchasable> getPurchasedItems() { public List<Purchasable> getPurchasedItems() {
if (mPurchasedItems == null || mPurchasedItems.size() == 0) { if (mPurchasedItems == null || mPurchasedItems.isEmpty()) {
Log.w("nul"); Log.w("nul");
} }
return mPurchasedItems; return mPurchasedItems;
@ -145,7 +145,7 @@ public class InAppPurchaseActivity extends Activity
public void onPurchasedItemsQueryFinished(ArrayList<Purchasable> items) { public void onPurchasedItemsQueryFinished(ArrayList<Purchasable> items) {
mPurchasedItems = items; mPurchasedItems = items;
if (items == null || items.size() == 0) { if (items == null || items.isEmpty()) {
mInAppPurchaseHelper.getAvailableItemsForPurchaseAsync(); mInAppPurchaseHelper.getAvailableItemsForPurchaseAsync();
} else { } else {
for (Purchasable purchasedItem : mPurchasedItems) { for (Purchasable purchasedItem : mPurchasedItems) {

View file

@ -199,7 +199,7 @@ public class LinphonePreferences {
public String getRingtone(String defaultRingtone) { public String getRingtone(String defaultRingtone) {
String ringtone = getConfig().getString("app", "ringtone", defaultRingtone); String ringtone = getConfig().getString("app", "ringtone", defaultRingtone);
if (ringtone == null || ringtone.length() == 0) ringtone = defaultRingtone; if (ringtone == null || ringtone.isEmpty()) ringtone = defaultRingtone;
return ringtone; return ringtone;
} }
@ -817,7 +817,7 @@ public class LinphonePreferences {
public void setRemoteProvisioningUrl(String url) { public void setRemoteProvisioningUrl(String url) {
if (getLc() == null) return; if (getLc() == null) return;
if (url != null && url.length() == 0) { if (url != null && url.isEmpty()) {
url = null; url = null;
} }
getLc().setProvisioningUri(url); getLc().setProvisioningUri(url);