From 652f5f89c2cd75b066b608bf3be370b0bb86611e Mon Sep 17 00:00:00 2001 From: brahmkshatriya <69040506+brahmkshatriya@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:32:00 +0530 Subject: [PATCH] More detailed error for parsing the eapk --- .../extensions/RequiredExtensionsException.kt | 1 + .../echo/ui/exception/ExceptionFragment.kt | 13 +++++++++++++ .../ExtensionInstallerBottomSheet.kt | 19 +++++++++++++++---- app/src/main/res/values/strings.xml | 1 + 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/dev/brahmkshatriya/echo/extensions/RequiredExtensionsException.kt b/app/src/main/java/dev/brahmkshatriya/echo/extensions/RequiredExtensionsException.kt index bef1132d..d2fc2333 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/extensions/RequiredExtensionsException.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/extensions/RequiredExtensionsException.kt @@ -1,5 +1,6 @@ package dev.brahmkshatriya.echo.extensions data class RequiredExtensionsException( + val name: String, val requiredExtensions: List ) : Exception("Required extensions not found") \ No newline at end of file diff --git a/app/src/main/java/dev/brahmkshatriya/echo/ui/exception/ExceptionFragment.kt b/app/src/main/java/dev/brahmkshatriya/echo/ui/exception/ExceptionFragment.kt index bd8cb705..8d06711a 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/ui/exception/ExceptionFragment.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/ui/exception/ExceptionFragment.kt @@ -12,6 +12,8 @@ import androidx.fragment.app.Fragment import dev.brahmkshatriya.echo.EchoApplication.Companion.appVersion import dev.brahmkshatriya.echo.R import dev.brahmkshatriya.echo.databinding.FragmentExceptionBinding +import dev.brahmkshatriya.echo.extensions.ExtensionLoadingException +import dev.brahmkshatriya.echo.extensions.RequiredExtensionsException import dev.brahmkshatriya.echo.playback.MediaItemUtils.audioIndex import dev.brahmkshatriya.echo.playback.MediaItemUtils.clientId import dev.brahmkshatriya.echo.playback.MediaItemUtils.track @@ -90,6 +92,12 @@ class ExceptionFragment : Fragment() { is IncompatibleClassChangeError -> getString(R.string.extension_out_of_date) is UnknownHostException, is UnresolvedAddressException -> getString(R.string.no_internet) is PlayerViewModel.PlayerException -> throwable.details.title + is ExtensionLoadingException -> getString(R.string.invalid_extension) + is RequiredExtensionsException -> getString( + R.string.extension_requires_following_extensions, + throwable.name, + throwable.requiredExtensions.joinToString(", ") + ) is AppException -> throwable.run { when (this) { is AppException.Unauthorized -> @@ -115,6 +123,11 @@ Track : ${throwable.mediaItem?.track} Stream : ${throwable.mediaItem?.run { track.audioStreamables.getOrNull(audioIndex) }} ${throwable.details.causedBy} +""".trimIndent() + + is RequiredExtensionsException -> """ +Extension : ${throwable.name} +Required Extensions : ${throwable.requiredExtensions.joinToString(", ")} """.trimIndent() is AppException -> """ diff --git a/app/src/main/java/dev/brahmkshatriya/echo/ui/extension/ExtensionInstallerBottomSheet.kt b/app/src/main/java/dev/brahmkshatriya/echo/ui/extension/ExtensionInstallerBottomSheet.kt index 121198ec..2d27b885 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/ui/extension/ExtensionInstallerBottomSheet.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/ui/extension/ExtensionInstallerBottomSheet.kt @@ -9,6 +9,8 @@ import android.view.ViewGroup import androidx.core.net.toFile import androidx.core.net.toUri import androidx.core.view.isVisible +import androidx.fragment.app.activityViewModels +import androidx.lifecycle.lifecycleScope import com.google.android.material.bottomsheet.BottomSheetDialogFragment import dev.brahmkshatriya.echo.ExtensionOpenerActivity.Companion.EXTENSION_INSTALLER import dev.brahmkshatriya.echo.R @@ -16,13 +18,15 @@ import dev.brahmkshatriya.echo.common.helpers.ExtensionType import dev.brahmkshatriya.echo.common.helpers.ImportType import dev.brahmkshatriya.echo.common.models.ImageHolder.Companion.toImageHolder import dev.brahmkshatriya.echo.databinding.DialogExtensionInstallerBinding +import dev.brahmkshatriya.echo.extensions.ExtensionLoadingException import dev.brahmkshatriya.echo.extensions.getType import dev.brahmkshatriya.echo.extensions.plugger.ApkManifestParser import dev.brahmkshatriya.echo.extensions.plugger.ApkPluginSource import dev.brahmkshatriya.echo.utils.ApkLinkParser import dev.brahmkshatriya.echo.utils.autoCleared import dev.brahmkshatriya.echo.utils.loadWith -import dev.brahmkshatriya.echo.viewmodels.SnackBar.Companion.createSnack +import dev.brahmkshatriya.echo.viewmodels.ExtensionViewModel +import kotlinx.coroutines.launch class ExtensionInstallerBottomSheet : BottomSheetDialogFragment() { @@ -62,12 +66,19 @@ class ExtensionInstallerBottomSheet : BottomSheetDialogFragment() { @SuppressLint("SetTextI18n") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { binding.topAppBar.setNavigationOnClickListener { dismiss() } - val value = pair.getOrNull() - if (value == null) { - createSnack(R.string.invalid_extension) + val value = pair.getOrElse { + val viewModel by activityViewModels() + lifecycleScope.launch { + viewModel.throwableFlow.emit(ExtensionLoadingException(ExtensionType.MUSIC, it)) + } dismiss() return } +// if (value == null) { +// createSnack(R.string.invalid_extension) +// dismiss() +// return +// } val (extensionType, metadata) = value binding.extensionTitle.text = metadata.name diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cbb8ec81..eef06229 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -253,6 +253,7 @@ Extension uninstalled successfully. Allow opening links To allow opening these links, you need to:\n- Scroll down and click on \"Open by Default\"\n- Click on \"+ Add Link\" + %1$s requires %2$s Highest Medium