From a4876050bcdfb2f18c44a6cd5a4f1948c62cc0a4 Mon Sep 17 00:00:00 2001 From: Eddy Date: Sat, 5 Nov 2022 20:44:29 +0100 Subject: [PATCH] New dialog to add tags! Now it is possible to take into account content from other countries and other categories --- .../kotlin/com/lagradost/MacIPTVProvider.kt | 10 ++- .../com/lagradost/MacIPTVProviderPlugin.kt | 4 +- .../com/lagradost/MacIptvSettingsFragment.kt | 83 +++++++++++++---- .../kotlin/com/lagradost/TagsMacIptvAPI.kt | 62 +++++++++++++ .../src/main/res/drawable/iptvbox.xml | 15 ++++ .../src/main/res/drawable/nginx.xml | 12 --- .../src/main/res/drawable/nginx_question.xml | 17 ---- .../src/main/res/drawable/tagsiptvbox.xml | 15 ++++ ...ginx_settings.xml => iptvbox_settings.xml} | 88 +++++++++++++++---- .../src/main/res/values-fr/strings.xml | 8 +- .../src/main/res/values/strings.xml | 6 +- 11 files changed, 250 insertions(+), 70 deletions(-) create mode 100644 MaciptvProvider/src/main/kotlin/com/lagradost/TagsMacIptvAPI.kt create mode 100644 MaciptvProvider/src/main/res/drawable/iptvbox.xml delete mode 100644 MaciptvProvider/src/main/res/drawable/nginx.xml delete mode 100644 MaciptvProvider/src/main/res/drawable/nginx_question.xml create mode 100644 MaciptvProvider/src/main/res/drawable/tagsiptvbox.xml rename MaciptvProvider/src/main/res/layout/{nginx_settings.xml => iptvbox_settings.xml} (55%) diff --git a/MaciptvProvider/src/main/kotlin/com/lagradost/MacIPTVProvider.kt b/MaciptvProvider/src/main/kotlin/com/lagradost/MacIPTVProvider.kt index 1077f49..d5b54ad 100644 --- a/MaciptvProvider/src/main/kotlin/com/lagradost/MacIPTVProvider.kt +++ b/MaciptvProvider/src/main/kotlin/com/lagradost/MacIPTVProvider.kt @@ -58,6 +58,9 @@ class MacIPTVProvider(override var lang: String) : MainAPI() { } private suspend fun getAuthHeader() { + tags = tags ?: "" + if (tags?.uppercase()?.trim() == "NONE" || tags?.isBlank() == true) tags = lang + tags = tags?.uppercase() oldAthMac = loginMac oldAthUrl = overrideUrl mainUrl = overrideUrl.toString() @@ -539,7 +542,8 @@ class MacIPTVProvider(override var lang: String) : MainAPI() { if (idGenre!!.contains("""\d""".toRegex()) && (categoryTitle.uppercase() .contains(rgxcodeCountry) || categoryTitle.isContainsTargetCountry(provider) - ) + ) || categoryTitle.uppercase() + .contains(findKeyWord(tags.toString())) ) { val itr = channels.iterator() while (itr.hasNext()) { @@ -585,7 +589,8 @@ class MacIPTVProvider(override var lang: String) : MainAPI() { if (categoryTitle.uppercase() .contains(rgxcodeCountry) || categoryTitle.isContainsTargetCountry( provider - ) + ) || categoryTitle.uppercase() + .contains(findKeyWord(tags.toString())) ) { flag = getFlag(categoryTitle) val nameGenre = if (firstCat) { @@ -648,6 +653,7 @@ class MacIPTVProvider(override var lang: String) : MainAPI() { var companionName: String? = null var loginMac: String? = null var overrideUrl: String? = null + var tags: String? = null private var oldAthMac: String? = null private var oldAthUrl: String? = null private var headerMac = mutableMapOf() diff --git a/MaciptvProvider/src/main/kotlin/com/lagradost/MacIPTVProviderPlugin.kt b/MaciptvProvider/src/main/kotlin/com/lagradost/MacIPTVProviderPlugin.kt index b870dd6..653bad0 100644 --- a/MaciptvProvider/src/main/kotlin/com/lagradost/MacIPTVProviderPlugin.kt +++ b/MaciptvProvider/src/main/kotlin/com/lagradost/MacIPTVProviderPlugin.kt @@ -13,6 +13,7 @@ import com.lagradost.cloudstream3.ui.settings.SettingsAccount @CloudstreamPlugin class MacIPTVProviderPlugin : Plugin() { val iptvboxApi = MacIptvAPI(0) + val tagsiptvboxApi = TagsMacIptvAPI(1) override fun load(context: Context) { // All providers should be added in this manner. Please don't edit the providers list directly. @@ -22,6 +23,7 @@ class MacIPTVProviderPlugin : Plugin() { registerMainAPI(MacIPTVProvider("ar")) ioSafe { iptvboxApi.initialize() + tagsiptvboxApi.initialize() } } @@ -29,7 +31,7 @@ class MacIPTVProviderPlugin : Plugin() { this.openSettings = { val activity = it as? AppCompatActivity if (activity != null) { - val frag = MacIptvSettingsFragment(this, iptvboxApi) + val frag = MacIptvSettingsFragment(this, iptvboxApi,tagsiptvboxApi) frag.show(activity.supportFragmentManager, iptvboxApi.name) } } diff --git a/MaciptvProvider/src/main/kotlin/com/lagradost/MacIptvSettingsFragment.kt b/MaciptvProvider/src/main/kotlin/com/lagradost/MacIptvSettingsFragment.kt index 97df0e4..a24b386 100644 --- a/MaciptvProvider/src/main/kotlin/com/lagradost/MacIptvSettingsFragment.kt +++ b/MaciptvProvider/src/main/kotlin/com/lagradost/MacIptvSettingsFragment.kt @@ -12,14 +12,17 @@ import android.widget.TextView import androidx.core.content.res.ResourcesCompat import com.lagradost.cloudstream3.R import com.google.android.material.bottomsheet.BottomSheetDialogFragment -import com.lagradost.cloudstream3.AcraApplication.Companion.openBrowser import com.lagradost.cloudstream3.plugins.Plugin import com.lagradost.cloudstream3.ui.settings.SettingsAccount.Companion.showLoginInfo import com.lagradost.cloudstream3.ui.settings.SettingsAccount.Companion.addAccount import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute -class MacIptvSettingsFragment(private val plugin: Plugin, val maciptvAPI: MacIptvAPI) : +class MacIptvSettingsFragment( + private val plugin: Plugin, + val maciptvAPI: MacIptvAPI, + val tagsmaciptvAPI: TagsMacIptvAPI +) : BottomSheetDialogFragment() { override fun onCreateView( @@ -27,7 +30,11 @@ class MacIptvSettingsFragment(private val plugin: Plugin, val maciptvAPI: MacIpt savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment - val id = plugin.resources!!.getIdentifier("nginx_settings", "layout", BuildConfig.LIBRARY_PACKAGE_NAME) + val id = plugin.resources!!.getIdentifier( + "iptvbox_settings", + "layout", + BuildConfig.LIBRARY_PACKAGE_NAME + ) val layout = plugin.resources!!.getLayout(id) return inflater.inflate(layout, container, false) } @@ -38,46 +45,48 @@ class MacIptvSettingsFragment(private val plugin: Plugin, val maciptvAPI: MacIpt } private fun getDrawable(name: String): Drawable? { - val id = plugin.resources!!.getIdentifier(name, "drawable", BuildConfig.LIBRARY_PACKAGE_NAME) + val id = + plugin.resources!!.getIdentifier(name, "drawable", BuildConfig.LIBRARY_PACKAGE_NAME) return ResourcesCompat.getDrawable(plugin.resources!!, id, null) } private fun getString(name: String): String? { - val id = plugin.resources!!.getIdentifier(name, "string", BuildConfig.LIBRARY_PACKAGE_NAME) + val id = + plugin.resources!!.getIdentifier(name, "string", BuildConfig.LIBRARY_PACKAGE_NAME) return plugin.resources!!.getString(id) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val infoView = view.findView("nginx_info") + val infoView = view.findView("iptvbox_info") val infoTextView = view.findView("info_main_text") val infoSubTextView = view.findView("info_sub_text") - val infoImageView = view.findView("nginx_info_imageview") + //val infoImageView = view.findView("iptvbox_info_imageview") - infoTextView.text = getString("nginx_info_title") ?: "MacIPTV" - infoSubTextView.text = getString("nginx_info_summary") ?: "" - infoImageView.setImageDrawable(getDrawable("nginx_question")) + infoTextView.text = getString("iptvbox_info_title") ?: "MacIPTV" + infoSubTextView.text = getString("iptvbox_info_summary") ?: "" + /* infoImageView.setImageDrawable(getDrawable("iptvbox_question")) infoImageView.imageTintList = - ColorStateList.valueOf(view.context.colorFromAttribute(R.attr.white)) + ColorStateList.valueOf(view.context.colorFromAttribute(R.attr.white))*/ - val loginView = view.findView("nginx_login") + val loginView = view.findView("iptvbox_login") val loginTextView = view.findView("main_text") - val loginImageView = view.findView("nginx_login_imageview") - loginImageView.setImageDrawable(getDrawable("nginx")) + val loginImageView = view.findView("iptvbox_login_imageview") + loginImageView.setImageDrawable(getDrawable("iptvbox")) loginImageView.imageTintList = ColorStateList.valueOf(view.context.colorFromAttribute(R.attr.white)) - // object : View.OnClickListener is required to make it compile because otherwise it used invoke-customs infoView.setOnClickListener(object : View.OnClickListener { override fun onClick(v: View?) { - openBrowser(maciptvAPI.createAccountUrl) + println("It's OK") } }) loginTextView.text = view.context.resources.getString(R.string.login_format).format( maciptvAPI.name, - view.context.resources.getString(R.string.account)) + view.context.resources.getString(R.string.account) + ) loginView.setOnClickListener(object : View.OnClickListener { override fun onClick(v: View?) { @@ -89,5 +98,45 @@ class MacIptvSettingsFragment(private val plugin: Plugin, val maciptvAPI: MacIpt } } }) + + val infoViewTags = view.findView("tags_info") + val infoTextViewTags = view.findView("tagsinfo_main_text") + val infoSubTextViewTags = view.findView("tags_sub_text") + + infoTextViewTags.text = getString("tags_info_title") ?: "MacIPTV" + infoSubTextViewTags.text = getString("tags_info_summary") ?: "" + + + val loginViewTags = view.findView("tags_login") + val loginTextViewTags = view.findView("tagsmain_text") + val loginImageViewTags = view.findView("tagsiptvbox_login_imageview") + + loginImageViewTags.setImageDrawable(getDrawable("tagsiptvbox")) + loginImageViewTags.imageTintList = + ColorStateList.valueOf(view.context.colorFromAttribute(R.attr.white)) + + // object : View.OnClickListener is required to make it compile because otherwise it used invoke-customs + infoViewTags.setOnClickListener(object : View.OnClickListener { + override fun onClick(v: View?) { + println("It's OK") + } + }) + + + loginTextViewTags.text = view.context.resources.getString(R.string.login_format).format( + tagsmaciptvAPI.name, + view.context.resources.getString(R.string.account) + ) + + loginViewTags.setOnClickListener(object : View.OnClickListener { + override fun onClick(v: View?) { + val info = tagsmaciptvAPI.loginInfo() + if (info?.accountIndex != null) { + showLoginInfo(activity, tagsmaciptvAPI, info) + } else { + addAccount(activity, tagsmaciptvAPI) + } + } + }) } } \ No newline at end of file diff --git a/MaciptvProvider/src/main/kotlin/com/lagradost/TagsMacIptvAPI.kt b/MaciptvProvider/src/main/kotlin/com/lagradost/TagsMacIptvAPI.kt new file mode 100644 index 0000000..c7a192c --- /dev/null +++ b/MaciptvProvider/src/main/kotlin/com/lagradost/TagsMacIptvAPI.kt @@ -0,0 +1,62 @@ +package com.lagradost + +import com.lagradost.cloudstream3.AcraApplication.Companion.getKey +import com.lagradost.cloudstream3.AcraApplication.Companion.setKey +import com.lagradost.cloudstream3.R +import com.lagradost.cloudstream3.syncproviders.AuthAPI +import com.lagradost.cloudstream3.syncproviders.InAppAuthAPI +import com.lagradost.cloudstream3.syncproviders.InAppAuthAPIManager + +class TagsMacIptvAPI(index: Int) : InAppAuthAPIManager(index) { + override val name = "Tags" + override val idPrefix = "tagsiptvbox" + override val icon = R.drawable.ic_baseline_extension_24 + override val requiresUsername = false + override val requiresPassword = false + override val requiresServer = true + override val createAccountUrl = "" + + companion object { + const val IPTVBOX_USER_KEY1: String = "tagsiptvbox_user" + } + + override fun getLatestLoginData(): InAppAuthAPI.LoginData? { + return getKey(accountId, IPTVBOX_USER_KEY1) + } + + override fun loginInfo(): AuthAPI.LoginInfo? { + val data = getLatestLoginData() ?: return null + return AuthAPI.LoginInfo( + name = data.server?:"MyTags", + accountIndex = accountIndex + ) + } + + override suspend fun login(data: InAppAuthAPI.LoginData): Boolean { + if (data.server.isNullOrBlank()) return false // we require a tags + switchToNewAccount() + setKey(accountId, IPTVBOX_USER_KEY1, data) + registerAccount() + initialize() + inAppAuths + + return true + } + + override fun logOut() { + removeAccountKeys() + initializeData() + } + + private fun initializeData() { + val data = getLatestLoginData() ?: run { + MacIPTVProvider.tags = null + return + } + MacIPTVProvider.tags = data.server.toString() + } + + override suspend fun initialize() { + initializeData() + } +} \ No newline at end of file diff --git a/MaciptvProvider/src/main/res/drawable/iptvbox.xml b/MaciptvProvider/src/main/res/drawable/iptvbox.xml new file mode 100644 index 0000000..238994b --- /dev/null +++ b/MaciptvProvider/src/main/res/drawable/iptvbox.xml @@ -0,0 +1,15 @@ + + + + + + diff --git a/MaciptvProvider/src/main/res/drawable/nginx.xml b/MaciptvProvider/src/main/res/drawable/nginx.xml deleted file mode 100644 index 1e7d7ac..0000000 --- a/MaciptvProvider/src/main/res/drawable/nginx.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - diff --git a/MaciptvProvider/src/main/res/drawable/nginx_question.xml b/MaciptvProvider/src/main/res/drawable/nginx_question.xml deleted file mode 100644 index 747ffb0..0000000 --- a/MaciptvProvider/src/main/res/drawable/nginx_question.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - diff --git a/MaciptvProvider/src/main/res/drawable/tagsiptvbox.xml b/MaciptvProvider/src/main/res/drawable/tagsiptvbox.xml new file mode 100644 index 0000000..0978243 --- /dev/null +++ b/MaciptvProvider/src/main/res/drawable/tagsiptvbox.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/MaciptvProvider/src/main/res/layout/nginx_settings.xml b/MaciptvProvider/src/main/res/layout/iptvbox_settings.xml similarity index 55% rename from MaciptvProvider/src/main/res/layout/nginx_settings.xml rename to MaciptvProvider/src/main/res/layout/iptvbox_settings.xml index b1c4bd8..8a110bc 100644 --- a/MaciptvProvider/src/main/res/layout/nginx_settings.xml +++ b/MaciptvProvider/src/main/res/layout/iptvbox_settings.xml @@ -8,14 +8,14 @@ android:orientation="vertical"> - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MaciptvProvider/src/main/res/values-fr/strings.xml b/MaciptvProvider/src/main/res/values-fr/strings.xml index 3cd3362..f629260 100644 --- a/MaciptvProvider/src/main/res/values-fr/strings.xml +++ b/MaciptvProvider/src/main/res/values-fr/strings.xml @@ -1,9 +1,11 @@ - C\'est quoi Maciptv ? + C\'est quoi Maciptv ? NomIPTV - Maciptv est un emulateur qui va vous permettre de profiter de vos comptes IPTV. Donner l\'url portail du fournisseur http:\/\/exemple.com\/c\/ et votre mac 00:1A:79:XX:XX:XX comme password123. Pour sélectionner/revenir au compte par défaut, créer un compte avec \'none\' à la place de \'127.0.0.1\' et pas besoin de renseigner les autres infos - Addresse du serveur IPTV + Maciptv est un emulateur qui va vous permettre de profiter de vos comptes IPTV. Donner l\'url portail du fournisseur http:\/\/exemple.com\/c\/ et votre mac 00:1A:79:XX:XX:XX comme password123. Pour sélectionner/revenir au compte par défaut, créer un compte avec \'none\' à la place de \'127.0.0.1\' et pas besoin de renseigner les autres infos + Addresse du serveur IPTV 00:1A:79:XX:XX http:\/\/exemple\-portal.com:8080\/c\/ + Ajoutez d\'autres pays ou catégories + Par défaut vous avez déja le contenu Arabe, Anglais et français. Dans la case \'127.0.0.1\', renseignez vos tags séparés par \| comme par exemple : Sport\|SportS\|vip\|canada\|ca\|brasil\|it\|italia\|france\|fr \ No newline at end of file diff --git a/MaciptvProvider/src/main/res/values/strings.xml b/MaciptvProvider/src/main/res/values/strings.xml index 6c1cc7f..23a0247 100644 --- a/MaciptvProvider/src/main/res/values/strings.xml +++ b/MaciptvProvider/src/main/res/values/strings.xml @@ -1,8 +1,10 @@ - What is Maciptv ? + What is Maciptv ? 00:1A:79:XX:XX http:\/\/exemple\-portal.com:8080\/c\/ MyCoolIPTVname - Maciptv is an extension that will allow you to enjoy your IPTV accounts. Give the provider\'s portal url http:\/\/exemple.com\/c\/ and your mac 00:1A:79:XX:XX as password123. To select/revert to the default account, create an account with \'none\' instead of \'127.0.0.1\' and no need to fill in the other info + Maciptv is an extension that will allow you to enjoy your IPTV accounts. Give the provider\'s portal url http:\/\/exemple.com\/c\/ and your mac 00:1A:79:XX:XX as password123. To select/revert to the default account, create an account with \'none\' instead of \'127.0.0.1\' and no need to fill in the other info + Add other countries or categories + By default you already have Arabic, English and French content. Fill the box \'127.0.0.1\' with your tags separated by \|. For example if you want all the categories that contain the word \'sport\' or \'sports\' and you also want the content from Canada (CA) and Italia (IT) then you can write: sport\|sports\|canada\|ca\|italia\|it \ No newline at end of file