Skip to content

Commit

Permalink
* Addressed crash on older Android devices and dependency injection f…
Browse files Browse the repository at this point in the history
…or preferences

* Fixed crash with using TTS and devices that do not have TTS installed.
  • Loading branch information
thanksmister committed Dec 24, 2017
1 parent 68260a2 commit 4b86c3f
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repositories {

def versionMajor = 0
def versionMinor = 6
def versionPatch = 1
def versionPatch = 2
def versionBuild = 0 // bump for dog food builds, public betas, etc.

def ALARM_CODE() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AboutFragment : BaseFragment() {

try {
val packageInfo = activity!!.packageManager.getPackageInfo(activity!!.packageName, 0)
val versionName = activity!!.findViewById<TextView>(R.id.versionName)
// val versionName = activity!!.findViewById<View>(R.id.versionName)
versionNumber = " v" + packageInfo.versionName
versionName.text = versionNumber
} catch (e: PackageManager.NameNotFoundException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ class AlarmSettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSh
private var confirmCode = false

override fun onAttach(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Perform injection here for M (API 23) due to deprecation of onAttach(Activity).
AndroidSupportInjection.inject(this)
}
AndroidSupportInjection.inject(this)
super.onAttach(context)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ class CameraSettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnS
private var rotatePreference: ListPreference? = null

override fun onAttach(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Perform injection here for M (API 23) due to deprecation of onAttach(Activity).
AndroidSupportInjection.inject(this)
}
AndroidSupportInjection.inject(this)
super.onAttach(context)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ class MqttSettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSha
private var passwordPreference: EditTextPreference? = null
private var mqttOptions: MQTTOptions? = null


override fun onAttach(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Perform injection here for M (API 23) due to deprecation of onAttach(Activity).
AndroidSupportInjection.inject(this)
}
AndroidSupportInjection.inject(this)
super.onAttach(context)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ class NotificationsSettingsFragment : PreferenceFragmentCompat(), SharedPreferen
private var mqttOptions: MQTTOptions? = null

override fun onAttach(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Perform injection here for M (API 23) due to deprecation of onAttach(Activity).
AndroidSupportInjection.inject(this)
}
AndroidSupportInjection.inject(this)
super.onAttach(context)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class PlatformSettingsFragment : PreferenceFragmentCompat(), SharedPreferences.O
private var webModulePreference: CheckBoxPreference? = null
private var webUrlPreference: EditTextPreference? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
// Perform injection here for M (API 23) due to deprecation of onAttach(Activity).
AndroidSupportInjection.inject(this)
}
}

override fun onAttach(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Perform injection here for M (API 23) due to deprecation of onAttach(Activity).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ class ScreenSettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnS
private var imageOptions: ImageOptions? = null

override fun onAttach(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Perform injection here for M (API 23) due to deprecation of onAttach(Activity).
AndroidSupportInjection.inject(this)
}
AndroidSupportInjection.inject(this)
super.onAttach(context)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ class WeatherSettingsFragment : PreferenceFragmentCompat(), SharedPreferences.On
}

override fun onAttach(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Perform injection here for M (API 23) due to deprecation of onAttach(Activity).
AndroidSupportInjection.inject(this)
}
AndroidSupportInjection.inject(this)
super.onAttach(context)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,18 @@ import timber.log.Timber
import java.util.*
import android.speech.tts.UtteranceProgressListener
import android.support.annotation.RequiresApi
import android.content.Intent
import android.support.v4.content.ContextCompat.startActivity
import android.icu.util.ULocale.getLanguage





/**
* Module to use Google Text-to-Speech to speak the payload of MQTT messages.
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
class TextToSpeechModule( base: Context?, private val configuration: Configuration) : ContextWrapper(base),
TextToSpeech.OnInitListener, LifecycleObserver {

Expand All @@ -53,11 +61,10 @@ class TextToSpeechModule( base: Context?, private val configuration: Configurati
}
}

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun onInit(status: Int) {
if (status == TextToSpeech.SUCCESS) {
val sdkVersion = Build.VERSION.SDK_INT
textToSpeech!!.language = Locale.getDefault()
textToSpeech!!.voice = textToSpeech!!.defaultVoice
textToSpeech!!.setOnUtteranceProgressListener(object : UtteranceProgressListener() {
override fun onError(p0: String?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
Expand Down

0 comments on commit 4b86c3f

Please sign in to comment.