Skip to content

Commit f2ca065

Browse files
authored
Merge pull request #4676 from wordpress-mobile/issue/64-remove-vectors
Replace Vectors with ArrayLists
2 parents 48d5a88 + 1e5ef86 commit f2ca065

File tree

3 files changed

+53
-44
lines changed

3 files changed

+53
-44
lines changed

WordPress/src/main/java/org/wordpress/android/WordPressDB.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ public List<Map<String, Object>> getBlogsBy(String byString, String[] extraField
565565
public List<Map<String, Object>> getBlogsBy(String byString, String[] extraFields,
566566
int limit, boolean hideJetpackWithoutCredentials) {
567567
if (db == null) {
568-
return new Vector<>();
568+
return new ArrayList<>();
569569
}
570570

571571
if (hideJetpackWithoutCredentials) {
@@ -591,7 +591,7 @@ public List<Map<String, Object>> getBlogsBy(String byString, String[] extraField
591591
Cursor c = db.query(BLOGS_TABLE, allFields, byString, null, null, null, null, limitStr);
592592
int numRows = c.getCount();
593593
c.moveToFirst();
594-
List<Map<String, Object>> blogs = new Vector<>();
594+
List<Map<String, Object>> blogs = new ArrayList<>();
595595
for (int i = 0; i < numRows; i++) {
596596
int id = c.getInt(0);
597597
String blogName = c.getString(1);
@@ -947,16 +947,16 @@ public List<String> loadStatsLogin(int id) {
947947

948948
c.moveToFirst();
949949

950-
List<String> returnVector = new Vector<String>();
950+
List<String> list = new ArrayList<>();
951951
if (c.getString(0) != null) {
952-
returnVector.add(c.getString(0));
953-
returnVector.add(decryptPassword(c.getString(1)));
952+
list.add(c.getString(0));
953+
list.add(decryptPassword(c.getString(1)));
954954
} else {
955-
returnVector = null;
955+
list = null;
956956
}
957957
c.close();
958958

959-
return returnVector;
959+
return list;
960960
}
961961

962962
/*
@@ -1397,17 +1397,17 @@ public List<String> loadCategories(int id) {
13971397
"category_name" }, "blog_id=" + Integer.toString(id), null, null, null, null);
13981398
int numRows = c.getCount();
13991399
c.moveToFirst();
1400-
List<String> returnVector = new Vector<String>();
1400+
List<String> list = new ArrayList<>();
14011401
for (int i = 0; i < numRows; ++i) {
14021402
String category_name = c.getString(2);
14031403
if (category_name != null) {
1404-
returnVector.add(category_name);
1404+
list.add(category_name);
14051405
}
14061406
c.moveToNext();
14071407
}
14081408
c.close();
14091409

1410-
return returnVector;
1410+
return list;
14111411
}
14121412

14131413
public int getCategoryId(int id, String category) {
@@ -1468,12 +1468,12 @@ public List<Map<String, Object>> getQuickPressShortcuts(int blogId) {
14681468
String id, name;
14691469
int numRows = c.getCount();
14701470
c.moveToFirst();
1471-
List<Map<String, Object>> blogs = new Vector<Map<String, Object>>();
1471+
List<Map<String, Object>> blogs = new ArrayList<>();
14721472
for (int i = 0; i < numRows; i++) {
14731473
id = c.getString(0);
14741474
name = c.getString(2);
14751475
if (id != null) {
1476-
Map<String, Object> thisHash = new HashMap<String, Object>();
1476+
Map<String, Object> thisHash = new HashMap<>();
14771477

14781478
thisHash.put("id", id);
14791479
thisHash.put("name", name);

WordPress/src/main/java/org/wordpress/android/ui/AddQuickPressShortcutActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import org.wordpress.android.util.GravatarUtils;
3232
import org.wordpress.android.util.StringUtils;
3333

34+
import java.util.ArrayList;
3435
import java.util.List;
3536
import java.util.Map;
36-
import java.util.Vector;
3737

3838
public class AddQuickPressShortcutActivity extends ListActivity {
3939
static final int ADD_ACCOUNT_REQUEST = 0;
@@ -43,7 +43,7 @@ public class AddQuickPressShortcutActivity extends ListActivity {
4343
public int[] accountIDs;
4444
public String[] accountUsers;
4545
public String[] blavatars;
46-
public List<String> accountNames = new Vector<String>();
46+
public List<String> accountNames = new ArrayList<>();
4747

4848
@Override
4949
public void onCreate(Bundle savedInstanceState) {

libs/utils/WordPressUtils/src/main/java/org/wordpress/android/util/helpers/WPHtmlTagHandler.java

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,62 @@
77

88
import org.xml.sax.XMLReader;
99

10-
import java.util.Vector;
10+
import java.util.ArrayList;
11+
import java.util.List;
1112

1213
/**
1314
* Handle tags that the Html class doesn't understand
1415
* Tweaked from source at http://stackoverflow.com/questions/4044509/android-how-to-use-the-html-taghandler
1516
*/
1617
public class WPHtmlTagHandler implements Html.TagHandler {
18+
19+
private static final int SPAN_INDENT_WIDTH = 15;
20+
1721
private int mListItemCount = 0;
18-
private Vector<String> mListParents = new Vector<String>();
22+
private List<String> mListParents = new ArrayList<>();
1923

2024
@Override
2125
public void handleTag(final boolean opening, final String tag, Editable output,
2226
final XMLReader xmlReader) {
23-
if (tag.equals("ul") || tag.equals("ol") || tag.equals("dd")) {
24-
if (opening) {
25-
mListParents.add(tag);
26-
} else {
27-
mListParents.remove(tag);
27+
if (tag != null) {
28+
if (tag.equals("ul") || tag.equals("ol") || tag.equals("dd")) {
29+
if (opening) {
30+
mListParents.add(tag);
31+
} else {
32+
mListParents.remove(tag);
33+
}
34+
mListItemCount = 0;
35+
} else if (tag.equals("li") && !opening) {
36+
handleListTag(output);
2837
}
29-
mListItemCount = 0;
30-
} else if (tag.equals("li") && !opening) {
31-
handleListTag(output);
3238
}
3339
}
3440

3541
private void handleListTag(Editable output) {
36-
if (mListParents.lastElement().equals("ul")) {
37-
output.append("\n");
38-
String[] split = output.toString().split("\n");
39-
int start = 0;
40-
if (split.length != 1) {
41-
int lastIndex = split.length - 1;
42-
start = output.length() - split[lastIndex].length() - 1;
43-
}
44-
output.setSpan(new BulletSpan(15 * mListParents.size()), start, output.length(), 0);
45-
} else if (mListParents.lastElement().equals("ol")) {
46-
mListItemCount++;
47-
output.append("\n");
48-
String[] split = output.toString().split("\n");
49-
int start = 0;
50-
if (split.length != 1) {
51-
int lastIndex = split.length - 1;
52-
start = output.length() - split[lastIndex].length() - 1;
42+
int size = mListParents.size();
43+
if (size > 0 && output != null) {
44+
if ("ul".equals(mListParents.get(size - 1))) {
45+
output.append("\n");
46+
String[] split = output.toString().split("\n");
47+
int start = 0;
48+
if (split.length != 1) {
49+
int lastIndex = split.length - 1;
50+
start = output.length() - split[lastIndex].length() - 1;
51+
}
52+
output.setSpan(new BulletSpan(SPAN_INDENT_WIDTH * mListParents.size()), start, output.length(), 0);
53+
} else if ("ol".equals(mListParents.get(size - 1))) {
54+
mListItemCount++;
55+
output.append("\n");
56+
String[] split = output.toString().split("\n");
57+
int start = 0;
58+
if (split.length != 1) {
59+
int lastIndex = split.length - 1;
60+
start = output.length() - split[lastIndex].length() - 1;
61+
}
62+
output.insert(start, mListItemCount + ". ");
63+
output.setSpan(new LeadingMarginSpan.Standard(SPAN_INDENT_WIDTH * mListParents.size()), start,
64+
output.length(), 0);
5365
}
54-
output.insert(start, mListItemCount + ". ");
55-
output.setSpan(new LeadingMarginSpan.Standard(15 * mListParents.size()), start,
56-
output.length(), 0);
5766
}
5867
}
5968
}

0 commit comments

Comments
 (0)