π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat(widget): android widget with title, subTitle, tap action & fixes for iOS widget
Prateek Sunalf21abd513385
diff --git a/mobile/android/app/build.gradle b/mobile/android/app/build.gradleindex 2555fee2a8..8c3148fae8 100644--- a/mobile/android/app/build.gradle+++ b/mobile/android/app/build.gradle@@ -2,6 +2,7 @@ plugins {id "com.android.application"id "kotlin-android"id "dev.flutter.flutter-gradle-plugin"+ id 'org.jetbrains.kotlin.plugin.serialization' version '2.1.10'}def localProperties = new Properties()def localPropertiesFile = rootProject.file('local.properties')@@ -133,7 +134,8 @@ flutter {dependencies {implementation 'io.sentry:sentry-android:2.0.0'- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.21"+ implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.21'+ implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0'implementation 'com.android.support:multidex:1.0.3'implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'implementation 'com.microsoft.onnxruntime:onnxruntime-android:1.8.1'diff --git a/mobile/android/app/src/main/AndroidManifest.xml b/mobile/android/app/src/main/AndroidManifest.xmlindex 13f28212a0..ff61f86f5e 100644--- a/mobile/android/app/src/main/AndroidManifest.xml+++ b/mobile/android/app/src/main/AndroidManifest.xml@@ -20,6 +20,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><intent-filter><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" />@@ -140,7 +143,7 @@android:value="https://[email protected]/4" /><meta-data android:name="firebase_analytics_collection_deactivated"android:value="true" />- <receiver android:name="SlideshowWidgetProvider" android:label="Favorites" android:exported="true">+ <receiver android:name="SlideshowWidgetProvider" android:label="Memories" android:exported="true"><intent-filter><action android:name="android.appwidget.action.APPWIDGET_UPDATE" /></intent-filter>diff --git a/mobile/android/app/src/main/kotlin/io/ente/photos/SlideshowWidgetProvider.kt b/mobile/android/app/src/main/kotlin/io/ente/photos/SlideshowWidgetProvider.ktindex 26e9724cb1..ecac694b3c 100644--- a/mobile/android/app/src/main/kotlin/io/ente/photos/SlideshowWidgetProvider.kt+++ b/mobile/android/app/src/main/kotlin/io/ente/photos/SlideshowWidgetProvider.kt@@ -6,6 +6,7 @@ import android.content.SharedPreferencesimport android.graphics.Bitmapimport android.graphics.BitmapFactoryimport android.graphics.drawable.BitmapDrawable+import android.net.Uriimport android.util.Logimport android.view.Viewimport android.widget.RemoteViews@@ -13,6 +14,12 @@ import androidx.core.content.ContextCompatimport es.antonborri.home_widget.HomeWidgetLaunchIntentimport es.antonborri.home_widget.HomeWidgetProviderimport java.io.File+import kotlinx.serialization.Serializable+import kotlinx.serialization.json.Json+import kotlinx.serialization.decodeFromString++@Serializable+data class MemoryFileData(val title: String?, val subText: String?, val generatedId: Int?)class SlideshowWidgetProvider : HomeWidgetProvider() {override fun onUpdate(@@ -24,14 +31,6 @@ class SlideshowWidgetProvider : HomeWidgetProvider() {appWidgetIds.forEach { widgetId ->val views =RemoteViews(context.packageName, R.layout.slideshow_layout).apply {- // Open App on Widget Click- val pendingIntent =- HomeWidgetLaunchIntent.getActivity(- context,- MainActivity::class.java- )- setOnClickPendingIntent(R.id.widget_container, pendingIntent)-val totalSet = widgetData.getInt("totalSet", 0)var randomNumber = 0if (totalSet > 0) {@@ -46,16 +45,53 @@ class SlideshowWidgetProvider : HomeWidgetProvider() {imageExists = imageFile.exists()}if (imageExists) {+ val data = widgetData.getString("slideshow_${randomNumber}_data", null)+ val decoded: MemoryFileData? = data?.let { Json.decodeFromString<MemoryFileData>(it) }+ val title = decoded?.title+ val subText = decoded?.subText+ val generatedId = decoded?.generatedId++ val deepLinkUri = Uri.parse("memoryWidget://message?generatedId=${generatedId}&homeWidget")++ val pendingIntent = HomeWidgetLaunchIntent.getActivity(+ context, MainActivity::class.java, deepLinkUri+ )++ setOnClickPendingIntent(R.id.widget_container, pendingIntent)++Log.d("SlideshowWidgetProvider", "Image exists: $imagePath")setViewVisibility(R.id.widget_img, View.VISIBLE)+ setViewVisibility(R.id.widget_placeholder_container , View.VISIBLE)+ setViewVisibility(R.id.widget_subtitle, View.VISIBLE)+ setViewVisibility(R.id.widget_title, View.VISIBLE)+ setViewVisibility(R.id.widget_overlay, View.VISIBLE)setViewVisibility(R.id.widget_placeholder, View.GONE)+ setViewVisibility(R.id.widget_placeholder_text, View.GONE)+ setViewVisibility(R.id.widget_placeholder_container, View.GONE)val bitmap: Bitmap = BitmapFactory.decodeFile(imagePath)setImageViewBitmap(R.id.widget_img, bitmap)+ setTextViewText(R.id.widget_title, title)+ setTextViewText(R.id.widget_subtitle, subText)} else {+ // Open App on Widget Click+ val pendingIntent =+ HomeWidgetLaunchIntent.getActivity(+ context,+ MainActivity::class.java+ )+ setOnClickPendingIntent(R.id.widget_container, pendingIntent)+Log.d("SlideshowWidgetProvider", "Image doesn't exists")setViewVisibility(R.id.widget_img, View.GONE)+ setViewVisibility(R.id.widget_placeholder_container , View.GONE)+ setViewVisibility(R.id.widget_subtitle, View.GONE)+ setViewVisibility(R.id.widget_title, View.GONE)+ setViewVisibility(R.id.widget_overlay, View.GONE)setViewVisibility(R.id.widget_placeholder, View.VISIBLE)+ setViewVisibility(R.id.widget_placeholder_text, View.VISIBLE)+ setViewVisibility(R.id.widget_placeholder_container, View.VISIBLE)val drawable =ContextCompat.getDrawable(diff --git a/mobile/android/app/src/main/res/drawable-hdpi/ic_home_widget_default.png b/mobile/android/app/src/main/res/drawable-hdpi/ic_home_widget_default.pngindex f66451a491..449ea27a83 100644Binary files a/mobile/android/app/src/main/res/drawable-hdpi/ic_home_widget_default.png and b/mobile/android/app/src/main/res/drawable-hdpi/ic_home_widget_default.png differdiff --git a/mobile/android/app/src/main/res/drawable-mdpi/ic_home_widget_default.png b/mobile/android/app/src/main/res/drawable-mdpi/ic_home_widget_default.pngindex b5be0ac8e9..4ae54e4339 100644Binary files a/mobile/android/app/src/main/res/drawable-mdpi/ic_home_widget_default.png and b/mobile/android/app/src/main/res/drawable-mdpi/ic_home_widget_default.png differdiff --git a/mobile/android/app/src/main/res/drawable-xhdpi/ic_home_widget_default.png b/mobile/android/app/src/main/res/drawable-xhdpi/ic_home_widget_default.pngindex bc9a25ab97..f158f6a086 100644Binary files a/mobile/android/app/src/main/res/drawable-xhdpi/ic_home_widget_default.png and b/mobile/android/app/src/main/res/drawable-xhdpi/ic_home_widget_default.png differdiff --git a/mobile/android/app/src/main/res/drawable-xxhdpi/ic_home_widget_default.png b/mobile/android/app/src/main/res/drawable-xxhdpi/ic_home_widget_default.pngindex 52971c10aa..224d849f3b 100644Binary files a/mobile/android/app/src/main/res/drawable-xxhdpi/ic_home_widget_default.png and b/mobile/android/app/src/main/res/drawable-xxhdpi/ic_home_widget_default.png differdiff --git a/mobile/android/app/src/main/res/drawable-xxxhdpi/ic_home_widget_default.png b/mobile/android/app/src/main/res/drawable-xxxhdpi/ic_home_widget_default.pngindex ca010e9da5..066e6e362a 100644Binary files a/mobile/android/app/src/main/res/drawable-xxxhdpi/ic_home_widget_default.png and b/mobile/android/app/src/main/res/drawable-xxxhdpi/ic_home_widget_default.png differdiff --git a/mobile/android/app/src/main/res/layout/gradient_overlay.xml b/mobile/android/app/src/main/res/layout/gradient_overlay.xmlnew file mode 100644index 0000000000..36fa5b2234--- /dev/null+++ b/mobile/android/app/src/main/res/layout/gradient_overlay.xml@@ -0,0 +1,8 @@+<shape xmlns:android="http://schemas.android.com/apk/res/android">+ <gradient+ android:angle="90"+ android:startColor="#80000000"+ android:endColor="#00000000"+ android:centerY="1.0"+ android:centerColor="#40000000"/>+</shape>diff --git a/mobile/android/app/src/main/res/layout/slideshow_layout.xml b/mobile/android/app/src/main/res/layout/slideshow_layout.xmlindex 2a3a8b57e0..3a11633cf6 100644--- a/mobile/android/app/src/main/res/layout/slideshow_layout.xml+++ b/mobile/android/app/src/main/res/layout/slideshow_layout.xml@@ -1,27 +1,81 @@<?xml version="1.0" encoding="utf-8"?>--<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"- xmlns:tools="http://schemas.android.com/tools"+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"- android:orientation="vertical"android:id="@+id/widget_container">++ <!-- Main Image (if available) --><ImageView- android:id="@+id/widget_placeholder"+ android:id="@+id/widget_img"android:layout_width="match_parent"android:layout_height="match_parent"- android:scaleType="fitCenter"- android:adjustViewBounds="true"- android:visibility="visible"- tools:visibility="visible"- />- <ImageView- android:id="@+id/widget_img"+ android:scaleType="centerCrop"+ android:visibility="gone" /> <!-- Initially hidden -->++ <!-- Gradient Overlay for Text Readability -->+ <LinearLayout+ android:id="@+id/widget_overlay"+ android:layout_width="match_parent"+ android:layout_height="wrap_content"+ android:layout_gravity="bottom"+ android:orientation="vertical"+ android:paddingStart="16dp"+ android:paddingEnd="16dp"+ android:paddingBottom="16dp"+ android:paddingTop="4dp"+ android:background="@layout/gradient_overlay"+ android:visibility="gone"> <!-- Initially hidden, shown when image is available -->++ <!-- Title -->+ <TextView+ android:id="@+id/widget_title"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="Where is the title?"+ android:textColor="@android:color/white"+ android:textSize="14sp"+ android:textStyle="bold"+ android:maxLines="1"+ android:ellipsize="end"+ android:visibility="gone"/>++ <!-- Subtitle -->+ <TextView+ android:id="@+id/widget_subtitle"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="Where is the subtitle?"+ android:textColor="@android:color/white"+ android:textSize="12sp"+ android:maxLines="1"+ android:ellipsize="end"+ android:visibility="gone"/>+ </LinearLayout>++ <!-- Placeholder View (when no image available) -->+ <LinearLayout+ android:id="@+id/widget_placeholder_container"android:layout_width="match_parent"android:layout_height="match_parent"- android:scaleType="fitCenter"- android:adjustViewBounds="true"- android:visibility="visible"- tools:visibility="visible"- />-</LinearLayout>\ No newline at end of file+ android:gravity="center"+ android:orientation="vertical"+ android:background="@color/widget_placeholder_bg">++ <ImageView+ android:id="@+id/widget_placeholder"+ android:layout_width="120dp"+ android:layout_height="120dp"+ android:src="@drawable/ic_home_widget_default"+ android:scaleType="fitCenter" />++ <TextView+ android:id="@+id/widget_placeholder_text"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="Your memories will appear here"+ android:textSize="14sp"+ android:textColor="@color/widget_text_color"+ android:layout_marginTop="12dp"/>+ </LinearLayout>++</FrameLayout>diff --git a/mobile/android/app/src/main/res/values-night/colors.xml b/mobile/android/app/src/main/res/values-night/colors.xmlnew file mode 100644index 0000000000..bbc601c13f--- /dev/null+++ b/mobile/android/app/src/main/res/values-night/colors.xml@@ -0,0 +1,4 @@+<resources>+ <color name="widget_placeholder_bg">#222222</color> <!-- Dark Mode -->+ <color name="widget_text_color">#EEEEEE</color>+</resources>diff --git a/mobile/android/app/src/main/res/values/colors.xml b/mobile/android/app/src/main/res/values/colors.xmlindex 527c0aab77..4427af4396 100644--- a/mobile/android/app/src/main/res/values/colors.xml+++ b/mobile/android/app/src/main/res/values/colors.xml@@ -4,4 +4,6 @@<color name="ic_launcher_background">#08C225</color><color name="ic_launcher_background_light">#ffffff</color><color name="ic_launcher_background_dark">#000000</color>+ <color name="widget_placeholder_bg">#FFFFFF</color> <!-- Default (Light Mode) -->+ <color name="widget_text_color">#222222</color></resources>\ No newline at end of filediff --git a/mobile/android/settings.gradle b/mobile/android/settings.gradleindex b9e43bd376..ff95b6f80e 100644--- a/mobile/android/settings.gradle+++ b/mobile/android/settings.gradle@@ -19,7 +19,7 @@ pluginManagement {plugins {id "dev.flutter.flutter-plugin-loader" version "1.0.0"id "com.android.application" version "8.1.0" apply false- id "org.jetbrains.kotlin.android" version "1.8.22" apply false+ id "org.jetbrains.kotlin.android" version "2.1.10" apply false}include ":app"diff --git a/mobile/ios/SlideshowWidget/SlideshowWidget.swift b/mobile/ios/SlideshowWidget/SlideshowWidget.swiftindex 48d74a77d7..0f9ce959fe 100644--- a/mobile/ios/SlideshowWidget/SlideshowWidget.swift+++ b/mobile/ios/SlideshowWidget/SlideshowWidget.swift@@ -42,8 +42,8 @@ struct Provider: TimelineProvider {data?.integer(forKey: "totalSet")if totalSet != nil && totalSet! > 0 {- totalSet = totalSet! > 5 ? 5 : totalSet!- for offset in 0..<totalSet! {+ let count = totalSet! > 5 ? 5 : totalSet+ for offset in 0..<count! {let randomInt = Int.random(in: 0..<totalSet!)let entryDate = Calendar.current.date(byAdding: .minute, value: X * offset, to: currentDate@@ -110,6 +110,7 @@ struct SlideshowWidgetEntryView: View {startPoint: .bottom,endPoint: .top)+.frame(height: geometry.size.height * 0.4).frame(maxHeight: .infinity, alignment: .bottom).backwardWidgetAccentable(true)@@ -125,7 +126,7 @@ struct SlideshowWidgetEntryView: View {Text(entry.subTitle ?? "Where is the sub title").font(.custom("Inter", size: 12, relativeTo: .caption2)).foregroundStyle(.white)- .shadow(radius: 2)+ .shadow(radius: 20)}.padding(.leading, geometry.size.width * 0.05).padding(.bottom, geometry.size.height * 0.05),diff --git a/mobile/lib/services/home_widget_service.dart b/mobile/lib/services/home_widget_service.dartindex 2693706d26..d6f33bc0e6 100644--- a/mobile/lib/services/home_widget_service.dart+++ b/mobile/lib/services/home_widget_service.dart@@ -1,3 +1,6 @@+import "dart:convert";+import "dart:io";+import "package:crypto/crypto.dart";import "package:figma_squircle/figma_squircle.dart";import "package:flutter/material.dart";@@ -102,12 +105,16 @@ class HomeWidgetService {) async {try {final thumbnail = await getThumbnail(ogFile);- const double minSize = 512;++ final decoded = await decodeImageFromList(thumbnail!);+ final double width = decoded.width.toDouble();+ final double height = decoded.height.toDouble();+final Image img = Image.memory(- thumbnail!,+ thumbnail,fit: BoxFit.cover,- cacheWidth: minSize.toInt(),- cacheHeight: minSize.toInt(),+ cacheWidth: width.toInt(),+ cacheHeight: height.toInt(),);await PreloadImage.loadImage(img.image);@@ -118,8 +125,8 @@ class HomeWidgetService {final widget = ClipSmoothRect(radius: SmoothBorderRadius(cornerRadius: 32, cornerSmoothing: 1),child: Container(- width: minSize,- height: minSize,+ width: width,+ height: height,decoration: BoxDecoration(color: platformBrightness == Brightness.light? const Color.fromRGBO(251, 251, 251, 1)@@ -130,19 +137,28 @@ class HomeWidgetService {);await hw.HomeWidget.renderFlutterWidget(widget,- logicalSize: const Size(minSize, minSize),+ logicalSize: Size(width, height),key: key,);- await hw.HomeWidget.saveWidgetData<Map<String, dynamic>>(- key + "_data",- {- "title": title,- "subText": SmartMemoriesService.getDateFormatted(- creationTime: ogFile.creationTime!,- ),- "generatedId": ogFile.generatedID!,- },- );++ final data = {+ "title": title,+ "subText": SmartMemoriesService.getDateFormatted(+ creationTime: ogFile.creationTime!,+ ),+ "generatedId": ogFile.generatedID!,+ };+ if (Platform.isIOS) {+ await hw.HomeWidget.saveWidgetData<Map<String, dynamic>>(+ key + "_data",+ data,+ );+ } else {+ await hw.HomeWidget.saveWidgetData<String>(+ key + "_data",+ jsonEncode(data),+ );+ }} catch (_, __) {_logger.severe("Failed to save the capture", _, __);return false;@@ -244,7 +260,7 @@ class HomeWidgetService {final keyHash = _getFilesKey(files);final value = await _getFilesHash();- if (value == keyHash) {+ if (value != keyHash) {_logger.info("No changes detected in memories");await _updateWidget();_logger.info(">>> Refreshing memory from same set");