diff --git a/app/build.gradle b/app/build.gradle index c65a9ac72..4b0cc6d9c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -81,7 +81,7 @@ dependencies { implementation 'com.google.android:flexbox:2.0.1' implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation "androidx.preference:preference:1.1.1" + implementation "androidx.preference:preference:1.2.1" testImplementation 'junit:junit:4.13.2' implementation 'com.github.parse-community:ParseLiveQuery-Android:1.2.2' implementation 'com.github.parse-community.Parse-SDK-Android:parse:4.2.1' diff --git a/app/src/main/kotlin/io/treehouses/remote/bases/BasePreferenceFragment.kt b/app/src/main/kotlin/io/treehouses/remote/bases/BasePreferenceFragment.kt index 4c640eba5..1cbe5a53e 100644 --- a/app/src/main/kotlin/io/treehouses/remote/bases/BasePreferenceFragment.kt +++ b/app/src/main/kotlin/io/treehouses/remote/bases/BasePreferenceFragment.kt @@ -25,12 +25,12 @@ abstract class BasePreferenceFragment: PreferenceFragmentCompat(), BackPressRece override fun onResume() { super.onResume() - preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceChangeListener) + preferenceScreen.sharedPreferences?.registerOnSharedPreferenceChangeListener(preferenceChangeListener) } override fun onPause() { super.onPause() - preferenceScreen.sharedPreferences.unregisterOnSharedPreferenceChangeListener(preferenceChangeListener) + preferenceScreen.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(preferenceChangeListener) } override fun onBackPressed() { diff --git a/app/src/main/kotlin/io/treehouses/remote/bases/BaseTerminalKeyListener.kt b/app/src/main/kotlin/io/treehouses/remote/bases/BaseTerminalKeyListener.kt index 5b22a8ee3..2a79332d8 100644 --- a/app/src/main/kotlin/io/treehouses/remote/bases/BaseTerminalKeyListener.kt +++ b/app/src/main/kotlin/io/treehouses/remote/bases/BaseTerminalKeyListener.kt @@ -21,6 +21,7 @@ import androidx.preference.PreferenceManager import android.text.ClipboardManager import android.view.KeyCharacterMap import android.view.KeyEvent +import io.treehouses.remote.MainApplication.Companion.context import io.treehouses.remote.views.terminal.VDUBuffer import io.treehouses.remote.views.terminal.vt320 import io.treehouses.remote.PreferenceConstants @@ -60,7 +61,7 @@ open class BaseTerminalKeyListener(var manager: TerminalManager?, private var clipboard: ClipboardManager? = null protected var selectingForCopy = false protected val selectionArea: SelectionArea = SelectionArea() - protected val prefs: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(manager) + protected val prefs: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) protected fun handleDpadCenter(keyCode: Int, flag: Boolean): Boolean { var newFlag = flag diff --git a/app/src/main/kotlin/io/treehouses/remote/fragments/SettingsFragment.kt b/app/src/main/kotlin/io/treehouses/remote/fragments/SettingsFragment.kt index ca7bf2dd3..fa32276c2 100644 --- a/app/src/main/kotlin/io/treehouses/remote/fragments/SettingsFragment.kt +++ b/app/src/main/kotlin/io/treehouses/remote/fragments/SettingsFragment.kt @@ -35,12 +35,12 @@ class SettingsFragment : PreferenceFragmentCompat(), Preference.OnPreferenceClic override fun onResume() { super.onResume() - preferenceScreen.sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceChangeListener) + preferenceScreen.sharedPreferences?.registerOnSharedPreferenceChangeListener(preferenceChangeListener) } override fun onPause() { super.onPause() - preferenceScreen.sharedPreferences.unregisterOnSharedPreferenceChangeListener(preferenceChangeListener) + preferenceScreen.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(preferenceChangeListener) } override fun onPreferenceClick(preference: Preference): Boolean { diff --git a/app/src/main/kotlin/io/treehouses/remote/fragments/preferencefragments/UserCustomizationPreferenceFragment.kt b/app/src/main/kotlin/io/treehouses/remote/fragments/preferencefragments/UserCustomizationPreferenceFragment.kt index d73afe0d9..d5aa9649e 100644 --- a/app/src/main/kotlin/io/treehouses/remote/fragments/preferencefragments/UserCustomizationPreferenceFragment.kt +++ b/app/src/main/kotlin/io/treehouses/remote/fragments/preferencefragments/UserCustomizationPreferenceFragment.kt @@ -28,17 +28,13 @@ class UserCustomizationPreferenceFragment: BasePreferenceFragment() { val clearSSHHosts = findPreference("ssh_hosts") val clearSSHKeys = findPreference("ssh_keys") val fontSize = findPreference("font_size") - - //fontSize?.setOnPreferenceChangeListener(object: Preference.OnPreferenceChangeListener(SharedPreferences, "font_size")) - fontSize?.setOnPreferenceChangeListener(object : Preference.OnPreferenceChangeListener{ - @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1) - override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { - PreferenceManager.getDefaultSharedPreferences(activity).edit().putInt("font_size", newValue.toString().toInt()).commit() + fontSize?.onPreferenceChangeListener = + Preference.OnPreferenceChangeListener { _, newValue -> + PreferenceManager.getDefaultSharedPreferences(requireContext()).edit().putInt("font_size", newValue.toString().toInt()).commit() adjustFontScale(resources.configuration, newValue.toString().toInt()) activity?.recreate() - return false + false } - }) SettingsUtils.setClickListener(this, clearCommandsList) SettingsUtils.setClickListener(this, resetCommandsList) SettingsUtils.setClickListener(this, clearNetworkProfiles) @@ -48,7 +44,6 @@ class UserCustomizationPreferenceFragment: BasePreferenceFragment() { @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1) fun adjustFontScale(configuration: Configuration?, fontSize: Int) { - configuration?.let { it.fontScale = 0.05F*fontSize.toFloat() val metrics: DisplayMetrics = resources.displayMetrics @@ -58,7 +53,6 @@ class UserCustomizationPreferenceFragment: BasePreferenceFragment() { MainApplication.context.createConfigurationContext(it) MainApplication.context.resources.displayMetrics.setTo(metrics) - } } @@ -69,7 +63,6 @@ class UserCustomizationPreferenceFragment: BasePreferenceFragment() { "network_profiles" -> networkProfiles() "ssh_hosts" -> clearSSHHosts() "ssh_keys" -> clearSSHKeys() - } return false } @@ -124,4 +117,4 @@ class UserCustomizationPreferenceFragment: BasePreferenceFragment() { private const val CLEAR_SSH_HOSTS = 4 private const val CLEAR_SSH_KEYS = 5 } -} \ No newline at end of file +} diff --git a/app/src/main/kotlin/io/treehouses/remote/ui/home/HomeFragment.kt b/app/src/main/kotlin/io/treehouses/remote/ui/home/HomeFragment.kt index 7c5e25a58..b4da84469 100644 --- a/app/src/main/kotlin/io/treehouses/remote/ui/home/HomeFragment.kt +++ b/app/src/main/kotlin/io/treehouses/remote/ui/home/HomeFragment.kt @@ -57,7 +57,7 @@ class HomeFragment : BaseHomeFragment() { private lateinit var bind: ActivityHomeFragmentBinding override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { bind = ActivityHomeFragmentBinding.inflate(inflater, container, false) - preferences = PreferenceManager.getDefaultSharedPreferences(context) + preferences = PreferenceManager.getDefaultSharedPreferences(requireContext()) setupProfiles() showDialogOnce(preferences!!) connectRpiListener() @@ -213,7 +213,7 @@ class HomeFragment : BaseHomeFragment() { */ private fun testConnectionListener() { bind.testConnection.setOnClickListener { - val preference = PreferenceManager.getDefaultSharedPreferences(context).getString("led_pattern", "LED Heavy Metal") + val preference = PreferenceManager.getDefaultSharedPreferences(requireContext()).getString("led_pattern", "LED Heavy Metal") val options = listOf(*resources.getStringArray(R.array.led_options)) val optionsCode = resources.getStringArray(R.array.led_options_commands) viewModel.selectedLed = options.indexOf(preference) diff --git a/app/src/main/kotlin/io/treehouses/remote/views/RoundedListPreference.kt b/app/src/main/kotlin/io/treehouses/remote/views/RoundedListPreference.kt index 0902fb1d2..eaa9f8d54 100644 --- a/app/src/main/kotlin/io/treehouses/remote/views/RoundedListPreference.kt +++ b/app/src/main/kotlin/io/treehouses/remote/views/RoundedListPreference.kt @@ -12,17 +12,17 @@ import io.treehouses.remote.R class RoundedListPreference : ListPreference { - constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super( + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super( context, attrs, defStyleAttr ) - constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) - constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) + constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) - constructor(context: Context?) : super(context) + constructor(context: Context) : super(context) override fun onClick() { val currentIndex = findIndexOfValue(value)