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

Commit a424ccce authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

Merge branch '3737-remove-auth-from-home' into 'main'

refactor: remove authentication from Home screen

See merge request !599
parents d59fd0a0 a3869e6c
Loading
Loading
Loading
Loading
Loading
+11 −80
Original line number Diff line number Diff line
/*
 * Apps  Quickly and easily install Android apps onto your device!
 * Copyright (C) 2021  E FOUNDATION
 * Copyright (C) 2021-2025 e Foundation
 *
 * 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
@@ -14,29 +13,25 @@
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

package foundation.e.apps.ui.home

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import dagger.hilt.android.AndroidEntryPoint
import foundation.e.apps.R
import foundation.e.apps.data.enums.Status
import foundation.e.apps.data.application.ApplicationInstaller
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.login.AuthObject
import foundation.e.apps.data.login.exceptions.GPlayException
import foundation.e.apps.data.login.exceptions.GPlayLoginException
import foundation.e.apps.data.enums.Status
import foundation.e.apps.databinding.FragmentHomeBinding
import foundation.e.apps.di.CommonUtilsModule.safeNavigate
import foundation.e.apps.install.download.data.DownloadProgress
import foundation.e.apps.install.pkg.PwaManager
import foundation.e.apps.ui.AppInfoFetchViewModel
@@ -45,14 +40,12 @@ import foundation.e.apps.ui.MainActivityViewModel
import foundation.e.apps.ui.application.subFrags.ApplicationDialogFragment
import foundation.e.apps.ui.home.model.HomeChildRVAdapter
import foundation.e.apps.ui.home.model.HomeParentRVAdapter
import foundation.e.apps.ui.parentFragment.TimeoutFragment
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.util.Locale
import javax.inject.Inject

@AndroidEntryPoint
class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstaller {
class HomeFragment : Fragment(R.layout.fragment_home), ApplicationInstaller {

    /*
     * Make adapter nullable to avoid memory leaks.
@@ -63,7 +56,7 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall
    private val binding get() = _binding!!

    private val homeViewModel: HomeViewModel by viewModels()
    override val mainActivityViewModel: MainActivityViewModel by activityViewModels()
    val mainActivityViewModel: MainActivityViewModel by activityViewModels()
    private val appProgressViewModel: AppProgressViewModel by viewModels()
    private val appInfoFetchViewModel: AppInfoFetchViewModel by viewModels()

@@ -74,7 +67,7 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall
        super.onViewCreated(view, savedInstanceState)
        _binding = FragmentHomeBinding.bind(view)

        loadHomePageData()
        loadData()

        homeParentRVAdapter = initHomeParentRVAdapter()

@@ -106,19 +99,6 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall
        }
    }

    private fun loadHomePageData() {
        setupListening()

        authObjects.observe(viewLifecycleOwner) {
            if (it == null) return@observe
            loadDataWhenNetworkAvailable(it)
        }

        homeViewModel.exceptionsLiveData.observe(viewLifecycleOwner) {
            handleExceptionsCommon(it)
        }
    }

    private fun showPaidAppMessage(application: Application) {
        ApplicationDialogFragment(
            title = getString(R.string.dialog_title_paid_app, application.name),
@@ -135,66 +115,22 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall
        ).show(childFragmentManager, "HomeFragment")
    }

    override fun onTimeout(
        exception: Exception,
        predefinedDialog: AlertDialog.Builder
    ): AlertDialog.Builder? {
        return predefinedDialog.apply {
            if (exception is GPlayException) {
                setMessage(R.string.timeout_desc_gplay)
                setNegativeButton(R.string.open_settings) { _, _ ->
                    openSettings()
                }
            } else {
                setMessage(R.string.timeout_desc_cleanapk)
            }
            setCancelable(false)
        }
    }

    override fun onSignInError(
        exception: GPlayLoginException,
        predefinedDialog: AlertDialog.Builder
    ): AlertDialog.Builder? {
        return predefinedDialog.apply {
            setNegativeButton(R.string.open_settings) { _, _ ->
                openSettings()
            }
        }
    }

    override fun onDataLoadError(
        exception: Exception,
        predefinedDialog: AlertDialog.Builder
    ): AlertDialog.Builder? {
        return predefinedDialog.apply {
            if (exception is GPlayException) {
                setNegativeButton(R.string.open_settings) { _, _ ->
                    openSettings()
                }
            }
        }
    }

    override fun loadData(authObjectList: List<AuthObject>) {
    private fun loadData() {
        if (shouldLoadData()) {
            showLoadingUI()
            homeViewModel.loadData(authObjectList, viewLifecycleOwner) { _ ->
                clearAndRestartGPlayLogin()
                true
            }
            homeViewModel.getHomeScreenData(viewLifecycleOwner)
        }
    }

    private fun shouldLoadData() = homeViewModel.haveSourcesChanged() || !homeViewModel.hasData()

    override fun showLoadingUI() {
    private fun showLoadingUI() {
        binding.shimmerLayout.startShimmer()
        binding.shimmerLayout.visibility = View.VISIBLE
        binding.parentRV.visibility = View.GONE
    }

    override fun stopLoadingUI() {
    private fun stopLoadingUI() {
        binding.shimmerLayout.stopShimmer()
        binding.shimmerLayout.visibility = View.GONE
        binding.parentRV.visibility = View.VISIBLE
@@ -281,9 +217,4 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall
    override fun cancelDownload(app: Application) {
        mainActivityViewModel.cancelDownload(app)
    }

    private fun openSettings() {
        view?.findNavController()
            ?.safeNavigate(R.id.homeFragment, R.id.action_homeFragment_to_SettingsFragment)
    }
}
+5 −27
Original line number Diff line number Diff line
/*
 * Apps  Quickly and easily install Android apps onto your device!
 * Copyright (C) 2021  E FOUNDATION
 * Copyright (C) 2021-2025 e Foundation
 *
 * 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
@@ -14,6 +13,7 @@
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

package foundation.e.apps.ui.home
@@ -21,6 +21,7 @@ package foundation.e.apps.ui.home
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import foundation.e.apps.data.ResultSupreme
@@ -29,10 +30,8 @@ import foundation.e.apps.data.Stores
import foundation.e.apps.data.application.ApplicationRepository
import foundation.e.apps.data.application.data.Home
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.login.AuthObject
import foundation.e.apps.data.preference.AppLoungePreference
import foundation.e.apps.ui.applicationlist.ApplicationDiffUtil
import foundation.e.apps.ui.parentFragment.LoadingViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@@ -40,7 +39,7 @@ import javax.inject.Inject
class HomeViewModel @Inject constructor(
    private val applicationRepository: ApplicationRepository,
    private val stores: Stores
) : LoadingViewModel() {
) : ViewModel() {

    @Inject
    lateinit var appLoungePreference: AppLoungePreference
@@ -61,25 +60,6 @@ class HomeViewModel @Inject constructor(
        return homeScreenData.value?.data?.isNotEmpty() ?: false
    }

    fun loadData(
        authObjectList: List<AuthObject>,
        lifecycleOwner: LifecycleOwner,
        retryBlock: (failedObjects: List<AuthObject>) -> Boolean,
    ) {
        super.onLoadData(authObjectList, { successAuthList, _ ->

            successAuthList.find { it is AuthObject.GPlayAuth }?.run {
                getHomeScreenData(lifecycleOwner)
                return@onLoadData
            }

            successAuthList.find { it is AuthObject.CleanApk }?.run {
                getHomeScreenData(lifecycleOwner)
                return@onLoadData
            }
        }, retryBlock)
    }

    fun haveSourcesChanged(): Boolean {
        val newStores = stores.getStores()
        if (newStores == previousStores) {
@@ -90,9 +70,7 @@ class HomeViewModel @Inject constructor(
        return true
    }

    private fun getHomeScreenData(
        lifecycleOwner: LifecycleOwner,
    ) {
    fun getHomeScreenData(lifecycleOwner: LifecycleOwner) {
        viewModelScope.launch {
            applicationRepository.getHomeScreenData().observe(lifecycleOwner) {
                postHomeResult(it)
+6 −5
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>

<!--
  ~ Apps  Quickly and easily install Android apps onto your device!
  ~ Copyright (C) 2021  E FOUNDATION
  ~ Copyright (C) 2021-2025 e Foundation
  ~
  ~ 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
@@ -16,6 +15,7 @@
  ~
  ~ You should have received a copy of the GNU General Public License
  ~ along with this program.  If not, see <https://www.gnu.org/licenses/>.
  ~
  -->

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
@@ -53,6 +53,7 @@
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/app_icon"
            tools:src="@tools:sample/avatars"
            android:scaleType="fitXY" />
    </androidx.cardview.widget.CardView>

@@ -70,7 +71,7 @@
        app:layout_constraintLeft_toRightOf="@+id/app_icon_card"
        app:layout_constraintRight_toLeftOf="@+id/installButton"
        app:layout_constraintTop_toTopOf="@+id/app_icon_card"
        tools:text="Google Chrome - Fast and Secured" />
        tools:text="@tools:sample/lorem/random" />

    <com.google.android.material.textview.MaterialTextView
        android:id="@+id/app_author"
@@ -85,7 +86,7 @@
        app:layout_constraintLeft_toLeftOf="@+id/app_title"
        app:layout_constraintRight_toLeftOf="@+id/installButton"
        app:layout_constraintBottom_toBottomOf="@+id/app_icon_card"
        tools:text="App author" />
        tools:text="@tools:sample/full_names" />

    <ImageView
        android:id="@+id/icon_star"
+8 −5
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ Apps  Quickly and easily install Android apps onto your device!
  ~ Copyright (C) 2021  E FOUNDATION
  ~ Copyright (C) 2021-2025 e Foundation
  ~
  ~ 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
@@ -14,6 +13,7 @@
  ~
  ~ 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"
@@ -27,7 +27,8 @@
        android:id="@+id/shimmerLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        android:orientation="vertical"
        tools:visibility="gone">

        <ScrollView
            android:layout_width="match_parent"
@@ -64,6 +65,8 @@
        android:clipToPadding="false"
        android:paddingTop="20dp"
        android:paddingBottom="10dp"
        android:visibility="gone" />
        android:visibility="gone"
        tools:listitem="@layout/home_parent_list_item"
        tools:visibility="visible" />

</LinearLayout>
+6 −3
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ Apps  Quickly and easily install Android apps onto your device!
  ~ Copyright (C) 2021  E FOUNDATION
  ~ Copyright (C) 2021-2025 e Foundation
  ~
  ~ 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
@@ -14,10 +13,12 @@
  ~
  ~ 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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/homeLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
@@ -41,6 +42,7 @@
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/app_icon"
            tools:src="@tools:sample/avatars"
            android:scaleType="fitXY" />

    </com.google.android.material.card.MaterialCardView>
@@ -55,6 +57,7 @@
        android:lines="2"
        android:textAlignment="center"
        android:textColor="?android:textColorPrimary"
        tools:text="@tools:sample/lorem/random"
        android:textSize="12sp" />

    <RelativeLayout
Loading