more correcting of problems/suggestions

This commit is contained in:
Eric House 2024-09-27 10:28:32 -07:00
parent 786214e0f5
commit 3cba8e8c31
2 changed files with 36 additions and 50 deletions

View file

@ -112,6 +112,7 @@ class EditColorPreference(private val mContext: Context, attrs: AttributeSet?) :
return arr.getInteger(index, 0) return arr.getInteger(index, 0)
} }
@Deprecated("Deprecated in Java")
override fun onSetInitialValue(restoreValue: Boolean, defaultValue: Any?) { override fun onSetInitialValue(restoreValue: Boolean, defaultValue: Any?) {
if (!restoreValue) { if (!restoreValue) {
persistInt((defaultValue as Int)) persistInt((defaultValue as Int))
@ -159,31 +160,26 @@ class EditColorPreference(private val mContext: Context, attrs: AttributeSet?) :
private fun onBindDialogView(view: View?) { private fun onBindDialogView(view: View?) {
LocUtils.xlateView(mContext, view) LocUtils.xlateView(mContext, view)
mCurColor = persistedColor mCurColor = persistedColor
setOneByte(view, 0) view?.let {
setOneByte(view, 1) setOneByte(it, 0)
setOneByte(view, 2) setOneByte(it, 1)
view!!.findViewById<View>(R.id.color_edit_sample) setOneByte(it, 2)
.setBackgroundColor(mCurColor) it.findViewById<View>(R.id.color_edit_sample)
.setBackgroundColor(mCurColor)
}
} }
private fun setOneByte(parent: View?, indx: Int) { private fun setOneByte(parent: View, indx: Int) {
val shift = 16 - indx * 8 val shift = 16 - indx * 8
val byt = mCurColor shr shift and 0xFF val byt = mCurColor shr shift and 0xFF
val seekbar = parent!!.findViewById<View>(m_seekbarIds[indx]) as SeekBar val seekbar = parent.findViewById<SeekBar>(m_seekbarIds[indx])
val edittext = parent.findViewById<View>(m_editIds[indx]) as EditText val edittext = parent.findViewById<EditText>(m_editIds[indx])
if (null != seekbar) {
seekbar.progress = byt seekbar.progress = byt
seekbar.setOnSeekBarChangeListener( seekbar.setOnSeekBarChangeListener(
SBCL( SBCL(parent, edittext, indx)
parent, edittext,
indx
)
) )
} edittext.setText(String.format("%d", byt))
if (null != edittext) { edittext.addTextChangedListener(TCL(seekbar))
edittext.setText(String.format("%d", byt))
edittext.addTextChangedListener(TCL(seekbar))
}
} }
private val persistedColor: Int private val persistedColor: Int
@ -201,13 +197,10 @@ class EditColorPreference(private val mContext: Context, attrs: AttributeSet?) :
) )
private fun getOneByte(parent: DialogInterface, id: Int): Int { private fun getOneByte(parent: DialogInterface, id: Int): Int {
var `val` = 0
val dialog = parent as Dialog val dialog = parent as Dialog
val seekbar = dialog.findViewById<View>(id) as SeekBar val seekbar = dialog.findViewById<SeekBar>(id)
if (null != seekbar) { val result = seekbar.progress
`val` = seekbar.progress return result
}
return `val`
} }
} }
} }

View file

@ -153,19 +153,17 @@ open class XWPrefs {
fun getPrefsInt(context: Context, keyID: Int, defaultValue: Int): Int { fun getPrefsInt(context: Context, keyID: Int, defaultValue: Int): Int {
var result = defaultValue var result = defaultValue
if (null != context) { val key = context.getString(keyID)
val key = context.getString(keyID) val sp = PreferenceManager
val sp = PreferenceManager .getDefaultSharedPreferences(context)
.getDefaultSharedPreferences(context) try {
result = sp.getInt(key, defaultValue)
// If it's in a pref, it'll be a string (editable) So will get CCE
} catch (cce: ClassCastException) {
val asStr = sp.getString(key, String.format("%d", defaultValue))
try { try {
result = sp.getInt(key, defaultValue) result = asStr!!.toInt()
// If it's in a pref, it'll be a string (editable) So will get CCE } catch (ex: Exception) {
} catch (cce: ClassCastException) {
val asStr = sp.getString(key, String.format("%d", defaultValue))
try {
result = asStr!!.toInt()
} catch (ex: Exception) {
}
} }
} }
return result return result
@ -252,26 +250,21 @@ open class XWPrefs {
fun getSMSPhones(context: Context): JSONObject { fun getSMSPhones(context: Context): JSONObject {
val asStr = getPrefsString(context, R.string.key_sms_phones) val asStr = getPrefsString(context, R.string.key_sms_phones)
var obj: JSONObject? = null var obj =
try {
if (null != asStr) {
obj = try {
JSONObject(asStr) JSONObject(asStr)
} catch (ex: JSONException) { } catch (ex: JSONException) {
null null
} }
}
if (null == obj) { if (null == obj) {
obj = JSONObject() obj = JSONObject()
if (null != asStr) { val numbers = TextUtils.split(asStr, "\n")
val numbers = TextUtils.split(asStr, "\n") for (number in numbers) {
for (number in numbers) { try {
try { obj.put(number, "") // null removes any entry
obj.put(number, "") // null removes any entry } catch (ex: JSONException) {
} catch (ex: JSONException) { Log.ex(TAG, ex)
Log.ex(TAG, ex)
}
} }
} }
} }
@ -404,7 +397,7 @@ open class XWPrefs {
protected fun getPrefsStringArray(context: Context, keyID: Int): Array<String>? { protected fun getPrefsStringArray(context: Context, keyID: Int): Array<String>? {
val asStr = getPrefsString(context, keyID) val asStr = getPrefsString(context, keyID)
val result = if (null == asStr) null else TextUtils.split(asStr, "\n") val result = TextUtils.split(asStr, "\n")
return result return result
} }