Skip to content

Commit

Permalink
More detailed error for parsing the eapk
Browse files Browse the repository at this point in the history
  • Loading branch information
brahmkshatriya committed Oct 17, 2024
1 parent 9eed17c commit 652f5f8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.brahmkshatriya.echo.extensions

data class RequiredExtensionsException(
val name: String,
val requiredExtensions: List<String>
) : Exception("Required extensions not found")
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand All @@ -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 -> """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ 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
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() {

Expand Down Expand Up @@ -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<ExtensionViewModel>()
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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
<string name="extension_uninstalled_successfully">Extension uninstalled successfully.</string>
<string name="allow_opening_links">Allow opening links</string>
<string name="open_links_instruction">To allow opening these links, you need to:\n- Scroll down and click on \"Open by Default\"\n- Click on \"+ Add Link\"</string>
<string name="extension_requires_following_extensions">%1$s requires %2$s</string>
<string-array name="stream_qualities">
<item>Highest</item>
<item>Medium</item>
Expand Down

0 comments on commit 652f5f8

Please sign in to comment.