Skip to content

Commit

Permalink
Merge pull request #126 from Team-Wable/feature/#123-version-update
Browse files Browse the repository at this point in the history
[Feature/#123] : select by version, force update
  • Loading branch information
sohyun127 authored Nov 26, 2024
2 parents 4d2b8f5 + 462bf30 commit b8124da
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ fun Context.showAlertDialog(
dialog.dismiss()
onPositiveClick()
}
.setNegativeButton(negativeButtonText) { dialog, _ -> dialog.dismiss() }
val isFlexibleUpdate = negativeButtonText.isNotEmpty()
if (isFlexibleUpdate) builder.setNegativeButton(negativeButtonText) { dialog, _ -> dialog.dismiss() }

builder.create().show()
builder.create().apply {
setCancelable(isFlexibleUpdate)
setCanceledOnTouchOutside(isFlexibleUpdate)
show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ interface FeedClickListener {

fun onKebabBtnClick(feed: Feed)

fun onCommentBtnClick(postAuthorNickname: String)
fun onCommentBtnClick(postAuthorNickname: String, feedId: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class FeedViewHolder private constructor(
setupClickListener(binding.ivFeedProfileImg, binding.tvFeedNickname) { feedClickListener.onPostAuthorProfileClick(item.postAuthorId) }
setupClickListener(binding.ivFeedImg) { feedClickListener.onFeedImageClick(item.image) }
setupClickListener(binding.btnFeedMore) { feedClickListener.onKebabBtnClick(item) }
setupClickListener(binding.btnFeedComment) { feedClickListener.onCommentBtnClick(item.postAuthorNickname) }
setupClickListener(binding.btnFeedComment) { feedClickListener.onCommentBtnClick(item.postAuthorNickname, item.feedId) }
}

private fun setupClickListener(vararg views: View, action: () -> Unit) {
Expand Down
1 change: 1 addition & 0 deletions core/ui/src/main/res/layout/item_comment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:autoLink="web"
android:textAppearance="@style/TextAppearance.Wable.Body4"
android:textColor="@color/gray_800"
app:layout_constraintEnd_toEndOf="@id/guideline_end"
Expand Down
14 changes: 9 additions & 5 deletions feature/home/src/main/java/com/teamwable/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(FragmentHomeBinding::i
)
}

override fun onCommentBtnClick(postAuthorNickname: String) {}
override fun onCommentBtnClick(postAuthorNickname: String, feedId: Long) {
navigateToHomeDetailFragment(feedId)
}
}

private fun handleProfileNavigation(id: Long) {
Expand Down Expand Up @@ -226,10 +228,12 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(FragmentHomeBinding::i

private val requestPermission = registerForActivityResult(
ActivityResultContracts.RequestPermission(),
) {
when (it) {
true -> handlePushAlarmPermissionGranted()
false -> handlePushAlarmPermissionDenied()
) { isGranted ->
when {
isGranted -> handlePushAlarmPermissionGranted()
shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS) -> {
handlePushAlarmPermissionDenied()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class HomeDetailFragment : BindingFragment<FragmentHomeDetailBinding>(FragmentHo
)
}

override fun onCommentBtnClick(postAuthorNickname: String) {
override fun onCommentBtnClick(postAuthorNickname: String, feedId: Long) {
handleCommentBtnClick(postAuthorNickname, CommentType.PARENT)
viewModel.setParentCommentIds(PARENT_COMMENT_DEFAULT, PARENT_COMMENT_DEFAULT)
}
Expand Down
9 changes: 9 additions & 0 deletions feature/main/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ plugins {
}
android {
namespace = "com.teamwable.main"

defaultConfig {
val versionCode = libs.versions.versionCode.get().toInt()
buildConfigField("Integer", "VERSION_CODE", "$versionCode")
}

buildFeatures.apply {
buildConfig = true
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ class AppUpdateHandler(private val appUpdateManager: AppUpdateManager) {
}

fun startUpdate(appUpdateInfo: AppUpdateInfo, activityResultLauncher: ActivityResultLauncher<IntentSenderRequest>) {
val appUpdateType = if (checkIsImmediate(appUpdateInfo)) AppUpdateType.IMMEDIATE else AppUpdateType.FLEXIBLE
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
activityResultLauncher,
AppUpdateOptions.newBuilder(AppUpdateType.FLEXIBLE).build(),
AppUpdateOptions.newBuilder(appUpdateType).build(),
)
}

fun checkIsImmediate(appUpdateInfo: AppUpdateInfo): Boolean {
val isFirstCodeDifferent = (BuildConfig.VERSION_CODE / 100) != (appUpdateInfo.availableVersionCode() / 100)
val isSecondCodeDifferent = ((BuildConfig.VERSION_CODE % 100) / 10) != ((appUpdateInfo.availableVersionCode() % 100) / 10)
return isFirstCodeDifferent || isSecondCodeDifferent
}
}
19 changes: 11 additions & 8 deletions feature/main/src/main/java/com/teamwable/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MainActivity : AppCompatActivity(), Navigation {
if (state.installStatus() == InstallStatus.DOWNLOADED) {
Timber.i("Download Complete")
lifecycleScope.launch {
delay(5000)
delay(1000)
appUpdateManager.completeUpdate()
}
}
Expand Down Expand Up @@ -90,13 +90,16 @@ class MainActivity : AppCompatActivity(), Navigation {
}
}

private fun showUpdateDialog(appUpdateInfo: AppUpdateInfo) = showAlertDialog(
title = getString(R.string.label_in_app_update_title),
message = getString(R.string.label_in_app_update_content),
positiveButtonText = getString(R.string.label_in_app_update_yes),
negativeButtonText = getString(R.string.label_in_app_update_next),
onPositiveClick = { appUpdateHelper.startUpdate(appUpdateInfo, activityResultLauncher) },
)
private fun showUpdateDialog(appUpdateInfo: AppUpdateInfo) {
val negativeText = if (appUpdateHelper.checkIsImmediate(appUpdateInfo)) "" else getString(R.string.label_in_app_update_next)
showAlertDialog(
title = getString(R.string.label_in_app_update_title),
message = getString(R.string.label_in_app_update_content),
positiveButtonText = getString(R.string.label_in_app_update_yes),
negativeButtonText = negativeText,
onPositiveClick = { appUpdateHelper.startUpdate(appUpdateInfo, activityResultLauncher) },
)
}

private fun initView() {
setBottomNavigation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ProfileFeedListFragment : BindingFragment<FragmentProfileFeedBinding>(Frag
)
}

override fun onCommentBtnClick(postAuthorNickname: String) {}
override fun onCommentBtnClick(postAuthorNickname: String, feedId: Long) {}
}

private fun setAdapter() {
Expand Down

0 comments on commit b8124da

Please sign in to comment.