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

Commit 6624bec4 authored by Saalim Quadri's avatar Saalim Quadri
Browse files

Merge branch '3370-navig-error' into 'main'

feat: Redirect to homepage if app is not available

See merge request !589
parents 1b362512 99996d7a
Loading
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -258,6 +258,10 @@ class MainActivity : AppCompatActivity() {
                launch {
                    observeSuccessfulLogin()
                }

                launch {
                    observeAppNotFoundAutoRedirect()
                }
            }
        }
    }
@@ -594,6 +598,23 @@ class MainActivity : AppCompatActivity() {
        }
    }

    private suspend fun observeAppNotFoundAutoRedirect() {
        EventBus.events.filterIsInstance<AppEvent.AppNotFoundAutoRedirect>()
            .collectLatest {
                try {
                    findNavController(R.id.fragment).navigateUp()
                } catch (e: IllegalArgumentException) {
                    Timber.w(e, "Failed to navigate up from app not found")

                    try {
                        findNavController(R.id.fragment).popBackStack()
                    } catch (e2: IllegalArgumentException) {
                        Timber.w(e2, "Failed to pop back stack from app not found")
                    }
                }
            }
    }

    fun showSnackbarMessage(message: String) {
        Snackbar.make(binding.root, message, Snackbar.LENGTH_LONG).show()
    }
+14 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import foundation.e.apps.ui.parentFragment.LoadingViewModel
import foundation.e.apps.utils.eventBus.AppEvent
import foundation.e.apps.utils.eventBus.EventBus
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
@@ -155,6 +156,7 @@ class ApplicationViewModel @Inject constructor(
                }
            } catch (e: InternalException.AppNotFound) {
                _errorMessageLiveData.postValue(R.string.app_not_found)
                scheduleAutoRedirect()
            } catch (e: Exception) {
                _errorMessageLiveData.postValue(R.string.unknown_error)
            }
@@ -194,6 +196,7 @@ class ApplicationViewModel @Inject constructor(
                val app = apps.firstOrNull()
                if (app == null || app.package_name.isBlank()) {
                    _errorMessageLiveData.postValue(R.string.app_not_found)
                    scheduleAutoRedirect()
                    return@launch
                }

@@ -233,6 +236,17 @@ class ApplicationViewModel @Inject constructor(
    fun isKnownNsfwApp(app: Application): Boolean {
        return app.package_name in fDroidAntiFeatureRepository.fDroidNsfwApps
    }

    private fun scheduleAutoRedirect() {
        viewModelScope.launch {
            delay(REDIRECT_DELAY_MS)
            EventBus.invokeEvent(AppEvent.AppNotFoundAutoRedirect())
        }
    }

    companion object {
        private const val REDIRECT_DELAY_MS = 2000L
    }
}

sealed class ShareButtonVisibilityState {
+1 −0
Original line number Diff line number Diff line
@@ -41,4 +41,5 @@ sealed class AppEvent(val data: Any) {
        val onClose: CompletableDeferred<Unit>? = null
    ) : AppEvent(type)
    class SuccessfulLogin(user: User): AppEvent(user)
    class AppNotFoundAutoRedirect : AppEvent(Unit)
}