From cc8c0c015cb524ae4b1ab4453d9d18d2378c319c Mon Sep 17 00:00:00 2001 From: Javinator9889 Date: Tue, 21 Apr 2020 10:24:18 +0200 Subject: [PATCH 1/6] Solved an error for ActivityRecognition API for devices lower than Android Q For devices targeting Android P or less the Activity Recognition Permission is automatically granted --- app/build.gradle | 2 +- .../views/fragments/settings/ActivityCheckbox.kt | 4 +++- .../handwashingreminder/appintro/IntroActivity.kt | 13 ++++++++++--- tgs | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 23bc85f..d1e0f2e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,7 +43,7 @@ android { applicationId "com.javinator9889.handwashingreminder" minSdkVersion 17 targetSdkVersion 29 - versionCode 91 + versionCode 92 versionName "1.0-${gitCommitHash}" multiDexEnabled true diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/settings/ActivityCheckbox.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/settings/ActivityCheckbox.kt index 7e4b08a..5575ce4 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/settings/ActivityCheckbox.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/settings/ActivityCheckbox.kt @@ -28,6 +28,8 @@ import com.google.android.gms.common.ConnectionResult import com.google.android.gms.common.GoogleApiAvailability import com.javinator9889.handwashingreminder.R import com.javinator9889.handwashingreminder.application.HandwashingApplication +import com.javinator9889.handwashingreminder.utils.AndroidVersion +import com.javinator9889.handwashingreminder.utils.isAtLeast import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.typeface.library.ionicons.Ionicons import com.mikepenz.iconics.utils.sizeDp @@ -57,7 +59,7 @@ class ActivityCheckbox : CheckBoxPreference { if (!isViewDisabled) { if (ContextCompat.checkSelfPermission( context, Manifest.permission.ACTIVITY_RECOGNITION - ) == PERMISSION_DENIED + ) == PERMISSION_DENIED && isAtLeast(AndroidVersion.Q) ) { isViewDisabled = true summaryOff = diff --git a/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt b/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt index 504c47c..08b8c90 100644 --- a/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt +++ b/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt @@ -81,7 +81,11 @@ class IntroActivity : AppIntro2(), firebaseAnalytics.logEvent( FirebaseAnalytics.Event.TUTORIAL_BEGIN, null ) - firebaseAnalytics.setCurrentScreen(this@IntroActivity, "Intro", null) + firebaseAnalytics.setCurrentScreen( + this@IntroActivity, + "Intro", + null + ) } val firstSlide = SliderPageBuilder.Builder() @@ -168,7 +172,8 @@ class IntroActivity : AppIntro2(), if (activityRecognitionPermissionGranted) { putStringSet( Preferences.ACTIVITIES_ENABLED, - Preferences.DEFAULT_ACTIVITY_SET) + Preferences.DEFAULT_ACTIVITY_SET + ) } putBoolean(Preferences.APP_INIT_KEY, true) } @@ -355,7 +360,9 @@ class IntroActivity : AppIntro2(), ) { if (requestCode == PERMISSIONS_REQUEST_CODE) { activityRecognitionPermissionGranted = - grantResults.isNotEmpty() && grantResults[0] == PERMISSION_GRANTED + (grantResults.isNotEmpty() && + grantResults[0] == PERMISSION_GRANTED) || + !isAtLeast(AndroidVersion.Q) } super.onRequestPermissionsResult(requestCode, permissions, grantResults) } diff --git a/tgs b/tgs index b044e17..4676059 160000 --- a/tgs +++ b/tgs @@ -1 +1 @@ -Subproject commit b044e176bc14768d4175bbbfd02cd162b110de99 +Subproject commit 4676059b8faa579d10f585ee121d4b2c9c66f121 From b7df31bc8455dd77ee2dfdf53f1d1df2bbdf1986 Mon Sep 17 00:00:00 2001 From: Javinator9889 Date: Tue, 21 Apr 2020 11:05:32 +0200 Subject: [PATCH 2/6] Removed custom constructor in SliderView For avoiding restoration errors, the position is provided via "arguments" --- .../views/fragments/washinghands/SliderView.kt | 17 +++++++++++++---- .../washinghands/WashingHandsFragment.kt | 5 ++++- .../appintro/IntroActivity.kt | 2 ++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/SliderView.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/SliderView.kt index b3587fa..c4c8f10 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/SliderView.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/SliderView.kt @@ -39,14 +39,15 @@ import java.util.concurrent.atomic.AtomicInteger import kotlin.properties.Delegates private const val WAITING_ITEMS_COUNT = 4 +internal const val ARG_POSITION = "bundle:position" -class SliderView(position: Int) : BaseFragmentView() { +class SliderView : BaseFragmentView() { override val layoutId: Int = R.layout.wash_your_hands_demo private lateinit var videoURI: Uri private var drawableId by Delegates.notNull() private val counter = AtomicInteger(0) - private val videoModelFactory = VideoModelFactory(position) - private val handsFactory = WashingHandsModelFactory(position) + private lateinit var videoModelFactory: VideoModelFactory + private lateinit var handsFactory: WashingHandsModelFactory private val viewModel: VideoModel by viewModels { SavedViewModelFactory(videoModelFactory, this) } @@ -88,6 +89,14 @@ class SliderView(position: Int) : BaseFragmentView() { } } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val args = arguments ?: savedInstanceState ?: throw + IllegalStateException("Arguments cannot be null") + videoModelFactory = VideoModelFactory(args.getInt(ARG_POSITION)) + handsFactory = WashingHandsModelFactory(args.getInt(ARG_POSITION)) + } + override fun onPause() { Timber.d("Slide paused") video.requestFocus() @@ -121,7 +130,7 @@ class SliderView(position: Int) : BaseFragmentView() { washingHandsModel.setImageSize(it.measuredWidth, it.measuredHeight) } } - + private fun incrementCounter() { Timber.d("Counter incremented") if (counter.incrementAndGet() < WAITING_ITEMS_COUNT) diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/WashingHandsFragment.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/WashingHandsFragment.kt index a38894d..05afd44 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/WashingHandsFragment.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/WashingHandsFragment.kt @@ -82,7 +82,10 @@ class WashingHandsFragment : BaseFragmentView() { if (position == 0) { return FirstSlide() } - with(SliderView(position - 1)) { + with(SliderView()) { + val args = Bundle(1) + args.putInt(ARG_POSITION, position - 1) + this.arguments = args items[position] = WeakReference(this) return this } diff --git a/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt b/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt index 08b8c90..5efb269 100644 --- a/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt +++ b/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt @@ -165,6 +165,8 @@ class IntroActivity : AppIntro2(), Preferences.ADS_ENABLED, sharedPreferences.getBoolean(Preferences.ADS_ENABLED, true) ) + if (!isAtLeast(AndroidVersion.Q)) + activityRecognitionPermissionGranted = true putBoolean( Preferences.ACTIVITY_TRACKING_ENABLED, activityRecognitionPermissionGranted From 7b2609291a7091d0280577a8fdfb05e34ec9720c Mon Sep 17 00:00:00 2001 From: Javinator9889 Date: Tue, 21 Apr 2020 11:49:46 +0200 Subject: [PATCH 3/6] Moved initialization logic out of application --- app/build.gradle | 4 +- .../activities/DynamicFeatureProgress.kt | 6 +- .../activities/LauncherActivity.kt | 65 +++++++++++++------ .../activities/MainActivity.kt | 15 +++-- .../activities/PrivacyTermsActivity.kt | 7 +- .../views/fragments/diseases/adapter/Ads.kt | 1 - .../views/fragments/settings/SettingsView.kt | 34 +++++----- .../settings/TimePickerPreference.kt | 5 -- .../fragments/washinghands/SliderView.kt | 7 ++ .../viewmodels/DiseaseInformationViewModel.kt | 4 +- .../application/HandwashingApplication.kt | 36 +--------- .../jobs/workers/WorkHandler.kt | 2 +- .../appintro/IntroActivity.kt | 31 +++++---- 13 files changed, 109 insertions(+), 108 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d1e0f2e..bb22664 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,8 +43,8 @@ android { applicationId "com.javinator9889.handwashingreminder" minSdkVersion 17 targetSdkVersion 29 - versionCode 92 - versionName "1.0-${gitCommitHash}" + versionCode 93 + versionName "1.0.1-${gitCommitHash}" multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/DynamicFeatureProgress.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/DynamicFeatureProgress.kt index 4a28ce1..d31fdd6 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/DynamicFeatureProgress.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/DynamicFeatureProgress.kt @@ -31,10 +31,10 @@ import com.google.android.play.core.splitinstall.SplitInstallRequest import com.google.android.play.core.splitinstall.SplitInstallSessionState import com.google.android.play.core.splitinstall.SplitInstallStateUpdatedListener import com.google.android.play.core.splitinstall.model.SplitInstallSessionStatus +import com.google.firebase.analytics.FirebaseAnalytics import com.javinator9889.handwashingreminder.BuildConfig import com.javinator9889.handwashingreminder.R import com.javinator9889.handwashingreminder.activities.base.SplitCompatBaseActivity -import com.javinator9889.handwashingreminder.application.HandwashingApplication import com.javinator9889.handwashingreminder.utils.AndroidVersion import com.javinator9889.handwashingreminder.utils.CONFIRMATION_REQUEST_CODE import com.javinator9889.handwashingreminder.utils.filterNotEmpty @@ -60,8 +60,8 @@ class DynamicFeatureProgress : SplitCompatBaseActivity(), override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) splitInstallManager.registerListener(this) - with(HandwashingApplication.getInstance()) { - firebaseAnalytics.setCurrentScreen( + with(FirebaseAnalytics.getInstance(this)) { + setCurrentScreen( this@DynamicFeatureProgress, "Dynamic module", null ) } diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/LauncherActivity.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/LauncherActivity.kt index e10d14b..fa427d7 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/LauncherActivity.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/LauncherActivity.kt @@ -31,6 +31,9 @@ import com.google.android.gms.common.ConnectionResult import com.google.android.gms.common.GoogleApiAvailability import com.google.android.play.core.splitcompat.SplitCompat import com.google.android.play.core.splitinstall.SplitInstallManagerFactory +import com.google.firebase.analytics.FirebaseAnalytics +import com.google.firebase.perf.FirebasePerformance +import com.google.firebase.remoteconfig.FirebaseRemoteConfig import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings import com.javinator9889.handwashingreminder.R import com.javinator9889.handwashingreminder.application.HandwashingApplication @@ -43,9 +46,12 @@ import com.javinator9889.handwashingreminder.utils.Preferences.Companion.ADS_ENA import com.javinator9889.handwashingreminder.utils.Preferences.Companion.APP_INIT_KEY import com.javinator9889.handwashingreminder.utils.RemoteConfig.Keys.SPECIAL_EVENT import com.mikepenz.iconics.Iconics +import javinator9889.localemanager.utils.languagesupport.LanguagesSupport import kotlinx.android.synthetic.main.splash_screen.* import kotlinx.coroutines.* import timber.log.Timber +import java.util.* +import kotlin.collections.ArrayList internal const val FAST_START_KEY = "intent:fast_start" internal const val PENDING_INTENT_CODE = 201 @@ -53,6 +59,7 @@ internal const val PENDING_INTENT_CODE = 201 class LauncherActivity : AppCompatActivity() { private var launchOnInstall = false private var launchFromNotification = false + private var canFinishActivity = false private lateinit var app: HandwashingApplication private lateinit var initDeferred: Deferred @@ -85,9 +92,9 @@ class LauncherActivity : AppCompatActivity() { } private suspend fun displayWelcomeScreen() { - val isThereAnySpecialEvent = - app.remoteConfig.getBoolean(SPECIAL_EVENT) && - !launchFromNotification + val isThereAnySpecialEvent = with(FirebaseRemoteConfig.getInstance()) { + getBoolean(SPECIAL_EVENT) && !launchFromNotification + } var sleepDuration = 0L var animationLoaded = false val fadeInAnimation = @@ -161,15 +168,13 @@ class LauncherActivity : AppCompatActivity() { overridePendingTransition(0, android.R.anim.fade_out) } } - finish() + if (canFinishActivity) + finish() + else + canFinishActivity = true } } - override fun finish() { - super.finish() - overridePendingTransition(0, android.R.anim.fade_out) - } - private fun installRequiredModules() { val modules = ArrayList(MODULE_COUNT) val googleApi = GoogleApiAvailability.getInstance() @@ -216,6 +221,8 @@ class LauncherActivity : AppCompatActivity() { } private fun initVariables() { + Timber.d("Initializing Iconics") + Iconics.init(this) if (app.sharedPreferences.getBoolean( Preferences.ACTIVITY_TRACKING_ENABLED, false ) && with(GoogleApiAvailability.getInstance()) { @@ -227,42 +234,62 @@ class LauncherActivity : AppCompatActivity() { } else { app.activityHandler.disableActivityTracker() } - - setupFirebaseProperties() app.billingService = BillingService(this) - Timber.d("Initializing Iconics") - Iconics.init(this) try { app.workHandler.enqueuePeriodicNotificationsWorker() Timber.d("Adding periodic notifications if not enqueued yet") } catch (_: UninitializedPropertyAccessException) { Timber.i("Scheduler times have not been initialized") } + setupFirebaseProperties() } private fun setupFirebaseProperties() { + val firebaseAnalytics = FirebaseAnalytics.getInstance(this) + val firebaseRemoteConfig = FirebaseRemoteConfig.getInstance() + val firebasePerformance = FirebasePerformance.getInstance() val config = with(FirebaseRemoteConfigSettings.Builder()) { minimumFetchIntervalInSeconds = 10 fetchTimeoutInSeconds = 5 build() } - with(app.remoteConfig) { + with(firebaseRemoteConfig) { Timber.d("Initializing Firebase Remote Config") setConfigSettingsAsync(config) - setDefaultsAsync(app.remoteConfigSettings) - fetchAndActivate() + setDefaultsAsync(when (Locale.getDefault().language) { + Locale(LanguagesSupport.Language.SPANISH).language -> { + firebaseAnalytics.setUserProperty( + Firebase.Properties.LANGUAGE, + LanguagesSupport.Language.SPANISH + ) + R.xml.remote_config_defaults_es + } + else -> { + firebaseAnalytics.setUserProperty( + Firebase.Properties.LANGUAGE, + LanguagesSupport.Language.ENGLISH + ) + R.xml.remote_config_defaults + } + }) + fetchAndActivate().addOnSuccessListener { + if (canFinishActivity) + finish() + else + canFinishActivity = true + } } - app.firebaseAnalytics.setAnalyticsCollectionEnabled( + firebaseAnalytics.setAnalyticsCollectionEnabled( app.sharedPreferences.getBoolean( Preferences.ANALYTICS_ENABLED, true ) ) - app.firebasePerformance.isPerformanceCollectionEnabled = + firebasePerformance.isPerformanceCollectionEnabled = app.sharedPreferences.getBoolean( Preferences.PERFORMANCE_ENABLED, true ) - Timber.d("Performance enabled: ${app.firebasePerformance.isPerformanceCollectionEnabled}") + Timber.d("Performance enabled: ${firebasePerformance.isPerformanceCollectionEnabled}") } } \ No newline at end of file diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/MainActivity.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/MainActivity.kt index 629eba0..74fb405 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/MainActivity.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/MainActivity.kt @@ -28,7 +28,9 @@ import androidx.core.view.forEach import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentTransaction import com.google.android.material.bottomnavigation.BottomNavigationView +import com.google.firebase.analytics.FirebaseAnalytics import com.google.firebase.perf.metrics.AddTrace +import com.google.firebase.remoteconfig.FirebaseRemoteConfig import com.javinator9889.handwashingreminder.R import com.javinator9889.handwashingreminder.activities.support.ActionBarBase import com.javinator9889.handwashingreminder.activities.views.fragments.diseases.DiseasesFragment @@ -56,9 +58,12 @@ class MainActivity : ActionBarBase(), @AddTrace(name = "onCreateMainView") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - app = HandwashingApplication.getInstance() - app.firebaseAnalytics.setCurrentScreen(this, "Main view", null) - app.remoteConfig.fetchAndActivate() + with(FirebaseAnalytics.getInstance(this)) { + setCurrentScreen(this@MainActivity, "Main view", null) + } + with(FirebaseRemoteConfig.getInstance()) { + fetchAndActivate() + } delegateMenuIcons(menu) val ids = arrayOf(R.id.diseases, R.id.handwashing, R.id.news, R.id.settings) @@ -123,7 +128,9 @@ class MainActivity : ActionBarBase(), R.id.settings -> "settings" else -> "Main view" } - app.firebaseAnalytics.setCurrentScreen(this, screenTitle, null) + with(FirebaseAnalytics.getInstance(this)) { + setCurrentScreen(this@MainActivity, screenTitle, null) + } return onItemSelected(item.itemId) } diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/PrivacyTermsActivity.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/PrivacyTermsActivity.kt index 32b8869..11dfdfa 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/PrivacyTermsActivity.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/PrivacyTermsActivity.kt @@ -25,7 +25,6 @@ import com.google.android.material.tabs.TabLayoutMediator import com.google.firebase.analytics.FirebaseAnalytics import com.javinator9889.handwashingreminder.R import com.javinator9889.handwashingreminder.activities.support.ActionBarBase -import com.javinator9889.handwashingreminder.application.HandwashingApplication import com.javinator9889.handwashingreminder.collections.PrivacyTermsCollectionAdapter import kotlinx.android.synthetic.main.disease_view_expanded.* @@ -39,11 +38,9 @@ class PrivacyTermsActivity : ActionBarBase() { supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowTitleEnabled(true) - with(HandwashingApplication.getInstance()) { + with(FirebaseAnalytics.getInstance(this)) { val bundle = Bundle(1).apply { putString("view", "privacy") } - firebaseAnalytics.logEvent( - FirebaseAnalytics.Event.VIEW_ITEM, bundle - ) + logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle) } val adapter = PrivacyTermsCollectionAdapter(this) diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/diseases/adapter/Ads.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/diseases/adapter/Ads.kt index 94ae6ad..f00e806 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/diseases/adapter/Ads.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/diseases/adapter/Ads.kt @@ -47,6 +47,5 @@ class Ads : AbstractItem() { it.destroy() } } - } } \ No newline at end of file diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/settings/SettingsView.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/settings/SettingsView.kt index 58212a5..12a7dc0 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/settings/SettingsView.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/settings/SettingsView.kt @@ -34,6 +34,7 @@ import androidx.preference.SwitchPreference import com.afollestad.materialdialogs.MaterialDialog import com.android.billingclient.api.BillingClient.BillingResponseCode import com.google.firebase.analytics.FirebaseAnalytics +import com.google.firebase.perf.FirebasePerformance import com.javinator9889.handwashingreminder.R import com.javinator9889.handwashingreminder.activities.PrivacyTermsActivity import com.javinator9889.handwashingreminder.application.HandwashingApplication @@ -109,9 +110,9 @@ class SettingsView : PreferenceFragmentCompat(), share?.let { it.icon = icon(Ionicons.Icon.ion_android_share) it.setOnPreferenceClickListener { - app.firebaseAnalytics.logEvent( - FirebaseAnalytics.Event.SHARE, null - ) + with(FirebaseAnalytics.getInstance(requireContext())) { + logEvent(FirebaseAnalytics.Event.SHARE, null) + } with(Intent.createChooser(Intent().apply { action = Intent.ACTION_SEND putExtra( @@ -251,9 +252,9 @@ class SettingsView : PreferenceFragmentCompat(), val bundle = Bundle(1).apply { putString("view", "libs") } - app.firebaseAnalytics.logEvent( - FirebaseAnalytics.Event.VIEW_ITEM, bundle - ) + with(FirebaseAnalytics.getInstance(requireContext())) { + logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle) + } LibsBuilder() .withAutoDetect(true) .withFields(R.string::class.java.fields) @@ -335,17 +336,19 @@ class SettingsView : PreferenceFragmentCompat(), ::firebaseAnalyticsPreference.isInitialized && preference == firebaseAnalyticsPreference.get() -> { val enabled = newValue as Boolean - app.firebaseAnalytics.setAnalyticsCollectionEnabled(enabled) - if (!enabled) - app.firebaseAnalytics.setCurrentScreen( - requireActivity(), null, null - ) + with(FirebaseAnalytics.getInstance(requireContext())) { + setAnalyticsCollectionEnabled(enabled) + if (!enabled) + setCurrentScreen(requireActivity(), null, null) + } true } ::firebasePerformancePreference.isInitialized && preference == firebasePerformancePreference.get() -> { val enabled = newValue as Boolean - app.firebasePerformance.isPerformanceCollectionEnabled = enabled + with(FirebasePerformance.getInstance()) { + isPerformanceCollectionEnabled = enabled + } true } ::adsPreference.isInitialized && @@ -483,10 +486,9 @@ class SettingsView : PreferenceFragmentCompat(), return val website = Uri.parse(url) val bundle = Bundle(1).apply { putString("url", url) } - app.firebaseAnalytics.logEvent( - FirebaseAnalytics.Event.VIEW_ITEM, - bundle - ) + with(FirebaseAnalytics.getInstance(requireContext())) { + logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle) + } with(Intent(Intent.ACTION_VIEW, website)) { if (resolveActivity(requireContext().packageManager) != null diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/settings/TimePickerPreference.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/settings/TimePickerPreference.kt index c1a4566..6e9ba48 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/settings/TimePickerPreference.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/settings/TimePickerPreference.kt @@ -57,11 +57,6 @@ class TimePickerPreference : EditTextPreference, setSummary(time ?: text) } - /*override fun onSetInitialValue(defaultValue: Any?) { - text = getPersistedString("00:00") - setSummary(text) - }*/ - override fun onClick() { val time = text.split(":") val tpHour = Integer.parseInt(time[0]) diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/SliderView.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/SliderView.kt index c4c8f10..7b50a1e 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/SliderView.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/SliderView.kt @@ -46,6 +46,7 @@ class SliderView : BaseFragmentView() { private lateinit var videoURI: Uri private var drawableId by Delegates.notNull() private val counter = AtomicInteger(0) + private var position by Delegates.notNull() private lateinit var videoModelFactory: VideoModelFactory private lateinit var handsFactory: WashingHandsModelFactory private val viewModel: VideoModel by viewModels { @@ -95,6 +96,7 @@ class SliderView : BaseFragmentView() { IllegalStateException("Arguments cannot be null") videoModelFactory = VideoModelFactory(args.getInt(ARG_POSITION)) handsFactory = WashingHandsModelFactory(args.getInt(ARG_POSITION)) + position = args.getInt(ARG_POSITION) } override fun onPause() { @@ -131,6 +133,11 @@ class SliderView : BaseFragmentView() { } } + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + outState.putInt(ARG_POSITION, position) + } + private fun incrementCounter() { Timber.d("Counter incremented") if (counter.incrementAndGet() < WAITING_ITEMS_COUNT) diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/viewmodels/DiseaseInformationViewModel.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/viewmodels/DiseaseInformationViewModel.kt index be232be..f582f0b 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/viewmodels/DiseaseInformationViewModel.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/viewmodels/DiseaseInformationViewModel.kt @@ -27,7 +27,7 @@ import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.liveData import com.beust.klaxon.Klaxon -import com.javinator9889.handwashingreminder.application.HandwashingApplication +import com.google.firebase.remoteconfig.FirebaseRemoteConfig import com.javinator9889.handwashingreminder.collections.DiseasesInformation import com.javinator9889.handwashingreminder.collections.DiseasesList import com.javinator9889.handwashingreminder.collections.DiseasesListWrapper @@ -55,7 +55,7 @@ class DiseaseInformationViewModel( state.get>(PARSED_JSON_KEY)!! ) val diseasesString = - with(HandwashingApplication.getInstance().remoteConfig) { + with(FirebaseRemoteConfig.getInstance()) { getString(DISEASES_JSON) } Klaxon().parse(diseasesString) diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/application/HandwashingApplication.kt b/app/src/main/java/com/javinator9889/handwashingreminder/application/HandwashingApplication.kt index 027475e..ca67d1e 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/application/HandwashingApplication.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/application/HandwashingApplication.kt @@ -23,23 +23,16 @@ import android.content.SharedPreferences import androidx.multidex.MultiDex import androidx.preference.PreferenceManager import com.google.android.play.core.splitcompat.SplitCompat -import com.google.firebase.analytics.FirebaseAnalytics import com.google.firebase.crashlytics.FirebaseCrashlytics -import com.google.firebase.perf.FirebasePerformance -import com.google.firebase.remoteconfig.FirebaseRemoteConfig -import com.javinator9889.handwashingreminder.R import com.javinator9889.handwashingreminder.gms.activity.ActivityHandler import com.javinator9889.handwashingreminder.gms.ads.AdLoader import com.javinator9889.handwashingreminder.gms.vendor.BillingService import com.javinator9889.handwashingreminder.jobs.workers.WorkHandler -import com.javinator9889.handwashingreminder.utils.Firebase import com.javinator9889.handwashingreminder.utils.LogReportTree import com.javinator9889.handwashingreminder.utils.isDebuggable import javinator9889.localemanager.application.BaseApplication import javinator9889.localemanager.utils.languagesupport.LanguagesSupport.Language import timber.log.Timber -import java.util.* -import kotlin.properties.Delegates class HandwashingApplication : BaseApplication() { @@ -47,11 +40,7 @@ class HandwashingApplication : BaseApplication() { lateinit var workHandler: WorkHandler lateinit var billingService: BillingService lateinit var activityHandler: ActivityHandler - lateinit var remoteConfig: FirebaseRemoteConfig lateinit var sharedPreferences: SharedPreferences - lateinit var firebaseAnalytics: FirebaseAnalytics - lateinit var firebasePerformance: FirebasePerformance - var remoteConfigSettings by Delegates.notNull() companion object { private lateinit var instance: HandwashingApplication @@ -81,32 +70,11 @@ class HandwashingApplication : BaseApplication() { with(FirebaseCrashlytics.getInstance()) { setCrashlyticsCollectionEnabled(false) } - } else + } else { Timber.plant(LogReportTree()) + } activityHandler = ActivityHandler(this) workHandler = WorkHandler(this) - firebaseAnalytics = FirebaseAnalytics.getInstance(this) - firebasePerformance = FirebasePerformance.getInstance() - remoteConfig = FirebaseRemoteConfig.getInstance() - initFirebaseUserProperties() - } - - private fun initFirebaseUserProperties() { - Timber.d("User default locale: ${Locale.getDefault().language}") - remoteConfigSettings = when (Locale.getDefault().language) { - Locale(Language.SPANISH).language -> { - firebaseAnalytics.setUserProperty( - Firebase.Properties.LANGUAGE, Language.SPANISH - ) - R.xml.remote_config_defaults_es - } - else -> { - firebaseAnalytics.setUserProperty( - Firebase.Properties.LANGUAGE, Language.ENGLISH - ) - R.xml.remote_config_defaults_es - } - } } /** diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/WorkHandler.kt b/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/WorkHandler.kt index 2a52b28..201f745 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/WorkHandler.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/WorkHandler.kt @@ -103,7 +103,7 @@ class WorkHandler(private val context: Context) { with(workManager) { enqueueUniqueWork( who, - ExistingWorkPolicy.APPEND, + ExistingWorkPolicy.REPLACE, jobRequest ) } diff --git a/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt b/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt index 5efb269..20043f3 100644 --- a/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt +++ b/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt @@ -43,6 +43,7 @@ import com.google.android.material.snackbar.Snackbar import com.google.android.play.core.splitcompat.SplitCompat import com.google.android.play.core.splitinstall.SplitInstallManagerFactory import com.google.firebase.analytics.FirebaseAnalytics +import com.google.firebase.perf.FirebasePerformance import com.javinator9889.handwashingreminder.activities.MainActivity import com.javinator9889.handwashingreminder.appintro.config.TimeConfigActivity import com.javinator9889.handwashingreminder.appintro.custom.SliderPageBuilder @@ -77,15 +78,9 @@ class IntroActivity : AppIntro2(), override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - with(HandwashingApplication.getInstance()) { - firebaseAnalytics.logEvent( - FirebaseAnalytics.Event.TUTORIAL_BEGIN, null - ) - firebaseAnalytics.setCurrentScreen( - this@IntroActivity, - "Intro", - null - ) + with(FirebaseAnalytics.getInstance(this)) { + logEvent(FirebaseAnalytics.Event.TUTORIAL_BEGIN, null) + setCurrentScreen(this@IntroActivity, "Intro", null) } val firstSlide = SliderPageBuilder.Builder() @@ -186,6 +181,7 @@ class IntroActivity : AppIntro2(), else app.activityHandler.disableActivityTracker() app.workHandler.enqueuePeriodicNotificationsWorker() + val firebaseAnalytics = FirebaseAnalytics.getInstance(this) with(Bundle(2)) { putBoolean( "analytics_enabled", @@ -195,19 +191,22 @@ class IntroActivity : AppIntro2(), "performance_enabled", policySlide.firebasePerformance.isChecked ) - app.firebaseAnalytics.logEvent( - FirebaseAnalytics.Event.SELECT_ITEM, this + firebaseAnalytics.logEvent( + FirebaseAnalytics.Event.SELECT_ITEM, + this ) } - app.firebaseAnalytics.logEvent( + firebaseAnalytics.logEvent( FirebaseAnalytics.Event.TUTORIAL_COMPLETE, null ) if (!policySlide.firebaseAnalytics.isChecked) { - app.firebaseAnalytics.setCurrentScreen(this, null, null) - app.firebaseAnalytics.setAnalyticsCollectionEnabled(false) + firebaseAnalytics.setCurrentScreen(this, null, null) + firebaseAnalytics.setAnalyticsCollectionEnabled(false) + } + with(FirebasePerformance.getInstance()) { + isPerformanceCollectionEnabled = + policySlide.firebasePerformance.isChecked } - app.firebasePerformance.isPerformanceCollectionEnabled = - policySlide.firebasePerformance.isChecked val intent = Intent(this, MainActivity::class.java) startActivity(intent) this.finish() From 0e9e747d4a33597a8fcacd079a9ca7ddeae78dbb Mon Sep 17 00:00:00 2001 From: Javinator9889 Date: Tue, 21 Apr 2020 12:10:44 +0200 Subject: [PATCH 4/6] Updated update policy and wrapped EmojiCompat with try/catch block --- .../activities/LauncherActivity.kt | 5 +++++ .../jobs/workers/NotificationsWorker.kt | 20 +++++++++++++------ .../jobs/workers/WorkHandler.kt | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/LauncherActivity.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/LauncherActivity.kt index fa427d7..750d19a 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/LauncherActivity.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/LauncherActivity.kt @@ -175,6 +175,11 @@ class LauncherActivity : AppCompatActivity() { } } + override fun finish() { + Timber.d("Calling finish") + super.finish() + } + private fun installRequiredModules() { val modules = ArrayList(MODULE_COUNT) val googleApi = GoogleApiAvailability.getInstance() diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/NotificationsWorker.kt b/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/NotificationsWorker.kt index ebce8d4..87e9616 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/NotificationsWorker.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/NotificationsWorker.kt @@ -43,7 +43,7 @@ data class NotificationStructure( class NotificationsWorker( private val context: Context, - private val params: WorkerParameters + params: WorkerParameters ) : CoroutineWorker(context, params) { override suspend fun doWork(): Result = coroutineScope { @@ -70,11 +70,19 @@ class NotificationsWorker( val emojiCompat = emojiLoader.await() - val title = - emojiCompat.process(context.getString(notificationData.title)) - val comments = - context.resources.getStringArray(notificationData.content) - val comment = emojiCompat.process(comments.asList().random()) + var title: CharSequence + var comment: CharSequence + try { + title = + emojiCompat.process(context.getString(notificationData.title)) + val comments = + context.resources.getStringArray(notificationData.content) + comment = emojiCompat.process(comments.asList().random()) + } catch (_: IllegalStateException) { + title = context.getText(notificationData.title) + comment = context.resources + .getStringArray(notificationData.content).asList().random() + } withContext(Dispatchers.Main) { notificationsHandler.createNotification( diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/WorkHandler.kt b/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/WorkHandler.kt index 201f745..2a52b28 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/WorkHandler.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/WorkHandler.kt @@ -103,7 +103,7 @@ class WorkHandler(private val context: Context) { with(workManager) { enqueueUniqueWork( who, - ExistingWorkPolicy.REPLACE, + ExistingWorkPolicy.APPEND, jobRequest ) } From 050c8350b6b2134689db16fc9370bb0ef0fc51ab Mon Sep 17 00:00:00 2001 From: Javinator9889 Date: Tue, 21 Apr 2020 12:16:50 +0200 Subject: [PATCH 5/6] Created receiver when application is updated for rescheduling jobs --- app/src/main/AndroidManifest.xml | 12 ++++++- .../jobs/UpdateReceiver.kt | 32 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/javinator9889/handwashingreminder/jobs/UpdateReceiver.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9e36794..5d6b744 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -58,7 +58,17 @@ android:exported="true"> - + + + + + + diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/jobs/UpdateReceiver.kt b/app/src/main/java/com/javinator9889/handwashingreminder/jobs/UpdateReceiver.kt new file mode 100644 index 0000000..9a0b4c7 --- /dev/null +++ b/app/src/main/java/com/javinator9889/handwashingreminder/jobs/UpdateReceiver.kt @@ -0,0 +1,32 @@ +/* + * Copyright © 2020 - present | Handwashing reminder by Javinator9889 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see https://www.gnu.org/licenses/. + * + * Created by Javinator9889 on 21/04/20 - Handwashing reminder. + */ +package com.javinator9889.handwashingreminder.jobs + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import com.javinator9889.handwashingreminder.application.HandwashingApplication + +class UpdateReceiver : BroadcastReceiver() { + override fun onReceive(context: Context?, intent: Intent?) { + with(HandwashingApplication.getInstance().workHandler) { + enqueuePeriodicNotificationsWorker(true) + } + } +} \ No newline at end of file From 0b41adc162c0c5497b3eb6204ebce75087069f2b Mon Sep 17 00:00:00 2001 From: Javinator9889 Date: Tue, 21 Apr 2020 12:53:44 +0200 Subject: [PATCH 6/6] Committing shared preferences instead of applying and wrapping Glide with try/catch On low-end devices Glide sometimes fails (Android 4.3) --- app/build.gradle | 2 +- .../fragments/washinghands/SliderView.kt | 26 +++++++++++++------ .../jobs/workers/WorkHandler.kt | 8 +++--- .../appintro/IntroActivity.kt | 2 +- .../appintro/config/TimeConfigActivity.kt | 16 ++++++++---- .../timeconfig/TimeConfigViewHolder.kt | 16 ++++++++---- 6 files changed, 46 insertions(+), 24 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index bb22664..3a26d9c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -43,7 +43,7 @@ android { applicationId "com.javinator9889.handwashingreminder" minSdkVersion 17 targetSdkVersion 29 - versionCode 93 + versionCode 94 versionName "1.0.1-${gitCommitHash}" multiDexEnabled true diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/SliderView.kt b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/SliderView.kt index 7b50a1e..8bd3f4e 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/SliderView.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/activities/views/fragments/washinghands/SliderView.kt @@ -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() @@ -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() } diff --git a/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/WorkHandler.kt b/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/WorkHandler.kt index 2a52b28..90898da 100644 --- a/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/WorkHandler.kt +++ b/app/src/main/java/com/javinator9889/handwashingreminder/jobs/workers/WorkHandler.kt @@ -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() diff --git a/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt b/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt index 20043f3..3c13fd8 100644 --- a/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt +++ b/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/IntroActivity.kt @@ -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) { diff --git a/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/config/TimeConfigActivity.kt b/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/config/TimeConfigActivity.kt index aa449bf..5e8fa0e 100644 --- a/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/config/TimeConfigActivity.kt +++ b/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/config/TimeConfigActivity.kt @@ -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 : @@ -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()) } } diff --git a/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/timeconfig/TimeConfigViewHolder.kt b/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/timeconfig/TimeConfigViewHolder.kt index a628bbb..395cdef 100644 --- a/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/timeconfig/TimeConfigViewHolder.kt +++ b/appintro/src/main/java/com/javinator9889/handwashingreminder/appintro/timeconfig/TimeConfigViewHolder.kt @@ -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) : @@ -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) + } } } \ No newline at end of file