Skip to content

Commit

Permalink
Fix AndroidX preferences (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
dozingcat authored Sep 7, 2020
1 parent ad95ac7 commit 2f24d23
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "androidx.preference:preference-ktx:1.1.1"
testImplementation 'junit:junit:4.12'
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0"
implementation 'com.jaredrummler:colorpicker:1.1.0'
// The xiph.org Vorbis encoding library is included as source, in src/main/java/org/xiph.
// It was downloaded from https://xiph.org/downloads/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import android.content.Intent
import android.content.res.Configuration
import android.os.Bundle
import android.os.Handler
import android.preference.PreferenceManager
import android.provider.MediaStore
import android.renderscript.RenderScript
import android.util.Log
import android.util.Size
import android.util.TypedValue
import androidx.preference.PreferenceManager
import com.dozingcatsoftware.util.getLandscapeDisplaySize
import kotlinx.android.synthetic.main.activity_main.*
import java.io.FileOutputStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.os.Build
import android.os.Bundle
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat

class VCPreferencesActivity: AppCompatActivity() {
Expand Down Expand Up @@ -40,12 +41,11 @@ class VCPreferencesFragment : PreferenceFragmentCompat() {
setPreferencesFromResource(R.xml.preferences, rootKey)
val pm = this.preferenceManager

val autoConvertPref = pm.findPreference(getString(R.string.autoConvertPicturesPrefsKey))
val autoConvertPref: Preference? = findPreference(getString(R.string.autoConvertPicturesPrefsKey))
autoConvertPref!!.setOnPreferenceChangeListener { pref, value ->
// Update broadcast receivers immediately so the change takes effect even if the user
// doesn't go back to the main activity.
setAutoConvertEnabled(
this@VCPreferencesFragment.context!!, java.lang.Boolean.TRUE == value)
setAutoConvertEnabled(this.requireContext(), java.lang.Boolean.TRUE == value)
true
}

Expand All @@ -58,9 +58,9 @@ class VCPreferencesFragment : PreferenceFragmentCompat() {
getString(R.string.ansiColorPixelCharsPrefId),
getString(R.string.fullColorPixelCharsPrefId))
for (prefId in asciiPrefIds) {
pm.findPreference(prefId).setOnPreferenceChangeListener { pref, value ->
pm.findPreference<Preference?>(prefId)!!.setOnPreferenceChangeListener { pref, value ->
handler.post {
val storedPrefs = VCPreferences(this.context!!)
val storedPrefs = VCPreferences(this.requireContext())
if (storedPrefs.effectName() == "ascii") {
val params = storedPrefs.effectParameters()
if (params["prefId"] == prefId) {
Expand All @@ -76,9 +76,9 @@ class VCPreferencesFragment : PreferenceFragmentCompat() {
// Same for number of characters.
val textEffectNames = setOf("ascii", "matrix")
val numColumnsPrefId = getString(R.string.numAsciiColumnsPrefId)
pm.findPreference(numColumnsPrefId).setOnPreferenceChangeListener { pref, value ->
pm.findPreference<Preference?>(numColumnsPrefId)!!.setOnPreferenceChangeListener { pref, value ->
handler.post {
val storedPrefs = VCPreferences(this.context!!)
val storedPrefs = VCPreferences(this.requireContext())
if (textEffectNames.contains(storedPrefs.effectName())) {
val params = storedPrefs.effectParameters()
val newEffectParams = HashMap(params)
Expand All @@ -90,9 +90,9 @@ class VCPreferencesFragment : PreferenceFragmentCompat() {
}
// And update matrix text color.
val matrixColorPrefId = getString(R.string.matrixTextColorPrefId)
pm.findPreference(matrixColorPrefId).setOnPreferenceChangeListener { pref, value ->
pm.findPreference<Preference?>(matrixColorPrefId)!!.setOnPreferenceChangeListener { pref, value ->
handler.post {
val storedPrefs = VCPreferences(this.context!!)
val storedPrefs = VCPreferences(this.requireContext())
if (storedPrefs.effectName() == "matrix") {
val params = storedPrefs.effectParameters()
val newEffectParams = HashMap(params)
Expand Down

0 comments on commit 2f24d23

Please sign in to comment.