Feature/screen orientation (#3362)

* feature/landscape add setting for fix landscape orientation

* feature/landscape add setting for fix screen orientation

* feature/screen_orientation code review

* feature/screen_orientation code review
This commit is contained in:
dmiales 2023-02-24 22:31:53 +03:00 committed by GitHub
parent ebda0a23a5
commit 9a4d00f05d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 62 additions and 0 deletions

View file

@ -81,6 +81,7 @@ class SettingsPresenterImpl @Inject constructor(
when (key) {
"themes" -> themesManager.getCurrentTheme()
"languages" -> langsManager.getCurrentLang()
"screen_orientation" -> prefsRepository.getScreenOrientation()
else -> throw IllegalArgumentException("No string found by this key: $key")
}
}
@ -90,6 +91,7 @@ class SettingsPresenterImpl @Inject constructor(
when (key) {
"themes" -> themesManager.saveTheme(value)
"languages" -> langsManager.saveLang(value)
"screen_orientation" -> prefsRepository.saveScreenOrientation(value)
else -> throw IllegalArgumentException("No string found by this key: $key")
}
}

View file

@ -6,6 +6,7 @@ import android.app.PictureInPictureParams
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.graphics.Color
@ -762,6 +763,12 @@ class WebViewActivity : BaseActivity(), io.homeassistant.companion.android.webvi
WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG || presenter.isWebViewDebugEnabled())
requestedOrientation = when (presenter.getScreenOrientation()) {
getString(commonR.string.screen_orientation_option_value_portrait) -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
getString(commonR.string.screen_orientation_option_value_landscape) -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
else -> ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
}
if (presenter.isKeepScreenOnEnabled())
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
else

View file

@ -25,6 +25,8 @@ interface WebViewPresenter {
fun isFullScreen(): Boolean
fun getScreenOrientation(): String?
fun isKeepScreenOnEnabled(): Boolean
fun isPinchToZoomEnabled(): Boolean

View file

@ -212,6 +212,10 @@ class WebViewPresenterImpl @Inject constructor(
prefsRepository.isFullScreenEnabled()
}
override fun getScreenOrientation(): String? = runBlocking {
prefsRepository.getScreenOrientation()
}
override fun isKeepScreenOnEnabled(): Boolean = runBlocking {
prefsRepository.isKeepScreenOnEnabled()
}

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/colorAccent"
android:pathData="M7.5,21.5C4.25,19.94 1.91,16.76 1.55,13H0.05C0.56,19.16 5.71,24 12,24L12.66,23.97L8.85,20.16M14.83,21.19L2.81,9.17L9.17,2.81L21.19,14.83M10.23,1.75C9.64,1.16 8.69,1.16 8.11,1.75L1.75,8.11C1.16,8.7 1.16,9.65 1.75,10.23L13.77,22.25C14.36,22.84 15.31,22.84 15.89,22.25L22.25,15.89C22.84,15.3 22.84,14.35 22.25,13.77L10.23,1.75M16.5,2.5C19.75,4.07 22.09,7.24 22.45,11H23.95C23.44,4.84 18.29,0 12,0L11.34,0.03L15.15,3.84L16.5,2.5Z"/>
</vector>

View file

@ -10,6 +10,16 @@
<item>@string/themes_option_value_light</item>
<item>@string/themes_option_value_dark</item>
</string-array>
<string-array name="pref_screen_orientation_option_values">
<item>@string/screen_orientation_option_value_system</item>
<item>@string/screen_orientation_option_value_landscape</item>
<item>@string/screen_orientation_option_value_portrait</item>
</string-array>
<string-array name="pref_screen_orientation_option_labels">
<item>@string/screen_orientation_option_label_system</item>
<item>@string/screen_orientation_option_label_landscape</item>
<item>@string/screen_orientation_option_label_portrait</item>
</string-array>
<string-array name="tile_ids">
<item>tile_1</item>
<item>tile_2</item>

View file

@ -39,6 +39,14 @@
android:icon="@drawable/ic_fullscreen"
android:title="@string/fullscreen"
android:summary="@string/fullscreen_def"/>
<ListPreference
android:key="screen_orientation"
android:defaultValue="@string/screen_orientation_option_value_system"
android:entries="@array/pref_screen_orientation_option_labels"
android:entryValues="@array/pref_screen_orientation_option_values"
android:icon="@drawable/ic_screen_orientation"
android:title="@string/screen_orientation_title_settings"
app:useSimpleSummaryProvider="true"/>
<SwitchPreference
android:key="keep_screen_on"
android:icon="@drawable/ic_phone_check"

View file

@ -35,6 +35,10 @@ interface PrefsRepository {
suspend fun setKeepScreenOnEnabled(enabled: Boolean)
suspend fun getScreenOrientation(): String?
suspend fun saveScreenOrientation(orientation: String?)
suspend fun isPinchToZoomEnabled(): Boolean
suspend fun setPinchToZoomEnabled(enabled: Boolean)

View file

@ -19,6 +19,7 @@ class PrefsRepositoryImpl @Inject constructor(
private const val PREF_THEME = "theme"
private const val PREF_LANG = "lang"
private const val PREF_LOCALES = "locales"
private const val PREF_SCREEN_ORIENTATION = "screen_orientation"
private const val PREF_CONTROLS_AUTH_REQUIRED = "controls_auth_required"
private const val PREF_CONTROLS_AUTH_ENTITIES = "controls_auth_entities"
private const val PREF_FULLSCREEN_ENABLED = "fullscreen_enabled"
@ -97,6 +98,14 @@ class PrefsRepositoryImpl @Inject constructor(
localStorage.putString(PREF_LOCALES, locales)
}
override suspend fun getScreenOrientation(): String? {
return localStorage.getString(PREF_SCREEN_ORIENTATION)
}
override suspend fun saveScreenOrientation(orientation: String?) {
localStorage.putString(PREF_SCREEN_ORIENTATION, orientation)
}
override suspend fun getControlsAuthRequired(): ControlsAuthRequiredSetting {
val current = localStorage.getString(PREF_CONTROLS_AUTH_REQUIRED)
return ControlsAuthRequiredSetting.values().firstOrNull {

View file

@ -241,6 +241,13 @@
<string name="firebase_error_title">Firebase Error</string>
<string name="fullscreen_def">Put application in full screen</string>
<string name="fullscreen">Fullscreen</string>
<string name="screen_orientation_title_settings">Screen orientation</string>
<string name="screen_orientation_option_label_system">Follow System Settings</string>
<string name="screen_orientation_option_label_portrait">Portrait</string>
<string name="screen_orientation_option_label_landscape">Landscape</string>
<string name="screen_orientation_option_value_system">system</string>
<string name="screen_orientation_option_value_portrait">portrait</string>
<string name="screen_orientation_option_value_landscape">landscape</string>
<string name="get_help">Get Help</string>
<string name="grant_permission">Grant Permission</string>
<string name="help">Help</string>