Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ec722fb3 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

Merge branch '864-grey_out_settings_option' into 'main'

Issue 864: Grey out settings option

See merge request !284
parents 30bfca5a 194993c5
Loading
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import androidx.lifecycle.ViewModelProvider
import androidx.navigation.findNavController
import androidx.preference.CheckBoxPreference
import androidx.preference.Preference
import androidx.preference.Preference.OnPreferenceChangeListener
import androidx.preference.PreferenceFragmentCompat
import androidx.work.ExistingPeriodicWorkPolicy
import coil.load
@@ -160,6 +161,14 @@ class SettingsFragment : PreferenceFragmentCompat() {

        super.onViewCreated(view, savedInstanceState)

        val autoInstallUpdate = fetchCheckboxPreference(R.string.auto_install_enabled)
        val onlyUnmeteredNetwork = fetchCheckboxPreference(R.string.only_unmetered_network)

        setCheckboxDependency(onlyUnmeteredNetwork, autoInstallUpdate)

        // This is useful if a user from older App Lounge updates to this version
        disableDependentCheckbox(onlyUnmeteredNetwork, autoInstallUpdate)

        mainActivityViewModel.gPlayAuthData.let { authData ->
            mainActivityViewModel.getUser().name.let { user ->
                when (user) {
@@ -226,6 +235,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
        }
    }

    private fun fetchCheckboxPreference(id: Int): CheckBoxPreference? {
        return findPreference(getString(id))
    }

    fun isAnyAppSourceSelected() =
        showAllApplications?.isChecked == true || showFOSSApplications?.isChecked == true || showPWAApplications?.isChecked == true

@@ -238,6 +251,34 @@ class SettingsFragment : PreferenceFragmentCompat() {
        }
    }

    private fun disableDependentCheckbox(
        checkBox: CheckBoxPreference?,
        parentCheckBox: CheckBoxPreference?
    ) {
        checkBox?.apply {
            if (parentCheckBox?.isChecked == false) {
                this.isChecked = false
                this.isEnabled = false
            }
        }
    }

    private fun setCheckboxDependency(
        checkBox: CheckBoxPreference?,
        parentCheckBox: CheckBoxPreference?,
        parentCheckBoxPreferenceChangeListener: OnPreferenceChangeListener? = null,
    ) {
        checkBox?.dependency = parentCheckBox?.key
        parentCheckBox?.onPreferenceChangeListener =
            OnPreferenceChangeListener { preference, newValue ->
                if (newValue == false) {
                    checkBox?.isChecked = false
                }
                parentCheckBoxPreferenceChangeListener?.onPreferenceChange(preference, newValue)
                    ?: true
            }
    }

    override fun onDestroyView() {
        if (sourcesChangedFlag) {
            UpdatesDao.addItemsForUpdate(emptyList())
+0 −71
Original line number Diff line number Diff line
<!--
  ~ Apps  Quickly and easily install Android apps onto your device!
  ~ Copyright (C) 2022  MURENA SAS
  ~
  ~ This program is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ This program is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU General Public License for more details.
  ~
  ~ You should have received a copy of the GNU General Public License
  ~ along with this program.  If not, see <https://www.gnu.org/licenses/>.
  -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/selectableItemBackground"
    android:gravity="center_vertical"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:paddingStart="16dp"
    android:paddingEnd="16dp"
    android:paddingBottom="24dp">

    <ImageView
        android:id="@android:id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dip"
        android:layout_marginTop="8dip"
        android:layout_marginBottom="8dip"
        android:layout_weight="1">

        <TextView
            android:id="@android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorPrimary"
            android:textSize="16sp" />

        <TextView
            android:id="@android:id/summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@android:id/title"
            android:layout_alignStart="@android:id/title"
            android:maxLines="4"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary" />
    </RelativeLayout>
    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout
        android:id="@android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:orientation="vertical" />
</LinearLayout>
 No newline at end of file
+5 −7
Original line number Diff line number Diff line
@@ -33,33 +33,33 @@
            android:entries="@array/update_interval_names"
            android:entryValues="@array/update_interval_values"
            android:key="@string/update_check_intervals"
            android:layout="@layout/layout_custom_checkbox_preference"
            android:summary="%s"
            android:title="@string/preference_update_interval_title"
            app:singleLineTitle="false"
            app:iconSpaceReserved="false" />

        <CheckBoxPreference
            android:defaultValue="true"
            android:key="@string/updateNotify"
            android:layout="@layout/layout_custom_checkbox_preference"
            android:summary="@string/preference_update_notify_available_description"
            android:title="@string/preference_update_notify_available_title"
            app:singleLineTitle="false"
            app:iconSpaceReserved="false" />

        <CheckBoxPreference
            android:defaultValue="true"
            android:key="@string/auto_install_enabled"
            android:layout="@layout/layout_custom_checkbox_preference"
            android:summary="@string/preference_update_install_automatically_description"
            android:title="@string/preference_update_install_automatically_title"
            app:singleLineTitle="false"
            app:iconSpaceReserved="false" />

        <CheckBoxPreference
            android:defaultValue="true"
            android:key="@string/only_unmetered_network"
            android:layout="@layout/layout_custom_checkbox_preference"
            android:summary="@string/preference_update_wifi_only_description"
            android:title="@string/preference_update_wifi_only_title"
            app:singleLineTitle="false"
            app:iconSpaceReserved="false" />
    </PreferenceCategory>

@@ -70,7 +70,6 @@
        <CheckBoxPreference
            android:defaultValue="true"
            android:key="showAllApplications"
            android:layout="@layout/layout_custom_checkbox_preference"
            android:title="@string/Show_common_apps"
            app:iconSpaceReserved="false"
            app:singleLineTitle="false" />
@@ -78,7 +77,6 @@
        <CheckBoxPreference
            android:defaultValue="true"
            android:key="showFOSSApplications"
            android:layout="@layout/layout_custom_checkbox_preference"
            android:title="@string/show_only_open_source_apps"
            app:iconSpaceReserved="false"
            app:singleLineTitle="false" />
@@ -86,7 +84,6 @@
        <CheckBoxPreference
            android:defaultValue="true"
            android:key="showPWAApplications"
            android:layout="@layout/layout_custom_checkbox_preference"
            android:title="@string/show_only_pwa_apps"
            app:iconSpaceReserved="false"
            app:singleLineTitle="false" />
@@ -100,6 +97,7 @@
        <foundation.e.apps.settings.LongPressPreference
            android:key="versionInfo"
            android:title="@string/app_version_label"
            app:singleLineTitle="false"
            app:iconSpaceReserved="false"
            tools:summary="2.2.1" />