From 6e5107b2d0a3a19fb34f2683f3f82aa1b1fcd7e5 Mon Sep 17 00:00:00 2001 From: koalasat Date: Mon, 28 Jul 2025 11:11:12 +0200 Subject: [PATCH] Fix --- .../main/java/com/robosats/MainActivity.kt | 35 +++++++++++++++---- .../main/java/com/robosats/WebAppInterface.kt | 7 +++- .../com/robosats/models/LanguageManager.kt | 3 -- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/android/app/src/main/java/com/robosats/MainActivity.kt b/android/app/src/main/java/com/robosats/MainActivity.kt index 5747899e..c6a0ff8d 100644 --- a/android/app/src/main/java/com/robosats/MainActivity.kt +++ b/android/app/src/main/java/com/robosats/MainActivity.kt @@ -34,7 +34,10 @@ import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import com.robosats.models.EncryptedStorage import com.robosats.models.LanguageManager +import com.robosats.models.LanguageManager.LANGUAGE_KEY +import com.robosats.models.LanguageManager.applyLanguage import com.robosats.services.NotificationsService +import java.util.Locale import com.robosats.tor.TorKmp import com.robosats.tor.TorKmpManager import com.robosats.tor.TorKmpManager.getTorKmpObject @@ -58,6 +61,8 @@ class MainActivity : AppCompatActivity() { // Initialize language manager and apply saved language setting LanguageManager.init(this) + val languageCode = EncryptedStorage.getEncryptedStorage(LANGUAGE_KEY) + changeAppLanguage(languageCode) // Lock the screen orientation to portrait mode requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT @@ -93,6 +98,7 @@ class MainActivity : AppCompatActivity() { } val intent = intent + intentData = "" if (intent != null) { val orderId = intent.getStringExtra("order_id") if (orderId?.isNotEmpty() == true) { @@ -100,13 +106,14 @@ class MainActivity : AppCompatActivity() { } } - // Initialize Tor and setup WebView only after Tor is properly connected - initializeTor() val settingProxy = EncryptedStorage.getEncryptedStorage("settings_use_proxy") if (settingProxy == "false") { // Setup WebView to use Orbot if the user previously clicked onUseOrbotButtonClicked() + } else { + // Initialize Tor and setup WebView only after Tor is properly connected + initializeTor() } } @@ -376,11 +383,13 @@ class MainActivity : AppCompatActivity() { val notifications = EncryptedStorage.getEncryptedStorage("settings_notifications") if (notifications != "false") initializeNotifications() - webView.post { - try { - webView.evaluateJavascript("javascript:window.AndroidDataRobosats = { navigateToPage: '$intentData' }", null) - } catch (e: Exception) { - Log.e("NavigateToPage", "Error evaluating JavaScript: $e") + if (intentData != "") { + webView.post { + try { + webView.evaluateJavascript("javascript:window.AndroidDataRobosats = { navigateToPage: '$intentData' }", null) + } catch (e: Exception) { + Log.e("NavigateToPage", "Error evaluating JavaScript: $e") + } } } } @@ -465,6 +474,18 @@ class MainActivity : AppCompatActivity() { webSettings.textZoom = 100 } + /** + * Change the app's language and recreate the activity + * @param languageCode The language code to switch to (e.g., "en", "es", "fr") + */ + fun changeAppLanguage(languageCode: String) { + // Apply the language change + if (LanguageManager.applyLanguage(languageCode)) { + // Restart the activity to apply changes + recreate() + } + } + /** * Clear all WebView data when activity is destroyed */ diff --git a/android/app/src/main/java/com/robosats/WebAppInterface.kt b/android/app/src/main/java/com/robosats/WebAppInterface.kt index 47976981..31a08573 100644 --- a/android/app/src/main/java/com/robosats/WebAppInterface.kt +++ b/android/app/src/main/java/com/robosats/WebAppInterface.kt @@ -368,7 +368,12 @@ class WebAppInterface(private val context: MainActivity, private val webView: We EncryptedStorage.setEncryptedStorage(sanitizedKey, sanitizedValue) if (key == "garage_slots") NostrClient.refresh() - if (key == "settings_language") LanguageManager.applyLanguage(value) + if (key == "settings_language") { + context.changeAppLanguage(value) + // Return immediately as recreate() will be called + resolvePromise(uuid, key) + return + } if (key == "settings_notifications") { val serviceIntent = Intent(context, NotificationsService::class.java) if (value == "true") { diff --git a/android/app/src/main/java/com/robosats/models/LanguageManager.kt b/android/app/src/main/java/com/robosats/models/LanguageManager.kt index 1d9e10bd..47225253 100644 --- a/android/app/src/main/java/com/robosats/models/LanguageManager.kt +++ b/android/app/src/main/java/com/robosats/models/LanguageManager.kt @@ -13,9 +13,6 @@ object LanguageManager { val LANGUAGE_KEY = "settings_language" fun init(context: MainActivity) { - val value = EncryptedStorage.getEncryptedStorage(LANGUAGE_KEY) - applyLanguage(value) - resources = context.resources }