Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,31 @@
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:label="Campus">

<receiver
android:name=".widgets.calendar.CalendarWidget"
android:exported="false">
android:name=".widgets.calendar.CalendarWidgetProvider"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/calendar_widget_info" />
</receiver>

<receiver
android:name="es.antonborri.home_widget.HomeWidgetBackgroundReceiver"
android:exported="true">
<intent-filter>
<action android:name="es.antonborri.home_widget.action.BACKGROUND" />
</intent-filter>
</receiver>

<service
android:name="es.antonborri.home_widget.HomeWidgetBackgroundService"
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" />

<service
android:name=".widgets.calendar.CalendarWidgetService"
android:permission="android.permission.BIND_REMOTEVIEWS" />
Expand Down Expand Up @@ -74,6 +87,9 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="es.antonborri.home_widget.action.LAUNCH" />
</intent-filter>
</activity>
<!--
Don't delete the meta-data below.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package de.tum.`in`.tumcampus.widgets.calendar

import android.appwidget.AppWidgetManager
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.view.View
import android.widget.RemoteViews
import de.tum.`in`.tumcampus.MainActivity
import de.tum.`in`.tumcampus.R
import de.tum.`in`.tumcampus.util.DateTimeSerializer
import de.tum.`in`.tumcampus.util.timeAgo
import es.antonborri.home_widget.HomeWidgetLaunchIntent
import es.antonborri.home_widget.HomeWidgetProvider
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.Period
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.time.format.TextStyle
import java.util.Locale
import androidx.core.net.toUri

class CalendarWidgetProvider : HomeWidgetProvider() {
override fun onUpdate(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetIds: IntArray,
widgetData: SharedPreferences
) {
// There may be multiple widgets active, so update all of them
for (appWidgetId in appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId, widgetData)
}
}

private fun updateAppWidget(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetId: Int,
widgetData: SharedPreferences
) {
// Instantiate the RemoteViews object for the app widget layout.
val remoteViews = RemoteViews(context.packageName, R.layout.calendar_widget)

// Set formatted date in the header
val localDate = LocalDate.now()
val dateFormatter =
DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).withLocale(Locale.getDefault())
val date = localDate.format(dateFormatter)
val weekday = localDate.dayOfWeek.getDisplayName(TextStyle.FULL, Locale.getDefault())
remoteViews.setTextViewText(R.id.calendar_widget_date, "$weekday, $date")

// Set last saved date in the header
val lastSaved = widgetData.getString("calendar_save", null)
val lastSavedDate = DateTimeSerializer.deserializeStringToDate(lastSaved)
val lastSavedDateString = (lastSavedDate ?: LocalDateTime.now()).timeAgo(context)
remoteViews.setTextViewText(R.id.calendar_widget_updated_on, lastSavedDateString)

if (lastSavedDate != null && Period.between(
LocalDate.now(),
lastSavedDate.toLocalDate(),
).days < 14
) {
// Set up the intent that starts the calendarWidgetService
val intent = Intent(context, CalendarWidgetService::class.java)
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
intent.data = intent.toUri(Intent.URI_INTENT_SCHEME).toUri()
remoteViews.setRemoteAdapter(R.id.calendar_widget_listview, intent)

// The empty view is displayed when the collection has no items.
// It should be in the same layout used to instantiate the RemoteViews
// object above.
remoteViews.setEmptyView(R.id.calendar_widget_listview, R.id.empty_list_item)
remoteViews.setViewVisibility(R.id.old_data_item, View.INVISIBLE)
} else {
remoteViews.setViewVisibility(R.id.old_data_item, View.VISIBLE)
remoteViews.setViewVisibility(R.id.calendar_widget_listview, View.INVISIBLE)
}

val pendingIntentWithData = HomeWidgetLaunchIntent.getActivity(
context,
MainActivity::class.java,
"tumCampusApp://message?homeWidget=calendar".toUri()
)
remoteViews.setOnClickPendingIntent(R.id.calendar_widget, pendingIntentWithData)

// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, remoteViews)
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.calendar_widget_listview)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package de.tum.`in`.tumcampus.widgets.calendar

import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.os.Build
import android.widget.RemoteViews
import android.widget.RemoteViewsService
import de.tum.`in`.tumcampus.util.DateTimeUtils
Expand Down Expand Up @@ -94,11 +96,19 @@ class CalendarWidgetService : RemoteViewsService() {
}

// Setup event color
remoteViews.setInt(
R.id.calendar_widget_event,
"setBackgroundColor",
currentItem.getEventColor(applicationContext)
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
remoteViews.setColorStateList(
R.id.calendar_widget_event,
"setBackgroundTintList",
ColorStateList.valueOf(currentItem.getEventColor(applicationContext))
)
} else {
remoteViews.setInt(
R.id.calendar_widget_event,
"setBackgroundColor",
currentItem.getEventColor(applicationContext)
)
}

// Setup event title
remoteViews.setTextViewText(R.id.calendar_widget_event_title, currentItem.title)
Expand Down
6 changes: 6 additions & 0 deletions android/app/src/main/res/drawable/rounded_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners android:radius="8dp" />
</shape>
5 changes: 3 additions & 2 deletions android/app/src/main/res/layout/calendar_widget_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@
android:layout_height="wrap_content"
android:layout_below="@id/calendar_widget_date_month"
android:layout_marginStart="30dp"
android:background="@drawable/rounded_background"
android:backgroundTint="@color/color_primary"
android:orientation="vertical"
android:padding="@dimen/material_small_padding"
tools:background="@color/text_dark_gray">
android:padding="@dimen/material_small_padding">

