diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EditColorPreference.kt b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EditColorPreference.kt index 29a1fd089..548d1cccf 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EditColorPreference.kt +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EditColorPreference.kt @@ -112,6 +112,7 @@ class EditColorPreference(private val mContext: Context, attrs: AttributeSet?) : return arr.getInteger(index, 0) } + @Deprecated("Deprecated in Java") override fun onSetInitialValue(restoreValue: Boolean, defaultValue: Any?) { if (!restoreValue) { persistInt((defaultValue as Int)) @@ -159,31 +160,26 @@ class EditColorPreference(private val mContext: Context, attrs: AttributeSet?) : private fun onBindDialogView(view: View?) { LocUtils.xlateView(mContext, view) mCurColor = persistedColor - setOneByte(view, 0) - setOneByte(view, 1) - setOneByte(view, 2) - view!!.findViewById(R.id.color_edit_sample) - .setBackgroundColor(mCurColor) + view?.let { + setOneByte(it, 0) + setOneByte(it, 1) + setOneByte(it, 2) + it.findViewById(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 byt = mCurColor shr shift and 0xFF - val seekbar = parent!!.findViewById(m_seekbarIds[indx]) as SeekBar - val edittext = parent.findViewById(m_editIds[indx]) as EditText - if (null != seekbar) { + val seekbar = parent.findViewById(m_seekbarIds[indx]) + val edittext = parent.findViewById(m_editIds[indx]) seekbar.progress = byt seekbar.setOnSeekBarChangeListener( - SBCL( - parent, edittext, - indx - ) + SBCL(parent, edittext, indx) ) - } - if (null != edittext) { - edittext.setText(String.format("%d", byt)) - edittext.addTextChangedListener(TCL(seekbar)) - } + edittext.setText(String.format("%d", byt)) + edittext.addTextChangedListener(TCL(seekbar)) } private val persistedColor: Int @@ -201,13 +197,10 @@ class EditColorPreference(private val mContext: Context, attrs: AttributeSet?) : ) private fun getOneByte(parent: DialogInterface, id: Int): Int { - var `val` = 0 val dialog = parent as Dialog - val seekbar = dialog.findViewById(id) as SeekBar - if (null != seekbar) { - `val` = seekbar.progress - } - return `val` + val seekbar = dialog.findViewById(id) + val result = seekbar.progress + return result } } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.kt b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.kt index 8130e9b8a..62578f433 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.kt +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.kt @@ -153,19 +153,17 @@ open class XWPrefs { fun getPrefsInt(context: Context, keyID: Int, defaultValue: Int): Int { var result = defaultValue - if (null != context) { - val key = context.getString(keyID) - val sp = PreferenceManager - .getDefaultSharedPreferences(context) + val key = context.getString(keyID) + val sp = PreferenceManager + .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 { - 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 { - result = asStr!!.toInt() - } catch (ex: Exception) { - } + result = asStr!!.toInt() + } catch (ex: Exception) { } } return result @@ -252,26 +250,21 @@ open class XWPrefs { fun getSMSPhones(context: Context): JSONObject { val asStr = getPrefsString(context, R.string.key_sms_phones) - var obj: JSONObject? = null - - if (null != asStr) { - obj = try { + var obj = + try { JSONObject(asStr) } catch (ex: JSONException) { null } - } if (null == obj) { obj = JSONObject() - if (null != asStr) { - val numbers = TextUtils.split(asStr, "\n") - for (number in numbers) { - try { - obj.put(number, "") // null removes any entry - } catch (ex: JSONException) { - Log.ex(TAG, ex) - } + val numbers = TextUtils.split(asStr, "\n") + for (number in numbers) { + try { + obj.put(number, "") // null removes any entry + } catch (ex: JSONException) { + Log.ex(TAG, ex) } } } @@ -404,7 +397,7 @@ open class XWPrefs { protected fun getPrefsStringArray(context: Context, keyID: Int): Array? { val asStr = getPrefsString(context, keyID) - val result = if (null == asStr) null else TextUtils.split(asStr, "\n") + val result = TextUtils.split(asStr, "\n") return result }