-
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.
- Loading branch information
Showing
5 changed files
with
153 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package sopt.uni.presentation | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.lifecycle.lifecycleScope | ||
import com.google.android.play.core.appupdate.AppUpdateManagerFactory | ||
import com.google.android.play.core.install.model.AppUpdateType | ||
import com.google.android.play.core.install.model.UpdateAvailability | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
import sopt.uni.R | ||
import sopt.uni.data.datasource.local.SparkleStorage | ||
import sopt.uni.databinding.ActivitySplashBinding | ||
import sopt.uni.presentation.home.HomeActivity | ||
import sopt.uni.presentation.invite.NickNameActivity | ||
import sopt.uni.presentation.onboarding.OnBoardingActivity | ||
import sopt.uni.util.binding.BindingActivity | ||
import sopt.uni.util.extension.startActivity | ||
|
||
@AndroidEntryPoint | ||
class SplashActivity : BindingActivity<ActivitySplashBinding>(R.layout.activity_splash) { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(binding.root) | ||
isUpdateAvailable() | ||
|
||
lifecycleScope.launch { | ||
delay(2000) | ||
if (SparkleStorage.accessToken != null) { | ||
if (SparkleStorage.partnerId != -1) { | ||
startActivity<HomeActivity>() | ||
} else { | ||
startActivity<NickNameActivity>() | ||
} | ||
} else { | ||
if (SparkleStorage.partnerId != -1) { | ||
startActivity<HomeActivity>() | ||
} else { | ||
startActivity<OnBoardingActivity>() | ||
} | ||
} | ||
overridePendingTransition(0, 0) | ||
finish() | ||
} | ||
} | ||
|
||
private fun isUpdateAvailable() { | ||
val appUpdateManager = AppUpdateManagerFactory.create(this) | ||
val appUpdateInfoTask = appUpdateManager.appUpdateInfo | ||
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo -> | ||
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed( | ||
AppUpdateType.IMMEDIATE, | ||
) | ||
) { | ||
SparkleStorage.setUpdateAvailableBoolean(IS_UPDATE_AVAILABLE, true) | ||
Log.e("subin", "${SparkleStorage.getUpdateAvailableBoolean(IS_UPDATE_AVAILABLE)}") | ||
} else { | ||
SparkleStorage.setUpdateAvailableBoolean(IS_UPDATE_AVAILABLE, false) | ||
Log.e("subin", "${SparkleStorage.getUpdateAvailableBoolean(IS_UPDATE_AVAILABLE)}") | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
const val IS_UPDATE_AVAILABLE = "IS_UPDATE_AVAILABLE" | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
app/src/main/java/sopt/uni/presentation/home/UpdateDialogFragment.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,70 @@ | ||
package sopt.uni.presentation.home | ||
|
||
import android.app.Activity.RESULT_OK | ||
import android.os.Bundle | ||
import android.view.View | ||
import android.widget.Toast | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
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 | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import sopt.uni.R | ||
import sopt.uni.data.datasource.local.SparkleStorage | ||
import sopt.uni.databinding.TitleAction2DialogBinding | ||
import sopt.uni.presentation.BindingDialogFragment | ||
import sopt.uni.util.extension.setOnSingleClickListener | ||
|
||
@AndroidEntryPoint | ||
class UpdateDialogFragment : | ||
BindingDialogFragment<TitleAction2DialogBinding>(R.layout.title_action2_dialog) { | ||
|
||
private val startForResult = | ||
registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { | ||
if (it.resultCode != RESULT_OK) { | ||
Toast.makeText(requireContext(), "업데이트에 실패했습니다. 다시 시도해주세요.", Toast.LENGTH_SHORT) | ||
.show() | ||
} else { | ||
SparkleStorage.setUpdateAvailableBoolean(IS_UPDATE_AVAILABLE, false) | ||
dismiss() | ||
} | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
with(binding) { | ||
dialogTitle.setText(getString(R.string.update_dialog_title)) | ||
dialogBody.setText(getString(R.string.update_dialog_body)) | ||
btnRight.setText(getString(R.string.update_dialog_ok)) | ||
btnLeft.setOnSingleClickListener { | ||
dismiss() | ||
} | ||
btnRight.setOnSingleClickListener { | ||
requestUpdate() | ||
} | ||
} | ||
} | ||
|
||
private fun requestUpdate() { | ||
val appUpdateManager = AppUpdateManagerFactory.create(requireContext()) | ||
val appUpdateInfoTask = appUpdateManager.appUpdateInfo | ||
appUpdateInfoTask.addOnSuccessListener { appUpdateInfo -> | ||
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed( | ||
AppUpdateType.IMMEDIATE, | ||
) | ||
) { | ||
appUpdateManager.startUpdateFlowForResult( | ||
appUpdateInfo, | ||
startForResult, | ||
AppUpdateOptions.newBuilder(AppUpdateType.IMMEDIATE).build(), | ||
) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
const val IS_UPDATE_AVAILABLE = "IS_UPDATE_AVAILABLE" | ||
} | ||
} |
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