Skip to content

Commit

Permalink
#121 / 업데이트 다이얼로그 콜백 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
l2zh committed Jan 28, 2024
1 parent 004e3b7 commit 8d6f6fd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
20 changes: 14 additions & 6 deletions app/src/main/java/sopt/uni/presentation/IntroActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import timber.log.Timber
import javax.inject.Inject

@AndroidEntryPoint
class IntroActivity : AppCompatActivity() {
class IntroActivity : AppCompatActivity(), UpdateDialogFragment.UpdateDialogListener {
@Inject
lateinit var shortGameRepository: ShortGameRepository

Expand Down Expand Up @@ -52,15 +52,23 @@ class IntroActivity : AppCompatActivity() {
}
appUpdateInfoTask.addOnFailureListener { exception ->
Timber.tag("inappUpdate").e("업데이트 체크 실패: ${exception.message}")
showUpdateDialog()
checkUserStatus()
}
}

override fun onDialogDismissed() {
checkUserStatus()
}

override fun onUpdateComplete() {
checkUserStatus()
}

private fun showUpdateDialog() {
UpdateDialogFragment().show(
supportFragmentManager,
"UpdateDialog",
)
val dialogFragment = UpdateDialogFragment().apply {
updateDialogListener = this@IntroActivity
}
dialogFragment.show(supportFragmentManager, "UpdateDialog")
}

private fun checkUserStatus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.app.Activity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import com.google.android.play.core.appupdate.AppUpdateManager
import com.google.android.play.core.appupdate.AppUpdateOptions
Expand All @@ -15,12 +14,15 @@ import sopt.uni.data.datasource.local.SparkleStorage
import sopt.uni.databinding.TitleAction2DialogBinding
import sopt.uni.util.binding.BindingDialogFragment
import sopt.uni.util.extension.setOnSingleClickListener
import sopt.uni.util.extension.showSnackbar
import javax.inject.Inject

@AndroidEntryPoint
class UpdateDialogFragment :
BindingDialogFragment<TitleAction2DialogBinding>(R.layout.title_action2_dialog) {

lateinit var updateDialogListener: UpdateDialogListener

@Inject
lateinit var appUpdateManager: AppUpdateManager

Expand All @@ -34,6 +36,7 @@ class UpdateDialogFragment :
btnRight.setText(getString(R.string.update_dialog_ok))
btnLeft.setOnSingleClickListener {
dismiss()
updateDialogListener.onDialogDismissed()
}
btnRight.setOnSingleClickListener {
updateSparkle()
Expand All @@ -52,18 +55,23 @@ class UpdateDialogFragment :
private val startForResult =
registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) {
if (it.resultCode != Activity.RESULT_OK) {
Toast.makeText(requireContext(), "업데이트에 실패했습니다. 다시 시도해주세요.", Toast.LENGTH_SHORT)
.show()
showSnackbar(binding.root, "업데이트에 실패했습니다. 다시 시도해주세요.")
Log.e("update", it.resultCode.toString())
} else {
SparkleStorage.setUpdateAvailableBoolean(
IS_UPDATE_AVAILABLE,
true,
)
updateDialogListener.onUpdateComplete()
}
}

companion object {
const val IS_UPDATE_AVAILABLE = "IS_UPDATE_AVAILABLE"
}

interface UpdateDialogListener {
fun onUpdateComplete()
fun onDialogDismissed()
}
}

0 comments on commit 8d6f6fd

Please sign in to comment.