fix chip tint and make adding repos by url easier

This commit is contained in:
Cloudburst 2022-10-31 12:33:09 +01:00
parent d349190238
commit 7272dc67b7
3 changed files with 43 additions and 30 deletions

View File

@ -70,6 +70,28 @@ object RepositoryManager {
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? {
return suspendSafeApiCall {
// Take manifestVersion and such into account later

View File

@ -33,8 +33,6 @@ import com.lagradost.cloudstream3.widget.LinearRecycleViewLayoutManager
import kotlinx.android.synthetic.main.add_repo_input.*
import kotlinx.android.synthetic.main.fragment_extensions.*
const val PUBLIC_REPOSITORIES_LIST = "https://recloudstream.github.io/repos/"
class ExtensionsFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
@ -186,15 +184,7 @@ class ExtensionsFragment : Fragment() {
(activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager?)?.primaryClip?.getItemAt(
0
)?.text?.toString()?.let { copy ->
// Fix our own repo links and only paste the text if it's a link.
if (copy.startsWith("http")) {
val fixedUrl = if (copy.startsWith("https://cs.repo")) {
"https://" + copy.substringAfter("?")
} else {
copy
}
dialog.repo_url_input?.setText(fixedUrl)
}
dialog.repo_url_input?.setText(copy)
}
// dialog.list_repositories?.setOnClickListener {
@ -206,21 +196,21 @@ class ExtensionsFragment : Fragment() {
// dialog.text2?.text = provider.name
dialog.apply_btt?.setOnClickListener secondListener@{
val name = dialog.repo_name_input?.text?.toString()
val url = dialog.repo_url_input?.text?.toString()
if (url.isNullOrBlank()) {
showToast(activity, R.string.error_invalid_data, Toast.LENGTH_SHORT)
return@secondListener
}
ioSafe {
val fixedName = if (!name.isNullOrBlank()) name
else RepositoryManager.parseRepository(url)?.name ?: "No name"
val url = dialog.repo_url_input?.text?.toString()
?.let { it1 -> RepositoryManager.parseRepoUrl(it1) }
if (url.isNullOrBlank()) {
showToast(activity, R.string.error_invalid_data, Toast.LENGTH_SHORT)
} else {
val fixedName = if (!name.isNullOrBlank()) name
else RepositoryManager.parseRepository(url)?.name ?: "No name"
val newRepo = RepositoryData(fixedName, url)
RepositoryManager.addRepository(newRepo)
extensionViewModel.loadStats()
extensionViewModel.loadRepositories()
this@ExtensionsFragment.activity?.downloadAllPluginsDialog(url, fixedName)
val newRepo = RepositoryData(fixedName, url)
RepositoryManager.addRepository(newRepo)
extensionViewModel.loadStats()
extensionViewModel.loadRepositories()
this@ExtensionsFragment.activity?.downloadAllPluginsDialog(url, fixedName)
}
}
dialog.dismissSafe(activity)
}

View File

@ -81,6 +81,7 @@
<item name="chipStrokeColor">@color/transparent</item>
<item name="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 name="AmoledMode">
@ -137,13 +138,13 @@
</style>
<style name="OverlayPrimaryColorMonetTwo">
<item name="colorPrimary">@color/material_dynamic_tertiary80</item>
<item name="android:colorPrimary">@color/material_dynamic_tertiary80</item>
<item name="colorPrimaryDark">@color/material_dynamic_tertiary30</item>
<item name="colorAccent">@color/material_dynamic_tertiary80</item>
<item name="colorOnPrimary">@color/material_dynamic_tertiary20</item>
<item name="colorPrimary">@color/material_dynamic_secondary80</item>
<item name="android:colorPrimary">@color/material_dynamic_secondary80</item>
<item name="colorPrimaryDark">@color/material_dynamic_secondary30</item>
<item name="colorAccent">@color/material_dynamic_secondary80</item>
<item name="colorOnPrimary">@color/material_dynamic_secondary20</item>
<!-- Needed for leanback fuckery -->
<item name="android:colorAccent">@color/material_dynamic_tertiary30</item>
<item name="android:colorAccent">@color/material_dynamic_secondary30</item>
</style>
<style name="OverlayPrimaryColorBlue">