<TextView
android:id="@+id/calendar_widget_event_title"
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip
2 changes: 1 addition & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version '8.8.1' apply false
id "com.android.application" version '8.9.0' apply false
id "org.jetbrains.kotlin.android" version "1.9.20" apply false
id "org.jetbrains.kotlin.plugin.serialization" version "2.0.21" apply false
id "com.google.gms.google-services" version "4.4.2" apply false
Expand Down
24 changes: 12 additions & 12 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ PODS:
- Firebase/RemoteConfig (11.8.0):
- Firebase/CoreOnly
- FirebaseRemoteConfig (~> 11.8.0)
- firebase_core (3.12.0):
- firebase_core (3.12.1):
- Firebase/CoreOnly (= 11.8.0)
- Flutter
- firebase_crashlytics (4.3.3):
- firebase_crashlytics (4.3.4):
- Firebase/Crashlytics (= 11.8.0)
- firebase_core
- Flutter
- firebase_remote_config (5.4.1):
- firebase_remote_config (5.4.2):
- Firebase/RemoteConfig (= 11.8.0)
- firebase_core
- Flutter
Expand Down Expand Up @@ -52,7 +52,7 @@ PODS:
- FirebaseSharedSwift (~> 11.0)
- GoogleUtilities/Environment (~> 8.0)
- "GoogleUtilities/NSData+zlib (~> 8.0)"
- FirebaseRemoteConfigInterop (11.8.0)
- FirebaseRemoteConfigInterop (11.9.0)
- FirebaseSessions (11.8.0):
- FirebaseCore (~> 11.8.0)
- FirebaseCoreExtension (~> 11.8.0)
Expand All @@ -62,7 +62,7 @@ PODS:
- GoogleUtilities/UserDefaults (~> 8.0)
- nanopb (~> 3.30910.0)
- PromisesSwift (~> 2.1)
- FirebaseSharedSwift (11.8.0)
- FirebaseSharedSwift (11.9.0)
- Flutter (1.0.0)
- flutter_native_splash (2.4.3):
- Flutter
Expand Down Expand Up @@ -136,7 +136,7 @@ PODS:
- sqlite3_flutter_libs (0.0.1):
- Flutter
- FlutterMacOS
- sqlite3 (~> 3.49.0)
- sqlite3 (~> 3.49.1)
- sqlite3/dbstatvtab
- sqlite3/fts5
- sqlite3/perf-threadsafe
Expand Down Expand Up @@ -236,19 +236,19 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
device_info_plus: 21fcca2080fbcd348be798aa36c3e5ed849eefbe
Firebase: d80354ed7f6df5f9aca55e9eb47cc4b634735eaf
firebase_core: 6cbed78b4f298ed103a9fd034e6dbc846320480f
firebase_crashlytics: eb5eb0ef5e6910395adfe177b9ca4a62e8a2f1aa
firebase_remote_config: fd021c0d4a6dcf859042b3b74a24cd4d988625c3
firebase_core: 8d552814f6c01ccde5d88939fced4ec26f2f5510
firebase_crashlytics: 05519be6b623981a77fe54fb52e6061956cb6047
firebase_remote_config: ca499f96ddbcc63db863b941bf9f5e6e9a81ceba
FirebaseABTesting: 7d6eee42b9137541eac2610e5fea3568d956707a
FirebaseCore: 99fe0c4b44a39f37d99e6404e02009d2db5d718d
FirebaseCoreExtension: 3d3f2017a00d06e09ab4ebe065391b0bb642565e
FirebaseCoreInternal: df24ce5af28864660ecbd13596fc8dd3a8c34629
FirebaseCrashlytics: a1102c035f18d5dd94a5969ee439c526d0c9e313
FirebaseInstallations: 6c963bd2a86aca0481eef4f48f5a4df783ae5917
FirebaseRemoteConfig: f63724461fd97f0d62f20021314b59388f3e8ef8
FirebaseRemoteConfigInterop: 98897a64aa372eac3c5b3fe2816594ccfaac55ef
FirebaseRemoteConfigInterop: 710954a00e956c5fe5144a8e46164f0361389203
FirebaseSessions: c4d40a97f88f9eaff2834d61b4fea0a522d62123
FirebaseSharedSwift: 672954eac7b141d6954fab9a32d45d6b1d922df8
FirebaseSharedSwift: 574e6a5602afe4397a55c8d4f767382d620285de
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_native_splash: c32d145d68aeda5502d5f543ee38c192065986cf
flutter_secure_storage: 1ed9476fba7e7a782b22888f956cce43e2c62f13
Expand All @@ -270,7 +270,7 @@ SPEC CHECKSUMS:
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
sqlite3: fc1400008a9b3525f5914ed715a5d1af0b8f4983
sqlite3_flutter_libs: 3c323550ef3b928bc0aa9513c841e45a7d242832
sqlite3_flutter_libs: f8fc13346870e73fe35ebf6dbb997fbcd156b241
url_launcher_ios: 694010445543906933d732453a59da0a173ae33d
video_player_avfoundation: 2cef49524dd1f16c5300b9cd6efd9611ce03639b

Expand Down
2 changes: 1 addition & 1 deletion lib/base/routing/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const locationPermission = "/locationPermission";
const permissionCheck = "/permissionCheck";

/// Home tab
const home = "/home";
const home = "/";
const departures = "/departures";
const cafeteriaWidget = "/cafeteriaWidget";
const closestStudyRoom = "/closestStudyRoom";
Expand Down
2 changes: 1 addition & 1 deletion lib/calendarComponent/viewModels/calendar_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CalendarViewModel {
);
await HomeWidget.updateWidget(
iOSName: "CalendarWidget",
androidName: "widgets.calendar.CalendarWidget",
androidName: "widgets.calendar.CalendarWidgetProvider",
);
}

Expand Down
Loading