Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix wallpaper orientation, dismissal, and localization

Neeraj Gupta1f89bb5125f6
diff --git a/.github/workflows/mobile-crowdin-push-sources.yml b/.github/workflows/mobile-crowdin-push-sources.yml
index c5dbd703f8..c066e09b22 100644
--- a/.github/workflows/mobile-crowdin-push-sources.yml
+++ b/.github/workflows/mobile-crowdin-push-sources.yml
@@ -5,6 +5,7 @@ on:
branches: [main]
paths:
- ".github/workflows/mobile-crowdin-push-sources.yml"
+ - "mobile/packages/strings/android/values/*.xml"
- "mobile/packages/strings/crowdin.yml"
- "mobile/packages/strings/lib/l10n/arb/strings_en.arb"
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/build.gradle b/mobile/apps/photos/plugins/ente_photos_platform/android/build.gradle
index 00bd3fba24..3dff0a1317 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/android/build.gradle
+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/build.gradle
@@ -39,6 +39,7 @@ android {
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
+ main.res.srcDir '../../../../../packages/strings/android'
main.assets.srcDir layout.buildDirectory.dir('generated/wallpaperAssets')
}
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/AndroidManifest.xml b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/AndroidManifest.xml
index d039972950..dbed2c7d4a 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/AndroidManifest.xml
+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/AndroidManifest.xml
@@ -1,9 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.SET_WALLPAPER" />
- <application>
+ <application android:supportsRtl="true">
<activity
- android:name="io.ente.photos.platform.wallpaper.WallpaperActivity"
+ android:name="io.ente.photos.platform.flutter.WallpaperActivity"
android:exported="true"
+ android:enableOnBackInvokedCallback="true"
android:label="@string/wallpaper"
android:theme="@style/WallpaperTheme">
<intent-filter>
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/WallpaperActivity.kt b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/WallpaperActivity.kt
new file mode 100644
index 0000000000..0fc5e0009d
--- /dev/null
+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/flutter/WallpaperActivity.kt
@@ -0,0 +1,19 @@
+package io.ente.photos.platform.flutter
+
+import android.content.Context
+import android.content.res.Configuration
+import java.util.Locale
+
+class WallpaperActivity : io.ente.photos.platform.wallpaper.WallpaperActivity() {
+ override fun attachBaseContext(base: Context) {
+ val language = base.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE)
+ .getString("flutter.locale", null)
+ val localized = if (language == null) base else {
+ val configuration = Configuration(base.resources.configuration).apply {
+ setLocale(Locale.forLanguageTag(language.replace('_', '-')))
+ }
+ base.createConfigurationContext(configuration)
+ }
+ super.attachBaseContext(localized)
+ }
+}
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/wallpaper/WallpaperActivity.kt b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/wallpaper/WallpaperActivity.kt
index 593bb83441..5105532957 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/wallpaper/WallpaperActivity.kt
+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/kotlin/io/ente/photos/platform/wallpaper/WallpaperActivity.kt
@@ -9,10 +9,13 @@ import android.graphics.Typeface
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.RippleDrawable
import android.net.Uri
+import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.Gravity
+import android.view.Surface
import android.view.View
+import android.window.OnBackInvokedDispatcher
import android.widget.Button
import android.widget.FrameLayout
import android.widget.ImageButton
@@ -25,10 +28,11 @@ import java.util.concurrent.CompletableFuture
import java.util.concurrent.Executors
@android.annotation.TargetApi(24)
-class WallpaperActivity : Activity() {
+open class WallpaperActivity : Activity() {
private val executor = Executors.newSingleThreadExecutor()
private lateinit var preview: WallpaperCropView
private lateinit var applyButton: Button
+ private lateinit var closeButton: ImageButton
private lateinit var progress: ProgressBar
private lateinit var service: WallpaperService
private lateinit var imageUri: Uri
@@ -57,6 +61,11 @@ class WallpaperActivity : Activity() {
val displaySize = Point()
@Suppress("DEPRECATION")
windowManager.defaultDisplay.getRealSize(displaySize)
+ @Suppress("DEPRECATION")
+ val rotation = windowManager.defaultDisplay.rotation
+ if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
+ displaySize.set(displaySize.y, displaySize.x)
+ }
preview = WallpaperCropView(this, displaySize)
preview.restoreCrop(savedInstanceState?.getFloatArray("crop"))
val content = LinearLayout(this).apply {
@@ -77,12 +86,13 @@ class WallpaperActivity : Activity() {
gravity = Gravity.CENTER_VERTICAL
setPadding(dp(8), dp(4), dp(20), dp(4))
}
- header.addView(ImageButton(this).apply {
+ closeButton = ImageButton(this).apply {
setImageResource(R.drawable.wallpaper_close)
contentDescription = getString(android.R.string.cancel)
background = RippleDrawable(ColorStateList.valueOf(0x29FFFFFF), null, null)
- setOnClickListener { finish() }
- }, LinearLayout.LayoutParams(dp(48), dp(48)))
+ setOnClickListener { close() }
+ }
+ header.addView(closeButton, LinearLayout.LayoutParams(dp(48), dp(48)))
header.addView(TextView(this).apply {
setText(R.string.wallpaper)
typeface = semibold
@@ -123,6 +133,9 @@ class WallpaperActivity : Activity() {
})
setBusy(true)
setContentView(content)
+ if (Build.VERSION.SDK_INT >= 33) {
+ onBackInvokedDispatcher.registerOnBackInvokedCallback(OnBackInvokedDispatcher.PRIORITY_DEFAULT) { close() }
+ }
retained?.let(::observeApply)
executor.execute {
try {
@@ -153,7 +166,6 @@ class WallpaperActivity : Activity() {
private fun applyWallpaper(destination: Destination) {
if (pendingApply != null) return
- setBusy(true)
val crop = preview.selection()
val task = CompletableFuture.supplyAsync({
val bitmap = service.render(imageUri, crop)
@@ -164,6 +176,7 @@ class WallpaperActivity : Activity() {
}
}, executor)
pendingApply = task
+ setBusy(true)
observeApply(task)
}
@@ -185,6 +198,8 @@ class WallpaperActivity : Activity() {
}
private fun setBusy(busy: Boolean) {
+ closeButton.isEnabled = pendingApply == null
+ closeButton.alpha = if (closeButton.isEnabled) 1f else 0.4f
applyButton.isEnabled = !busy
applyButton.alpha = if (busy) 0.4f else 1f
applyButton.setTextColor(if (busy) Color.TRANSPARENT else Color.WHITE)
@@ -194,6 +209,13 @@ class WallpaperActivity : Activity() {
private fun dp(value: Int) = (value * resources.displayMetrics.density).toInt()
+ private fun close() {
+ if (pendingApply == null) finish()
+ }
+
+ @Suppress("OVERRIDE_DEPRECATION")
+ override fun onBackPressed() = close()
+
private fun showFailure(error: Throwable) {
Log.e("Wallpaper", "Wallpaper operation failed", error)
Toast.makeText(this, R.string.wallpaper_failed, Toast.LENGTH_LONG).show()
diff --git a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/res/values/wallpaper.xml b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/res/values/wallpaper.xml
index 62d7557dc6..3f488fed7a 100644
--- a/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/res/values/wallpaper.xml
+++ b/mobile/apps/photos/plugins/ente_photos_platform/android/src/main/res/values/wallpaper.xml
@@ -1,12 +1,4 @@
<resources>
- <string name="wallpaper">Wallpaper</string>
- <string name="wallpaper_set">Set wallpaper</string>
- <string name="wallpaper_home">Home screen</string>
- <string name="wallpaper_lock">Lock screen</string>
- <string name="wallpaper_both">Home and lock screens</string>
- <string name="wallpaper_done">Wallpaper set</string>
- <string name="wallpaper_failed">Could not set wallpaper</string>
- <string name="wallpaper_unavailable">Wallpaper changes are not allowed on this device</string>
<style name="WallpaperTheme" parent="android:style/Theme.Material.NoActionBar">
<item name="android:colorAccent">#08C225</item>
<item name="android:windowBackground">#000000</item>
diff --git a/mobile/packages/strings/README.md b/mobile/packages/strings/README.md
index 9dabe78402..0644dc0170 100644
--- a/mobile/packages/strings/README.md
+++ b/mobile/packages/strings/README.md
@@ -2,6 +2,8 @@
This package contains the user-facing strings and translations shared by the Auth, Locker, and Photos apps. Flutter's localization generator turns the ARB files in `lib/l10n/arb` into the Dart files in `lib/l10n`.
+Native Android strings live in `android/values/`. Crowdin syncs their translations into `android/values-<locale>/`; Android modules include this resource directory directly.
+
## Translate
The strings can be translated in the [Ente Mobile Crowdin project](https://crowdin.com/project/ente-photos-app).
diff --git a/mobile/packages/strings/android/values/wallpaper.xml b/mobile/packages/strings/android/values/wallpaper.xml
new file mode 100644
index 0000000000..cec697968c
--- /dev/null
+++ b/mobile/packages/strings/android/values/wallpaper.xml
@@ -0,0 +1,10 @@
+<resources>
+ <string name="wallpaper">Wallpaper</string>
+ <string name="wallpaper_set">Set wallpaper</string>
+ <string name="wallpaper_home">Home screen</string>
+ <string name="wallpaper_lock">Lock screen</string>
+ <string name="wallpaper_both">Home and lock screens</string>
+ <string name="wallpaper_done">Wallpaper set</string>
+ <string name="wallpaper_failed">Could not set wallpaper</string>
+ <string name="wallpaper_unavailable">Wallpaper changes are not allowed on this device</string>
+</resources>
diff --git a/mobile/packages/strings/crowdin.yml b/mobile/packages/strings/crowdin.yml
index 1c8bf94cc6..38b81f333f 100644
--- a/mobile/packages/strings/crowdin.yml
+++ b/mobile/packages/strings/crowdin.yml
@@ -77,3 +77,6 @@ files:
ur-IN: ur
zh-CN: zh_CN
zh-TW: zh_TW
+ - source: /android/values/wallpaper.xml
+ translation: /android/values-%android_code%/wallpaper.xml
+ type: android