1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Use TextUtils.isEmpty

This commit is contained in:
Jan Berkel 2014-12-11 21:48:22 +00:00
parent 37b0666f4a
commit ca10e4d94a
11 changed files with 75 additions and 89 deletions

View File

@ -2,19 +2,19 @@ package com.fsck.k9.activity;
import java.util.Locale;
import com.fsck.k9.K9;
import com.fsck.k9.activity.misc.SwipeGestureDetector;
import com.fsck.k9.activity.misc.SwipeGestureDetector.OnSwipeGestureListener;
import com.fsck.k9.helper.StringUtils;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.view.GestureDetector;
import android.view.MotionEvent;
import com.fsck.k9.K9;
import com.fsck.k9.activity.misc.SwipeGestureDetector;
import com.fsck.k9.activity.misc.SwipeGestureDetector.OnSwipeGestureListener;
/**
* This class implements functionality common to most activities used in K-9 Mail.
@ -39,7 +39,7 @@ public class K9ActivityCommon {
public static void setLanguage(Context context, String language) {
Locale locale;
if (StringUtils.isNullOrEmpty(language)) {
if (TextUtils.isEmpty(language)) {
locale = Locale.getDefault();
} else if (language.length() == 5 && language.charAt(2) == '_') {
// language is in the form: en_US

View File

@ -91,7 +91,6 @@ import com.fsck.k9.helper.ContactItem;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.helper.HtmlConverter;
import com.fsck.k9.helper.IdentityHelper;
import com.fsck.k9.helper.StringUtils;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Body;
@ -1216,7 +1215,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
}
private void addAddresses(MultiAutoCompleteTextView view, String addresses) {
if (StringUtils.isNullOrEmpty(addresses)) {
if (TextUtils.isEmpty(addresses)) {
return;
}
for (String address : addresses.split(",")) {
@ -2782,7 +2781,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
// of the forwarded message in the references and the reply to. TB
// only includes ID of the message being forwarded in the reference,
// even if there are multiple references.
if (!StringUtils.isNullOrEmpty(message.getMessageId())) {
if (!TextUtils.isEmpty(message.getMessageId())) {
mInReplyTo = message.getMessageId();
mReferences = mInReplyTo;
} else {

View File

@ -23,9 +23,10 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.v4.util.LruCache;
import android.text.TextUtils;
import android.widget.QuickContactBadge;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.helper.StringUtils;
import com.fsck.k9.mail.Address;
public class ContactPictureLoader {
@ -169,7 +170,7 @@ public class ContactPictureLoader {
letter = m.group(0).toUpperCase(Locale.US);
}
return (StringUtils.isNullOrEmpty(letter)) ?
return (TextUtils.isEmpty(letter)) ?
FALLBACK_CONTACT_LETTER : letter.substring(0, 1);
}

View File

@ -15,11 +15,16 @@ import java.util.Set;
import java.util.concurrent.Future;
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.Loader;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.graphics.Color;
@ -30,15 +35,10 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.app.DialogFragment;
import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.CursorLoader;
import android.content.Loader;
import android.support.v4.content.LocalBroadcastManager;
import android.widget.CursorAdapter;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
@ -59,6 +59,7 @@ import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.QuickContactBadge;
import android.widget.TextView;
@ -81,7 +82,6 @@ import com.fsck.k9.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmen
import com.fsck.k9.helper.ContactPicture;
import com.fsck.k9.helper.MergeCursorWithUniqueId;
import com.fsck.k9.helper.MessageHelper;
import com.fsck.k9.helper.StringUtils;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Flag;
@ -100,6 +100,7 @@ import com.fsck.k9.search.SearchSpecification;
import com.fsck.k9.search.SearchSpecification.SearchCondition;
import com.fsck.k9.search.SearchSpecification.Searchfield;
import com.fsck.k9.search.SqlQueryBuilder;
import com.handmark.pulltorefresh.library.ILoadingLayout;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
@ -1943,7 +1944,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
int threadCount = (mThreadedList) ? cursor.getInt(THREAD_COUNT_COLUMN) : 0;
String subject = cursor.getString(SUBJECT_COLUMN);
if (StringUtils.isNullOrEmpty(subject)) {
if (TextUtils.isEmpty(subject)) {
subject = getString(R.string.general_no_subject);
} else if (threadCount > 1) {
// If this is a thread, strip the RE/FW from the subject. "Be like Outlook."
@ -3449,10 +3450,10 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
if (mIsThreadDisplay) {
if (cursor.moveToFirst()) {
mTitle = cursor.getString(SUBJECT_COLUMN);
if (!StringUtils.isNullOrEmpty(mTitle)) {
if (!TextUtils.isEmpty(mTitle)) {
mTitle = Utility.stripSubject(mTitle);
}
if (StringUtils.isNullOrEmpty(mTitle)) {
if (TextUtils.isEmpty(mTitle)) {
mTitle = getString(R.string.general_no_subject);
}
updateTitle();

View File

@ -1,22 +0,0 @@
package com.fsck.k9.helper;
public final class StringUtils {
public static boolean isNullOrEmpty(String string){
return string == null || string.isEmpty();
}
public static boolean containsAny(String haystack, String[] needles) {
if (haystack == null) {
return false;
}
for (String needle : needles) {
if (haystack.contains(needle)) {
return true;
}
}
return false;
}
}

View File

@ -13,15 +13,14 @@ import org.apache.james.mime4j.field.address.AddressBuilder;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.text.util.Rfc822Token;
import android.text.util.Rfc822Tokenizer;
import android.util.Log;
import com.fsck.k9.K9;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.helper.StringUtils;
import com.fsck.k9.helper.Utility;
@ -69,7 +68,7 @@ public class Address {
Rfc822Token token = tokens[0];
mAddress = token.getAddress();
String name = token.getName();
if (!StringUtils.isNullOrEmpty(name)) {
if (!TextUtils.isEmpty(name)) {
/*
* Don't use the "personal" argument if "address" is of the form:
* James Bond <james.bond@mi6.uk>
@ -130,11 +129,11 @@ public class Address {
*/
public static Address[] parseUnencoded(String addressList) {
List<Address> addresses = new ArrayList<Address>();
if (!StringUtils.isNullOrEmpty(addressList)) {
if (!TextUtils.isEmpty(addressList)) {
Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressList);
for (Rfc822Token token : tokens) {
String address = token.getAddress();
if (!StringUtils.isNullOrEmpty(address)) {
if (!TextUtils.isEmpty(address)) {
addresses.add(new Address(token.getAddress(), token.getName(), false));
}
}
@ -150,7 +149,7 @@ public class Address {
* @return An array of 0 or more Addresses.
*/
public static Address[] parse(String addressList) {
if (StringUtils.isNullOrEmpty(addressList)) {
if (TextUtils.isEmpty(addressList)) {
return EMPTY_ADDRESS_ARRAY;
}
List<Address> addresses = new ArrayList<Address>();
@ -198,7 +197,7 @@ public class Address {
@Override
public String toString() {
if (!StringUtils.isNullOrEmpty(mPersonal)) {
if (!TextUtils.isEmpty(mPersonal)) {
return Utility.quoteAtoms(mPersonal) + " <" + mAddress + ">";
} else {
return mAddress;
@ -213,7 +212,7 @@ public class Address {
}
public String toEncodedString() {
if (!StringUtils.isNullOrEmpty(mPersonal)) {
if (!TextUtils.isEmpty(mPersonal)) {
return EncoderUtil.encodeAddressDisplayName(mPersonal) + " <" + mAddress + ">";
} else {
return mAddress;
@ -279,7 +278,7 @@ public class Address {
}
}
return (!StringUtils.isNullOrEmpty(mPersonal)) ? mPersonal : mAddress;
return (!TextUtils.isEmpty(mPersonal)) ? mPersonal : mAddress;
}
public static CharSequence toFriendly(Address[] addresses) {

View File

@ -1,11 +1,11 @@
package com.fsck.k9.mail.internet;
import android.text.TextUtils;
import android.util.Log;
import com.fsck.k9.K9;
import com.fsck.k9.activity.InsertableHtmlContent;
import com.fsck.k9.helper.HtmlConverter;
import com.fsck.k9.helper.StringUtils;
import com.fsck.k9.mail.Body;
public class TextBodyBuilder {
@ -177,7 +177,7 @@ public class TextBodyBuilder {
private String getSignature() {
String signature = "";
if (!StringUtils.isNullOrEmpty(mSignature)) {
if (!TextUtils.isEmpty(mSignature)) {
signature = "\r\n" + mSignature;
}
@ -186,7 +186,7 @@ public class TextBodyBuilder {
private String getSignatureHtml() {
String signature = "";
if (!StringUtils.isNullOrEmpty(mSignature)) {
if (!TextUtils.isEmpty(mSignature)) {
signature = textToHtmlFragment("\r\n" + mSignature);
}
return signature;
@ -194,7 +194,7 @@ public class TextBodyBuilder {
private String getQuotedText() {
String quotedText = "";
if (!StringUtils.isNullOrEmpty(mQuotedText)) {
if (!TextUtils.isEmpty(mQuotedText)) {
quotedText = mQuotedText;
}
return quotedText;

View File

@ -26,8 +26,6 @@ import java.security.Security;
import java.security.cert.CertificateException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Deque;
@ -48,23 +46,19 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
import javax.net.ssl.SSLException;
import org.apache.commons.io.IOUtils;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.PowerManager;
import android.text.TextUtils;
import android.util.Log;
import com.beetstra.jutf7.CharsetProvider;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.R;
import com.fsck.k9.controller.MessageRetrievalListener;
import com.fsck.k9.helper.StringUtils;
import com.fsck.k9.helper.UrlEncodingHelper;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.helper.power.TracingPowerManager;
@ -99,8 +93,11 @@ import com.fsck.k9.mail.store.ImapResponseParser.ImapResponse;
import com.fsck.k9.mail.store.imap.ImapUtility;
import com.fsck.k9.mail.transport.imap.ImapSettings;
import com.fsck.k9.net.ssl.TrustedSocketFactory;
import com.beetstra.jutf7.CharsetProvider;
import com.jcraft.jzlib.JZlib;
import com.jcraft.jzlib.ZOutputStream;
import org.apache.commons.io.IOUtils;
/**
* <pre>
@ -2009,7 +2006,7 @@ public class ImapStore extends Store {
String newUid = appendList.getString(2);
if (!StringUtils.isNullOrEmpty(newUid)) {
if (!TextUtils.isEmpty(newUid)) {
message.setUid(newUid);
uidMap.put(message.getUid(), newUid);
continue;
@ -2027,7 +2024,7 @@ public class ImapStore extends Store {
Log.d(K9.LOG_TAG, "Got UID " + newUid + " for message for " + getLogId());
}
if (!StringUtils.isNullOrEmpty(newUid)) {
if (!TextUtils.isEmpty(newUid)) {
uidMap.put(message.getUid(), newUid);
message.setUid(newUid);
}

View File

@ -11,7 +11,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import android.app.Application;
import android.content.ContentResolver;
import android.content.ContentValues;
@ -20,26 +19,25 @@ import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.controller.MessageRetrievalListener;
import com.fsck.k9.helper.StringUtils;
import com.fsck.k9.helper.UrlEncodingHelper;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.store.LockableDatabase;
import com.fsck.k9.mail.store.StorageManager;
import com.fsck.k9.mail.store.UnavailableStorageException;
import com.fsck.k9.mail.store.LockableDatabase.DbCallback;
import com.fsck.k9.mail.store.LockableDatabase.WrappedException;
import com.fsck.k9.mail.store.StorageManager;
import com.fsck.k9.mail.store.StorageManager.StorageProvider;
import com.fsck.k9.mail.store.UnavailableStorageException;
import com.fsck.k9.provider.EmailProvider;
import com.fsck.k9.provider.EmailProvider.MessageColumns;
import com.fsck.k9.search.LocalSearch;
@ -539,7 +537,7 @@ public class LocalStore extends Store implements Serializable {
"LEFT JOIN threads ON (threads.message_id = messages.id) " +
"LEFT JOIN folders ON (folders.id = messages.folder_id) WHERE " +
"((empty IS NULL OR empty != 1) AND deleted = 0)" +
((!StringUtils.isNullOrEmpty(where)) ? " AND (" + where + ")" : "") +
((!TextUtils.isEmpty(where)) ? " AND (" + where + ")" : "") +
" ORDER BY date DESC";
if (K9.DEBUG) {

View File

@ -8,14 +8,13 @@ import java.util.Map;
import com.fsck.k9.Account;
import com.fsck.k9.Preferences;
import com.fsck.k9.cache.EmailProviderCacheCursor;
import com.fsck.k9.helper.StringUtils;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.store.LockableDatabase;
import com.fsck.k9.mail.store.LockableDatabase.DbCallback;
import com.fsck.k9.mail.store.LockableDatabase.WrappedException;
import com.fsck.k9.mail.store.local.LocalStore;
import com.fsck.k9.mail.store.UnavailableStorageException;
import com.fsck.k9.mail.store.local.LocalStore;
import com.fsck.k9.search.SqlQueryBuilder;
import android.content.ContentProvider;
@ -27,6 +26,7 @@ import android.database.Cursor;
import android.database.CursorWrapper;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.text.TextUtils;
/**
* Content Provider used to display the message list etc.
@ -303,7 +303,7 @@ public class EmailProvider extends ContentProvider {
UnavailableStorageException {
String where;
if (StringUtils.isNullOrEmpty(selection)) {
if (TextUtils.isEmpty(selection)) {
where = InternalMessageColumns.DELETED + "=0 AND (" +
InternalMessageColumns.EMPTY + " IS NULL OR " +
InternalMessageColumns.EMPTY + "!=1)";
@ -416,7 +416,7 @@ public class EmailProvider extends ContentProvider {
}
query.append("WHERE m." + MessageColumns.DATE + " = a." + MessageColumns.DATE);
if (!StringUtils.isNullOrEmpty(sortOrder)) {
if (!TextUtils.isEmpty(sortOrder)) {
query.append(" ORDER BY ");
query.append(SqlQueryBuilder.addPrefixToSelection(
FIXUP_AGGREGATED_MESSAGES_COLUMNS, "a.", sortOrder));
@ -469,7 +469,7 @@ public class EmailProvider extends ContentProvider {
InternalMessageColumns.EMPTY + " != 1))");
if (!StringUtils.isNullOrEmpty(selection)) {
if (!TextUtils.isEmpty(selection)) {
query.append(" AND (");
query.append(selection);
query.append(")");
@ -570,13 +570,13 @@ public class EmailProvider extends ContentProvider {
// Table selection
sql.append(" FROM messages");
if (StringUtils.containsAny(selection, FOLDERS_COLUMNS)) {
if (containsAny(selection, FOLDERS_COLUMNS)) {
sql.append(" JOIN folders ON (folders.id = messages.folder_id)");
}
// WHERE clause
sql.append(" WHERE (deleted=0 AND (empty IS NULL OR empty!=1))");
if (!StringUtils.isNullOrEmpty(selection)) {
if (!TextUtils.isEmpty(selection)) {
sql.append(" AND (");
sql.append(selection);
sql.append(")");
@ -816,4 +816,18 @@ public class EmailProvider extends ContentProvider {
return super.isNull(realColumnIndex);
}
}
private static boolean containsAny(String haystack, String[] needles) {
if (haystack == null) {
return false;
}
for (String needle : needles) {
if (haystack.contains(needle)) {
return true;
}
}
return false;
}
}

View File

@ -1,5 +1,10 @@
package com.fsck.k9.view;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Parcel;
@ -9,37 +14,31 @@ import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.style.StyleSpan;
import android.util.Log;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.QuickContactBadge;
import android.widget.TextView;
import android.widget.Toast;
import com.fsck.k9.Account;
import com.fsck.k9.FontSizes;
import com.fsck.k9.K9;
import com.fsck.k9.R;
import com.fsck.k9.activity.misc.ContactPictureLoader;
import com.fsck.k9.helper.ContactPicture;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.Account;
import com.fsck.k9.helper.MessageHelper;
import com.fsck.k9.helper.StringUtils;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.internet.MimeUtility;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public class MessageHeader extends LinearLayout implements OnClickListener {
private Context mContext;
private TextView mFromView;
@ -260,7 +259,7 @@ public class MessageHeader extends LinearLayout implements OnClickListener {
}
final String subject = message.getSubject();
if (StringUtils.isNullOrEmpty(subject)) {
if (TextUtils.isEmpty(subject)) {
mSubjectView.setText(mContext.getText(R.string.general_no_subject));
} else {
mSubjectView.setText(subject);