Skip to content

Commit 0d102f7

Browse files
committed
Move ListenableFutureTask up to parent.
1 parent 28cb1ed commit 0d102f7

9 files changed

Lines changed: 97 additions & 69 deletions

File tree

libtextsecure/src/main/java/org/whispersystems/textsecure/util/FutureTaskListener.java

Lines changed: 0 additions & 6 deletions
This file was deleted.

libtextsecure/src/main/java/org/whispersystems/textsecure/util/ListenableFutureTask.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/org/thoughtcrime/securesms/ConversationItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
import org.thoughtcrime.securesms.util.DateUtils;
5555
import org.thoughtcrime.securesms.util.Dialogs;
5656
import org.thoughtcrime.securesms.util.Emoji;
57-
import org.whispersystems.textsecure.util.FutureTaskListener;
58-
import org.whispersystems.textsecure.util.ListenableFutureTask;
57+
import org.thoughtcrime.securesms.util.FutureTaskListener;
58+
import org.thoughtcrime.securesms.util.ListenableFutureTask;
5959

6060
/**
6161
* A view that displays an individual conversation item within a conversation

src/org/thoughtcrime/securesms/database/MmsDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import org.thoughtcrime.securesms.util.LRUCache;
5252
import org.whispersystems.libaxolotl.util.guava.Optional;
5353
import org.whispersystems.textsecure.util.InvalidNumberException;
54-
import org.whispersystems.textsecure.util.ListenableFutureTask;
54+
import org.thoughtcrime.securesms.util.ListenableFutureTask;
5555
import org.thoughtcrime.securesms.util.Trimmer;
5656
import org.whispersystems.textsecure.util.Util;
5757

src/org/thoughtcrime/securesms/database/model/MediaMmsMessageRecord.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@
2727
import org.thoughtcrime.securesms.mms.SlideDeck;
2828
import org.thoughtcrime.securesms.recipients.Recipient;
2929
import org.thoughtcrime.securesms.recipients.Recipients;
30-
import org.whispersystems.textsecure.push.exceptions.NotFoundException;
31-
import org.whispersystems.textsecure.util.FutureTaskListener;
32-
import org.whispersystems.textsecure.util.ListenableFutureTask;
30+
import org.thoughtcrime.securesms.util.FutureTaskListener;
31+
import org.thoughtcrime.securesms.util.ListenableFutureTask;
3332

34-
import java.util.List;
3533
import java.util.concurrent.ExecutionException;
3634

3735
/**

src/org/thoughtcrime/securesms/recipients/Recipient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import org.thoughtcrime.securesms.contacts.ContactPhotoFactory;
2727
import org.thoughtcrime.securesms.recipients.RecipientProvider.RecipientDetails;
2828
import org.thoughtcrime.securesms.util.GroupUtil;
29-
import org.whispersystems.textsecure.util.FutureTaskListener;
30-
import org.whispersystems.textsecure.util.ListenableFutureTask;
29+
import org.thoughtcrime.securesms.util.FutureTaskListener;
30+
import org.thoughtcrime.securesms.util.ListenableFutureTask;
3131

3232
import java.util.HashSet;
3333

src/org/thoughtcrime/securesms/recipients/RecipientProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.thoughtcrime.securesms.recipients;
1818

1919
import android.content.Context;
20-
import android.database.ContentObserver;
2120
import android.database.Cursor;
2221
import android.graphics.Bitmap;
2322
import android.graphics.BitmapFactory;
@@ -34,7 +33,7 @@
3433
import org.thoughtcrime.securesms.util.GroupUtil;
3534
import org.thoughtcrime.securesms.util.LRUCache;
3635
import org.thoughtcrime.securesms.util.Util;
37-
import org.whispersystems.textsecure.util.ListenableFutureTask;
36+
import org.thoughtcrime.securesms.util.ListenableFutureTask;
3837

3938
import java.io.IOException;
4039
import java.util.Collections;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (C) 2014 Open Whisper Systems
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
package org.thoughtcrime.securesms.util;
18+
19+
public interface FutureTaskListener<V> {
20+
public void onSuccess(V result);
21+
public void onFailure(Throwable error);
22+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright (C) 2014 Open Whisper Systems
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
package org.thoughtcrime.securesms.util;
18+
19+
import java.util.LinkedList;
20+
import java.util.List;
21+
import java.util.concurrent.Callable;
22+
import java.util.concurrent.ExecutionException;
23+
import java.util.concurrent.FutureTask;
24+
25+
public class ListenableFutureTask<V> extends FutureTask<V> {
26+
27+
private final List<FutureTaskListener<V>> listeners = new LinkedList<>();
28+
29+
public ListenableFutureTask(Callable<V> callable) {
30+
super(callable);
31+
}
32+
33+
public synchronized void addListener(FutureTaskListener<V> listener) {
34+
if (this.isDone()) {
35+
callback(listener);
36+
} else {
37+
this.listeners.add(listener);
38+
}
39+
}
40+
41+
public synchronized void removeListener(FutureTaskListener<V> listener) {
42+
this.listeners.remove(listener);
43+
}
44+
45+
@Override
46+
protected synchronized void done() {
47+
callback();
48+
}
49+
50+
private void callback() {
51+
for (FutureTaskListener<V> listener : listeners) {
52+
callback(listener);
53+
}
54+
}
55+
56+
private void callback(FutureTaskListener<V> listener) {
57+
if (listener != null) {
58+
try {
59+
listener.onSuccess(get());
60+
} catch (InterruptedException e) {
61+
throw new AssertionError(e);
62+
} catch (ExecutionException e) {
63+
listener.onFailure(e);
64+
}
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)