Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3479: Implement Progress Bar for Zoom Activity #3481

Merged
merged 5 commits into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/media/ZoomableActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,30 @@
import butterknife.BindView;
import butterknife.ButterKnife;
import fr.free.nrw.commons.R;
import com.facebook.drawee.drawable.ProgressBarDrawable;
import fr.free.nrw.commons.media.zoomControllers.zoomable.DoubleTapGestureListener;
import fr.free.nrw.commons.media.zoomControllers.zoomable.ZoomableDraweeView;
import timber.log.Timber;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Animatable;
import android.net.Uri;
import android.os.Bundle;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.controller.BaseControllerListener;
import com.facebook.drawee.controller.ControllerListener;
import com.facebook.drawee.drawable.ScalingUtils;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.interfaces.DraweeController;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;

import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.imagepipeline.image.ImageInfo;
import com.github.chrisbanes.photoview.PhotoView;

import java.io.InputStream;
Expand All @@ -32,6 +41,8 @@ public class ZoomableActivity extends AppCompatActivity {

@BindView(R.id.zoomable)
ZoomableDraweeView photo;
@BindView(R.id.zoom_progress_bar)
ProgressBar spinner;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -48,13 +59,42 @@ protected void onCreate(Bundle savedInstanceState) {
init();
}

/**
* Two types of loading indicators have been added to the zoom activity:
* 1. An Indeterminate spinner for showing the time lapsed between dispatch of the image request
* and starting to receiving the image.
* 2. ProgressBarDrawable that reflects how much image has been downloaded
*/
private final ControllerListener loadingListener = new BaseControllerListener<ImageInfo>() {
@Override
public void onSubmit(String id, Object callerContext) {
// Sometimes the spinner doesn't appear when rapidly switching between images, this fixes that
spinner.setVisibility(View.VISIBLE);
}

@Override
public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes intermediate image is also slowly appears. I think we should also use the progressbar for that phase. What do you think @kbhardwaj123 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neslihanturan actually i inspected this thing and found that if i place a log statement for onIntermediateImageSet it won't appear in the logs, i think it would be better if i make the Indeterminate spinner INVISIBLE as soon as Intermediate image is set

spinner.setVisibility(View.GONE);
}
@Override
public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) {
spinner.setVisibility(View.GONE);
}
};
private void init() {
if( imageUri != null ) {
GenericDraweeHierarchy hierarchy = GenericDraweeHierarchyBuilder.newInstance(getResources())
.setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
.setProgressBarImage(new ProgressBarDrawable())
.setProgressBarImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
.build();
photo.setHierarchy(hierarchy);
photo.setAllowTouchInterceptionWhileZoomed(true);
photo.setIsLongpressEnabled(false);
photo.setTapListener(new DoubleTapGestureListener(photo));
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(imageUri)
.setControllerListener(loadingListener)
.build();
photo.setController(controller);
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout/activity_zoomable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,14 @@
android:layout_width="match_parent"
app:actualImageScaleType="fitCenter"
/>
<ProgressBar
android:layout_width="@dimen/dimen_72"
android:layout_height="@dimen/dimen_72"
android:id="@+id/zoom_progress_bar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>

</androidx.constraintlayout.widget.ConstraintLayout>