compose: Migrate onboarding logic to compose
* Still needs implementation for showing microG installation screen on huawei * No anonymous mode on huawei * Needs handling for showing permissions screen via settings Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -1,164 +0,0 @@
|
||||
package com.aurora.store.view.ui.onboarding
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.aurora.Constants.PACKAGE_NAME_GMS
|
||||
import com.aurora.extensions.browse
|
||||
import com.aurora.store.AuroraApp
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.event.Event
|
||||
import com.aurora.store.data.event.InstallerEvent
|
||||
import com.aurora.store.data.model.Dash
|
||||
import com.aurora.store.data.model.DownloadStatus
|
||||
import com.aurora.store.databinding.FragmentOnboardingMicrogBinding
|
||||
import com.aurora.store.util.PackageUtil
|
||||
import com.aurora.store.view.epoxy.views.EpoxyTextViewModel_
|
||||
import com.aurora.store.view.epoxy.views.preference.DashViewModel_
|
||||
import com.aurora.store.view.ui.commons.BaseFragment
|
||||
import com.aurora.store.viewmodel.onboarding.MicroGViewModel
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MicroGFragment : BaseFragment<FragmentOnboardingMicrogBinding>() {
|
||||
// Shared ViewModel
|
||||
val microGViewModel: MicroGViewModel by activityViewModels()
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
with(binding) {
|
||||
// RecyclerView
|
||||
epoxyRecycler.withModels {
|
||||
setFilterDuplicates(true)
|
||||
|
||||
add(
|
||||
EpoxyTextViewModel_()
|
||||
.id("microg_desc")
|
||||
.title(getString(R.string.onboarding_gms_missing))
|
||||
.size(14)
|
||||
.style(R.style.AuroraTextStyle)
|
||||
)
|
||||
|
||||
add(
|
||||
EpoxyTextViewModel_()
|
||||
.id("microg_gms")
|
||||
.title(getString(R.string.onboarding_gms_microg))
|
||||
.size(14)
|
||||
.style(R.style.AuroraTextStyle)
|
||||
)
|
||||
|
||||
|
||||
dashItems().forEach {
|
||||
add(
|
||||
DashViewModel_()
|
||||
.id(it.id)
|
||||
.dash(it)
|
||||
.click { _ ->
|
||||
requireContext().browse(it.url)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
checkboxAgreement.setOnCheckedChangeListener { _, value ->
|
||||
microGViewModel.markAgreement(value)
|
||||
btnMicroG.isEnabled = value
|
||||
}
|
||||
|
||||
btnMicroG.setOnClickListener { microGViewModel.downloadMicroG() }
|
||||
}
|
||||
|
||||
microGViewModel.download.filterNotNull().onEach {
|
||||
when (it.downloadStatus) {
|
||||
DownloadStatus.DOWNLOADING -> updateProgressBar(visible = true, it.progress)
|
||||
DownloadStatus.FAILED -> updateProgressBar(visible = false, 0)
|
||||
DownloadStatus.QUEUED -> updateProgressBar(visible = true, -1)
|
||||
DownloadStatus.COMPLETED -> updateProgressBar(visible = true, -1)
|
||||
else -> {}
|
||||
}
|
||||
}.launchIn(viewLifecycleOwner.lifecycleScope)
|
||||
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
AuroraApp.events.installerEvent.collect { onEvent(it) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun onEvent(event: Event) {
|
||||
when (event) {
|
||||
is InstallerEvent.Installed -> {
|
||||
if (event.packageName == PACKAGE_NAME_GMS) {
|
||||
microGViewModel.downloadCompanion()
|
||||
}
|
||||
|
||||
if (PackageUtil.isMicroGBundleInstalled(requireContext())) {
|
||||
markInstallationComplete()
|
||||
}
|
||||
}
|
||||
|
||||
is InstallerEvent.Failed -> markInstallationFailed()
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateProgressBar(visible: Boolean, downloadProgress: Int) {
|
||||
with(binding.progressBar) {
|
||||
if (visible) show() else hide()
|
||||
isIndeterminate = downloadProgress == -1
|
||||
progress = downloadProgress
|
||||
}
|
||||
}
|
||||
|
||||
private fun markInstallationComplete() {
|
||||
with(binding) {
|
||||
with(btnMicroG) {
|
||||
isEnabled = false
|
||||
text = getString(R.string.title_installed)
|
||||
}
|
||||
checkboxAgreement.isEnabled = false
|
||||
progressBar.hide()
|
||||
}
|
||||
}
|
||||
|
||||
private fun markInstallationFailed() {
|
||||
with(binding) {
|
||||
with(btnMicroG) {
|
||||
isEnabled = false
|
||||
text = getString(R.string.action_install)
|
||||
}
|
||||
checkboxAgreement.isChecked = false
|
||||
progressBar.hide()
|
||||
}
|
||||
}
|
||||
|
||||
private fun dashItems(): List<Dash> {
|
||||
return listOf(
|
||||
Dash(
|
||||
id = 2,
|
||||
title = requireContext().getString(R.string.details_dev_website),
|
||||
subtitle = requireContext().getString(R.string.microg_website),
|
||||
icon = R.drawable.ic_network,
|
||||
url = "https://microG.org"
|
||||
),
|
||||
Dash(
|
||||
id = 4,
|
||||
title = requireContext().getString(R.string.privacy_policy_title),
|
||||
subtitle = requireContext().getString(R.string.microg_privacy_policy),
|
||||
icon = R.drawable.ic_privacy,
|
||||
url = "https://microg.org/privacy.html"
|
||||
),
|
||||
Dash(
|
||||
id = 5,
|
||||
title = requireContext().getString(R.string.menu_disclaimer),
|
||||
subtitle = requireContext().getString(R.string.microg_license_agreement),
|
||||
icon = R.drawable.ic_disclaimer,
|
||||
url = "https://raw.githubusercontent.com/microg/GmsCore/refs/heads/master/LICENSE"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store 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 Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.store.view.ui.onboarding
|
||||
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.aurora.extensions.isHuawei
|
||||
import com.aurora.store.data.providers.BlacklistProvider
|
||||
import com.aurora.store.util.PackageUtil
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_AUTO_DELETE
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_DEFAULT_SELECTED_TAB
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_DISPENSER_URLS
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_FILTER_AURORA_ONLY
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_FILTER_FDROID
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_FOR_YOU
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_INSTALLER_ID
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_STYLE
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_CHECK_INTERVAL
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_EXTENDED
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_VENDING_VERSION
|
||||
import com.aurora.store.util.save
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class OnboardingFragment : BaseFlavouredOnboardingFragment() {
|
||||
@Inject
|
||||
lateinit var blacklistProvider: BlacklistProvider
|
||||
|
||||
override fun loadDefaultPreferences() {
|
||||
/*Filters*/
|
||||
save(PREFERENCE_FILTER_AURORA_ONLY, false)
|
||||
save(PREFERENCE_FILTER_FDROID, true)
|
||||
|
||||
/*Network*/
|
||||
save(PREFERENCE_DISPENSER_URLS, emptySet())
|
||||
save(PREFERENCE_VENDING_VERSION, 0)
|
||||
|
||||
/*Customization*/
|
||||
save(PREFERENCE_THEME_STYLE, 0)
|
||||
save(PREFERENCE_DEFAULT_SELECTED_TAB, 0)
|
||||
save(PREFERENCE_FOR_YOU, true)
|
||||
|
||||
/*Installer*/
|
||||
save(PREFERENCE_AUTO_DELETE, true)
|
||||
save(PREFERENCE_INSTALLER_ID, 0)
|
||||
|
||||
/*Updates*/
|
||||
save(PREFERENCE_UPDATES_EXTENDED, false)
|
||||
save(PREFERENCE_UPDATES_CHECK_INTERVAL, 3)
|
||||
}
|
||||
|
||||
override fun onboardingPages(): List<Fragment> {
|
||||
var pages = mutableListOf(
|
||||
WelcomeFragment(),
|
||||
PermissionsFragment.newInstance()
|
||||
)
|
||||
|
||||
/**
|
||||
* MicroG Fragment Preconditions:
|
||||
* 1. It should be a Huawei device
|
||||
* 2. Supported App Gallery should be available, i.e. v15.1.x or above
|
||||
* 3. MicroG bundle should not be already installed
|
||||
*/
|
||||
if (
|
||||
isHuawei &&
|
||||
PackageUtil.hasSupportedAppGallery(requireContext()) &&
|
||||
!PackageUtil.isMicroGBundleInstalled(requireContext())
|
||||
) {
|
||||
pages.add(MicroGFragment())
|
||||
}
|
||||
|
||||
return pages
|
||||
}
|
||||
|
||||
override fun setupAutoUpdates() {
|
||||
super.setupAutoUpdates()
|
||||
|
||||
// Remove super & implement variant logic here
|
||||
}
|
||||
|
||||
override fun finishOnboarding() {
|
||||
blacklistProvider.blacklist("com.android.vending")
|
||||
blacklistProvider.blacklist("com.google.android.gms")
|
||||
|
||||
super.finishOnboarding()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user