-
Notifications
You must be signed in to change notification settings - Fork 0
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
[1.1.0/AN-FEAT] 인앱 업데이트 기능 구현 #358
base: an/develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package poke.rogue.helper.update | ||
|
||
import android.content.Context | ||
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.activity.result.IntentSenderRequest | ||
import com.google.android.play.core.appupdate.AppUpdateInfo | ||
import com.google.android.play.core.appupdate.AppUpdateManager | ||
import com.google.android.play.core.appupdate.AppUpdateManagerFactory | ||
import com.google.android.play.core.appupdate.AppUpdateOptions | ||
import com.google.android.play.core.install.InstallStateUpdatedListener | ||
import com.google.android.play.core.install.model.AppUpdateType | ||
import com.google.android.play.core.install.model.InstallStatus | ||
import com.google.android.play.core.install.model.UpdateAvailability | ||
import timber.log.Timber | ||
|
||
class UpdateManager( | ||
private val context: Context, | ||
) { | ||
private val appUpdateManager: AppUpdateManager = AppUpdateManagerFactory.create(context) | ||
private val updateType = AppUpdateType.FLEXIBLE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 정말 개인적으로 이건 변수로 따로 안 빼는게 좋아 보입니다. 이게 더 빨리 읽힘 ㅎ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 동의합니다! 중복이 되긴하지만 지역 변수로 만들거나 그대로 사용하는게 더 잘 읽히는 것 같네요 ㅋㅅㅋ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 변수로 뺀 이유는, UpdateManager에서 updateType은 가장 중요하다고 생각해서 뺏습니다 ! |
||
|
||
private val installStateUpdateListener = | ||
InstallStateUpdatedListener { state -> | ||
when (state.installStatus()) { | ||
InstallStatus.INSTALLING -> Timber.i("Update is downloading") | ||
|
||
InstallStatus.DOWNLOADED -> { | ||
Timber.i("Update installed successfully") | ||
appUpdateManager.completeUpdate() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거 다운로드 완료되면 어떻게 되나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다운로드 완료되면 플레이스토어 들어가져서 설치하고 재시작됩니다 ! an.feat._.webm |
||
} | ||
|
||
InstallStatus.CANCELED -> Timber.e("Update was cancelled") | ||
} | ||
} | ||
|
||
fun checkForAppUpdates(appUpdateLauncher: ActivityResultLauncher<IntentSenderRequest>) { | ||
appUpdateManager.appUpdateInfo.addOnSuccessListener { info -> | ||
if (checkForAppUpdate(info)) { | ||
val updateOptions = AppUpdateOptions.newBuilder(updateType).build() | ||
appUpdateManager.startUpdateFlowForResult( | ||
info, | ||
appUpdateLauncher, | ||
updateOptions, | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun checkForAppUpdate(info: AppUpdateInfo): Boolean { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. boolean 을 리턴하는데 메서드 네이밍이
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 이런 경우
근데 이건 동사인가..? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
헉쓰 그렇네요~
|
||
val isUpdateAvailable = info.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE | ||
val isUpdateAllowed = info.isUpdateTypeAllowed(updateType) | ||
return isUpdateAvailable && isUpdateAllowed | ||
} | ||
|
||
fun registerInstallStateUpdateListener() { | ||
appUpdateManager.registerListener(installStateUpdateListener) | ||
} | ||
|
||
fun unregisterInstallStateUpdateListener() { | ||
appUpdateManager.unregisterListener(installStateUpdateListener) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ datastore = "1.0.0" | |
google-services = "4.4.2" | ||
firebase = "33.1.2" | ||
firebase-crashlytics = "3.0.2" | ||
app-update = "2.1.0" | ||
|
||
# Android-Test | ||
android-junit5-plugin = "1.10.0.0" | ||
|
@@ -89,6 +90,8 @@ firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "fir | |
firebase-analytics = { module = "com.google.firebase:firebase-analytics-ktx" } | ||
firebase-crashlytics = { module = "com.google.firebase:firebase-crashlytics-ktx" } | ||
firebase-crashlytics-plugin = { module = "com.google.firebase:firebase-crashlytics-gradle", version.ref = "firebase-crashlytics" } | ||
app-update = { module = "com.google.android.play:app-update", version.ref = "app-update" } | ||
app-update-ktx = { module = "com.google.android.play:app-update-ktx", version.ref = "app-update" } | ||
Comment on lines
+93
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 뭔가 ktx 만 추가해도 될 것 같다는 느낌?? 아닌가욥? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그러게요 코틀린 환경에서만 사용하는거면 ktx만 추가해도 되는군요 ! |
||
# android test | ||
androidx-test-junit = { module = "androidx.test.ext:junit", version.ref = "androidx-test-junit" } | ||
android-test-fragment = { module = "androidx.fragment:fragment-testing", version.ref = "androidx-test-fragment" } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
별건 아니긴하지만 레벨 4에서배운 DefaultLifecycleObserver 를 활용한다면 �액티비티의 생명주기에 맞게 알아서 register/unregister 해줄 수 있을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
옹 좋은데요 ??? 👍👍
DefaultLifecycleObserver
를 활용해서 리스너 관리 할게요