From 4d75f4ca0c2a553d47c50049e9ad4a0bfdbba020 Mon Sep 17 00:00:00 2001 From: Tommaso Berlose Date: Fri, 22 May 2020 18:20:08 +0200 Subject: [PATCH] Fix #150 --- .../helpers/GlanceProviderHelper.kt | 14 ++++++++------ .../ui/fragments/ClockTabFragment.kt | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/GlanceProviderHelper.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/GlanceProviderHelper.kt index 7306878..9ba8763 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/GlanceProviderHelper.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/GlanceProviderHelper.kt @@ -1,6 +1,7 @@ package com.tommasoberlose.anotherwidget.helpers import android.content.Context +import android.util.Log import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.db.EventRepository import com.tommasoberlose.anotherwidget.global.Constants @@ -80,13 +81,14 @@ object GlanceProviderHelper { fun showGlanceProviders(context: Context): Boolean { val eventRepository = EventRepository(context) BatteryHelper.updateBatteryInfo(context) - val showGlance = Preferences.showGlance && eventRepository.getEventsCount() == 0 && ( + + val showGlance = Preferences.showGlance && (eventRepository.getEventsCount() == 0 || !Preferences.showEvents) && ( (Preferences.showNextAlarm && AlarmHelper.getNextAlarm(context) != "") || - (MediaPlayerHelper.isSomeonePlaying(context)) || - (Preferences.showBatteryCharging && Preferences.isCharging || Preferences.isBatteryLevelLow) || - (Preferences.customNotes.isNotEmpty()) || - (Preferences.showDailySteps && Preferences.googleFitSteps > 0) - ) + (MediaPlayerHelper.isSomeonePlaying(context)) || + (Preferences.showBatteryCharging && Preferences.isCharging || Preferences.isBatteryLevelLow) || + (Preferences.customNotes.isNotEmpty()) || + (Preferences.showDailySteps && Preferences.googleFitSteps > 0) + ) eventRepository.close() return showGlance } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/ClockTabFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/ClockTabFragment.kt index f152a00..46630df 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/ClockTabFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/ClockTabFragment.kt @@ -9,6 +9,7 @@ import android.content.IntentFilter import android.content.pm.PackageManager import android.os.Bundle import android.text.format.DateFormat +import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -31,6 +32,7 @@ import com.tommasoberlose.anotherwidget.helpers.AlarmHelper import com.tommasoberlose.anotherwidget.helpers.ColorHelper import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toHexValue import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toIntValue +import com.tommasoberlose.anotherwidget.helpers.IntentHelper import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity import com.tommasoberlose.anotherwidget.ui.activities.MainActivity import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel @@ -153,8 +155,18 @@ class ClockTabFragment : Fragment() { viewModel.clockAppName.observe(viewLifecycleOwner, Observer { maintainScrollPosition { - clock_app_label?.text = - if (Preferences.clockAppName != "") Preferences.clockAppName else getString(R.string.default_clock_app) + clock_app_label?.text = try { + with(requireContext().packageManager) { + Log.d("ciao", "app: ${IntentHelper.getClockIntent(requireContext()).resolveActivity(this)}") + if (IntentHelper.getClockIntent(requireContext()).resolveActivity(this) == null) + throw Exception() + } + if (Preferences.clockAppName != "") Preferences.clockAppName else getString( + R.string.default_clock_app + ) + } catch (ex: Exception) { + "Nothing" + } } }) }