mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 21:13:12 -07:00
Save Discovery Enabled in Preferences on Android
This commit is contained in:
parent
bf57359929
commit
950b86454d
4 changed files with 22 additions and 3 deletions
|
@ -64,6 +64,11 @@ class Preferences(context: Context)
|
||||||
|
|
||||||
private val resources = context.resources
|
private val resources = context.resources
|
||||||
|
|
||||||
|
val discoveryEnabledKey get() = resources.getString(R.string.preferences_discovery_enabled_key)
|
||||||
|
var discoveryEnabled
|
||||||
|
get() = sharedPreferences.getBoolean(discoveryEnabledKey, true)
|
||||||
|
set(value) { sharedPreferences.edit().putBoolean(discoveryEnabledKey, value).apply() }
|
||||||
|
|
||||||
val logVerboseKey get() = resources.getString(R.string.preferences_log_verbose_key)
|
val logVerboseKey get() = resources.getString(R.string.preferences_log_verbose_key)
|
||||||
var logVerbose
|
var logVerbose
|
||||||
get() = sharedPreferences.getBoolean(logVerboseKey, false)
|
get() = sharedPreferences.getBoolean(logVerboseKey, false)
|
||||||
|
|
|
@ -70,7 +70,7 @@ class MainActivity : AppCompatActivity()
|
||||||
registerLabelButton.setOnClickListener { showRegistration() }
|
registerLabelButton.setOnClickListener { showRegistration() }
|
||||||
|
|
||||||
viewModel = ViewModelProviders
|
viewModel = ViewModelProviders
|
||||||
.of(this, viewModelFactory { MainViewModel(getDatabase(this)) })
|
.of(this, viewModelFactory { MainViewModel(getDatabase(this), Preferences(this)) })
|
||||||
.get(MainViewModel::class.java)
|
.get(MainViewModel::class.java)
|
||||||
|
|
||||||
val recyclerViewAdapter = DisplayHostRecyclerViewAdapter(this::hostTriggered)
|
val recyclerViewAdapter = DisplayHostRecyclerViewAdapter(this::hostTriggered)
|
||||||
|
|
|
@ -21,14 +21,26 @@ import androidx.lifecycle.ViewModel
|
||||||
import com.metallic.chiaki.common.AppDatabase
|
import com.metallic.chiaki.common.AppDatabase
|
||||||
import com.metallic.chiaki.common.DiscoveredDisplayHost
|
import com.metallic.chiaki.common.DiscoveredDisplayHost
|
||||||
import com.metallic.chiaki.common.ManualDisplayHost
|
import com.metallic.chiaki.common.ManualDisplayHost
|
||||||
|
import com.metallic.chiaki.common.Preferences
|
||||||
import com.metallic.chiaki.common.ext.toLiveData
|
import com.metallic.chiaki.common.ext.toLiveData
|
||||||
import com.metallic.chiaki.discovery.DiscoveryManager
|
import com.metallic.chiaki.discovery.DiscoveryManager
|
||||||
import com.metallic.chiaki.discovery.ps4Mac
|
import com.metallic.chiaki.discovery.ps4Mac
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxkotlin.Observables
|
import io.reactivex.rxkotlin.Observables
|
||||||
|
import io.reactivex.rxkotlin.addTo
|
||||||
|
|
||||||
class MainViewModel(val database: AppDatabase): ViewModel()
|
class MainViewModel(val database: AppDatabase, val preferences: Preferences): ViewModel()
|
||||||
{
|
{
|
||||||
val discoveryManager = DiscoveryManager().also { it.active = true /* TODO: from shared preferences */ }
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
|
val discoveryManager = DiscoveryManager().also {
|
||||||
|
it.active = preferences.discoveryEnabled
|
||||||
|
it.discoveryActive
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe { preferences.discoveryEnabled = it }
|
||||||
|
.addTo(disposable)
|
||||||
|
}
|
||||||
|
|
||||||
val displayHosts by lazy {
|
val displayHosts by lazy {
|
||||||
Observables.combineLatest(
|
Observables.combineLatest(
|
||||||
|
@ -55,6 +67,7 @@ class MainViewModel(val database: AppDatabase): ViewModel()
|
||||||
override fun onCleared()
|
override fun onCleared()
|
||||||
{
|
{
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
|
disposable.dispose()
|
||||||
discoveryManager.dispose()
|
discoveryManager.dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -60,6 +60,7 @@
|
||||||
<string name="preferences_log_verbose_summary">Warning: This logs a LOT! Don\'t enable for regular use.</string>
|
<string name="preferences_log_verbose_summary">Warning: This logs a LOT! Don\'t enable for regular use.</string>
|
||||||
|
|
||||||
<!-- Don't localize these -->
|
<!-- Don't localize these -->
|
||||||
|
<string name="preferences_discovery_enabled_key">discovery_enabled</string>
|
||||||
<string name="preferences_log_verbose_key">log_verbose</string>
|
<string name="preferences_log_verbose_key">log_verbose</string>
|
||||||
<string name="preferences_resolution_key">stream_resolution</string>
|
<string name="preferences_resolution_key">stream_resolution</string>
|
||||||
<string name="preferences_resolution_title_360p">360p</string>
|
<string name="preferences_resolution_title_360p">360p</string>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue