Skip to content

Instantly share code, notes, and snippets.

@simpleton
Created July 31, 2014 23:23
Show Gist options
  • Save simpleton/d6ba5b084552a2b36c47 to your computer and use it in GitHub Desktop.
Save simpleton/d6ba5b084552a2b36c47 to your computer and use it in GitHub Desktop.
private List<WeakReference<IFileDownloader.IFileDownloadCallBack> > callbackList
= Collections.synchronizedList(new ArrayList<WeakReference<IFileDownloader.IFileDownloadCallBack>>());
public void addCallback(IFileDownloader.IFileDownloadCallBack cb) {
if (cb != null) {
for (int i=0; i < callbackList.size(); ++i) {
IFileDownloader.IFileDownloadCallBack callback = callbackList.get(i).get();
if (callback == cb) {
return;
}
}
callbackList.add(new WeakReference<IFileDownloader.IFileDownloadCallBack>(cb));
}
}
public void removeCallback(IFileDownloader.IFileDownloadCallBack cb) {
if (cb != null) {
for (int i=0; i < callbackList.size(); ++i) {
IFileDownloader.IFileDownloadCallBack callback = callbackList.get(i).get();
if (callback == null) {
callbackList.remove(i--);
} else if (callback == cb) {
callbackList.remove(i);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment