mirror of
https://github.com/recloudstream/cloudstream-extensions.git
synced 2024-08-15 03:03:54 +00:00
Nginx settings testing
This commit is contained in:
parent
9bd5bc00df
commit
81995a860b
7 changed files with 276 additions and 4 deletions
|
@ -1,3 +1,9 @@
|
|||
dependencies {
|
||||
implementation("androidx.legacy:legacy-support-v4:1.0.0")
|
||||
implementation("com.google.android.material:material:1.4.0")
|
||||
implementation("androidx.lifecycle:lifecycle-extensions:2.2.0")
|
||||
}
|
||||
|
||||
// use an integer for version numbers
|
||||
version = 1
|
||||
|
||||
|
@ -22,5 +28,5 @@ cloudstream {
|
|||
"TvSeries",
|
||||
"Movie",
|
||||
)
|
||||
|
||||
requiresResources = true
|
||||
}
|
62
NginxProvider/src/main/kotlin/com/lagradost/NginxApi.kt
Normal file
62
NginxProvider/src/main/kotlin/com/lagradost/NginxApi.kt
Normal file
|
@ -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.AccountManager
|
||||
import com.lagradost.cloudstream3.syncproviders.AuthAPI
|
||||
import com.lagradost.cloudstream3.syncproviders.InAppAuthAPI
|
||||
import com.lagradost.cloudstream3.syncproviders.InAppAuthAPIManager
|
||||
|
||||
class NginxApi(index: Int) : InAppAuthAPIManager(index) {
|
||||
override val name = "Nginx"
|
||||
override val idPrefix = "nginx"
|
||||
override val icon = R.drawable.nginx
|
||||
override val requiresUsername = true
|
||||
override val requiresPassword = true
|
||||
override val requiresServer = true
|
||||
override val createAccountUrl = "https://www.sarlays.com/use-nginx-with-cloudstream/"
|
||||
|
||||
companion object {
|
||||
const val NGINX_USER_KEY: String = "nginx_user"
|
||||
}
|
||||
|
||||
override fun getLatestLoginData(): InAppAuthAPI.LoginData? {
|
||||
return getKey(accountId, NGINX_USER_KEY)
|
||||
}
|
||||
|
||||
override fun loginInfo(): AuthAPI.LoginInfo? {
|
||||
val data = getLatestLoginData() ?: return null
|
||||
return AuthAPI.LoginInfo(name = data.username ?: data.server, accountIndex = accountIndex)
|
||||
}
|
||||
|
||||
override suspend fun login(data: InAppAuthAPI.LoginData): Boolean {
|
||||
if (data.server.isNullOrBlank()) return false // we require a server
|
||||
switchToNewAccount()
|
||||
setKey(accountId, NGINX_USER_KEY, data)
|
||||
registerAccount()
|
||||
initialize()
|
||||
AccountManager.inAppAuths
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun logOut() {
|
||||
removeAccountKeys()
|
||||
initializeData()
|
||||
}
|
||||
|
||||
private fun initializeData() {
|
||||
val data = getLatestLoginData() ?: run {
|
||||
NginxProvider.overrideUrl = null
|
||||
NginxProvider.loginCredentials = null
|
||||
return
|
||||
}
|
||||
NginxProvider.overrideUrl = data.server?.removeSuffix("/")
|
||||
NginxProvider.loginCredentials = "${data.username ?: ""}:${data.password ?: ""}"
|
||||
}
|
||||
|
||||
override suspend fun initialize() {
|
||||
initializeData()
|
||||
}
|
||||
}
|
|
@ -1,14 +1,33 @@
|
|||
|
||||
package com.lagradost
|
||||
|
||||
import com.lagradost.cloudstream3.plugins.CloudstreamPlugin
|
||||
import com.lagradost.cloudstream3.plugins.Plugin
|
||||
import android.content.Context
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.context
|
||||
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.getActivity
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsAccount
|
||||
|
||||
@CloudstreamPlugin
|
||||
class NginxProviderPlugin : Plugin() {
|
||||
val nginxApi = NginxApi(0)
|
||||
|
||||
override fun load(context: Context) {
|
||||
// All providers should be added in this manner. Please don't edit the providers list directly.
|
||||
registerMainAPI(NginxProvider())
|
||||
ioSafe {
|
||||
nginxApi.initialize()
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
this.openSettings = {
|
||||
val activity = context as? AppCompatActivity
|
||||
if (activity != null) {
|
||||
val frag = NginxSettingsFragment(this, nginxApi)
|
||||
frag.show(activity.supportFragmentManager, nginxApi.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.lagradost
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.openBrowser
|
||||
import com.lagradost.cloudstream3.R.string.*
|
||||
import com.lagradost.cloudstream3.plugins.Plugin
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsAccount.Companion.showLoginInfo
|
||||
import com.lagradost.cloudstream3.ui.settings.SettingsAccount.Companion.addAccount
|
||||
|
||||
class NginxSettingsFragment(private val plugin: Plugin, val nginxApi: NginxApi) :
|
||||
BottomSheetDialogFragment() {
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
// Inflate the layout for this fragment
|
||||
val id = plugin.resources!!.getIdentifier("nginx_settings", "layout", "com.lagradost")
|
||||
val layout = plugin.resources!!.getLayout(id)
|
||||
return inflater.inflate(layout, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val infoView = view.findViewById<LinearLayout>(R.id.nginx_info)
|
||||
val infoTextView = view.findViewById<TextView>(R.id.info_main_text)
|
||||
val infoSubTextView = view.findViewById<TextView>(R.id.info_sub_text)
|
||||
|
||||
infoTextView.text = getString(nginx_info_title)
|
||||
infoSubTextView.text = getString(nginx_info_summary)
|
||||
|
||||
val loginView = view.findViewById<LinearLayout>(R.id.nginx_login)
|
||||
val loginTextView = view.findViewById<TextView>(R.id.main_text)
|
||||
|
||||
// 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("https://www.sarlays.com/use-nginx-with-cloudstream/")
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
loginTextView.text = getString(login_format).format(nginxApi.name, getString(account))
|
||||
loginView.setOnClickListener(object : View.OnClickListener {
|
||||
override fun onClick(v: View?) {
|
||||
val info = nginxApi.loginInfo()
|
||||
if (info != null) {
|
||||
showLoginInfo(activity, nginxApi, info)
|
||||
} else {
|
||||
addAccount(activity, nginxApi)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
12
NginxProvider/src/main/res/drawable/nginx.xml
Normal file
12
NginxProvider/src/main/res/drawable/nginx.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:name="vector"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="283"
|
||||
android:viewportHeight="283">
|
||||
<path
|
||||
android:name="path"
|
||||
android:pathData="M 253.41 62.61 L 154.22 5.34 C 150.42 3.146 146.108 1.991 141.72 1.991 C 137.332 1.991 133.02 3.146 129.22 5.34 L 30 62.61 C 26.202 64.807 23.049 67.966 20.858 71.768 C 18.668 75.57 17.516 79.882 17.52 84.27 L 17.52 198.8 C 17.516 203.188 18.668 207.5 20.858 211.302 C 23.049 215.104 26.202 218.263 30 220.46 L 129.19 277.72 C 132.99 279.914 137.302 281.069 141.69 281.069 C 146.078 281.069 150.39 279.914 154.19 277.72 L 253.38 220.46 C 257.183 218.266 260.343 215.109 262.539 211.307 C 264.735 207.505 265.891 203.191 265.89 198.8 L 265.89 84.27 C 265.894 79.882 264.742 75.57 262.552 71.768 C 260.361 67.966 257.208 64.807 253.41 62.61 Z M 203.28 185.33 Q 203.28 200.61 187.03 200.61 C 184.56 200.637 182.098 200.331 179.71 199.7 C 177.529 199.086 175.467 198.109 173.61 196.81 C 171.687 195.463 169.917 193.91 168.33 192.18 Q 165.9 189.52 163.45 186.76 L 106.86 119.16 L 106.86 187.16 Q 106.86 193.81 102.86 197.22 C 100.004 199.558 96.388 200.768 92.7 200.62 Q 86.3 200.62 82.44 197.18 Q 78.58 193.74 78.58 187.18 L 78.58 97.63 C 78.438 94.563 78.992 91.503 80.2 88.68 C 81.685 86.126 83.925 84.093 86.61 82.86 C 89.603 81.356 92.911 80.585 96.26 80.61 C 98.633 80.541 101.001 80.879 103.26 81.61 C 105.096 82.243 106.813 83.179 108.34 84.38 C 109.979 85.728 111.477 87.239 112.81 88.89 C 114.33 90.74 115.91 92.66 117.53 94.67 L 175.53 163.06 L 175.53 94.06 Q 175.53 87.34 179.24 83.97 Q 182.95 80.6 189.24 80.61 C 193.57 80.61 197 81.73 199.5 83.97 C 202 86.21 203.26 89.58 203.26 94.06 Z"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeWidth="1" />
|
||||
</vector>
|
17
NginxProvider/src/main/res/drawable/nginx_question.xml
Normal file
17
NginxProvider/src/main/res/drawable/nginx_question.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:name="vector"
|
||||
android:width="35dp"
|
||||
android:height="26dp"
|
||||
android:viewportWidth="379"
|
||||
android:viewportHeight="279">
|
||||
<path
|
||||
android:name="path"
|
||||
android:pathData="M 235.89 60.62 L 136.7 3.35 C 132.9 1.156 128.588 0.001 124.2 0.001 C 119.812 0.001 115.5 1.156 111.7 3.35 L 12.48 60.62 C 8.682 62.817 5.529 65.976 3.338 69.778 C 1.148 73.58 -0.004 77.892 0 82.28 L 0 196.81 C -0.004 201.198 1.148 205.51 3.338 209.312 C 5.529 213.114 8.682 216.273 12.48 218.47 L 111.67 275.73 C 115.47 277.924 119.782 279.079 124.17 279.079 C 128.558 279.079 132.87 277.924 136.67 275.73 L 235.86 218.47 C 239.663 216.276 242.823 213.119 245.019 209.317 C 247.215 205.515 248.371 201.201 248.37 196.81 L 248.37 82.28 C 248.374 77.892 247.222 73.58 245.032 69.778 C 242.841 65.976 239.688 62.817 235.89 60.62 Z M 185.76 183.34 Q 185.76 198.62 169.51 198.62 C 167.04 198.647 164.578 198.341 162.19 197.71 C 160.009 197.096 157.947 196.119 156.09 194.82 C 154.167 193.473 152.397 191.92 150.81 190.19 Q 148.38 187.53 145.93 184.77 L 89.34 117.17 L 89.34 185.17 Q 89.34 191.82 85.34 195.23 C 82.484 197.568 78.868 198.778 75.18 198.63 Q 68.78 198.63 64.92 195.19 Q 61.06 191.75 61.06 185.19 L 61.06 95.64 C 60.918 92.573 61.472 89.513 62.68 86.69 C 64.165 84.136 66.405 82.103 69.09 80.87 C 72.083 79.366 75.391 78.595 78.74 78.62 C 81.113 78.551 83.481 78.889 85.74 79.62 C 87.576 80.253 89.293 81.189 90.82 82.39 C 92.459 83.738 93.957 85.249 95.29 86.9 C 96.81 88.75 98.39 90.67 100.01 92.68 L 158.01 161.07 L 158.01 92.07 Q 158.01 85.35 161.72 81.98 Q 165.43 78.61 171.72 78.62 C 176.05 78.62 179.48 79.74 181.98 81.98 C 184.48 84.22 185.74 87.59 185.74 92.07 Z"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeWidth="1" />
|
||||
<path
|
||||
android:name="path_1"
|
||||
android:pathData="M 312.84 143.37 C 320.84 128.98 336.13 120.49 345.04 107.75 C 354.48 94.4 349.18 69.45 322.48 69.45 C 304.98 69.45 296.39 82.7 292.77 93.67 L 265.94 82.39 C 273.29 60.39 293.27 41.39 322.37 41.39 C 346.69 41.39 363.37 52.47 371.85 66.34 C 379.1 78.25 383.34 100.51 372.16 117.07 C 359.74 135.39 347.83 140.98 341.41 152.79 C 338.83 157.55 337.79 160.65 337.79 175.98 L 307.87 175.98 C 307.77 167.9 306.53 154.75 312.84 143.37 Z M 343.17 217.37 C 343.175 222.063 341.584 226.62 338.661 230.291 C 335.737 233.962 331.651 236.533 327.077 237.579 C 322.502 238.625 317.705 238.086 313.477 236.05 C 309.249 234.015 305.835 230.601 303.8 226.373 C 301.764 222.145 301.225 217.348 302.271 212.773 C 303.317 208.199 305.888 204.113 309.559 201.189 C 313.23 198.266 317.787 196.675 322.48 196.68 C 327.963 196.698 333.221 198.888 337.097 202.767 C 340.972 206.646 343.157 211.907 343.17 217.39 Z"
|
||||
android:fillColor="#ffffff"
|
||||
android:strokeWidth="1" />
|
||||
</vector>
|
96
NginxProvider/src/main/res/layout/nginx_settings.xml
Normal file
96
NginxProvider/src/main/res/layout/nginx_settings.xml
Normal file
|
@ -0,0 +1,96 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/settings_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/nginx_login"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="20dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/nginx" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- <LinearLayout-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="match_parent"-->
|
||||
<!-- android:orientation="horizontal">-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/main_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp" />
|
||||
<!-- </LinearLayout>-->
|
||||
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/sub_text"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:text="@string/nginx_info_summary"-->
|
||||
<!-- android:textSize="12sp" />-->
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/nginx_info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="20dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/entry_icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/nginx_question" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/info_main_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/info_sub_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in a new issue