fix(android): remove explicit use of UI thread (#698)
No need to send events via UI thread. This causes app to use main thread unnecessary that may result in a ARN exception.
This commit is contained in:
parent
250b4e5539
commit
5d2894e442
|
@ -1,8 +1,6 @@
|
||||||
package com.dylanvann.fastimage;
|
package com.dylanvann.fastimage;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
@ -82,12 +80,6 @@ public class FastImageOkHttpProgressGlideModule extends LibraryGlideModule {
|
||||||
private final Map<String, FastImageProgressListener> LISTENERS = new WeakHashMap<>();
|
private final Map<String, FastImageProgressListener> LISTENERS = new WeakHashMap<>();
|
||||||
private final Map<String, Long> PROGRESSES = new HashMap<>();
|
private final Map<String, Long> PROGRESSES = new HashMap<>();
|
||||||
|
|
||||||
private final Handler handler;
|
|
||||||
|
|
||||||
DispatchingProgressListener() {
|
|
||||||
this.handler = new Handler(Looper.getMainLooper());
|
|
||||||
}
|
|
||||||
|
|
||||||
void forget(String key) {
|
void forget(String key) {
|
||||||
LISTENERS.remove(key);
|
LISTENERS.remove(key);
|
||||||
PROGRESSES.remove(key);
|
PROGRESSES.remove(key);
|
||||||
|
@ -107,12 +99,7 @@ public class FastImageOkHttpProgressGlideModule extends LibraryGlideModule {
|
||||||
forget(key);
|
forget(key);
|
||||||
}
|
}
|
||||||
if (needsDispatch(key, bytesRead, contentLength, listener.getGranularityPercentage())) {
|
if (needsDispatch(key, bytesRead, contentLength, listener.getGranularityPercentage())) {
|
||||||
handler.post(new Runnable() {
|
listener.onProgress(key, bytesRead, contentLength);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
listener.onProgress(key, bytesRead, contentLength);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue