diff --git a/android/app/src/main/java/com/metallic/chiaki/common/Preferences.kt b/android/app/src/main/java/com/metallic/chiaki/common/Preferences.kt
new file mode 100644
index 0000000..2805d3a
--- /dev/null
+++ b/android/app/src/main/java/com/metallic/chiaki/common/Preferences.kt
@@ -0,0 +1,72 @@
+/*
+ * This file is part of Chiaki.
+ *
+ * Chiaki is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chiaki is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Chiaki. If not, see .
+ */
+
+package com.metallic.chiaki.common
+
+import android.content.Context
+import androidx.annotation.StringRes
+import androidx.preference.PreferenceManager
+import com.metallic.chiaki.R
+import com.metallic.chiaki.lib.VideoFPSPreset
+import com.metallic.chiaki.lib.VideoResolutionPreset
+
+class Preferences(context: Context)
+{
+ enum class Resolution(val value: String, @StringRes val title: Int, val preset: VideoResolutionPreset)
+ {
+ RES_360P("360p", R.string.preferences_resolution_title_360p, VideoResolutionPreset.RES_360P),
+ RES_540P("540p", R.string.preferences_resolution_title_540p, VideoResolutionPreset.RES_540P),
+ RES_720P("720p", R.string.preferences_resolution_title_720p, VideoResolutionPreset.RES_720P),
+ RES_1080P("1080p", R.string.preferences_resolution_title_1080p, VideoResolutionPreset.RES_1080P),
+ }
+
+ enum class FPS(val value: String, @StringRes val title: Int, val preset: VideoFPSPreset)
+ {
+ FPS_30("30", R.string.preferences_fps_title_30, VideoFPSPreset.FPS_30),
+ FPS_60("60", R.string.preferences_fps_title_60, VideoFPSPreset.FPS_60)
+ }
+
+ companion object
+ {
+ val resolutionDefault = Resolution.RES_720P
+ val resolutionAll = Resolution.values()
+ val fpsDefault = FPS.FPS_60
+ val fpsAll = FPS.values()
+ }
+
+ private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
+ private val resources = context.resources
+
+ val logVerboseKey get() = resources.getString(R.string.preferences_log_verbose_key)
+ var logVerbose
+ get() = sharedPreferences.getBoolean(logVerboseKey, false)
+ set(value) { sharedPreferences.edit().putBoolean(logVerboseKey, value).apply() }
+
+ val resolutionKey get() = resources.getString(R.string.preferences_resolution_key)
+ var resolution
+ get() = sharedPreferences.getString(resolutionKey, resolutionDefault.value)?.let { value ->
+ Resolution.values().firstOrNull { it.value == value }
+ } ?: resolutionDefault
+ set(value) { sharedPreferences.edit().putString(resolutionKey, value.value).apply() }
+
+ val fpsKey get() = resources.getString(R.string.preferences_fps_key)
+ var fps
+ get() =sharedPreferences.getString(fpsKey, fpsDefault.value)?.let { value ->
+ FPS.values().firstOrNull { it.value == value }
+ } ?: fpsDefault
+ set(value) { sharedPreferences.edit().putString(fpsKey, value.value).apply() }
+}
\ No newline at end of file
diff --git a/android/app/src/main/java/com/metallic/chiaki/lib/Chiaki.kt b/android/app/src/main/java/com/metallic/chiaki/lib/Chiaki.kt
index 4e8717c..9a3afc6 100644
--- a/android/app/src/main/java/com/metallic/chiaki/lib/Chiaki.kt
+++ b/android/app/src/main/java/com/metallic/chiaki/lib/Chiaki.kt
@@ -8,6 +8,20 @@ import java.lang.Exception
import java.net.InetSocketAddress
import kotlin.math.abs
+enum class VideoResolutionPreset(val value: Int)
+{
+ RES_360P(1),
+ RES_540P(2),
+ RES_720P(3),
+ RES_1080P(4)
+}
+
+enum class VideoFPSPreset(val value: Int)
+{
+ FPS_30(30),
+ FPS_60(60)
+}
+
@Parcelize
data class ConnectVideoProfile(
val width: Int,
diff --git a/android/app/src/main/java/com/metallic/chiaki/settings/SettingsActivity.kt b/android/app/src/main/java/com/metallic/chiaki/settings/SettingsActivity.kt
index 1d0a466..7ac9e24 100644
--- a/android/app/src/main/java/com/metallic/chiaki/settings/SettingsActivity.kt
+++ b/android/app/src/main/java/com/metallic/chiaki/settings/SettingsActivity.kt
@@ -23,11 +23,8 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
-import androidx.transition.TransitionManager
import com.metallic.chiaki.R
-import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_settings.*
-import kotlinx.android.synthetic.main.activity_settings.toolbar
interface TitleFragment
{
diff --git a/android/app/src/main/java/com/metallic/chiaki/settings/SettingsFragment.kt b/android/app/src/main/java/com/metallic/chiaki/settings/SettingsFragment.kt
index 8adb263..5ef7575 100644
--- a/android/app/src/main/java/com/metallic/chiaki/settings/SettingsFragment.kt
+++ b/android/app/src/main/java/com/metallic/chiaki/settings/SettingsFragment.kt
@@ -21,21 +21,79 @@ import android.content.res.Resources
import android.os.Bundle
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
-import androidx.preference.Preference
-import androidx.preference.PreferenceFragmentCompat
+import androidx.preference.*
import com.metallic.chiaki.R
-import com.metallic.chiaki.common.AppDatabase
+import com.metallic.chiaki.common.Preferences
import com.metallic.chiaki.common.ext.viewModelFactory
import com.metallic.chiaki.common.getDatabase
+class DataStore(val preferences: Preferences): PreferenceDataStore()
+{
+ override fun getBoolean(key: String?, defValue: Boolean) = when(key)
+ {
+ preferences.logVerboseKey -> preferences.logVerbose
+ else -> defValue
+ }
+
+ override fun putBoolean(key: String?, value: Boolean)
+ {
+ when(key)
+ {
+ preferences.logVerboseKey -> preferences.logVerbose = value
+ }
+ }
+
+ override fun getString(key: String, defValue: String?) = when(key)
+ {
+ preferences.resolutionKey -> preferences.resolution.value
+ preferences.fpsKey -> preferences.fps.value
+ else -> defValue
+ }
+
+ override fun putString(key: String, value: String?)
+ {
+ when(key)
+ {
+ preferences.resolutionKey ->
+ {
+ val resolution = Preferences.Resolution.values().firstOrNull { it.value == value } ?: return
+ preferences.resolution = resolution
+ }
+ preferences.fpsKey ->
+ {
+ val fps = Preferences.FPS.values().firstOrNull { it.value == value } ?: return
+ preferences.fps = fps
+ }
+ }
+ }
+}
+
class SettingsFragment: PreferenceFragmentCompat(), TitleFragment
{
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?)
{
+ val context = context ?: return
+
+ val preferences = Preferences(context)
+ preferenceManager.preferenceDataStore = DataStore(preferences)
setPreferencesFromResource(R.xml.preferences, rootKey)
+
val registeredHostsPreference = preferenceScreen.findPreference("registered_hosts")
+ preferenceScreen.findPreference(getString(R.string.preferences_resolution_key))?.let {
+ it.entryValues = Preferences.resolutionAll.map { res -> res.value }.toTypedArray()
+ it.entries = Preferences.resolutionAll.map { res -> getString(res.title) }.toTypedArray()
+ }
+
+ preferenceScreen.findPreference(getString(R.string.preferences_fps_key))?.let {
+ it.entryValues = Preferences.fpsAll.map { fps -> fps.value }.toTypedArray()
+ it.entries = Preferences.fpsAll.map { fps -> getString(fps.title) }.toTypedArray()
+ }
+
+ val bitratePreference = preferenceScreen.findPreference("bitrate")
+ bitratePreference?.summaryProvider = Preference.SummaryProvider { it.text }
+
val viewModel = ViewModelProviders
.of(this, viewModelFactory { SettingsViewModel(getDatabase(context!!)) })
.get(SettingsViewModel::class.java)
diff --git a/android/app/src/main/res/values/array.xml b/android/app/src/main/res/values/array.xml
deleted file mode 100644
index 64c1cda..0000000
--- a/android/app/src/main/res/values/array.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
- - 360p
- - 540p
- - 720p
- - 1080p
-
-
-
- - 360p
- - 540p
- - 720p
- - 1080p
-
-
-
- - 30
- - 60
-
-
-
- - 30
- - 60
-
-
\ No newline at end of file
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
index 88e6a39..9d04c1e 100644
--- a/android/app/src/main/res/values/strings.xml
+++ b/android/app/src/main/res/values/strings.xml
@@ -48,4 +48,16 @@
Bitrate
Verbose Logging
Warning: This logs a LOT! Don\'t enable for regular use.
+
+
+ log_verbose
+ stream_resolution
+ 360p
+ 540p
+ 720p
+ 1080p
+ stream_fps
+ 30
+ 60
+ stream_bitrate
diff --git a/android/app/src/main/res/xml/preferences.xml b/android/app/src/main/res/xml/preferences.xml
index 1d1dc60..1096cb8 100644
--- a/android/app/src/main/res/xml/preferences.xml
+++ b/android/app/src/main/res/xml/preferences.xml
@@ -22,19 +22,17 @@
app:key="category_stream"
app:title="@string/preferences_category_title_stream">
+ app:summary="%s" />
+ app:summary="%s"/>
+ app:key="@string/preferences_bitrate_key"
+ app:title="@string/preferences_bitrate_title"/>
\ No newline at end of file
diff --git a/lib/include/chiaki/session.h b/lib/include/chiaki/session.h
index 08a2832..9641117 100644
--- a/lib/include/chiaki/session.h
+++ b/lib/include/chiaki/session.h
@@ -74,15 +74,17 @@ typedef struct chiaki_connect_video_profile_t
} ChiakiConnectVideoProfile;
typedef enum {
- CHIAKI_VIDEO_RESOLUTION_PRESET_360p,
- CHIAKI_VIDEO_RESOLUTION_PRESET_540p,
- CHIAKI_VIDEO_RESOLUTION_PRESET_720p,
- CHIAKI_VIDEO_RESOLUTION_PRESET_1080p
+ // values must not change
+ CHIAKI_VIDEO_RESOLUTION_PRESET_360p = 1,
+ CHIAKI_VIDEO_RESOLUTION_PRESET_540p = 2,
+ CHIAKI_VIDEO_RESOLUTION_PRESET_720p = 3,
+ CHIAKI_VIDEO_RESOLUTION_PRESET_1080p = 4
} ChiakiVideoResolutionPreset;
typedef enum {
- CHIAKI_VIDEO_FPS_PRESET_30,
- CHIAKI_VIDEO_FPS_PRESET_60
+ // values must not change
+ CHIAKI_VIDEO_FPS_PRESET_30 = 30,
+ CHIAKI_VIDEO_FPS_PRESET_60 = 60
} ChiakiVideoFPSPreset;
CHIAKI_EXPORT void chiaki_connect_video_profile_preset(ChiakiConnectVideoProfile *profile, ChiakiVideoResolutionPreset resolution, ChiakiVideoFPSPreset fps);