From 757890128ea710b84a68be5b3015e6aa44acaffc Mon Sep 17 00:00:00 2001 From: Mustafa Ozhan Date: Fri, 31 May 2024 12:34:00 +0200 Subject: [PATCH] [Oztechan/CCC#3482] Set and Get navigation results according to destination's backstacks (#3483) --- .../content/calculator/CalculatorFragment.kt | 2 +- .../ccc/android/ui/mobile/util/ViewExtensions.kt | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/content/calculator/CalculatorFragment.kt b/android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/content/calculator/CalculatorFragment.kt index 841bb89829..daa4bade9e 100755 --- a/android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/content/calculator/CalculatorFragment.kt +++ b/android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/content/calculator/CalculatorFragment.kt @@ -78,7 +78,7 @@ class CalculatorFragment : BaseVBFragment() { private fun observeNavigationResults() = getNavigationResult( CHANGE_BASE_EVENT, R.id.calculatorFragment - )?.observe(viewLifecycleOwner) { + ).observe(viewLifecycleOwner) { Logger.i { "CalculatorFragment observeNavigationResults $it" } calculatorViewModel.event.onBaseChange(it) } diff --git a/android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/ViewExtensions.kt b/android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/ViewExtensions.kt index f355573f7a..3c672d166f 100644 --- a/android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/ViewExtensions.kt +++ b/android/ui/mobile/src/main/kotlin/com/oztechan/ccc/android/ui/mobile/util/ViewExtensions.kt @@ -22,7 +22,6 @@ import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import com.github.submob.scopemob.castTo -import com.github.submob.scopemob.whether import com.oztechan.ccc.android.core.ad.AdManager import com.oztechan.ccc.android.core.ad.BannerAdView import com.oztechan.ccc.android.ui.mobile.R @@ -77,19 +76,18 @@ fun Fragment.getNavigationResult( key: String, destinationId: Int ) = findNavController() - .currentBackStackEntry - ?.whether { it.destination.id == destinationId } - ?.savedStateHandle - ?.getLiveData(key) + .getBackStackEntry(destinationId) + .savedStateHandle + .getLiveData(key) fun Fragment.setNavigationResult( destinationId: Int, result: T, key: String ) = findNavController() - .previousBackStackEntry - ?.whether { it.destination.id == destinationId } - ?.savedStateHandle?.set(key, result) + .getBackStackEntry(destinationId) + .savedStateHandle + .set(key, result) fun View?.visibleIf(visible: Boolean, bringFront: Boolean = false) = this?.apply { if (visible) {