Skip to content

Commit f7c423e

Browse files
committed
fixes #437
1 parent be70dcf commit f7c423e

1 file changed

Lines changed: 38 additions & 22 deletions

File tree

cSploit/src/main/java/org/csploit/android/MainActivity.java

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -964,16 +964,20 @@ public View getView(int position, View convertView, ViewGroup parent) {
964964
}
965965

966966
public void clearSelection() {
967-
for (Target t : list)
968-
t.setSelected(false);
967+
synchronized (this) {
968+
for (Target t : list)
969+
t.setSelected(false);
970+
}
969971
notifyDataSetChanged();
970972
if (mActionMode != null)
971973
mActionMode.finish();
972974
}
973975

974976
public void toggleSelection(int position) {
975-
Target t = list.get(position);
976-
t.setSelected(!t.isSelected());
977+
synchronized (this) {
978+
Target t = list.get(position);
979+
t.setSelected(!t.isSelected());
980+
}
977981
notifyDataSetChanged();
978982
if (mActionMode != null) {
979983
if (getSelectedCount() > 0)
@@ -985,27 +989,34 @@ public void toggleSelection(int position) {
985989

986990
public int getSelectedCount() {
987991
int i = 0;
988-
for (Target t : list)
989-
if (t.isSelected())
990-
i++;
992+
synchronized (this) {
993+
for (Target t : list)
994+
if (t.isSelected())
995+
i++;
996+
}
991997
return i;
992998
}
993999

9941000
public ArrayList<Target> getSelected() {
9951001
ArrayList<Target> result = new ArrayList<Target>();
996-
for (Target t : list)
997-
if (t.isSelected())
998-
result.add(t);
1002+
synchronized (this) {
1003+
for (Target t : list)
1004+
if (t.isSelected())
1005+
result.add(t);
1006+
}
9991007
return result;
10001008
}
10011009

10021010
public int[] getSelectedPositions() {
1003-
int[] res = new int[getSelectedCount()];
1011+
int[] res;
10041012
int j = 0;
10051013

1006-
for (int i = 0; i < list.size(); i++)
1007-
if (list.get(i).isSelected())
1008-
res[j++] = i;
1014+
synchronized (this) {
1015+
res = new int[getSelectedCount()];
1016+
for (int i = 0; i < list.size(); i++)
1017+
if (list.get(i).isSelected())
1018+
res[j++] = i;
1019+
}
10091020
return res;
10101021
}
10111022

@@ -1025,21 +1036,26 @@ public void update(Observable observable, Object data) {
10251036
public void run() {
10261037
if (lv == null)
10271038
return;
1028-
int start = lv.getFirstVisiblePosition();
1029-
for (int i = start, j = lv.getLastVisiblePosition(); i <= j; i++)
1030-
if (target == list.get(i)) {
1031-
View view = lv.getChildAt(i - start);
1032-
getView(i, view, lv);
1033-
break;
1034-
}
1039+
synchronized (this) {
1040+
int start = lv.getFirstVisiblePosition();
1041+
int end = Math.min(lv.getLastVisiblePosition(), list.size());
1042+
for (int i = start; i <= end; i++)
1043+
if (target == list.get(i)) {
1044+
View view = lv.getChildAt(i - start);
1045+
getView(i, view, lv);
1046+
break;
1047+
}
1048+
}
10351049
}
10361050
});
10371051

10381052
}
10391053

10401054
@Override
10411055
public void run() {
1042-
list = System.getTargets();
1056+
synchronized (this) {
1057+
list = System.getTargets();
1058+
}
10431059
notifyDataSetChanged();
10441060
}
10451061

0 commit comments

Comments
 (0)