Skip to content

Commit

Permalink
ui state fix (#2810)
Browse files Browse the repository at this point in the history
  • Loading branch information
anandwana001 authored Nov 5, 2024
1 parent c3ad147 commit f3ec6d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.os.Bundle
import android.widget.Toast
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import com.google.android.ground.Config
import com.google.android.ground.R

Expand All @@ -34,14 +35,10 @@ import com.google.android.ground.R
*/
class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClickListener {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val preferenceManager = preferenceManager
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
preferenceManager.sharedPreferencesName = Config.SHARED_PREFS_NAME
preferenceManager.sharedPreferencesMode = Config.SHARED_PREFS_MODE
}

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences, rootKey)
for (key in Keys.ALL_KEYS) {
val preference =
Expand All @@ -50,8 +47,14 @@ class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClic

preference.onPreferenceClickListener = this
}

val switchPreference = findPreference<SwitchPreferenceCompat>(Keys.UPLOAD_MEDIA)
switchPreference?.isChecked = loadSwitchPreferenceState()
}

private fun loadSwitchPreferenceState() =
preferenceManager.sharedPreferences?.getBoolean(Keys.UPLOAD_MEDIA, false) ?: false

override fun onPreferenceClick(preference: Preference): Boolean {
when (preference.key) {
Keys.VISIT_WEBSITE -> openUrl(preference.summary.toString())
Expand Down
2 changes: 1 addition & 1 deletion ground/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@

<!-- Settings -->
<string name="general_title">General</string>
<string name="upload_media_title">Upload Media</string>
<string name="upload_media_title">Upload photos</string>
<string name="over_wifi_summary">Over Wi-Fi only</string>
<string name="help_title">Help</string>
<string name="visit_website_title">Visit website</string>
Expand Down

0 comments on commit f3ec6d5

Please sign in to comment.