Skip to content

Commit d2498df

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents b7acaeb + dd9a373 commit d2498df

File tree

15 files changed

+109
-113
lines changed

15 files changed

+109
-113
lines changed

app/src/main/java/com/phlox/tvwebbrowser/Config.kt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.phlox.tvwebbrowser
22

33
import android.annotation.SuppressLint
44
import android.content.SharedPreferences
5+
import android.os.Build
56
import com.phlox.tvwebbrowser.utils.Utils
67
import com.phlox.tvwebbrowser.utils.observable.ObservableValue
78
import org.mozilla.geckoview.GeckoRuntimeSettings
@@ -34,15 +35,30 @@ class Config(val prefs: SharedPreferences) {
3435
const val NOTIFICATION_ABOUT_ENGINE_CHANGE_SHOWN_KEY = "notification_about_engine_change_shown"
3536
const val APP_VERSION_CODE_MARK_KEY = "app_version_code_mark"
3637

38+
const val ENGINE_GECKO_VIEW = "GeckoView"
39+
const val ENGINE_WEB_VIEW = "WebView"
40+
3741
const val DEFAULT_ADBLOCK_LIST_URL = "https://easylist.to/easylist/easylist.txt"
3842
val SearchEnginesTitles = arrayOf("Google", "Bing", "Yahoo!", "DuckDuckGo", "Yandex", "Startpage", "Custom")
3943
val SearchEnginesNames = arrayOf("google", "bing", "yahoo", "ddg", "yandex", "startpage", "custom")
4044
val SearchEnginesURLs = listOf("https://www.google.com/search?q=[query]", "https://www.bing.com/search?q=[query]",
4145
"https://search.yahoo.com/search?p=[query]", "https://duckduckgo.com/?q=[query]",
4246
"https://yandex.com/search/?text=[query]", "https://www.startpage.com/sp/search?query=[query]", "")
43-
val SupportedWebEngines = arrayOf("GeckoView", "WebView")
47+
val SupportedWebEngines = arrayOf(ENGINE_GECKO_VIEW, ENGINE_WEB_VIEW)
4448
const val HOME_PAGE_URL = "https://tvbro.phlox.dev/appcontent/home/"
4549
//const val HOME_PAGE_URL = "http://10.0.2.2:5000/appcontent/home/"
50+
51+
fun canRecommendGeckoView(): Boolean {
52+
var recommendedGeckoView = false
53+
val deviceRAM = Utils.memInfo(TVBro.instance).totalMem
54+
val cpuHas64Bit = Build.SUPPORTED_64_BIT_ABIS.isNotEmpty()
55+
val cpuCores = Runtime.getRuntime().availableProcessors()
56+
val threeGB = 3000000000L//~3GB minus protected memory
57+
if (deviceRAM >= threeGB && cpuHas64Bit && cpuCores >= 6) {
58+
recommendedGeckoView = true
59+
}
60+
return recommendedGeckoView
61+
}
4662
}
4763

