Do not use background threads for download UI events.

This commit is contained in:
Alan Evans 2019-04-10 13:13:10 -03:00 committed by GitHub
parent 38bcc6c293
commit 01a9931d92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 24 deletions

View File

@ -31,7 +31,6 @@ import org.thoughtcrime.securesms.events.PartProgressEvent;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.mms.AudioSlide; import org.thoughtcrime.securesms.mms.AudioSlide;
import org.thoughtcrime.securesms.mms.SlideClickListener; import org.thoughtcrime.securesms.mms.SlideClickListener;
import org.thoughtcrime.securesms.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -320,16 +319,11 @@ public class AudioView extends FrameLayout implements AudioSlidePlayer.Listener
} }
} }
@Subscribe(sticky = true, threadMode = ThreadMode.ASYNC) @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEventAsync(final PartProgressEvent event) { public void onEventAsync(final PartProgressEvent event) {
if (audioSlidePlayer != null && event.attachment.equals(this.audioSlidePlayer.getAudioSlide().asAttachment())) { if (audioSlidePlayer != null && event.attachment.equals(audioSlidePlayer.getAudioSlide().asAttachment())) {
Util.runOnMain(new Runnable() {
@Override
public void run() {
downloadProgress.setInstantProgress(((float) event.progress) / event.total); downloadProgress.setInstantProgress(((float) event.progress) / event.total);
} }
});
}
} }
} }

View File

@ -8,7 +8,6 @@ import android.graphics.PorterDuff;
import android.support.annotation.AttrRes; import android.support.annotation.AttrRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -147,16 +146,11 @@ public class DocumentView extends FrameLayout {
return ""; return "";
} }
@Subscribe(sticky = true, threadMode = ThreadMode.ASYNC) @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEventAsync(final PartProgressEvent event) { public void onEventAsync(final PartProgressEvent event) {
if (documentSlide != null && event.attachment.equals(this.documentSlide.asAttachment())) { if (documentSlide != null && event.attachment.equals(documentSlide.asAttachment())) {
Util.runOnMain(new Runnable() {
@Override
public void run() {
downloadProgress.setInstantProgress(((float) event.progress) / event.total); downloadProgress.setInstantProgress(((float) event.progress) / event.total);
} }
});
}
} }
private class DownloadClickedListener implements View.OnClickListener { private class DownloadClickedListener implements View.OnClickListener {

View File

@ -28,7 +28,6 @@ import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.database.AttachmentDatabase;
import org.thoughtcrime.securesms.events.PartProgressEvent; import org.thoughtcrime.securesms.events.PartProgressEvent;
import org.thoughtcrime.securesms.mms.Slide; import org.thoughtcrime.securesms.mms.Slide;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.ViewUtil;
import java.util.Collections; import java.util.Collections;
@ -253,13 +252,11 @@ public class TransferControlView extends FrameLayout {
return totalProgress; return totalProgress;
} }
@Subscribe(sticky = true, threadMode = ThreadMode.ASYNC) @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEventAsync(final PartProgressEvent event) { public void onEventAsync(final PartProgressEvent event) {
if (downloadProgress.containsKey(event.attachment)) { if (downloadProgress.containsKey(event.attachment)) {
Util.runOnMain(() -> { downloadProgress.put(event.attachment, ((float) event.progress) / event.total);
downloadProgress.put(event.attachment, ((float)event.progress) / event.total);
progressWheel.setInstantProgress(calculateProgress(downloadProgress)); progressWheel.setInstantProgress(calculateProgress(downloadProgress));
});
} }
} }
} }