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

Commit ac729e49 authored by Hasib Prince's avatar Hasib Prince
Browse files

multiple source handling for Home/category page

parent a1021890
Loading
Loading
Loading
Loading
Loading
+80 −75
Original line number Diff line number Diff line
@@ -143,23 +143,28 @@ class FusedAPIImpl @Inject constructor(
             * To prevent waiting so long and fail early, use withTimeout{}.
             */
            withTimeout(timeoutDurationInMillis) {
                if (applicationType != APP_TYPE_ANY) {
                    val response = if (applicationType == APP_TYPE_OPEN) {
                        cleanAPKRepository.getHomeScreenData(
                if (preferenceManagerModule.isGplaySelected()) {
                    list.addAll(fetchGPlayHome(authData))
                }

                if (preferenceManagerModule.isOpenSourceSelected()) {
                    val response = cleanAPKRepository.getHomeScreenData(
                        CleanAPKInterface.APP_TYPE_ANY,
                        CleanAPKInterface.APP_SOURCE_FOSS
                    ).body()
                    } else {
                        cleanAPKRepository.getHomeScreenData(
                    response?.home?.let {
                        list.addAll(generateCleanAPKHome(it, applicationType))
                    }
                }

                if (preferenceManagerModule.isPWASelected()) {
                    val response = cleanAPKRepository.getHomeScreenData(
                        CleanAPKInterface.APP_TYPE_PWA,
                        CleanAPKInterface.APP_SOURCE_ANY
                    ).body()
                    }
                    response?.home?.let {
                        list.addAll(generateCleanAPKHome(it, applicationType))
                    }
                } else {
                    list.addAll(fetchGPlayHome(authData))
                }
            }
        } catch (e: TimeoutCancellationException) {
@@ -190,20 +195,12 @@ class FusedAPIImpl @Inject constructor(
        var apiStatus: ResultStatus = ResultStatus.OK
        var applicationCategoryType = preferredApplicationType

        if (preferredApplicationType != APP_TYPE_ANY) {
            handleCleanApkCategories(preferredApplicationType, categoriesList, type).run {
                if (this != ResultStatus.OK) {
                    apiStatus = this
                }
            }
        } else {
        handleAllSourcesCategories(categoriesList, type, authData).run {
            if (first != ResultStatus.OK) {
                apiStatus = first
                applicationCategoryType = second
            }
        }
        }
        categoriesList.sortBy { item -> item.title.lowercase() }
        return Triple(categoriesList, applicationCategoryType, apiStatus)
    }
@@ -803,6 +800,7 @@ class FusedAPIImpl @Inject constructor(
        var apiStatus = ResultStatus.OK
        var errorApplicationCategory = ""

        if (preferenceManagerModule.isOpenSourceSelected()) {
            /*
         * Try within timeout limit for open source native apps categories.
         */
@@ -824,6 +822,9 @@ class FusedAPIImpl @Inject constructor(
                errorApplicationCategory = APP_TYPE_OPEN
                apiStatus = ResultStatus.UNKNOWN
            })
        }

        if (preferenceManagerModule.isPWASelected()) {

            /*
         * Try within timeout limit to get PWA categories
@@ -844,6 +845,9 @@ class FusedAPIImpl @Inject constructor(
                errorApplicationCategory = APP_TYPE_PWA
                apiStatus = ResultStatus.UNKNOWN
            })
        }

        if (preferenceManagerModule.isGplaySelected()) {

            /*
         * Try within timeout limit to get native app categories from Play Store
@@ -862,6 +866,7 @@ class FusedAPIImpl @Inject constructor(
                errorApplicationCategory = APP_TYPE_ANY
                apiStatus = ResultStatus.UNKNOWN
            })
        }

        return Pair(apiStatus, errorApplicationCategory)
    }
+10 −9
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.widget.Toast
import androidx.fragment.app.viewModels
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import androidx.preference.CheckBoxPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.work.ExistingPeriodicWorkPolicy
@@ -69,9 +70,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
        setPreferencesFromResource(R.xml.settings_preferences, rootKey)

        // Show applications preferences
        val showAllApplications = findPreference<RadioButtonPreference>("showAllApplications")
        val showFOSSApplications = findPreference<RadioButtonPreference>("showFOSSApplications")
        val showPWAApplications = findPreference<RadioButtonPreference>("showPWAApplications")
        val showAllApplications = findPreference<CheckBoxPreference>("showAllApplications")
        val showFOSSApplications = findPreference<CheckBoxPreference>("showFOSSApplications")
        val showPWAApplications = findPreference<CheckBoxPreference>("showPWAApplications")

        val updateCheckInterval =
            preferenceManager.findPreference<Preference>(getString(R.string.update_check_intervals))
@@ -88,22 +89,22 @@ class SettingsFragment : PreferenceFragmentCompat() {
        }

        showAllApplications?.setOnPreferenceChangeListener { _, _ ->
            showFOSSApplications?.isChecked = false
            showPWAApplications?.isChecked = false
//            showFOSSApplications?.isChecked = false
//            showPWAApplications?.isChecked = false
            backToMainActivity()
            true
        }

        showFOSSApplications?.setOnPreferenceChangeListener { _, _ ->
            showAllApplications?.isChecked = false
            showPWAApplications?.isChecked = false
//            showAllApplications?.isChecked = false
//            showPWAApplications?.isChecked = false
            backToMainActivity()
            true
        }

        showPWAApplications?.setOnPreferenceChangeListener { _, _ ->
            showFOSSApplications?.isChecked = false
            showAllApplications?.isChecked = false
//            showFOSSApplications?.isChecked = false
//            showAllApplications?.isChecked = false
            backToMainActivity()
            true
        }
+4 −0
Original line number Diff line number Diff line
@@ -42,6 +42,10 @@ class PreferenceManagerModule @Inject constructor(
        }
    }

    fun isOpenSourceSelected() = preferenceManager.getBoolean("showFOSSApplications", false)
    fun isPWASelected() = preferenceManager.getBoolean("showPWAApplications", false)
    fun isGplaySelected() = preferenceManager.getBoolean("showAllApplications", false)

    fun autoUpdatePreferred(): Boolean {
        return preferenceManager.getBoolean("updateInstallAuto", false)
    }
+5 −3
Original line number Diff line number Diff line
@@ -53,16 +53,18 @@

    <PreferenceCategory
        android:title="@string/Show_applications">
        <foundation.e.apps.settings.RadioButtonPreference
        <CheckBoxPreference
            android:defaultValue="true"
            android:key="showAllApplications"
            android:title="@string/Show_all_apps" />

        <foundation.e.apps.settings.RadioButtonPreference
        <CheckBoxPreference
            android:defaultValue="true"
            android:key="showFOSSApplications"
            android:title="@string/show_only_open_source_apps" />

        <foundation.e.apps.settings.RadioButtonPreference
        <CheckBoxPreference
            android:defaultValue="true"
            android:key="showPWAApplications"
            android:title="@string/show_only_pwa_apps" />
    </PreferenceCategory>