4864
enum class Theme {
@@ -125,7 +141,14 @@ class Config(val prefs: SharedPreferences) {
125141
var searchEngineURL = ObservableStringPreference(SearchEnginesURLs[0], SEARCH_ENGINE_URL_PREF_KEY)
126142

127143
var webEngine: String
128-
get() = prefs.getString(WEB_ENGINE, SupportedWebEngines[0])!!
144+
get() {
145+
if (!prefs.contains(WEB_ENGINE)) {
146+
prefs.edit().putString(WEB_ENGINE, if (canRecommendGeckoView())
147+
SupportedWebEngines[0] else SupportedWebEngines[1]).apply()
148+
}
149+
150+
return prefs.getString(WEB_ENGINE, SupportedWebEngines[0])!!
151+
}
129152
set(value) {
130153
prefs.edit().putString(WEB_ENGINE, value).apply()
131154
}

app/src/main/java/com/phlox/tvwebbrowser/activity/main/MainActivity.kt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ open class MainActivity : AppCompatActivity(), ActionBar.Callback {
418418
}
419419

420420
private fun loadState() = lifecycleScope.launch(Dispatchers.Main) {
421-
showWebViewSunsetDialogIfNeeded()
422421
WebEngineFactory.initialize(this@MainActivity, vb.flWebViewContainer)
423422

424423
vb.progressBarGeneric.visibility = View.VISIBLE
@@ -473,31 +472,6 @@ open class MainActivity : AppCompatActivity(), ActionBar.Callback {
473472
}
474473
}
475474

476-
private suspend fun showWebViewSunsetDialogIfNeeded() {
477-
suspendCoroutine{ coroutine ->
478-
if ((config.isWebEngineNotSet() || !config.isWebEngineGecko()) &&
479-
(config.notificationAboutEngineChangeShown == 0 || config.notificationAboutEngineChangeShown != BuildConfig.VERSION_CODE)) {
480-
AlertDialog.Builder(this@MainActivity)
481-
.setTitle(R.string.webview_sunset_dialog_title)
482-
.setMessage(R.string.webview_sunset_dialog_message)
483-
.setPositiveButton(R.string.webview_sunset_dialog_positive_button) { _, _ ->
484-
config.webEngine = Config.SupportedWebEngines[0]
485-
}
486-
.setNegativeButton(R.string.webview_sunset_dialog_negative_button) { _, _ ->
487-
config.webEngine = Config.SupportedWebEngines[1]
488-
}
489-
.setCancelable(false)
490-
.setOnDismissListener {
491-
config.notificationAboutEngineChangeShown = BuildConfig.VERSION_CODE
492-
coroutine.resume(Unit)
493-
}
494-
.show().getButton(DialogInterface.BUTTON_POSITIVE).requestFocus()
495-
} else {
496-
coroutine.resume(Unit)
497-
}
498-
}
499-
}
500-
501475
private fun openInNewTab(url: String?, index: Int = 0, needToHideMenuOverlay: Boolean = true, navigateImmediately: Boolean): WebEngine? {
502476
if (url == null) {
503477
return null

app/src/main/java/com/phlox/tvwebbrowser/activity/main/dialogs/settings/MainSettingsView.kt

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,54 @@ class MainSettingsView @JvmOverloads constructor(
6767
vb.spWebEngine.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
6868
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
6969
if (config.webEngine == Config.SupportedWebEngines[position]) return
70-
config.webEngine = Config.SupportedWebEngines[position]
71-
AlertDialog.Builder(context)
72-
.setTitle(R.string.need_restart)
73-
.setMessage(R.string.need_restart_message)
74-
.setPositiveButton(R.string.exit) { _, _ ->
75-
TVBro.instance.needToExitProcessAfterMainActivityFinish = true
76-
TVBro.instance.needRestartMainActivityAfterExitingProcess = true
77-
activity!!.finish()
70+
if (Config.SupportedWebEngines[position] == Config.ENGINE_GECKO_VIEW && !Config.canRecommendGeckoView()) {
71+
AlertDialog.Builder(context)
72+
.setTitle(R.string.warning)
73+
.setMessage(R.string.settings_engine_change_gecko_msg)
74+
.setPositiveButton(R.string.ok) { _, _ ->
75+
config.webEngine = Config.SupportedWebEngines[position]
76+
showRestartDialog()
77+
}
78+
.setNegativeButton(R.string.cancel) { _, _ ->
79+
vb.spWebEngine.setSelection(Config.SupportedWebEngines.indexOf(config.webEngine), false)
80+
}
81+
.show()
82+
return
83+
} else if (Config.SupportedWebEngines[position] == Config.ENGINE_WEB_VIEW) {
84+
AlertDialog.Builder(context)
85+
.setTitle(R.string.warning)
86+
.setMessage(R.string.settings_engine_change_webview_msg)
87+
.setPositiveButton(R.string.ok) { _, _ ->
88+
config.webEngine = Config.SupportedWebEngines[position]
89+
showRestartDialog()
90+
}
91+
.setNegativeButton(R.string.cancel) { _, _ ->
92+
vb.spWebEngine.setSelection(Config.SupportedWebEngines.indexOf(config.webEngine), false)
7893
}
79-
.setCancelable(false)
8094
.show()
95+
return
96+
}
97+
config.webEngine = Config.SupportedWebEngines[position]
98+
showRestartDialog()
8199
}
82100

83101
override fun onNothingSelected(parent: AdapterView<*>) {}
84102
}
85103
}
86104

105+
private fun showRestartDialog() {
106+
AlertDialog.Builder(context)
107+
.setTitle(R.string.need_restart)
108+
.setMessage(R.string.need_restart_message)
109+
.setPositiveButton(R.string.exit) { _, _ ->
110+
TVBro.instance.needToExitProcessAfterMainActivityFinish = true
111+
TVBro.instance.needRestartMainActivityAfterExitingProcess = true
112+
activity!!.finish()
113+
}
114+
.setCancelable(false)
115+
.show()
116+
}
117+
87118
private fun initThemeSettingsUI() {
88119
val webViewSupportsDarkening = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
89120
WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)

app/src/main/java/com/phlox/tvwebbrowser/utils/Utils.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,11 @@ object Utils {
278278
return (appProcessInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND
279279
|| appProcessInfo.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE)
280280
}
281+
282+
fun memInfo(ctx: Context): ActivityManager.MemoryInfo {
283+
val actManager = ctx.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
284+
val memInfo = ActivityManager.MemoryInfo()
285+
actManager.getMemoryInfo(memInfo)
286+
return memInfo
287+
}
281288
}

app/src/main/res/values-de/strings.xml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version='1.0' encoding='utf-8'?>
22
<resources>
33
<string name="app_name">TV Bro: Webbrowser für TVs</string>
44
<string name="error">Fehler</string>
@@ -188,12 +188,8 @@
188188
<string name="no">NEIN</string>
189189
<string name="site_asks_to_open_unknown_url">Die Website fordert zum Öffnen einer unbekannten URL auf</string>
190190
<string name="site_asks_to_open_unknown_url_message">Möchten Sie diese URL in einer externen App öffnen?</string>
191-
<string name="webview_sunset_dialog_title">TV Bro wechselt die Engine.</string>
192-
<string name="webview_sunset_dialog_message">Hallo! TV Bro wechselt die Engine. Seit jeher verwendet TV Bro die Systemkomponente WebView, um Webinhalte anzuzeigen. Dies führte jedoch immer wieder zu diversen Problemen, da das WebView selbstständig aktualisiert wird und oft eigene Fehler aufweist. Jetzt ändert TV Bro die Engine auf GeckoView, das eingebaut werden kann, damit es solche Probleme nicht mehr gibt. Leider ist das interne Datenformat dieser Engines nicht kompatibel, sodass die Daten offener Sessions bei der Umstellung verloren gehen. Daher wird TV Bro noch einige Zeit beide Engines unterstützen (man kann in den Einstellungen umschalten).
193-
194-
Sind Sie also bereit, die GeckoView-Version zu verwenden, oder möchten Sie vorerst auf der WebView bleiben?</string>
195-
<string name="webview_sunset_dialog_positive_button">Ja, beginnen wir mit der Verwendung einer neuen Engine</string>
196-
<string name="webview_sunset_dialog_negative_button">Nein, verwende vorerst die alte</string>
197191
<string name="err_no_app_to_handle_url">Kann keine geeignete Anwendung finden, um diese URL zu verarbeiten</string>
198192
<string name="home_page_links">Links auf der Homepage</string>
199-
</resources>
193+
<string name="settings_engine_change_gecko_msg">Von GeckoView empfohlene Systemanforderungen: 3 GB RAM, 64-Bit-Octa-Core-CPU. Möchtest du fortfahren\?</string>
194+
<string name="settings_engine_change_webview_msg">WebView wird in zukünftigen Updates weniger Funktionen haben. Möchtest du fortfahren\?</string>
195+
</resources>

app/src/main/res/values-fa/strings.xml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version='1.0' encoding='utf-8'?>
22
<resources>
33
<string name="app_name">"TV Bro: مرورگر وب تلویزیون"</string>
44
<string name="error">"خطا"</string>
@@ -192,12 +192,8 @@
192192
<string name="no">خیر</string>
193193
<string name="site_asks_to_open_unknown_url">سایت می خواهد URL ناشناخته را باز کند</string>
194194
<string name="site_asks_to_open_unknown_url_message">آیا می خواهید این URL را در برنامه خارجی باز کنید؟</string>
195-
<string name="webview_sunset_dialog_title">تی وی برادر موتور را عوض می کند.</string>
196-
<string name="webview_sunset_dialog_message">سلام! تی وی برادر موتور را عوض می کند. در تمام این مدت، TV Bro از مؤلفه سیستم WebView برای نمایش محتوای وب استفاده کرده است. اما این به دلیل اینکه WebView به طور مستقل به روز می شود و اغلب دارای اشکالات خاص خود است، همیشه به مشکلات مختلفی منجر می شود. اکنون TV Bro موتور را به GeckoView تغییر می دهد که می تواند در آن تعبیه شود بنابراین چنین مشکلاتی وجود نخواهد داشت. متأسفانه، فرمت داده های داخلی این موتورها سازگار نیست، بنابراین داده های جلسات باز در طول انتقال از بین می روند. بنابراین، برای مدتی TV Bro همچنان از هر دو موتور پشتیبانی می کند (می توانید در تنظیمات تغییر دهید).
197-
198-
بنابراین آیا آماده استفاده از نسخه GeckoView هستید یا می خواهید در حال حاضر در WebView بمانید؟</string>
199-
<string name="webview_sunset_dialog_positive_button">بله، بیایید استفاده از موتور جدید را شروع کنیم</string>
200-
<string name="webview_sunset_dialog_negative_button">نه، فعلا از قدیمی استفاده کنید</string>
201195
<string name="err_no_app_to_handle_url">نمی توان برنامه مناسبی برای مدیریت این URL پیدا کرد</string>
202196
<string name="home_page_links">لینک ها در صفحه اصلی</string>
203-
</resources>
197+
<string name="settings_engine_change_gecko_msg">سیستم مورد نیاز توصیه شده GeckoView: 3 گیگابایت رم، CPU هشت هسته ای 64 بیتی. می خواهید ادامه دهید؟</string>
198+
<string name="settings_engine_change_webview_msg">WebView در به روز رسانی های بعدی ویژگی های کمتری خواهد داشت. می خواهید ادامه دهید؟</string>
199+
</resources>

app/src/main/res/values-it/strings.xml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version='1.0' encoding='utf-8'?>
22
<resources>
33
<string name="app_name">TV Bro: TV Web Browser</string>
44
<string name="error">Errore</string>
@@ -188,12 +188,8 @@
188188
<string name="no">NO</string>
189189
<string name="site_asks_to_open_unknown_url">Il sito chiede di aprire un URL sconosciuto</string>
190190
<string name="site_asks_to_open_unknown_url_message">Vuoi aprire questo URL in un&amp;#39;app esterna?</string>
191-
<string name="webview_sunset_dialog_title">TV Bro cambia motore.</string>
192-
<string name="webview_sunset_dialog_message">Ciao! TV Bro cambia motore. Per tutto questo tempo, TV Bro ha utilizzato il componente di sistema WebView per visualizzare i contenuti web. Ma questo ha sempre portato a vari problemi dovuti al fatto che WebView viene aggiornato in modo indipendente e spesso presenta i propri bug. Ora TV Bro sta cambiando il motore in GeckoView, che può essere integrato, quindi non ci saranno problemi di questo tipo. Sfortunatamente, il formato dei dati interni di questi motori non è compatibile, quindi i dati delle sessioni aperte andranno persi durante la transizione. Pertanto, per qualche tempo TV Bro supporterà ancora entrambi i motori (puoi cambiare le impostazioni).
193-
194-
Quindi sei pronto per utilizzare la versione GeckoView o vuoi rimanere su WebView per ora?</string>
195-
<string name="webview_sunset_dialog_positive_button">Sì, iniziamo a utilizzare il nuovo motore</string>
196-
<string name="webview_sunset_dialog_negative_button">No, usa quello vecchio per ora</string>
197191
<string name="err_no_app_to_handle_url">Impossibile trovare un&amp;#39;applicazione adatta per gestire questo URL</string>
198192
<string name="home_page_links">Link in home page</string>
199-
</resources>
193+
<string name="settings_engine_change_gecko_msg">Requisiti di sistema consigliati da GeckoView: 3 GB di RAM, CPU octa-core a 64 bit. Vuoi continuare\?</string>
194+
<string name="settings_engine_change_webview_msg">WebView avrà meno funzionalità negli aggiornamenti futuri. Vuoi continuare\?</string>
195+
</resources>

app/src/main/res/values-iw/strings.xml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version='1.0' encoding='utf-8'?>
22
<resources>
33
<string name="app_name">"TV Bro: דפדפן לטלויזיה"</string>
44
<string name="error">"שגיאה"</string>
5-
<!-- Fuzzy -->
65
<string name="ok">"OK"</string>
76
<string name="loading">"טוען..."</string>
87
<string name="url_prompt">"הכנס טקסט לחיפוש או URL"</string>
@@ -192,12 +191,8 @@
192191
<string name="no">לא</string>
193192
<string name="site_asks_to_open_unknown_url">האתר מבקש לפתוח כתובת URL לא ידועה</string>
194193
<string name="site_asks_to_open_unknown_url_message">האם ברצונך לפתוח את כתובת האתר הזו באפליקציה חיצונית?</string>
195-
<string name="webview_sunset_dialog_title">TV Bro מחליף מנוע.</string>
196-
<string name="webview_sunset_dialog_message">שלום! TV Bro מחליף מנוע. כל הזמן הזה, TV Bro השתמש ברכיב מערכת WebView כדי להציג תוכן אינטרנט. אבל זה כל הזמן הוביל לבעיות שונות בגלל העובדה שה-WebView מתעדכן באופן עצמאי ולעתים קרובות יש לו באגים משלו. כעת TV Bro משנה את המנוע ל- GeckoView שניתן לבנות כך שלא יהיו בעיות כאלה. למרבה הצער, פורמט הנתונים הפנימי של המנועים הללו אינו תואם, כך שהנתונים של הפעלות פתוחות יאבדו במהלך המעבר. לכן, במשך זמן מה TV Bro עדיין יתמוך בשני המנועים (תוכל לעבור בהגדרות).
197-
198-
אז האם אתה מוכן להשתמש בגרסת GeckoView או רוצה להישאר ב-WebView לעת עתה?</string>
199-
<string name="webview_sunset_dialog_positive_button">כן, בואו נתחיל להשתמש במנוע חדש</string>
200-
<string name="webview_sunset_dialog_negative_button">לא, השתמש בישן לעת עתה</string>
201194
<string name="err_no_app_to_handle_url">לא ניתן למצוא אפליקציה מתאימה לטיפול בכתובת האתר הזו</string>
202195
<string name="home_page_links">קישורים בעמוד הבית</string>
203-
</resources>
196+
<string name="settings_engine_change_gecko_msg">דרישות מערכת מומלצות של GeckoView: 3GB RAM, מעבד מתומן ליבות של 64 סיביות. האם אתה רוצה להמשיך\?</string>
197+
<string name="settings_engine_change_webview_msg">ל-WebView יהיו פחות תכונות בעדכונים עתידיים. האם אתה רוצה להמשיך\?</string>
198+
</resources>

0 commit comments

Comments
 (0)