Skip to content

Commit

Permalink
Committing shared preferences instead of applying and wrapping Glide …
Browse files Browse the repository at this point in the history
…with try/catch

On low-end devices Glide sometimes fails (Android 4.3)
  • Loading branch information
Javinator9889 committed Apr 21, 2020
1 parent 050c835 commit 0b41adc
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Expand Up @@ -43,7 +43,7 @@ android {
applicationId "com.javinator9889.handwashingreminder"
minSdkVersion 17
targetSdkVersion 29
versionCode 93
versionCode 94
versionName "1.0.1-${gitCommitHash}"
multiDexEnabled true

Expand Down
Expand Up @@ -68,9 +68,14 @@ class SliderView : BaseFragmentView() {
Timber.d("Video finished loading")
})
washingHandsModel.image.observe(viewLifecycleOwner, Observer {
GlideApp.with(this@SliderView)
.load(it)
.into(image)
try {
GlideApp.with(this@SliderView)
.load(it)
.into(image)
} catch (e: Exception) {
Timber.e(e, "Error while loading Glide view")
image.setImageResource(it)
}
drawableId = it
Timber.d("Image finished loading")
incrementCounter()
Expand Down Expand Up @@ -118,11 +123,16 @@ class SliderView : BaseFragmentView() {
Timber.d("Slide resumed")
video.requestFocus()
video.start()
GlideApp.with(this)
.load(drawableId)
.centerInside()
.centerCrop()
.into(image)
try {
GlideApp.with(this)
.load(drawableId)
.centerInside()
.centerCrop()
.into(image)
} catch (e: Exception) {
Timber.e(e, "Error while loading Glide view")
image.setImageResource(drawableId)
}
super.onResume()
}

Expand Down
Expand Up @@ -41,10 +41,10 @@ class WorkHandler(private val context: Context) {
preferences.getString(Preferences.BREAKFAST_TIME, "")!!
val lunchTime = preferences.getString(Preferences.LUNCH_TIME, "")!!
val dinnerTime = preferences.getString(Preferences.DINNER_TIME, "")!!
if (breakfastTime == "" || lunchTime == "" || dinnerTime == "")
throw UninitializedPropertyAccessException(
"The scheduled time values are not initialized"
)
if (breakfastTime == "" || lunchTime == "" || dinnerTime == "") {
Timber.e("The scheduled times are not initialized")
return
}
val times = arrayOf(breakfastTime, lunchTime, dinnerTime)
times.forEach { time ->
val dueDate = Calendar.getInstance()
Expand Down
Expand Up @@ -136,7 +136,7 @@ class IntroActivity : AppIntro2(),
super.onDonePressed(currentFragment)
val app = HandwashingApplication.getInstance()
val sharedPreferences = app.sharedPreferences
sharedPreferences.edit {
sharedPreferences.edit(commit = true) {
timeConfigSlide.rvItems.forEach { item ->
val time = "${item.hours}:${item.minutes}"
when (item.id) {
Expand Down
Expand Up @@ -38,6 +38,7 @@ import com.javinator9889.handwashingreminder.utils.AndroidVersion
import com.javinator9889.handwashingreminder.utils.TimeConfig
import com.javinator9889.handwashingreminder.utils.formatTime
import com.javinator9889.handwashingreminder.utils.isAtLeast
import timber.log.Timber
import java.util.*

class TimeConfigActivity :
Expand Down Expand Up @@ -110,11 +111,16 @@ class TimeConfigActivity :
else -> null
}
if (imageRes != null)
GlideApp.with(this)
.load(imageRes)
.centerCrop()
.centerInside()
.into(image)
try {
GlideApp.with(this)
.load(imageRes)
.centerCrop()
.centerInside()
.into(image)
} catch (e: Exception) {
Timber.e(e, "Error while loading Glide view")
image.setImageResource(imageRes)
}
setHours(sHours.toString(), sMinutes.toString())
}
}
Expand Down
Expand Up @@ -29,6 +29,7 @@ import com.javinator9889.handwashingreminder.graphics.GlideApp
import com.javinator9889.handwashingreminder.listeners.ViewHolder
import com.javinator9889.handwashingreminder.utils.TimeConfig
import com.mikepenz.iconics.view.IconicsImageView
import timber.log.Timber


class TimeConfigViewHolder(private val view: View) :
Expand Down Expand Up @@ -110,10 +111,15 @@ class TimeConfigViewHolder(private val view: View) :

private fun loadImageView(@DrawableRes imageRes: Int?) {
if (imageRes != null)
GlideApp.with(view)
.load(imageRes)
.centerInside()
.centerCrop()
.into(image)
try {
GlideApp.with(view)
.load(imageRes)
.centerInside()
.centerCrop()
.into(image)
} catch (e: Exception) {
Timber.e(e, "Error while loading Glide view")
image.setImageResource(imageRes)
}
}
}

0 comments on commit 0b41adc

Please sign in to comment.