Skip to content

Commit

Permalink
Move desktop mode to domain settings
Browse files Browse the repository at this point in the history
Part to #159.
  • Loading branch information
Slion committed Sep 6, 2023
1 parent 33a48e6 commit 63ccedb
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,16 @@ class DomainPreferences constructor(
* Used to distinguish main domain from resource domain
*/
var entryPoint by preferences.booleanPreference(R.string.pref_key_entry_point, false)



/**
* True if desktop mode should be enabled by default for new tabs, false otherwise.
*/
var desktopModeOverride by preferences.booleanPreference(R.string.pref_key_desktop_mode_override, false)
var desktopModeLocal by preferences.booleanPreference(R.string.pref_key_desktop_mode, false)
val desktopModeParent: Boolean get() { return parent?.desktopMode ?: desktopModeLocal}
val desktopMode: Boolean get() { return if (isDefault || !desktopModeOverride) { desktopModeParent } else { desktopModeLocal } }

/**
* True if dark mode should be enabled by default for this domain, false otherwise.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ class UserPreferences @Inject constructor(
*/
var newTabPosition by preferences.enumPreference(R.string.pref_key_new_tab_position, NewTabPosition.AFTER_CURRENT_TAB)

/**
* True if desktop mode should be enabled by default for new tabs, false otherwise.
*/
var desktopModeDefault by preferences.booleanPreference(R.string.pref_key_desktop_mode_default, false)

/**
* The URL of the selected homepage.
*/
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/acr/browser/lightning/view/LightningView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ class LightningView(
*/
var darkModeBypassDomainSettings = false

/**
*
*/
var desktopModeBypassDomainSettings = false

/**
* Get our find in page search query.
*
Expand Down Expand Up @@ -342,7 +347,7 @@ class LightningView(
//TODO: it looks like our special URLs don't get frozen for some reason
createWebView()
initializeContent(tabInitializer)
desktopMode = userPreferences.desktopModeDefault
desktopMode = defaultDomainSettings.desktopMode
darkMode = defaultDomainSettings.darkModeParent
} else {
// Our WebView will only be created whenever our tab goes to the foreground
Expand Down Expand Up @@ -711,9 +716,10 @@ class LightningView(
* This method is used to toggle the user agent between desktop and the current preference of
* the user.
*/
fun toggleDesktopUserAgent() {
fun toggleDesktopUserAgent(aBypass: Boolean = true) {
// Toggle desktop mode
desktopMode = !desktopMode
desktopModeBypassDomainSettings = aBypass
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ class LightningWebClient(
if (!darkModeBypassDomainSettings) {
darkMode = domainPreferences.darkMode
}

if (!desktopModeBypassDomainSettings) {
desktopMode = domainPreferences.desktopMode
}
}


Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
<string name="pref_key_javascript">pref_key_javascript</string>
<string name="pref_key_request_save_data">pref_key_request_save_data</string>
<string name="pref_key_load_images">pref_key_load_images</string>
<string name="pref_key_desktop_mode_default">pref_key_desktop_mode_default</string>
<string name="pref_key_desktop_mode">pref_key_desktop_mode</string>
<string name="pref_key_desktop_mode_override">pref_key_desktop_mode_override</string>
<string name="pref_key_dark_mode">pref_key_dark_mode</string>
<string name="pref_key_dark_mode_override">pref_key_dark_mode_override</string>
<string name="pref_key_webrtc">pref_key_webrtc</string>
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/res/xml/preference_domain.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,31 @@

</PreferenceCategory>

<PreferenceCategory
a:title="@string/settings_title_desktop_mode_default">

<SwitchPreferenceCompat
a:defaultValue="false"
a:key="@string/pref_key_desktop_mode_override"
a:title="@string/settings_title_override"
a:summaryOn="@string/settings_summary_on_override"
a:summaryOff="@string/settings_summary_off_override"
a:iconSpaceReserved="true"
a:singleLineTitle="false" />

<SwitchPreferenceCompat
a:defaultValue="false"
a:key="@string/pref_key_desktop_mode"
a:title="@string/settings_title_desktop_mode_default"
a:summary="@string/settings_summary_desktop_mode_default"
a:dependency="@string/pref_key_desktop_mode_override"
a:iconSpaceReserved="false"
a:icon="@drawable/ic_desktop"
a:singleLineTitle="false" />

</PreferenceCategory>


<acr.browser.lightning.settings.preferences.PreferenceCategoryEx
a:title="@string/settings_title_launch_app"
a:summary="@string/dialog_message_third_party_app">
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/xml/preference_domain_default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
a:layout="@layout/preference_category_material"
tools:ignore="PrivateResource" />

<SwitchPreferenceCompat
a:defaultValue="false"
a:key="@string/pref_key_desktop_mode"
a:title="@string/settings_title_desktop_mode_default"
a:summary="@string/settings_summary_desktop_mode_default"
a:iconSpaceReserved="false"
a:icon="@drawable/ic_desktop"
a:singleLineTitle="false" />

<SwitchPreferenceCompat
a:defaultValue="false"
a:key="@string/pref_key_dark_mode"
Expand Down
9 changes: 0 additions & 9 deletions app/src/main/res/xml/preference_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,6 @@
app:icon="@drawable/ic_library_add"
app:singleLineTitle="false" />

<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/pref_key_desktop_mode_default"
android:title="@string/settings_title_desktop_mode_default"
android:summary="@string/settings_summary_desktop_mode_default"
app:iconSpaceReserved="false"
app:icon="@drawable/ic_desktop"
app:singleLineTitle="false" />

<!--
Disabled as currently not working.
-->
Expand Down

0 comments on commit 63ccedb

Please sign in to comment.