Skip to content

Commit

Permalink
Including install data is off by default and requires the pro upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rken committed Sep 14, 2024
1 parent a6f3701 commit eb0668d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import android.os.Bundle
import android.view.View
import androidx.annotation.Keep
import androidx.fragment.app.viewModels
import androidx.lifecycle.asLiveData
import androidx.preference.CheckBoxPreference
import dagger.hilt.android.AndroidEntryPoint
import eu.darken.octi.MainDirections
import eu.darken.octi.R
import eu.darken.octi.common.observe2
import eu.darken.octi.common.uix.PreferenceFragment3
import eu.darken.octi.module.core.GeneralModuleSettings
import eu.darken.octi.modules.apps.core.AppsSettings
Expand All @@ -25,16 +24,26 @@ class ModuleSettingsFragment : PreferenceFragment3() {
override val settings: GeneralModuleSettings by lazy { _settings }
override val preferenceFile: Int = R.xml.preferences_module

private val moduleApps: CheckBoxPreference
get() = findPreference("module.apps.enabled")!!

private val moduleAppsIncludeInstaller: CheckBoxPreference
get() = findPreference("module.apps.include.installer")!!

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
appsSettings.isEnabled.flow.asLiveData().observe2(this) {
moduleAppsIncludeInstaller.isEnabled = moduleApps.isChecked

vm.state.observe2 { state ->
moduleAppsIncludeInstaller.apply {
isEnabled = state.isAppModuleEnabled
setOnPreferenceClickListener {
if (!state.isPro) {
isChecked = false
MainDirections.goToUpgradeFragment().navigate()
true
} else {
false
}
}
}
}

super.onViewCreated(view, savedInstanceState)
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
package eu.darken.octi.module.ui.settings

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.asLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import eu.darken.octi.common.coroutine.DispatcherProvider
import eu.darken.octi.common.debug.logging.logTag
import eu.darken.octi.common.uix.ViewModel3
import eu.darken.octi.common.upgrade.UpgradeRepo
import eu.darken.octi.modules.apps.core.AppsSettings
import kotlinx.coroutines.flow.combine
import javax.inject.Inject

@HiltViewModel
class ModuleSettingsVM @Inject constructor(
@Suppress("unused") private val handle: SavedStateHandle,
dispatcherProvider: DispatcherProvider,
upgradeRepo: UpgradeRepo,
appsSettings: AppsSettings,
) : ViewModel3(dispatcherProvider) {


val state = combine(
upgradeRepo.upgradeInfo,
appsSettings.isEnabled.flow,
) { upgradeInfo, isAppsEnabled ->
State(
isPro = upgradeInfo.isPro,
isAppModuleEnabled = isAppsEnabled,
)
}.asLiveData()

data class State(
val isPro: Boolean,
val isAppModuleEnabled: Boolean,
)

companion object {
private val TAG = logTag("Settings", "Module", "VM")
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/xml/preferences_module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
android:summary="@string/module_apps_desc"
android:title="@string/module_apps_label" />
<CheckBoxPreference
android:enabled="false"
android:icon="@drawable/ic_store_24"
android:key="module.apps.include.installer"
android:summary="@string/module_apps_installer_desc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AppsSettings @Inject constructor(

override val isEnabled = dataStore.createValue("module.apps.enabled", true)

val includeInstaller = dataStore.createValue("module.apps.include.installer", true)
val includeInstaller = dataStore.createValue("module.apps.include.installer", false)

override val mapper: PreferenceStoreMapper = PreferenceStoreMapper(
isEnabled,
Expand Down

0 comments on commit eb0668d

Please sign in to comment.