mirror of
https://github.com/RoboSats/robosats.git
synced 2025-09-13 00:56:22 +00:00
Fix
This commit is contained in:
@ -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,6 +383,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val notifications = EncryptedStorage.getEncryptedStorage("settings_notifications")
|
||||
if (notifications != "false") initializeNotifications()
|
||||
|
||||
if (intentData != "") {
|
||||
webView.post {
|
||||
try {
|
||||
webView.evaluateJavascript("javascript:window.AndroidDataRobosats = { navigateToPage: '$intentData' }", null)
|
||||
@ -384,6 +392,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("WebViewSetup", "Security error in WebView setup: ${e.message}", 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
|
||||
*/
|
||||
|
||||
@ -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") {
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user