forked from recloudstream/cloudstream
Fixed "open with" in library
This commit is contained in:
parent
019e9a0c4f
commit
30dbd3920e
3 changed files with 67 additions and 19 deletions
|
@ -1,16 +1,20 @@
|
||||||
package com.lagradost.cloudstream3.ui.library
|
package com.lagradost.cloudstream3.ui.library
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.annotation.StringRes
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import com.google.android.material.tabs.TabLayoutMediator
|
import com.google.android.material.tabs.TabLayoutMediator
|
||||||
|
import com.lagradost.cloudstream3.APIHolder
|
||||||
import com.lagradost.cloudstream3.APIHolder.allProviders
|
import com.lagradost.cloudstream3.APIHolder.allProviders
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
||||||
|
import com.lagradost.cloudstream3.AcraApplication.Companion.openBrowser
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
|
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.mvvm.debugAssert
|
import com.lagradost.cloudstream3.mvvm.debugAssert
|
||||||
|
@ -20,6 +24,7 @@ import com.lagradost.cloudstream3.syncproviders.SyncIdName
|
||||||
import com.lagradost.cloudstream3.ui.result.txt
|
import com.lagradost.cloudstream3.ui.result.txt
|
||||||
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_LOAD
|
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_LOAD
|
||||||
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_SHOW_METADATA
|
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_SHOW_METADATA
|
||||||
|
import com.lagradost.cloudstream3.utils.AppUtils.loadResult
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult
|
import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult
|
||||||
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
|
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
|
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
|
||||||
|
@ -28,9 +33,11 @@ import kotlinx.android.synthetic.main.fragment_library.*
|
||||||
const val LIBRARY_FOLDER = "library_folder"
|
const val LIBRARY_FOLDER = "library_folder"
|
||||||
|
|
||||||
|
|
||||||
enum class LibraryOpenerType {
|
enum class LibraryOpenerType(@StringRes val stringRes: Int) {
|
||||||
Provider,
|
Default(R.string.default_subtitles), // TODO FIX AFTER MERGE
|
||||||
Browser,
|
Provider(R.string.none),
|
||||||
|
Browser(R.string.browser),
|
||||||
|
None(R.string.none),
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Used to store how the user wants to open said poster */
|
/** Used to store how the user wants to open said poster */
|
||||||
|
@ -111,31 +118,41 @@ class LibraryFragment : Fragment() {
|
||||||
/**
|
/**
|
||||||
* Shows a plugin selection dialogue and saves the response
|
* Shows a plugin selection dialogue and saves the response
|
||||||
**/
|
**/
|
||||||
fun showPluginSelectionDialog(key: String, syncId: SyncIdName) {
|
fun Activity.showPluginSelectionDialog(
|
||||||
|
key: String,
|
||||||
|
syncId: SyncIdName,
|
||||||
|
apiName: String? = null,
|
||||||
|
) {
|
||||||
val availableProviders = allProviders.filter {
|
val availableProviders = allProviders.filter {
|
||||||
it.supportedSyncNames.contains(syncId)
|
it.supportedSyncNames.contains(syncId)
|
||||||
}.map { it.name }
|
}.map { it.name } +
|
||||||
|
// Add the api if it exists
|
||||||
|
(APIHolder.getApiFromNameNull(apiName)?.let { listOf(it.name) } ?: emptyList())
|
||||||
|
|
||||||
val baseOptions = listOf(LibraryOpenerType.Browser.name)
|
val baseOptions = listOf(
|
||||||
|
txt(LibraryOpenerType.Default.stringRes).asString(this),
|
||||||
|
txt(LibraryOpenerType.None.stringRes).asString(this),
|
||||||
|
txt(LibraryOpenerType.Browser.stringRes).asString(this),
|
||||||
|
)
|
||||||
|
|
||||||
val items = baseOptions + availableProviders
|
val items = baseOptions + availableProviders
|
||||||
|
|
||||||
val savedSelection = getKey<LibraryOpener>(LIBRARY_FOLDER, key)
|
val savedSelection = getKey<LibraryOpener>(LIBRARY_FOLDER, key)
|
||||||
val selectedIndex =
|
val selectedIndex =
|
||||||
when {
|
when {
|
||||||
savedSelection == null -> -1
|
savedSelection == null -> 0
|
||||||
// If provider
|
// If provider
|
||||||
savedSelection.openType == LibraryOpenerType.Provider
|
savedSelection.openType == LibraryOpenerType.Provider
|
||||||
&& savedSelection.providerData?.apiName != null -> {
|
&& savedSelection.providerData?.apiName != null -> {
|
||||||
availableProviders.indexOf(savedSelection.providerData.apiName)
|
availableProviders.indexOf(savedSelection.providerData.apiName)
|
||||||
.takeIf { it != -1 }
|
.takeIf { it != -1 }
|
||||||
?.plus(baseOptions.size) ?: -1
|
?.plus(baseOptions.size) ?: 0
|
||||||
}
|
}
|
||||||
// Else base option
|
// Else base option
|
||||||
else -> baseOptions.indexOf(savedSelection.openType.name)
|
else -> baseOptions.indexOf(savedSelection.openType.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
activity?.showBottomDialog(
|
this.showBottomDialog(
|
||||||
items,
|
items,
|
||||||
selectedIndex,
|
selectedIndex,
|
||||||
"Open with",
|
"Open with",
|
||||||
|
@ -164,7 +181,7 @@ class LibraryFragment : Fragment() {
|
||||||
|
|
||||||
provider_selector?.setOnClickListener {
|
provider_selector?.setOnClickListener {
|
||||||
val syncName = libraryViewModel.currentSyncApi?.syncIdName ?: return@setOnClickListener
|
val syncName = libraryViewModel.currentSyncApi?.syncIdName ?: return@setOnClickListener
|
||||||
showPluginSelectionDialog(syncName.name, syncName)
|
activity?.showPluginSelectionDialog(syncName.name, syncName)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewpager?.setPageTransformer(LibraryScrollTransformer())
|
viewpager?.setPageTransformer(LibraryScrollTransformer())
|
||||||
|
@ -176,25 +193,55 @@ class LibraryFragment : Fragment() {
|
||||||
sort_fab?.extend()
|
sort_fab?.extend()
|
||||||
}
|
}
|
||||||
}) callback@{ searchClickCallback ->
|
}) callback@{ searchClickCallback ->
|
||||||
|
|
||||||
// To prevent future accidents
|
// To prevent future accidents
|
||||||
debugAssert({
|
debugAssert({
|
||||||
searchClickCallback.card !is SyncAPI.LibraryItem
|
searchClickCallback.card !is SyncAPI.LibraryItem
|
||||||
}, {
|
}, {
|
||||||
"searchClickCallback ${searchClickCallback.card} is not a LibraryItem"
|
"searchClickCallback ${searchClickCallback.card} is not a LibraryItem"
|
||||||
})
|
})
|
||||||
val syncId = (searchClickCallback.card as SyncAPI.LibraryItem).syncId
|
|
||||||
|
|
||||||
println("SEARCH CLICK $searchClickCallback")
|
val syncId = (searchClickCallback.card as SyncAPI.LibraryItem).syncId
|
||||||
when (searchClickCallback.action) {
|
|
||||||
SEARCH_ACTION_SHOW_METADATA -> {
|
|
||||||
val syncName =
|
val syncName =
|
||||||
libraryViewModel.currentSyncApi?.syncIdName ?: return@callback
|
libraryViewModel.currentSyncApi?.syncIdName ?: return@callback
|
||||||
showPluginSelectionDialog(syncId, syncName)
|
|
||||||
|
when (searchClickCallback.action) {
|
||||||
|
SEARCH_ACTION_SHOW_METADATA -> {
|
||||||
|
activity?.showPluginSelectionDialog(
|
||||||
|
syncId,
|
||||||
|
syncName,
|
||||||
|
searchClickCallback.card.apiName
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
SEARCH_ACTION_LOAD -> {
|
SEARCH_ACTION_LOAD -> {
|
||||||
val savedSelection = getKey<LibraryOpener>(LIBRARY_FOLDER, syncId)
|
// This basically first selects the individual opener and if that is default then
|
||||||
activity?.loadSearchResult(searchClickCallback.card)
|
// selects the whole list opener
|
||||||
|
val savedListSelection =
|
||||||
|
getKey<LibraryOpener>(LIBRARY_FOLDER, syncName.name)
|
||||||
|
val savedSelection = getKey<LibraryOpener>(LIBRARY_FOLDER, syncId).takeIf {
|
||||||
|
it?.openType != LibraryOpenerType.Default
|
||||||
|
} ?: savedListSelection
|
||||||
|
|
||||||
|
when (savedSelection?.openType) {
|
||||||
|
null, LibraryOpenerType.Default -> {
|
||||||
|
// Prevents opening MAL/AniList as a provider
|
||||||
|
if (APIHolder.getApiFromNameNull(searchClickCallback.card.apiName) != null) {
|
||||||
|
activity?.loadSearchResult(
|
||||||
|
searchClickCallback.card
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LibraryOpenerType.None -> {}
|
||||||
|
LibraryOpenerType.Provider ->
|
||||||
|
savedSelection.providerData?.apiName?.let { apiName ->
|
||||||
|
activity?.loadResult(
|
||||||
|
searchClickCallback.card.url,
|
||||||
|
apiName,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
LibraryOpenerType.Browser ->
|
||||||
|
openBrowser(searchClickCallback.card.url)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -457,7 +457,7 @@ object AppUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun AppCompatActivity.loadResult(
|
fun Activity.loadResult(
|
||||||
url: String,
|
url: String,
|
||||||
apiName: String,
|
apiName: String,
|
||||||
startAction: Int = 0,
|
startAction: Int = 0,
|
||||||
|
|
|
@ -111,6 +111,7 @@
|
||||||
<string name="result_tags">Genres</string>
|
<string name="result_tags">Genres</string>
|
||||||
<string name="result_share">Share</string>
|
<string name="result_share">Share</string>
|
||||||
<string name="result_open_in_browser">Open In Browser</string>
|
<string name="result_open_in_browser">Open In Browser</string>
|
||||||
|
<string name="browser">Browser</string>
|
||||||
<string name="skip_loading">Skip Loading</string>
|
<string name="skip_loading">Skip Loading</string>
|
||||||
<string name="loading">Loading…</string>
|
<string name="loading">Loading…</string>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue