Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PinchToZoom option #2252

Merged
merged 5 commits into from Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -47,6 +47,7 @@ class SettingsPresenterImpl @Inject constructor(
return@runBlocking when (key) {
"fullscreen" -> integrationUseCase.isFullScreenEnabled()
"keep_screen_on" -> integrationUseCase.isKeepScreenOnEnabled()
"pinch_to_zoom" -> integrationUseCase.isPinchToZoomEnabled()
"app_lock" -> authenticationUseCase.isLockEnabled()
"crash_reporting" -> prefsRepository.isCrashReporting()
"prioritize_internal" -> urlUseCase.isPrioritizeInternal()
Expand All @@ -61,6 +62,7 @@ class SettingsPresenterImpl @Inject constructor(
when (key) {
"fullscreen" -> integrationUseCase.setFullScreenEnabled(value)
"keep_screen_on" -> integrationUseCase.setKeepScreenOnEnabled(value)
"pinch_to_zoom" -> integrationUseCase.setPinchToZoomEnabled(value)
"app_lock" -> authenticationUseCase.setLockEnabled(value)
"crash_reporting" -> prefsRepository.setCrashReporting(value)
"prioritize_internal" -> urlUseCase.setPrioritizeInternal(value)
Expand Down
Expand Up @@ -590,6 +590,15 @@ class WebViewActivity : BaseActivity(), io.homeassistant.companion.android.webvi
// This enables the ability to have the launch screen behind the WebView until the web frontend gets rendered
binding.webview.setBackgroundColor(Color.TRANSPARENT)

// Enable pinch to zoom
if (presenter.isPinchToZoomEnabled()) {
webView.getSettings().setBuiltInZoomControls(true)
webView.getSettings().setDisplayZoomControls(false)
} else {
webView.getSettings().setBuiltInZoomControls(false)
webView.getSettings().setDisplayZoomControls(false)
}

micronen marked this conversation as resolved.
Show resolved Hide resolved
themesManager.setThemeForWebView(this, webView.settings)

val cookieManager = CookieManager.getInstance()
Expand Down Expand Up @@ -657,6 +666,15 @@ class WebViewActivity : BaseActivity(), io.homeassistant.companion.android.webvi
binding.blurView.setBlurEnabled(false)
}

// Enable pinch to zoom
if (presenter.isPinchToZoomEnabled()) {
webView.getSettings().setBuiltInZoomControls(true)
webView.getSettings().setDisplayZoomControls(false)
micronen marked this conversation as resolved.
Show resolved Hide resolved
} else {
webView.getSettings().setBuiltInZoomControls(false)
webView.getSettings().setDisplayZoomControls(false)
}

if (presenter.isKeepScreenOnEnabled())
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
else
Expand Down
Expand Up @@ -16,6 +16,8 @@ interface WebViewPresenter {

fun isKeepScreenOnEnabled(): Boolean

fun isPinchToZoomEnabled(): Boolean

fun isLockEnabled(): Boolean
fun isAutoPlayVideoEnabled(): Boolean

Expand Down
Expand Up @@ -138,6 +138,12 @@ class WebViewPresenterImpl @Inject constructor(
}
}

override fun isPinchToZoomEnabled(): Boolean {
return runBlocking {
integrationUseCase.isPinchToZoomEnabled()
}
}

override fun isLockEnabled(): Boolean {
return runBlocking {
authenticationUseCase.isLockEnabled()
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/preferences.xml
Expand Up @@ -80,6 +80,11 @@
android:icon="@drawable/ic_phone_check"
android:title="@string/keep_screen_on"
android:summary="@string/keep_screen_on_def"/>
<SwitchPreference
android:key="pinch_to_zoom"
android:icon="@drawable/ic_phone_check"
micronen marked this conversation as resolved.
Show resolved Hide resolved
android:title="@string/pinch_to_zoom"
android:summary="@string/pinch_to_zoom_def"/>
<SwitchPreference
android:key="autoplay_video"
android:icon="@drawable/ic_baseline_video_settings_24"
Expand Down
Expand Up @@ -25,6 +25,9 @@ interface IntegrationRepository {
suspend fun setKeepScreenOnEnabled(enabled: Boolean)
suspend fun isKeepScreenOnEnabled(): Boolean

suspend fun setPinchToZoomEnabled(enabled: Boolean)
suspend fun isPinchToZoomEnabled(): Boolean

suspend fun setAutoPlayVideo(enabled: Boolean)
suspend fun isAutoPlayVideoEnabled(): Boolean

Expand Down
Expand Up @@ -71,6 +71,7 @@ class IntegrationRepositoryImpl @Inject constructor(
private const val PREF_AUTOPLAY_VIDEO = "autoplay_video"
private const val PREF_FULLSCREEN_ENABLED = "fullscreen_enabled"
private const val PREF_KEEP_SCREEN_ON_ENABLED = "keep_screen_on_enabled"
private const val PREF_PINCH_TO_ZOOM_ENABLED = "pinch_to_zoom_enabled"
private const val PREF_SESSION_TIMEOUT = "session_timeout"
private const val PREF_SESSION_EXPIRE = "session_expire"
private const val PREF_SEC_WARNING_NEXT = "sec_warning_last"
Expand Down Expand Up @@ -340,6 +341,14 @@ class IntegrationRepositoryImpl @Inject constructor(
return localStorage.getBoolean(PREF_KEEP_SCREEN_ON_ENABLED)
}

override suspend fun setPinchToZoomEnabled(enabled: Boolean) {
localStorage.putBoolean(PREF_PINCH_TO_ZOOM_ENABLED, enabled)
}

override suspend fun isPinchToZoomEnabled(): Boolean {
return localStorage.getBoolean(PREF_PINCH_TO_ZOOM_ENABLED)
}

override suspend fun isAutoPlayVideoEnabled(): Boolean {
return localStorage.getBoolean(PREF_AUTOPLAY_VIDEO)
}
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/res/values/strings.xml
Expand Up @@ -223,6 +223,8 @@
<string name="irreversible">This action is irreversible</string>
<string name="keep_screen_on_def">Do not lock screen when Lovelace dashboard is active</string>
<string name="keep_screen_on">Keep screen On</string>
<string name="pinch_to_zoom_def">Allow Pinch-to-zoom gesture to zoom app window</string>
<string name="pinch_to_zoom">Pinch To Zoom</string>
<string name="label_attribute">Attribute:</string>
<string name="label_dynamic_data">Data:</string>
<string name="label_entity_id">Entity ID:</string>
Expand Down