-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.1.0-AN_FEAT] 스플래시 때 포켓몬 front 이미지 캐시 (#319)
* feat: Splash 화면에서 24개 사진 Preload * [1.1.0/AN_CD] Discord로 alpha 버전 apk 전달 (#290) * 🎉 Chore: PR_Comment_Notification.yml PR Comment 에 '/noti' 를 포함할 경우 Andorid 채널 혹은 Backend 채널로 노티가 간다 * 🎉 Chore: �Avatar, Content, Description 수정 * docs: README v0.1 * CD: discord로 apk 전달 * CD: cd되는지 확인 * ci: artifact 버전 v3로 수정 * test * build : 병렬처리 * Revert "Merge branch 'main' into an/cd/send_to_discord" This reverts commit 925c8db, reversing changes made to 346391c. * ci: google-service추가 * ci: 버저닝 label 추가 * fix: 매직 넘버 상수화 및 예외처리 문 추가 * fix * style: ktFormat * fix: withContext -> coroutineScope, 주석 변경 * fix: Splash 시간 최소 시간 설정
- Loading branch information
Showing
7 changed files
with
141 additions
and
8 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
92 changes: 92 additions & 0 deletions
92
android/data/src/main/java/poke/rogue/helper/data/cache/GlideImageCacher.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,92 @@ | ||
package poke.rogue.helper.data.cache | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.graphics.drawable.Drawable | ||
import com.bumptech.glide.Glide | ||
import com.bumptech.glide.load.DataSource | ||
import com.bumptech.glide.load.engine.GlideException | ||
import com.bumptech.glide.request.RequestListener | ||
import com.bumptech.glide.request.target.Target | ||
import kotlinx.coroutines.coroutineScope | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.suspendCancellableCoroutine | ||
import poke.rogue.helper.data.exception.UnknownException | ||
import kotlin.coroutines.resume | ||
import kotlin.coroutines.resumeWithException | ||
|
||
class GlideImageCacher(private val context: Context) : ImageCacher { | ||
override suspend fun cacheImages(urls: List<String>) = | ||
coroutineScope { | ||
urls.forEach { url -> | ||
launch { | ||
cacheImage(url) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* 백그라운드 작업에서는 submit() 메서드를 사용, 이 경우 RequestListener도 백그라운드 스레드에서 호출 | ||
* UI 작업을 할 때는 into() 메서드를 사용, 이 경우 Main 스레드에서 RequestListener 이 호출 | ||
*/ | ||
private suspend fun cacheImage(url: String) = | ||
suspendCancellableCoroutine<Unit> { con -> | ||
val requestListener = | ||
object : RequestListener<Drawable> { | ||
override fun onLoadFailed( | ||
e: GlideException?, | ||
model: Any?, | ||
target: Target<Drawable>?, | ||
isFirstResource: Boolean, | ||
): Boolean { | ||
con.resumeWithException( | ||
e ?: UnknownException(IllegalStateException("이미지 로드 실패 url: $url")), | ||
) | ||
return false | ||
} | ||
|
||
override fun onResourceReady( | ||
resource: Drawable?, | ||
model: Any?, | ||
target: Target<Drawable>?, | ||
dataSource: DataSource?, | ||
isFirstResource: Boolean, | ||
): Boolean { | ||
con.resume(Unit) | ||
return false | ||
} | ||
} | ||
|
||
val target = | ||
Glide.with(context) | ||
.load(url) | ||
.listener(requestListener) | ||
.submit() | ||
|
||
con.invokeOnCancellation { | ||
Glide.with(context).clear(target) | ||
} | ||
} | ||
|
||
override suspend fun clear() { | ||
Glide.get(context).clearMemory() | ||
} | ||
|
||
companion object { | ||
@SuppressLint("StaticFieldLeak") | ||
private var instance: GlideImageCacher? = null | ||
|
||
fun init(context: Context) { | ||
require(instance == null) { | ||
"GlideImageCacher is already initialized" | ||
} | ||
instance = GlideImageCacher(context) | ||
} | ||
|
||
fun instance(): GlideImageCacher { | ||
return requireNotNull(instance) { | ||
"GlideImageCacher is not initialized" | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
android/data/src/main/java/poke/rogue/helper/data/cache/ImageCacher.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,7 @@ | ||
package poke.rogue.helper.data.cache | ||
|
||
interface ImageCacher { | ||
suspend fun cacheImages(urls: List<String>) | ||
|
||
suspend fun clear() | ||
} |
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