diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/components/CustomNotesDialog.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/components/CustomNotesDialog.kt index 296a333..a20d9dc 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/components/CustomNotesDialog.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/components/CustomNotesDialog.kt @@ -9,7 +9,7 @@ import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.global.Preferences import kotlinx.android.synthetic.main.custom_notes_dialog_layout.view.* -class CustomNotesDialog(context: Context) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) { +class CustomNotesDialog(context: Context, callback: (() -> Unit)?) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) { init { val view = View.inflate(context, R.layout.custom_notes_dialog_layout, null) @@ -18,6 +18,7 @@ class CustomNotesDialog(context: Context) : BottomSheetDialog(context, R.style.B view.action_positive.setOnClickListener { Preferences.customNotes = view.notes.text.toString() this.dismiss() + callback?.invoke() } view.notes.requestFocus() diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/components/GlanceSettingsDialog.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/components/GlanceSettingsDialog.kt index 545bda4..2eac147 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/components/GlanceSettingsDialog.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/components/GlanceSettingsDialog.kt @@ -7,6 +7,7 @@ import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.os.Build +import android.util.EventLog import android.util.Log import android.view.View import androidx.core.app.NotificationManagerCompat @@ -30,9 +31,11 @@ import com.tommasoberlose.anotherwidget.helpers.MediaPlayerHelper import com.tommasoberlose.anotherwidget.receivers.ActivityDetectionReceiver import com.tommasoberlose.anotherwidget.ui.activities.AppNotificationsFilterActivity import com.tommasoberlose.anotherwidget.ui.activities.MusicPlayersFilterActivity +import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import kotlinx.android.synthetic.main.glance_provider_settings_layout.view.* import kotlinx.coroutines.* +import org.greenrobot.eventbus.EventBus class GlanceSettingsDialog(val context: Activity, val provider: Constants.GlanceProviderId, private val statusCallback: (() -> Unit)?) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) { @@ -48,6 +51,7 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> context.getString(R.string.settings_daily_steps_title) Constants.GlanceProviderId.NOTIFICATIONS -> context.getString(R.string.settings_show_notifications_title) Constants.GlanceProviderId.GREETINGS -> context.getString(R.string.settings_show_greetings_title) + Constants.GlanceProviderId.EVENTS -> context.getString(R.string.settings_show_events_as_glance_provider_title) } /* SUBTITLE*/ @@ -59,6 +63,7 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> context.getString(R.string.settings_daily_steps_subtitle) Constants.GlanceProviderId.NOTIFICATIONS -> context.getString(R.string.settings_show_notifications_subtitle) Constants.GlanceProviderId.GREETINGS -> context.getString(R.string.settings_show_greetings_subtitle) + Constants.GlanceProviderId.EVENTS -> context.getString(R.string.settings_show_events_as_glance_provider_subtitle) } /* SONG */ @@ -124,6 +129,13 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance view.divider.isVisible = false } + /* EVENTS */ + if (provider == Constants.GlanceProviderId.EVENTS) { + view.header.isVisible = false + view.divider.isVisible = false + checkCalendarConfig(view) + } + /* TOGGLE */ view.provider_switch.isChecked = when (provider) { Constants.GlanceProviderId.PLAYING_SONG -> Preferences.showMusic @@ -133,6 +145,7 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> Preferences.showDailySteps Constants.GlanceProviderId.NOTIFICATIONS -> Preferences.showNotifications Constants.GlanceProviderId.GREETINGS -> Preferences.showGreetings + Constants.GlanceProviderId.EVENTS -> Preferences.showEventsAsGlanceProvider } var job: Job? = null @@ -188,6 +201,9 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance checkFitnessPermission(view) checkGoogleFitConnection(view) } + Constants.GlanceProviderId.EVENTS -> { + Preferences.showEventsAsGlanceProvider = isChecked + } else -> { } } @@ -220,6 +236,19 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance statusCallback?.invoke() } + private fun checkCalendarConfig(view: View) { + if (!Preferences.showEvents || !context.checkGrantedPermission(Manifest.permission.READ_CALENDAR)) { + view.warning_container.isVisible = true + view.warning_title.text = context.getString(R.string.settings_show_events_as_glance_provider_error) + view.warning_container.setOnClickListener { + dismiss() + EventBus.getDefault().post(MainFragment.ChangeTabEvent(1)) + } + } else { + view.warning_container.isVisible = false + } + } + private fun checkNotificationPermission(view: View) { when { ActiveNotificationsHelper.checkNotificationAccess(context) -> { diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Constants.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Constants.kt index c4005fa..8bc81ab 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Constants.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Constants.kt @@ -32,7 +32,8 @@ object Constants { CUSTOM_INFO("CUSTOM_INFO"), GOOGLE_FIT_STEPS("GOOGLE_FIT_STEPS"), NOTIFICATIONS("NOTIFICATIONS"), - GREETINGS("GREETINGS"); + GREETINGS("GREETINGS"), + EVENTS("EVENTS"); companion object { private val map = GlanceProviderId.values().associateBy(GlanceProviderId::id) diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt index c4f8d52..ef8d78d 100755 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt @@ -141,6 +141,8 @@ object Preferences : KotprefModel() { var musicPlayersFilter by stringPref(default = "") var appNotificationsFilter by stringPref(default = "") + var showEventsAsGlanceProvider by booleanPref(default = false) + // Integrations var installedIntegrations by intPref(default = 0) } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/ActiveNotificationsHelper.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/ActiveNotificationsHelper.kt index c11f779..658ec79 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/ActiveNotificationsHelper.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/ActiveNotificationsHelper.kt @@ -9,6 +9,7 @@ import com.chibatching.kotpref.Kotpref import com.chibatching.kotpref.blockingBulk import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.receivers.NotificationListener +import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget object ActiveNotificationsHelper { fun showLastNotification(): Boolean { @@ -23,6 +24,7 @@ object ActiveNotificationsHelper { remove(Preferences::lastNotificationPackage) remove(Preferences::lastNotificationIcon) } + MainWidget.updateWidget(context) } fun checkNotificationAccess(context: Context): Boolean { 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 2d2dd6c..9fd5873 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/GlanceProviderHelper.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/GlanceProviderHelper.kt @@ -1,5 +1,6 @@ package com.tommasoberlose.anotherwidget.helpers +import android.Manifest import android.content.Context import android.util.Log import com.tommasoberlose.anotherwidget.R @@ -7,6 +8,7 @@ import com.tommasoberlose.anotherwidget.db.EventRepository import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.models.GlanceProvider +import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.checkIfFitInstalled import java.util.ArrayList @@ -20,7 +22,7 @@ object GlanceProviderHelper { } .toTypedArray() - providers.sortWith(Comparator { p1, p2 -> + return ArrayList(providers.filter { enabledProviders.contains(it.id) }.sortedWith(Comparator { p1, p2 -> when { enabledProviders.contains(p1.id) && enabledProviders.contains(p2.id) -> { enabledProviders.indexOf(p1.id).compareTo(enabledProviders.indexOf(p2.id)) @@ -35,8 +37,7 @@ object GlanceProviderHelper { p1.id.compareTo(p2.id) } } - }) - return ArrayList(providers.toList()) + }) + providers.filter { !enabledProviders.contains(it.id) }) } fun getGlanceProviderById(context: Context, providerId: Constants.GlanceProviderId): GlanceProvider? { @@ -83,10 +84,16 @@ object GlanceProviderHelper { R.drawable.round_history_edu ) } + Constants.GlanceProviderId.EVENTS -> { + GlanceProvider(providerId.id, + context.getString(R.string.settings_show_events_as_glance_provider_title), + R.drawable.round_event_note + ) + } } } - fun saveGlanceProviderOrder(list: ArrayList) { + fun saveGlanceProviderOrder(list: List) { Preferences.enabledGlanceProviderOrder = list.joinToString(separator = ",") } @@ -94,7 +101,7 @@ object GlanceProviderHelper { val eventRepository = EventRepository(context) BatteryHelper.updateBatteryInfo(context) - val showGlance = Preferences.showGlance && (eventRepository.getEventsCount() == 0 || !Preferences.showEvents) + val showGlance = Preferences.showGlance && (eventRepository.getEventsCount() == 0 || !Preferences.showEvents || Preferences.showEventsAsGlanceProvider) && ( (Preferences.showNotifications && ActiveNotificationsHelper.showLastNotification()) || (Preferences.showNextAlarm && AlarmHelper.getNextAlarm(context) != "") || @@ -102,7 +109,9 @@ object GlanceProviderHelper { (Preferences.showBatteryCharging && Preferences.isCharging || Preferences.isBatteryLevelLow) || (Preferences.customNotes.isNotEmpty()) || (Preferences.showDailySteps && Preferences.googleFitSteps > 0) || - (Preferences.showGreetings && GreetingsHelper.showGreetings()) + (Preferences.showGreetings && GreetingsHelper.showGreetings()) || + (Preferences.showEventsAsGlanceProvider && Preferences.showEvents && context.checkGrantedPermission( + Manifest.permission.READ_CALENDAR) && eventRepository.getNextEvent() != null) ) eventRepository.close() return showGlance diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/receivers/NotificationListener.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/receivers/NotificationListener.kt index 6d4a5f1..3b2d3c1 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/receivers/NotificationListener.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/receivers/NotificationListener.kt @@ -8,6 +8,7 @@ import android.os.Build import android.service.notification.NotificationListenerService import android.service.notification.StatusBarNotification import android.util.Log +import android.widget.Toast import com.tommasoberlose.anotherwidget.global.Actions import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Preferences @@ -33,7 +34,7 @@ class NotificationListener : NotificationListenerService() { val isGroupHeader = sbn.notification.flags and Notification.FLAG_GROUP_SUMMARY != 0 val isOngoing = sbn.notification.flags and Notification.FLAG_ONGOING_EVENT != 0 - if (bundle.containsKey(Notification.EXTRA_TITLE) && !isGroupHeader && !isOngoing && ActiveNotificationsHelper.isAppAccepted(sbn.packageName)) { + if (bundle.containsKey(Notification.EXTRA_TITLE) && !isGroupHeader && !isOngoing && ActiveNotificationsHelper.isAppAccepted(sbn.packageName) && !sbn.packageName.contains("com.android.systemui")) { Preferences.lastNotificationId = sbn.id Preferences.lastNotificationTitle = bundle.getString(Notification.EXTRA_TITLE) ?: "" if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/receivers/UpdatesReceiver.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/receivers/UpdatesReceiver.kt index 0dcbef4..6244a7c 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/receivers/UpdatesReceiver.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/receivers/UpdatesReceiver.kt @@ -33,9 +33,9 @@ class UpdatesReceiver : BroadcastReceiver() { Intent.ACTION_LOCALE_CHANGED, Intent.ACTION_DATE_CHANGED, Actions.ACTION_CALENDAR_UPDATE -> { - CalendarHelper.updateEventList(context) ActiveNotificationsHelper.clearLastNotification(context) MediaPlayerHelper.updatePlayingMediaInfo(context) + CalendarHelper.updateEventList(context) } "com.sec.android.widgetapp.APPWIDGET_RESIZE", diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GlanceTabFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GlanceTabFragment.kt index ea498c9..34fd828 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GlanceTabFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GlanceTabFragment.kt @@ -15,7 +15,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView -import androidx.core.app.NotificationManagerCompat import androidx.core.content.ContextCompat import androidx.core.view.ViewCompat import androidx.databinding.DataBindingUtil @@ -51,7 +50,6 @@ import kotlinx.android.synthetic.main.fragment_glance_settings.* import kotlinx.coroutines.delay import kotlinx.coroutines.launch import net.idik.lib.slimadapter.SlimAdapter -import java.util.* class GlanceTabFragment : Fragment() { @@ -63,6 +61,7 @@ class GlanceTabFragment : Fragment() { private var dialog: GlanceSettingsDialog? = null private lateinit var adapter: SlimAdapter private lateinit var viewModel: MainViewModel + private lateinit var list: ArrayList override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -84,6 +83,8 @@ class GlanceTabFragment : Fragment() { binding.lifecycleOwner = this binding.viewModel = viewModel + list = GlanceProviderHelper.getGlanceProviders(requireContext()) + return binding.root } @@ -107,7 +108,9 @@ class GlanceTabFragment : Fragment() { .clicked(R.id.item) { if (Preferences.showGlance) { if (provider == Constants.GlanceProviderId.CUSTOM_INFO) { - CustomNotesDialog(requireContext()).show() + CustomNotesDialog(requireContext()){ + adapter.notifyItemRangeChanged(0, adapter.data.size) + }.show() } else { dialog = GlanceSettingsDialog(requireActivity(), provider) { adapter.notifyItemRangeChanged(0, adapter.data.size) @@ -119,6 +122,7 @@ class GlanceTabFragment : Fragment() { } } } + var isVisible = false when (provider) { Constants.GlanceProviderId.PLAYING_SONG -> { when { @@ -129,16 +133,19 @@ class GlanceTabFragment : Fragment() { injector.text(R.id.label, if (Preferences.showMusic) getString(R.string.settings_visible) else getString( R.string.settings_not_visible)) + isVisible = Preferences.showMusic } Preferences.showMusic -> { injector.visibility(R.id.error_icon, View.VISIBLE) injector.visibility(R.id.info_icon, View.GONE) injector.text(R.id.label, getString(R.string.settings_not_visible)) + isVisible = false } else -> { injector.visibility(R.id.error_icon, View.GONE) injector.visibility(R.id.info_icon, View.VISIBLE) injector.text(R.id.label, getString(R.string.settings_not_visible)) + isVisible = false } } } @@ -156,6 +163,8 @@ class GlanceTabFragment : Fragment() { if (!(Preferences.showNextAlarm && AlarmHelper.isAlarmProbablyWrong( requireContext())) ) View.VISIBLE else View.GONE) + isVisible = !(Preferences.showNextAlarm && AlarmHelper.isAlarmProbablyWrong( + requireContext())) } Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> { injector.text(R.id.label, @@ -163,6 +172,7 @@ class GlanceTabFragment : Fragment() { R.string.settings_not_visible)) injector.visibility(R.id.error_icon, View.GONE) injector.visibility(R.id.info_icon, View.VISIBLE) + isVisible = Preferences.showBatteryCharging } Constants.GlanceProviderId.NOTIFICATIONS -> { when { @@ -172,16 +182,19 @@ class GlanceTabFragment : Fragment() { injector.text(R.id.label, if (Preferences.showNotifications) getString( R.string.settings_visible) else getString(R.string.settings_not_visible)) + isVisible = Preferences.showNotifications } Preferences.showNotifications -> { injector.visibility(R.id.error_icon, View.VISIBLE) injector.visibility(R.id.info_icon, View.GONE) injector.text(R.id.label, getString(R.string.settings_not_visible)) + isVisible = false } else -> { injector.visibility(R.id.error_icon, View.GONE) injector.visibility(R.id.info_icon, View.VISIBLE) injector.text(R.id.label, getString(R.string.settings_not_visible)) + isVisible = false } } } @@ -191,6 +204,7 @@ class GlanceTabFragment : Fragment() { R.string.settings_not_visible)) injector.visibility(R.id.error_icon, View.GONE) injector.visibility(R.id.info_icon, View.VISIBLE) + isVisible = Preferences.showGreetings } Constants.GlanceProviderId.CUSTOM_INFO -> { injector.text(R.id.label, @@ -198,6 +212,7 @@ class GlanceTabFragment : Fragment() { R.string.settings_not_visible)) injector.visibility(R.id.error_icon, View.GONE) injector.visibility(R.id.info_icon, View.VISIBLE) + isVisible = Preferences.customNotes != "" } Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> { val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(context) @@ -209,19 +224,34 @@ class GlanceTabFragment : Fragment() { R.string.settings_not_visible)) injector.visibility(R.id.error_icon, View.GONE) injector.visibility(R.id.info_icon, View.VISIBLE) + isVisible = Preferences.showDailySteps } else if (Preferences.showDailySteps) { ActivityDetectionReceiver.unregisterFence(requireContext()) injector.visibility(R.id.error_icon, View.VISIBLE) injector.visibility(R.id.info_icon, View.GONE) injector.text(R.id.label, getString(R.string.settings_not_visible)) + isVisible = false } else { ActivityDetectionReceiver.unregisterFence(requireContext()) injector.text(R.id.label, getString(R.string.settings_not_visible)) injector.visibility(R.id.error_icon, View.GONE) injector.visibility(R.id.info_icon, View.VISIBLE) + isVisible = false } } + Constants.GlanceProviderId.EVENTS -> { + isVisible = Preferences.showEventsAsGlanceProvider && Preferences.showEvents && requireContext().checkGrantedPermission(Manifest.permission.READ_CALENDAR) + injector.text(R.id.label, + if (isVisible) getString(R.string.settings_visible) else getString( + R.string.settings_not_visible)) + injector.visibility(R.id.error_icon, if (isVisible) View.GONE else View.VISIBLE) + injector.visibility(R.id.info_icon, if (isVisible) View.VISIBLE else View.GONE) + } } + + injector.alpha(R.id.title, if (isVisible) 1f else .25f) + injector.alpha(R.id.label, if (isVisible) 1f else .25f) + injector.alpha(R.id.icon, if (isVisible) 1f else .25f) } .attachTo(providers_list) @@ -231,8 +261,6 @@ class GlanceTabFragment : Fragment() { 0 ) { - val list = GlanceProviderHelper.getGlanceProviders(requireContext()) - override fun onMove( recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder, @@ -244,10 +272,6 @@ class GlanceTabFragment : Fragment() { return true } - override fun isItemViewSwipeEnabled(): Boolean { - return false - } - override fun onMoved( recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, @@ -257,14 +281,28 @@ class GlanceTabFragment : Fragment() { x: Int, y: Int ) { - with(list[fromPos]) { - list[fromPos] = list[toPos] - list[toPos] = this + with(list[toPos]) { + list[toPos] = list[fromPos] + list[fromPos] = this } - GlanceProviderHelper.saveGlanceProviderOrder(list) super.onMoved(recyclerView, viewHolder, fromPos, target, toPos, x, y) } + override fun isItemViewSwipeEnabled(): Boolean { + return false + } + + override fun clearView( + recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder + ) { + super.clearView(recyclerView, viewHolder) + GlanceProviderHelper.saveGlanceProviderOrder( + list + ) + adapter.updateData(list.mapNotNull { GlanceProviderHelper.getGlanceProviderById(requireContext(), it) }) + } + override fun onChildDraw( c: Canvas, recyclerView: RecyclerView, @@ -305,10 +343,7 @@ class GlanceTabFragment : Fragment() { }) mIth.attachToRecyclerView(providers_list) - adapter.updateData( - GlanceProviderHelper.getGlanceProviders(requireContext()) - .mapNotNull { GlanceProviderHelper.getGlanceProviderById(requireContext(), it) } - ) + adapter.updateData(list.mapNotNull { GlanceProviderHelper.getGlanceProviderById(requireContext(), it) }) providers_list.isNestedScrollingEnabled = false setupListener() @@ -338,6 +373,11 @@ class GlanceTabFragment : Fragment() { show_glance_switch.setOnCheckedChangeListener { _, enabled: Boolean -> Preferences.showGlance = enabled } + + action_show_glance.setOnLongClickListener { + Preferences.enabledGlanceProviderOrder = "" + true + } } private val nextAlarmChangeBroadcastReceiver = object : BroadcastReceiver() { diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt index 8e02583..9155218 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt @@ -365,7 +365,8 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList badgeGravity = BadgeDrawable.TOP_END }?.isVisible = ((Preferences.showMusic || Preferences.showNotifications) && !ActiveNotificationsHelper.checkNotificationAccess(requireContext())) || (Preferences.showDailySteps && !(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || requireActivity().checkGrantedPermission(Manifest.permission.ACTIVITY_RECOGNITION))) || - (AlarmHelper.isAlarmProbablyWrong(requireContext())) + (AlarmHelper.isAlarmProbablyWrong(requireContext())) || + (Preferences.showEventsAsGlanceProvider && (!Preferences.showEvents || !requireContext().checkGrantedPermission(Manifest.permission.READ_CALENDAR))) } override fun onResume() { @@ -396,6 +397,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList } class UpdateUiMessageEvent + class ChangeTabEvent(val page: Int) @Subscribe(threadMode = ThreadMode.MAIN) fun onMessageEvent(ignore: UpdateUiMessageEvent?) { @@ -407,4 +409,11 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList } } } + + @Subscribe(threadMode = ThreadMode.MAIN) + fun onMessageEvent(event: ChangeTabEvent?) { + event?.let { + pager.setCurrentItem(event.page, true) + } + } } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt index 0ad284a..fa9f1f2 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt @@ -172,7 +172,7 @@ class MainWidget : AppWidgetProvider() { val nextEvent = eventRepository.getNextEvent() val nextAlarm = AlarmHelper.getNextAlarm(context) - if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null) { + if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null && !Preferences.showEventsAsGlanceProvider) { if (Preferences.showNextEvent && eventRepository.getEventsCount() > 1) { views.setImageViewBitmap( R.id.action_next_rect, @@ -378,6 +378,26 @@ class MainWidget : AppWidgetProvider() { break@loop } } + Constants.GlanceProviderId.EVENTS -> { + if (Preferences.showEventsAsGlanceProvider&& Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null) { + val pIntentDetail = PendingIntent.getActivity( + context, + widgetID, + IntentHelper.getEventIntent( + context, + nextEvent, + forceEventDetails = true + ), + PendingIntent.FLAG_UPDATE_CURRENT + ) + views.setOnClickPendingIntent( + R.id.second_row_rect, + pIntentDetail + ) + showSomething = true + break@loop + } + } } } @@ -552,7 +572,7 @@ class MainWidget : AppWidgetProvider() { val nextEvent = eventRepository.getNextEvent() val nextAlarm = AlarmHelper.getNextAlarm(context) - if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null) { + if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null && !Preferences.showEventsAsGlanceProvider) { // Multiple counter v.action_next.isVisible = Preferences.showNextEvent && eventRepository.getEventsCount() > 1 @@ -765,6 +785,35 @@ class MainWidget : AppWidgetProvider() { break@loop } } + Constants.GlanceProviderId.EVENTS -> { + if (Preferences.showEventsAsGlanceProvider && Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null) { + v.next_event_date.text = context.getString(R.string.events_glance_provider_format).format(nextEvent.title, if (Preferences.showDiffTime && now.timeInMillis < nextEvent.startDate) { + if (!nextEvent.allDay) { + SettingsStringHelper.getDifferenceText( + context, + now.timeInMillis, + nextEvent.startDate + ) + .toLowerCase(Locale.getDefault()) + } else { + SettingsStringHelper.getAllDayEventDifferenceText( + context, + now.timeInMillis, + nextEvent.startDate + ).toLowerCase(Locale.getDefault()) + } + } else "").trimEnd() + v.second_row_icon.isVisible = true + v.second_row_icon.setImageDrawable( + ContextCompat.getDrawable( + context, + R.drawable.round_today + ) + ) + showSomething = true + break@loop + } + } } } diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 34c4601..24eb9f2 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -233,6 +233,10 @@ 15 minuti che viene eliminata + Eventi + Mostra il dettaglio dell\'evento avendo sempre la data visibile. + Attiva la visualizzazione degli eventi e concedi il permesso necessario per accedere al calendario. + %1$s %2$s Condividi diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dbd797d..399bf27 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -217,8 +217,8 @@ Alarm set by %s The next alarm clock seems to be wrong The next alarm clock seems to be correct - Lastest notifications - Check out the lastest notifications that showed up on your device. + Latest notifications + Check out the latest notifications that showed up on your device. Greetings View some cool phrase when you don\'t expect it. Account connected @@ -255,6 +255,10 @@ 15 minutes it\'s dismissed + Events + View a sneak peek of your calendar events and always show the current date. + Please enable the show of the events in the calendar tab and grant the required permission. + %1$s %2$s Share