Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
3.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
WangDaYeeeeee committed Sep 10, 2019
1 parent fee1fc5 commit f0e1edf
Show file tree
Hide file tree
Showing 25 changed files with 120 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public List<Photo> subList(int fromIndex, int toIndex) {
photosViewModel.setCollectionId(collection.id);
photosViewModel.setCurated(collection.curated);

ImageHelper.loadCollectionCover(this, cover, collection, null);
ImageHelper.loadCollectionCover(this, cover, collection, false, null);

title.setText(collection.title);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.wangdaye.collection.CollectionActivity;
import com.wangdaye.collection.R;
import com.wangdaye.base.unsplash.Collection;
import com.wangdaye.common.base.application.MysplashApplication;
import com.wangdaye.common.ui.transition.sharedElement.Recolor;
import com.wangdaye.common.ui.transition.sharedElement.RoundCornerTransition;

Expand All @@ -30,7 +29,6 @@ public static void startCollectionActivity(Activity a,
} else {
Recolor.addExtraProperties(background, b);
RoundCornerTransition.addExtraProperties(background, b);
MysplashApplication.getInstance().setSharedElementTransitionExtraProperties(b);

optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(
a,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.wangdaye.common.base.activity;

import android.app.SharedElementCallback;
import android.content.Intent;
import android.graphics.Rect;
import android.os.Build;
Expand All @@ -13,6 +12,7 @@
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.SharedElementCallback;

import com.wangdaye.common.base.application.MysplashApplication;
import com.wangdaye.common.base.dialog.MysplashDialogFragment;
Expand Down Expand Up @@ -68,18 +68,34 @@ public boolean hasTranslucentNavigationBar() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void registerSharedElementTransitionCallback() {
setEnterSharedElementCallback(new SharedElementCallback() {

@Override
public void onSharedElementStart(List<String> sharedElementNames,
List<View> sharedElements,
List<View> sharedElementSnapshots) {
super.onSharedElementStart(sharedElementNames, sharedElements, sharedElementSnapshots);
setExtraPropertiesForViews(sharedElementNames, sharedElements, true);
}

@Override
public void onSharedElementEnd(List<String> sharedElementNames,
List<View> sharedElements,
List<View> sharedElementSnapshots) {
super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots);
setExtraPropertiesForViews(sharedElementNames, sharedElements, false);
}

private void setExtraPropertiesForViews(List<String> sharedElementNames,
List<View> sharedElements,
boolean start) {
Intent intent = getIntent();
for (int i = 0; i < sharedElementNames.size(); i++) {
String name = sharedElementNames.get(i);
if (intent.hasExtra(name)) {
SharedElementTransition.setExtraPropertiesForView(
sharedElements.get(i),
intent.getBundleExtra(name)
intent.getBundleExtra(name),
start
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.graphics.Rect;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -32,7 +31,6 @@ public static MysplashApplication getInstance() {

private List<MysplashActivity> activityList;
private Rect windowInsets;
@Nullable private Bundle sharedElementTransitionExtraProperties;

@Override
public void onCreate() {
Expand Down Expand Up @@ -131,13 +129,4 @@ public void setWindowInsets(int left, int top, int right, int bottom) {
public Rect getWindowInsets() {
return windowInsets;
}

@Nullable
public Bundle getSharedElementTransitionExtraProperties() {
return sharedElementTransitionExtraProperties;
}

public void setSharedElementTransitionExtraProperties(@Nullable Bundle b) {
sharedElementTransitionExtraProperties = b;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.animation.AccelerateDecelerateInterpolator;

import com.bumptech.glide.request.animation.ViewPropertyAnimation;
import com.wangdaye.common.R;

/**
* Fade animator.
Expand All @@ -17,8 +18,9 @@ public class FadeAnimator implements ViewPropertyAnimation.Animator {

@Override
public void animate(View view) {
if (!view.isEnabled()) {
view.setEnabled(true);
Boolean fadeInFlag = (Boolean) view.getTag(R.id.tag_item_image_fade_in_flag);
if (fadeInFlag == null || fadeInFlag) {
view.setTag(R.id.tag_item_image_fade_in_flag, false);
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
animator.setDuration(300);
animator.setInterpolator(new AccelerateDecelerateInterpolator());
Expand Down
56 changes: 46 additions & 10 deletions common/src/main/java/com/wangdaye/common/image/ImageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.wangdaye.base.unsplash.User;
import com.wangdaye.common.utils.AnimUtils;
import com.wangdaye.common.utils.manager.ThemeManager;
import com.wangdaye.component.ComponentFactory;

import java.util.concurrent.ExecutionException;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -73,12 +74,44 @@ public boolean onResourceReady(R resource, T model, Target<R> target,
}
}

private static class SetEnableListener
private static class ExecuteSaturationAnimationListener
extends BaseRequestListener<String, GlideDrawable> {

private ImageView image;
private Photo photo;
private boolean executeAnimation;

ExecuteSaturationAnimationListener(ImageView image, Photo photo, boolean executeAnimation,
@Nullable OnLoadImageListener l) {
super(l);
this.image = image;
this.photo = photo;
this.executeAnimation = executeAnimation;
}

@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
boolean isFromMemoryCache, boolean isFirstResource) {
super.onResourceReady(resource, model, target, isFromMemoryCache, isFirstResource);
photo.loadPhotoSuccess = true;
if (!photo.hasFadedIn) {
photo.hasFadedIn = true;
if (executeAnimation) {
long duration = Long.parseLong(
ComponentFactory.getSettingsService().getSaturationAnimationDuration());
ImageHelper.startSaturationAnimation(image.getContext(), image, duration);
}
}
return false;
}
}

private static class CancelFadeInListener
implements RequestListener<String, GlideDrawable> {

private ImageView view;

SetEnableListener(ImageView view) {
CancelFadeInListener(ImageView view) {
this.view = view;
}

Expand All @@ -91,7 +124,7 @@ public boolean onException(Exception e, String model, Target<GlideDrawable> targ
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
boolean isFromMemoryCache, boolean isFirstResource) {
view.setEnabled(true);
view.setTag(R.id.tag_item_image_fade_in_flag, false);
return false;
}
}
Expand Down Expand Up @@ -123,24 +156,27 @@ public static void loadRegularPhoto(Context context, ImageView view, Photo photo
loadRegularPhoto(context, view, photo, true, l);
}

private static void loadRegularPhoto(Context context, ImageView view, Photo photo,
boolean saturation, @Nullable OnLoadImageListener l) {
public static void loadRegularPhoto(Context context, ImageView view, Photo photo,
boolean saturation, @Nullable OnLoadImageListener l) {
context = getValidContext(context);
if (photo != null && photo.urls != null
&& photo.width != 0 && photo.height != 0) {
// set fade in flag.
// true --> execute fade in animation after loading.
view.setTag(R.id.tag_item_image_fade_in_flag, true);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
&& !photo.hasFadedIn && saturation && l != null) {
AnimUtils.ObservableColorMatrix matrix = new AnimUtils.ObservableColorMatrix();
matrix.setSaturation(0);
view.setColorFilter(new ColorMatrixColorFilter(matrix));
}
view.setEnabled(false);

DrawableRequestBuilder<String> thumbnailRequest = Glide
.with(context)
.load(photo.urls.thumb)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.listener(new SetEnableListener(view));
.listener(new CancelFadeInListener(view));

int[] size = photo.getRegularSize(context);
Glide.with(context)
Expand All @@ -149,7 +185,7 @@ private static void loadRegularPhoto(Context context, ImageView view, Photo phot
.override(size[0], size[1])
.thumbnail(thumbnailRequest)
.animate(new FadeAnimator())
.listener(new BaseRequestListener<>(l))
.listener(new ExecuteSaturationAnimationListener(view, photo, saturation, l))
.into(view);
}
}
Expand All @@ -161,9 +197,9 @@ public static void loadBackgroundPhoto(Context context, final ImageView view, Ph
// collection cover.

public static void loadCollectionCover(Context context, ImageView view, Collection collection,
@Nullable OnLoadImageListener l) {
boolean saturation, @Nullable OnLoadImageListener l) {
if (collection != null) {
loadRegularPhoto(context, view, collection.cover_photo, true, l);
loadRegularPhoto(context, view, collection.cover_photo, saturation, l);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,7 @@ void onBindView(Collection collection, boolean header, Photo photo,
);

if (collection.cover_photo != null) {
ImageHelper.loadCollectionCover(image.getContext(), image, collection, () -> {
collection.cover_photo.loadPhotoSuccess = true;
if (!collection.cover_photo.hasFadedIn) {
collection.cover_photo.hasFadedIn = true;
long duration = Long.parseLong(
ComponentFactory.getSettingsService().getSaturationAnimationDuration());
ImageHelper.startSaturationAnimation(image.getContext(), image, duration);
}
});
ImageHelper.loadCollectionCover(image.getContext(), image, collection, true, null);
} else {
ImageHelper.loadResourceImage(image.getContext(), image, R.drawable.default_collection_cover);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.wangdaye.common.ui.widget.CoverImageView;
import com.wangdaye.common.ui.widget.longPressDrag.LongPressDragCardView;
import com.wangdaye.common.utils.DisplayUtils;
import com.wangdaye.component.ComponentFactory;

import java.util.Collections;

Expand Down Expand Up @@ -66,16 +65,8 @@ void onBindView(Collection collection,

if (collection.cover_photo != null) {
setCardText(context, collection, true);
ImageHelper.loadCollectionCover(image.getContext(), image, collection, () -> {
collection.cover_photo.loadPhotoSuccess = true;
if (!collection.cover_photo.hasFadedIn) {
collection.cover_photo.hasFadedIn = true;
long duration = Long.parseLong(
ComponentFactory.getSettingsService().getSaturationAnimationDuration());
ImageHelper.startSaturationAnimation(context, image, duration);
}
setCardText(context, collection, false);
});
ImageHelper.loadCollectionCover(image.getContext(), image, collection, true,
() -> setCardText(context, collection, false));
card.setCardBackgroundColor(
ImageHelper.computeCardBackgroundColor(
image.getContext(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ void onBindView(Photo photo, boolean showDeleteButton,
image.setShowShadow(false);

ImageHelper.loadRegularPhoto(image.getContext(), image, photo, () -> {
photo.loadPhotoSuccess = true;
if (!photo.hasFadedIn) {
photo.hasFadedIn = true;
long duration = Long.parseLong(
ComponentFactory.getSettingsService().getSaturationAnimationDuration());
ImageHelper.startSaturationAnimation(image.getContext(), image, duration);
}
title.setText(photo.user.name);
image.setShowShadow(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void initWidget(View v) {

AppCompatImageView cover = v.findViewById(R.id.dialog_select_collection_cover);
if (DisplayUtils.isTabletDevice(Objects.requireNonNull(getActivity()))) {
ImageHelper.loadRegularPhoto(getActivity(), cover, photo, null);
ImageHelper.loadRegularPhoto(getActivity(), cover, photo, false, null);
} else {
cover.setVisibility(View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,24 @@ public String[] getTransitionProperties() {

@Override
public void captureStartValues(TransitionValues transitionValues) {
if (isEnter(transitionValues.view)) {
int initColor = getBackgroundColor(transitionValues.view);
Bundle b = getExtraPropertiesFromApplication();
if (b != null && b.containsKey(PROPNAME_COLOR)) {
initColor = b.getInt(PROPNAME_COLOR);
}
transitionValues.values.put(PROPNAME_COLOR, initColor);
} else {
transitionValues.values.put(PROPNAME_COLOR, getBackgroundColor(transitionValues.view));
}
captureValues(transitionValues);
}

@Override
public void captureEndValues(TransitionValues transitionValues) {
if (isEnter(transitionValues.view)) {
transitionValues.values.put(PROPNAME_COLOR, getBackgroundColor(transitionValues.view));
} else {
captureValues(transitionValues);
}

private void captureValues(TransitionValues transitionValues) {
if (isStart(transitionValues.view)) {
int initColor = getBackgroundColor(transitionValues.view);
Bundle b = getExtraPropertiesFromView(transitionValues.view);
if (b != null && b.containsKey(PROPNAME_COLOR)) {
initColor = b.getInt(PROPNAME_COLOR);
}
transitionValues.values.put(PROPNAME_COLOR, initColor);
} else {
transitionValues.values.put(PROPNAME_COLOR, getBackgroundColor(transitionValues.view));
}
}

Expand Down
Loading

0 comments on commit f0e1edf

Please sign in to comment.