aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/view/adapter
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-10-11 13:48:40 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-10-11 13:48:40 +0900
commit81f0f42f2ddb087a1748f2e2141a127ebf38c858 (patch)
treeea2f4bad7e05401b5237cfa9ba1b2a61a1973700 /app/src/main/java/net/lacolaco/smileessence/view/adapter
parentf381863bdcf84cf975c5b9896d56feb14b5e0a67 (diff)
downloadSmileEssence-81f0f42f2ddb087a1748f2e2141a127ebf38c858.tar.gz
CustomListAdapter: synchronized ブロックの代わりにメソッドに synchronized キーワードを付けた
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/view/adapter')
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java9
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapter.java40
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/StatusListAdapter.java18
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.java46
4 files changed, 42 insertions, 71 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java
index ba888142..ab89189e 100644
--- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java
+++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/CustomListAdapter.java
@@ -13,7 +13,6 @@ public abstract class CustomListAdapter<T extends IViewModel> extends BaseAdapte
// ------------------------------ FIELDS ------------------------------
- protected final Object LOCK = new Object();
private boolean isNotifiable = true;
private List<T> frozenList = new ArrayList<>();
private Activity activity;
@@ -27,15 +26,11 @@ public abstract class CustomListAdapter<T extends IViewModel> extends BaseAdapte
// --------------------- GETTER / SETTER METHODS ---------------------
public final boolean isNotifiable() {
- synchronized (LOCK) {
- return isNotifiable;
- }
+ return isNotifiable;
}
public final void setNotifiable(boolean notifiable) {
- synchronized (LOCK) {
- isNotifiable = notifiable;
- }
+ isNotifiable = notifiable;
}
// --------------------- Interface BaseAdapter ---------------------
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapter.java
index 5e46e088..24ccc997 100644
--- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapter.java
+++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/OrderedCustomListAdapter.java
@@ -56,40 +56,30 @@ public class OrderedCustomListAdapter<T extends IViewModel & IdObject> extends C
// -------------------------- OTHER METHODS --------------------------
- public void addItem(T item) {
- synchronized (LOCK) {
- treeMap.put(item.getId(), item);
- }
+ public synchronized void addItem(T item) {
+ treeMap.put(item.getId(), item);
}
- public void addItems(List<T> items) {
- synchronized (LOCK) {
- for (T item : items) {
- treeMap.put(item.getId(), item);
- }
+ public synchronized void addItems(List<T> items) {
+ for (T item : items) {
+ treeMap.put(item.getId(), item);
}
}
- public void clear() {
- synchronized (LOCK) {
- treeMap.clear();
- }
+ public synchronized void clear() {
+ treeMap.clear();
}
- public T removeItem(T item) {
- synchronized (LOCK) {
- return treeMap.remove(item.getId());
- }
+ public synchronized T removeItem(T item) {
+ return treeMap.remove(item.getId());
}
- public int removeItemById(long id) {
- synchronized (LOCK) {
- T item = treeMap.remove(id);
- if (item == null) {
- return 0;
- } else {
- return 1;
- }
+ public synchronized int removeItemById(long id) {
+ T item = treeMap.remove(id);
+ if (item == null) {
+ return 0;
+ } else {
+ return 1;
}
}
}
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/StatusListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/StatusListAdapter.java
index b9f7929d..5fda8d56 100644
--- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/StatusListAdapter.java
+++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/StatusListAdapter.java
@@ -57,17 +57,15 @@ public class StatusListAdapter extends OrderedCustomListAdapter<StatusViewModel>
// -------------------------- OTHER METHODS --------------------------
@Override
- public int removeItemById(long statusID) {
- synchronized (LOCK) {
- int count = 0;
- count += super.removeItemById(statusID);
- Tweet t = Tweet.fetch(statusID);
- if (t != null) {
- for (long retweetId : t.getRetweets().values()) {
- count += super.removeItemById(retweetId);
- }
+ public synchronized int removeItemById(long statusID) {
+ int count = 0;
+ count += super.removeItemById(statusID);
+ Tweet t = Tweet.fetch(statusID);
+ if (t != null) {
+ for (long retweetId : t.getRetweets().values()) {
+ count += super.removeItemById(retweetId);
}
- return count;
}
+ return count;
}
}
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.java b/app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.java
index 8e72cc80..2afc0316 100644
--- a/app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.java
+++ b/app/src/main/java/net/lacolaco/smileessence/view/adapter/UnorderedCustomListAdapter.java
@@ -50,48 +50,36 @@ public class UnorderedCustomListAdapter<T extends IViewModel> extends CustomList
// -------------------------- OTHER METHODS --------------------------
- public void addItemToTop(T item) {
- synchronized (LOCK) {
- if (list.contains(item)) {
- list.add(0, item);
- }
+ public synchronized void addItemToTop(T item) {
+ if (!list.contains(item)) {
+ list.add(0, item);
}
}
- public void addItemsToTop(List<T> items) {
- synchronized (LOCK) {
- ListIterator<T> iterator = items.listIterator(items.size());
- while (iterator.hasPrevious()) {
- addItemToTop(iterator.previous());
- }
+ public synchronized void addItemsToTop(List<T> items) {
+ ListIterator<T> iterator = items.listIterator(items.size());
+ while (iterator.hasPrevious()) {
+ addItemToTop(iterator.previous());
}
}
- public void addItemToBottom(T item) {
- synchronized (LOCK) {
- if (list.contains(item)) {
- list.add(item);
- }
+ public synchronized void addItemToBottom(T item) {
+ if (!list.contains(item)) {
+ list.add(item);
}
}
- public void addItemsToBottom(List<T> items) {
- synchronized (LOCK) {
- for (T item : items) {
- addItemToBottom(item);
- }
+ public synchronized void addItemsToBottom(List<T> items) {
+ for (T item : items) {
+ addItemToBottom(item);
}
}
- public void clear() {
- synchronized (LOCK) {
- list.clear();
- }
+ public synchronized void clear() {
+ list.clear();
}
- public boolean removeItem(T item) {
- synchronized (LOCK) {
- return list.remove(item);
- }
+ public synchronized boolean removeItem(T item) {
+ return list.remove(item);
}
}