forked from recloudstream/cloudstream
fix chip tint and make adding repos by url easier
This commit is contained in:
parent
d349190238
commit
7272dc67b7
3 changed files with 43 additions and 30 deletions
|
@ -70,6 +70,28 @@ object RepositoryManager {
|
||||||
getKey("PREBUILT_REPOSITORIES") ?: emptyArray()
|
getKey("PREBUILT_REPOSITORIES") ?: emptyArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun parseRepoUrl(url: String): String? {
|
||||||
|
val fixedUrl = url.trim()
|
||||||
|
return if (fixedUrl.contains("^https?://".toRegex())) {
|
||||||
|
fixedUrl
|
||||||
|
} else if (fixedUrl.contains("^(cloudstreamrepo://)|(https://cs\\.repo/)".toRegex())) {
|
||||||
|
fixedUrl.replace("^(cloudstreamrepo://)|(https://cs\\.repo/)".toRegex(), "").let {
|
||||||
|
return@let if (!it.contains("^https?://".toRegex()))
|
||||||
|
"https://${it}"
|
||||||
|
else fixedUrl
|
||||||
|
}
|
||||||
|
} else if (fixedUrl.matches("^[a-zA-Z0-9!_-]+$".toRegex())) {
|
||||||
|
suspendSafeApiCall {
|
||||||
|
app.get("https://l.cloudstream.cf/${fixedUrl}").let {
|
||||||
|
return@let if (it.isSuccessful && !it.url.startsWith("https://cutt.ly/branded-domains")) it.url
|
||||||
|
else app.get("https://cutt.ly/${fixedUrl}").let let2@{ it2 ->
|
||||||
|
return@let2 if (it2.isSuccessful) it2.url else null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else null
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun parseRepository(url: String): Repository? {
|
suspend fun parseRepository(url: String): Repository? {
|
||||||
return suspendSafeApiCall {
|
return suspendSafeApiCall {
|
||||||
// Take manifestVersion and such into account later
|
// Take manifestVersion and such into account later
|
||||||
|
|
|
@ -33,8 +33,6 @@ import com.lagradost.cloudstream3.widget.LinearRecycleViewLayoutManager
|
||||||
import kotlinx.android.synthetic.main.add_repo_input.*
|
import kotlinx.android.synthetic.main.add_repo_input.*
|
||||||
import kotlinx.android.synthetic.main.fragment_extensions.*
|
import kotlinx.android.synthetic.main.fragment_extensions.*
|
||||||
|
|
||||||
const val PUBLIC_REPOSITORIES_LIST = "https://recloudstream.github.io/repos/"
|
|
||||||
|
|
||||||
class ExtensionsFragment : Fragment() {
|
class ExtensionsFragment : Fragment() {
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
|
@ -186,15 +184,7 @@ class ExtensionsFragment : Fragment() {
|
||||||
(activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager?)?.primaryClip?.getItemAt(
|
(activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager?)?.primaryClip?.getItemAt(
|
||||||
0
|
0
|
||||||
)?.text?.toString()?.let { copy ->
|
)?.text?.toString()?.let { copy ->
|
||||||
// Fix our own repo links and only paste the text if it's a link.
|
dialog.repo_url_input?.setText(copy)
|
||||||
if (copy.startsWith("http")) {
|
|
||||||
val fixedUrl = if (copy.startsWith("https://cs.repo")) {
|
|
||||||
"https://" + copy.substringAfter("?")
|
|
||||||
} else {
|
|
||||||
copy
|
|
||||||
}
|
|
||||||
dialog.repo_url_input?.setText(fixedUrl)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// dialog.list_repositories?.setOnClickListener {
|
// dialog.list_repositories?.setOnClickListener {
|
||||||
|
@ -206,13 +196,12 @@ class ExtensionsFragment : Fragment() {
|
||||||
// dialog.text2?.text = provider.name
|
// dialog.text2?.text = provider.name
|
||||||
dialog.apply_btt?.setOnClickListener secondListener@{
|
dialog.apply_btt?.setOnClickListener secondListener@{
|
||||||
val name = dialog.repo_name_input?.text?.toString()
|
val name = dialog.repo_name_input?.text?.toString()
|
||||||
|
ioSafe {
|
||||||
val url = dialog.repo_url_input?.text?.toString()
|
val url = dialog.repo_url_input?.text?.toString()
|
||||||
|
?.let { it1 -> RepositoryManager.parseRepoUrl(it1) }
|
||||||
if (url.isNullOrBlank()) {
|
if (url.isNullOrBlank()) {
|
||||||
showToast(activity, R.string.error_invalid_data, Toast.LENGTH_SHORT)
|
showToast(activity, R.string.error_invalid_data, Toast.LENGTH_SHORT)
|
||||||
return@secondListener
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
ioSafe {
|
|
||||||
val fixedName = if (!name.isNullOrBlank()) name
|
val fixedName = if (!name.isNullOrBlank()) name
|
||||||
else RepositoryManager.parseRepository(url)?.name ?: "No name"
|
else RepositoryManager.parseRepository(url)?.name ?: "No name"
|
||||||
|
|
||||||
|
@ -222,6 +211,7 @@ class ExtensionsFragment : Fragment() {
|
||||||
extensionViewModel.loadRepositories()
|
extensionViewModel.loadRepositories()
|
||||||
this@ExtensionsFragment.activity?.downloadAllPluginsDialog(url, fixedName)
|
this@ExtensionsFragment.activity?.downloadAllPluginsDialog(url, fixedName)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
dialog.dismissSafe(activity)
|
dialog.dismissSafe(activity)
|
||||||
}
|
}
|
||||||
dialog.cancel_btt?.setOnClickListener {
|
dialog.cancel_btt?.setOnClickListener {
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
<item name="chipStrokeColor">@color/transparent</item>
|
<item name="chipStrokeColor">@color/transparent</item>
|
||||||
<item name="textColor">@color/chip_color_text</item>
|
<item name="textColor">@color/chip_color_text</item>
|
||||||
<item name="android:textColor">@color/chip_color_text</item>
|
<item name="android:textColor">@color/chip_color_text</item>
|
||||||
|
<item name="checkedIconTint">@color/chip_color_text</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="AmoledMode">
|
<style name="AmoledMode">
|
||||||
|
@ -137,13 +138,13 @@
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="OverlayPrimaryColorMonetTwo">
|
<style name="OverlayPrimaryColorMonetTwo">
|
||||||
<item name="colorPrimary">@color/material_dynamic_tertiary80</item>
|
<item name="colorPrimary">@color/material_dynamic_secondary80</item>
|
||||||
<item name="android:colorPrimary">@color/material_dynamic_tertiary80</item>
|
<item name="android:colorPrimary">@color/material_dynamic_secondary80</item>
|
||||||
<item name="colorPrimaryDark">@color/material_dynamic_tertiary30</item>
|
<item name="colorPrimaryDark">@color/material_dynamic_secondary30</item>
|
||||||
<item name="colorAccent">@color/material_dynamic_tertiary80</item>
|
<item name="colorAccent">@color/material_dynamic_secondary80</item>
|
||||||
<item name="colorOnPrimary">@color/material_dynamic_tertiary20</item>
|
<item name="colorOnPrimary">@color/material_dynamic_secondary20</item>
|
||||||
<!-- Needed for leanback fuckery -->
|
<!-- Needed for leanback fuckery -->
|
||||||
<item name="android:colorAccent">@color/material_dynamic_tertiary30</item>
|
<item name="android:colorAccent">@color/material_dynamic_secondary30</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="OverlayPrimaryColorBlue">
|
<style name="OverlayPrimaryColorBlue">
|
||||||
|
|
Loading…
Reference in a new issue