Skip to content

Commit

Permalink
[#2854] Remove experimental multiplatform settings (#3259)
Browse files Browse the repository at this point in the history
* Revert "[#3253] Clean up Swift code (#3254)"

This reverts commit 92ac1b3.

* Revert "[#3251] Prevent multiple Api call when base change on click and add test cases (#3252)"

This reverts commit 6755d69.

* Revert "[#3191]  Add Flow Property for lastInput (#3192)"

This reverts commit 375da22.

* Revert "[#3189] Move to new getBaseFlow logic (#3190)"

This reverts commit 4e4efc9

* Revert "[#3185] Remove navigation result logics (#3186)"

This reverts commit ba25635.

* Revert "[#3183] Remove onBaseChange event (#3184)"

This reverts commit 917be17.

* Revert "[#3180] Remove ChangeBase Effect (#3181)"

This reverts commit 6fab011.

* Revert "[#3178] Replace CurrencyChange effect with DismissDialog (#3179)"

This reverts commit fc2f955.

* Revert "[#3176] Add Flow Property for currentBase (#3177)"

This reverts commit dd2bdc5.

* Revert "[#3144] Remove Persistence and use DI dispatchers in Coroutine based Persistences (#3145)"

This reverts commit c59e1a5.

* Revert "[#3141] Move sessionCount to Suspend (#3142)"

This reverts commit e2eaa85.

* Revert "[#3138] Move premiumEndDate to Suspend (#3140)"

This reverts commit bd0f4b9.

* Revert "[#2942] Move firstRun to Suspend (#3137)"

This reverts commit 2ff3edf.

* Revert "[#3128] Move appTheme to Suspend (#3135)"

This reverts commit 00c10be.

* Revert "[#3122] Move currentBase to Suspend (#3127)"

This reverts commit de4de42

* Revert "[#3123] Move precision to Suspend (#3124)"

This reverts commit 26af2a1

* Revert "[#3120] Move lastInput to Suspend (#3121)"

This reverts commit 9c53434.

* Revert "[#3038] Add missing Settings Koin definition for native target (#3039)"

This reverts commit 98870c3.

* Revert "[#2871] Add error test case for FlowPersistence (#2872)"

This reverts commit c1f8711.

* Revert "[#2867] Create test for FlowPersistence (#2868)"

This reverts commit 47ea4f9

* Revert "[#2865] Create test for SuspendPersistence (#2866)"

This reverts commit fdc952c.

* Revert "[#2869] Opt-in for ExperimentalSettingsApi (#2870)"

This reverts commit ef9f187.

* Revert "[#2863] Use relevant settings for persistencs (#2864)"

This reverts commit 00696db

* Revert "[#2857] Add Suspension support for multiplatform settings (#2859)"

This reverts commit 5eaa8b1

* Revert "[#2855] Add Flow support for multiplatform settings (#2856)"

This reverts commit 9b52909

* [#2854] Remove experimental multiplatform settings

* [#2854] Remove experimental multiplatform settings

* [#2854] Remove experimental multiplatform settings
  • Loading branch information
mustafaozhan authored Mar 24, 2024
1 parent e787206 commit 694dcac
Show file tree
Hide file tree
Showing 68 changed files with 1,017 additions and 1,220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.oztechan.ccc.android.ui.mobile.util.copyToClipBoard
import com.oztechan.ccc.android.ui.mobile.util.dataState
import com.oztechan.ccc.android.ui.mobile.util.destroyBanner
import com.oztechan.ccc.android.ui.mobile.util.getFromClipBoard
import com.oztechan.ccc.android.ui.mobile.util.getNavigationResult
import com.oztechan.ccc.android.ui.mobile.util.setBackgroundByName
import com.oztechan.ccc.android.ui.mobile.util.setBannerAd
import com.oztechan.ccc.android.ui.mobile.util.showSnack
Expand Down Expand Up @@ -56,6 +57,7 @@ class CalculatorFragment : BaseVBFragment<FragmentCalculatorBinding>() {
binding.observeStates()
binding.setListeners()
observeEffects()
observeNavigationResults()
}

override fun onResume() {
Expand All @@ -75,6 +77,14 @@ class CalculatorFragment : BaseVBFragment<FragmentCalculatorBinding>() {
super.onDestroyView()
}

private fun observeNavigationResults() = getNavigationResult<String>(
CHANGE_BASE_EVENT,
R.id.calculatorFragment
)?.observe(viewLifecycleOwner) {
Logger.i { "CalculatorFragment observeNavigationResults $it" }
calculatorViewModel.event.onBaseChange(it)
}

private fun FragmentCalculatorBinding.initViews() = viewLifecycleOwner.lifecycleScope.launch {
recyclerViewMain.adapter = calculatorAdapter
}
Expand Down Expand Up @@ -198,4 +208,8 @@ class CalculatorFragment : BaseVBFragment<FragmentCalculatorBinding>() {
private fun Button.setKeyboardListener() = setOnClickListener {
calculatorViewModel.event.onKeyPress(text.toString())
}

companion object {
const val CHANGE_BASE_EVENT = "change_base"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import com.github.submob.basemob.fragment.BaseVBFragment
import com.oztechan.ccc.android.core.ad.AdManager
import com.oztechan.ccc.android.ui.mobile.BuildConfig
import com.oztechan.ccc.android.ui.mobile.R
import com.oztechan.ccc.android.ui.mobile.content.calculator.CalculatorFragment.Companion.CHANGE_BASE_EVENT
import com.oztechan.ccc.android.ui.mobile.databinding.FragmentCurrenciesBinding
import com.oztechan.ccc.android.ui.mobile.util.destroyBanner
import com.oztechan.ccc.android.ui.mobile.util.hideKeyboard
import com.oztechan.ccc.android.ui.mobile.util.setBannerAd
import com.oztechan.ccc.android.ui.mobile.util.setNavigationResult
import com.oztechan.ccc.android.ui.mobile.util.showSnack
import com.oztechan.ccc.android.ui.mobile.util.visibleIf
import com.oztechan.ccc.client.core.analytics.AnalyticsManager
Expand Down Expand Up @@ -131,6 +133,12 @@ class CurrenciesFragment : BaseVBFragment<FragmentCurrenciesBinding>() {
findNavController().popBackStack()
view?.hideKeyboard()
}

is CurrenciesEffect.ChangeBase -> setNavigationResult(
R.id.calculatorFragment,
viewEffect.newBase,
CHANGE_BASE_EVENT
)
}
}.launchIn(viewLifecycleOwner.lifecycleScope)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import co.touchlab.kermit.Logger
import com.github.submob.basemob.activity.BaseActivity
import com.github.submob.scopemob.whether
import com.oztechan.ccc.android.core.ad.AdManager
import com.oztechan.ccc.android.ui.mobile.BuildConfig
import com.oztechan.ccc.android.ui.mobile.R
Expand Down Expand Up @@ -55,16 +54,12 @@ class MainActivity : BaseActivity() {
.flowWithLifecycle(lifecycle)
.onEach {
with(it) {
shouldOnboardUser?.let { shouldOnboardUser ->
setDestination(if (shouldOnboardUser) R.id.sliderFragment else R.id.calculatorFragment)
}
setDestination(if (shouldOnboardUser) R.id.sliderFragment else R.id.calculatorFragment)

// if dark mode is supported use theming according to user preference
it.appTheme
?.whether { Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q }
?.let { appTheme ->
AppCompatDelegate.setDefaultNightMode(getThemeMode(appTheme))
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
AppCompatDelegate.setDefaultNightMode(getThemeMode(it.appTheme))
}
}
}.launchIn(lifecycleScope)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import androidx.lifecycle.lifecycleScope
import co.touchlab.kermit.Logger
import com.github.submob.basemob.bottomsheet.BaseVBBottomSheetDialogFragment
import com.oztechan.ccc.android.ui.mobile.R
import com.oztechan.ccc.android.ui.mobile.content.calculator.CalculatorFragment.Companion.CHANGE_BASE_EVENT
import com.oztechan.ccc.android.ui.mobile.databinding.BottomSheetSelectCurrencyBinding
import com.oztechan.ccc.android.ui.mobile.util.setNavigationResult
import com.oztechan.ccc.android.ui.mobile.util.visibleIf
import com.oztechan.ccc.client.core.analytics.AnalyticsManager
import com.oztechan.ccc.client.core.analytics.model.ScreenName
Expand Down Expand Up @@ -83,7 +85,14 @@ class SelectCurrencyBottomSheet :
.onEach { viewEffect ->
Logger.i { "SelectCurrencyBottomSheet observeEffects ${viewEffect::class.simpleName}" }
when (viewEffect) {
is SelectCurrencyEffect.DismissDialog -> dismissDialog()
is SelectCurrencyEffect.CurrencyChange -> {
setNavigationResult(
R.id.calculatorFragment,
viewEffect.newBase,
CHANGE_BASE_EVENT
)
dismissDialog()
}

SelectCurrencyEffect.OpenCurrencies -> navigate(
R.id.selectCurrencyBottomSheet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import androidx.core.content.ContextCompat
import androidx.core.view.children
import androidx.core.view.isGone
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
Expand Down Expand Up @@ -70,6 +73,24 @@ fun View.animateHeight(startHeight: Int, endHeight: Int) {
startAnimation(animation)
}

fun <T> Fragment.getNavigationResult(
key: String,
destinationId: Int
) = findNavController()
.currentBackStackEntry
?.whether { it.destination.id == destinationId }
?.savedStateHandle
?.getLiveData<T>(key)

fun <T> Fragment.setNavigationResult(
destinationId: Int,
result: T,
key: String
) = findNavController()
.previousBackStackEntry
?.whether { it.destination.id == destinationId }
?.savedStateHandle?.set(key, result)

fun View?.visibleIf(visible: Boolean, bringFront: Boolean = false) = this?.apply {
if (visible) {
isVisible = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import com.oztechan.ccc.common.core.model.Currency
data class WidgetState(
var currencyList: List<Currency> = listOf(),
var lastUpdate: String = "",
var currentBase: String = "",
var isPremium: Boolean = true
var currentBase: String,
var isPremium: Boolean
) : BaseState

// Event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ class WidgetViewModel(
) : BaseSEEDViewModel<WidgetState, BaseEffect, WidgetEvent, WidgetData>(), WidgetEvent {

// region SEED
private val _state = MutableStateFlow(WidgetState())
private val _state = MutableStateFlow(
WidgetState(
currentBase = calculationStorage.currentBase,
isPremium = appStorage.premiumEndDate.isNotPassed()
)
)
override val state = _state.asStateFlow()

private val _effect = MutableSharedFlow<WidgetEffect>()
Expand All @@ -39,24 +44,13 @@ class WidgetViewModel(
override val data = WidgetData()
// endregion

init {
viewModelScope.launchIgnored {
_state.update {
it.copy(
currentBase = calculationStorage.getBase(),
isPremium = appStorage.getPremiumEndDate().isNotPassed()
)
}
}
}

private suspend fun refreshWidgetData() {
private fun refreshWidgetData() {
_state.update {
it.copy(
currencyList = listOf(),
lastUpdate = "",
currentBase = calculationStorage.getBase(),
isPremium = appStorage.getPremiumEndDate().isNotPassed()
currentBase = calculationStorage.currentBase,
isPremium = appStorage.premiumEndDate.isNotPassed()
)
}

Expand All @@ -67,14 +61,14 @@ class WidgetViewModel(

private fun getFreshWidgetData() = viewModelScope.launch {
val conversion = backendApiService
.getConversion(calculationStorage.getBase())
.getConversion(calculationStorage.currentBase)

currencyDataSource.getActiveCurrencies()
.filterNot { it.code == calculationStorage.getBase() }
.filterNot { it.code == calculationStorage.currentBase }
.onEach {
it.rate = conversion.getRateFromCode(it.code)
?.getFormatted(calculationStorage.getPrecision())
.orEmpty()
it.rate =
conversion.getRateFromCode(it.code)?.getFormatted(calculationStorage.precision)
.orEmpty()
}
.take(MAXIMUM_NUMBER_OF_CURRENCY)
.let { currencyList ->
Expand All @@ -92,7 +86,7 @@ class WidgetViewModel(

val newBaseIndex = activeCurrencies
.map { it.code }
.indexOf(calculationStorage.getBase())
.indexOf(calculationStorage.currentBase)
.let {
if (isToNext) {
it + 1
Expand All @@ -103,7 +97,7 @@ class WidgetViewModel(
(it + activeCurrencies.size) % activeCurrencies.size // it handles index -1 and index size +1
}

calculationStorage.setBase(activeCurrencies[newBaseIndex].code)
calculationStorage.currentBase = activeCurrencies[newBaseIndex].code
}

// region Event
Expand Down
Loading

0 comments on commit 694dcac

Please sign in to comment.