-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Hotfix/#103] in app error, like.. etc
- Loading branch information
Showing
9 changed files
with
73 additions
and
63 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
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
43 changes: 4 additions & 39 deletions
43
feature/main/src/main/java/com/teamwable/main/AppUpdateHandler.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 |
---|---|---|
@@ -1,63 +1,28 @@ | ||
package com.teamwable.main | ||
|
||
import android.content.Context | ||
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.activity.result.IntentSenderRequest | ||
import androidx.appcompat.app.AlertDialog | ||
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.model.AppUpdateType | ||
import com.google.android.play.core.install.model.UpdateAvailability | ||
|
||
class AppUpdateHandler(private val context: Context) { | ||
private lateinit var appUpdateManager: AppUpdateManager | ||
|
||
fun checkForAppUpdate(activityResultLauncher: ActivityResultLauncher<IntentSenderRequest>) { | ||
appUpdateManager = AppUpdateManagerFactory.create(context) | ||
class AppUpdateHandler(private val appUpdateManager: AppUpdateManager) { | ||
fun checkForAppUpdate(onUpdateAvailable: (AppUpdateInfo) -> Unit) { | ||
val appUpdateInfoTask = appUpdateManager.appUpdateInfo | ||
|
||
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo -> | ||
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE) | ||
showUpdateDialog(appUpdateInfo, activityResultLauncher) | ||
onUpdateAvailable(appUpdateInfo) | ||
} | ||
} | ||
|
||
private fun showUpdateDialog(appUpdateInfo: AppUpdateInfo, activityResultLauncher: ActivityResultLauncher<IntentSenderRequest>) { | ||
val builder = AlertDialog.Builder(context) | ||
builder.setTitle(context.getString(R.string.label_in_app_update_title)) | ||
.setMessage(context.getString(R.string.label_in_app_update_content)) | ||
.setPositiveButton(context.getString(R.string.label_in_app_update_yes)) { dialog, _ -> | ||
dialog.dismiss() | ||
startUpdate(appUpdateInfo, activityResultLauncher) | ||
} | ||
.setNegativeButton(context.getString(R.string.label_in_app_update_next)) { dialog, _ -> | ||
dialog.dismiss() | ||
} | ||
|
||
val dialog = builder.create() | ||
dialog.show() | ||
} | ||
|
||
private fun startUpdate(appUpdateInfo: AppUpdateInfo, activityResultLauncher: ActivityResultLauncher<IntentSenderRequest>) { | ||
fun startUpdate(appUpdateInfo: AppUpdateInfo, activityResultLauncher: ActivityResultLauncher<IntentSenderRequest>) { | ||
appUpdateManager.startUpdateFlowForResult( | ||
appUpdateInfo, | ||
activityResultLauncher, | ||
AppUpdateOptions.newBuilder(AppUpdateType.FLEXIBLE).build(), | ||
) | ||
} | ||
|
||
fun resumeUpdateIfNeeded(activityResultLauncher: ActivityResultLauncher<IntentSenderRequest>) { | ||
appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo -> | ||
if (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) { | ||
// In-app update가 이미 실행 중이면, 업데이트를 다시 시작 | ||
appUpdateManager.startUpdateFlowForResult( | ||
appUpdateInfo, | ||
activityResultLauncher, | ||
AppUpdateOptions.newBuilder(AppUpdateType.FLEXIBLE).build(), | ||
) | ||
} | ||
} | ||
} | ||
} |
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
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