-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20431 from wordpress-mobile/fix/12629-achievement…
…-image-loading-2 Replaces result listener animation with a Glide animation
- Loading branch information
Showing
7 changed files
with
170 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
WordPress/src/main/java/org/wordpress/android/util/image/GlidePopTransitionOptions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.wordpress.android.util.image | ||
|
||
import android.graphics.drawable.Drawable | ||
import android.view.animation.AnimationUtils | ||
import com.bumptech.glide.TransitionOptions | ||
import com.bumptech.glide.load.DataSource | ||
import com.bumptech.glide.request.transition.NoTransition | ||
import com.bumptech.glide.request.transition.Transition | ||
import com.bumptech.glide.request.transition.TransitionFactory | ||
import org.wordpress.android.R | ||
import org.wordpress.android.util.AppLog | ||
import java.lang.RuntimeException | ||
|
||
object GlidePopTransitionOptions : TransitionOptions<GlidePopTransitionOptions, Drawable>() { | ||
fun pop(): GlidePopTransitionOptions { | ||
return transition(GlidePopTransitionFactory()) | ||
} | ||
} | ||
|
||
class GlidePopTransition : Transition<Drawable> { | ||
@Suppress("TooGenericExceptionCaught") | ||
override fun transition(current: Drawable?, adapter: Transition.ViewAdapter?): Boolean { | ||
adapter?.view?.context?.let { | ||
adapter.setDrawable(current) | ||
try { | ||
val pop = AnimationUtils.loadAnimation(it, R.anim.pop) | ||
adapter.view.startAnimation(pop) | ||
} catch (e: RuntimeException) { | ||
AppLog.e(AppLog.T.UTILS, "Error animating drawable: $e") | ||
} | ||
} | ||
return true | ||
} | ||
} | ||
|
||
class GlidePopTransitionFactory : TransitionFactory<Drawable> { | ||
private val transition: GlidePopTransition by lazy { GlidePopTransition() } | ||
override fun build(dataSource: DataSource?, isFirstResource: Boolean): Transition<Drawable> { | ||
return if (dataSource == DataSource.MEMORY_CACHE) NoTransition.get<Drawable>() else transition | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
WordPress/src/test/java/org/wordpress/android/util/image/GlidePopTransitionOptionsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.wordpress.android.util.image | ||
|
||
import android.graphics.drawable.Drawable | ||
import android.view.View | ||
import com.bumptech.glide.load.DataSource | ||
import com.bumptech.glide.request.transition.NoTransition | ||
import com.bumptech.glide.request.transition.Transition | ||
import junit.framework.TestCase | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import org.junit.Test | ||
import org.mockito.Mockito | ||
import org.mockito.kotlin.whenever | ||
import org.wordpress.android.BaseUnitTest | ||
|
||
@ExperimentalCoroutinesApi | ||
class GlidePopTransitionOptionsTest : BaseUnitTest() { | ||
@Test | ||
fun testBuildWithCache() { | ||
val glidePopTransitionFactory = GlidePopTransitionFactory() | ||
|
||
val result = glidePopTransitionFactory.build(DataSource.MEMORY_CACHE, true) | ||
|
||
TestCase.assertTrue(result is NoTransition) | ||
} | ||
|
||
@Test | ||
fun testBuildWithNoCache() { | ||
val glidePopTransitionFactory = GlidePopTransitionFactory() | ||
|
||
val result = glidePopTransitionFactory.build(DataSource.REMOTE, true) | ||
|
||
TestCase.assertTrue(result is GlidePopTransition) | ||
} | ||
|
||
@Test | ||
fun testTransition() { | ||
val glidePopTransition = GlidePopTransition() | ||
val drawable: Drawable = Mockito.mock() | ||
val viewAdapter: Transition.ViewAdapter = Mockito.mock() | ||
val view: View = Mockito.mock() | ||
whenever(viewAdapter.view).thenReturn(view) | ||
whenever(view.context).thenReturn(Mockito.mock()) | ||
|
||
val result = glidePopTransition.transition(drawable, viewAdapter) | ||
|
||
TestCase.assertTrue(result) | ||
Mockito.verify(viewAdapter).setDrawable(drawable) | ||
} | ||
} |