Skip to content

Commit

Permalink
Included new settings' section for disabling animations
Browse files Browse the repository at this point in the history
  • Loading branch information
Javinator9889 committed Jun 30, 2020
1 parent f29cc65 commit 5f31f03
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Expand Up @@ -40,7 +40,7 @@ android {
applicationId "com.javinator9889.handwashingreminder"
minSdkVersion 17
targetSdkVersion 29
versionCode 132
versionCode 133
versionName "1.2.0-${gitCommitHash}"
multiDexEnabled true
resConfigs "en", "es"
Expand Down
Expand Up @@ -312,6 +312,10 @@ class SettingsLoader(
},
onChangeListener = this@with
).also { deferreds.add(it) }
setupPreferenceAsync(
Preferences.PERFORMANCE_ANIMATIONS,
Ionicons.Icon.ion_battery_low
).also { deferreds.add(it) }
deferreds.awaitAll()
arePreferencesInitialized.set(true)
}
Expand Down
Expand Up @@ -20,29 +20,36 @@ package com.javinator9889.handwashingreminder.graphics

import android.content.Context
import android.util.AttributeSet
import androidx.preference.PreferenceManager
import com.airbnb.lottie.LottieAnimationView
import com.airbnb.lottie.LottieComposition
import com.airbnb.lottie.LottieOnCompositionLoadedListener
import com.javinator9889.handwashingreminder.utils.Preferences
import com.javinator9889.handwashingreminder.utils.isHighPerformingDevice

class LottieAdaptedPerformanceAnimationView : LottieAnimationView,
LottieOnCompositionLoadedListener {
constructor(context: Context): super(context)
constructor(context: Context, attrs: AttributeSet): super(context, attrs)
constructor(context: Context, attrs: AttributeSet, attrStyle: Int):
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, attrStyle: Int) :
super(context, attrs, attrStyle)

private val areAnimationsEnabled: Boolean

init {
addLottieOnCompositionLoadedListener(this)
enableMergePathsForKitKatAndAbove(true)
setCacheComposition(true)
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
areAnimationsEnabled =
preferences.getBoolean(Preferences.PERFORMANCE_ANIMATIONS, true)
}

override fun getDuration(): Long =
if (isHighPerformingDevice()) super.getDuration() else 100L

override fun onCompositionLoaded(composition: LottieComposition?) {
if (!isHighPerformingDevice()) {
if (!isHighPerformingDevice() || !areAnimationsEnabled) {
setMinFrame(maxFrame.toInt())
repeatCount = 0
}
Expand Down
Expand Up @@ -43,6 +43,7 @@ object Preferences {
const val DONATIONS = "donations"
const val INITIAL_TUTORIAL_DONE = "app:tutorial:is_done"
const val ACTIVITY_MINIMUM_TIME = "activity:gms:minimumInterval"
const val PERFORMANCE_ANIMATIONS = "app:performance:animations"
}

object TimeConfig {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values-es/strings.xml
Expand Up @@ -285,4 +285,9 @@
<item quantity="one">%d minuto</item>
<item quantity="other">%d minutos</item>
</plurals>
<string name="performance_options">Opciones de rendimiento de la app</string>
<string name="disable_animations">Deshabilitar las animaciones en la app</string>
<string name="animations_on">Actualmente, las animaciones están activadas.
Ten en cuenta que esto puede afectar tanto al rendimiento como a la batería</string>
<string name="animations_off">No se mostrará ninguna animación</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -313,4 +313,9 @@
<item quantity="one">%d minute</item>
<item quantity="other">%d minutes</item>
</plurals>
<string name="performance_options">App\'s performance options</string>
<string name="disable_animations">Disable app\'s animations</string>
<string name="animations_on">Currently, the app will play some animations.
Keep in mind that it can affect both performance and battery life</string>
<string name="animations_off">No animations will be played</string>
</resources>
22 changes: 15 additions & 7 deletions app/src/main/res/xml/preferences.xml
Expand Up @@ -10,24 +10,24 @@
<Preference
android:key="playstore"
android:persistent="false"
android:title="@string/playstore"/>
android:title="@string/playstore" />
<Preference
android:icon="@drawable/ic_telegram"
android:key="telegram"
android:persistent="false"
android:icon="@drawable/ic_telegram"
android:title="@string/telegram" />
<Preference
android:key="github"
android:persistent="false"
android:title="@string/github"/>
android:title="@string/github" />
<Preference
android:key="linkedin"
android:persistent="false"
android:title="@string/linkedin"/>
android:title="@string/linkedin" />
<Preference
android:key="twitter"
android:persistent="false"
android:title="@string/twitter"/>
android:title="@string/twitter" />
</PreferenceCategory>

<PreferenceCategory
Expand Down Expand Up @@ -60,13 +60,21 @@

<EditTextPreference
android:defaultValue="15"
android:dependency="activity:gms:tracking"
android:dialogLayout="@layout/preference_edit_text"
android:key="activity:gms:minimumInterval"
android:selectAllOnFocus="true"
android:singleLine="true"
android:dependency="activity:gms:tracking"
android:dialogLayout="@layout/preference_edit_text"
android:title="@string/minimum_time" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/performance_options">
<SwitchPreference
android:defaultValue="true"
android:key="app:performance:animations"
android:summaryOff="@string/animations_off"
android:summaryOn="@string/animations_on"
android:title="@string/disable_animations" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/data_sharing_category">

<SwitchPreference
Expand Down

0 comments on commit 5f31f03

Please sign in to comment.