Add reference to public list

This commit is contained in:
Blatzar 2022-08-15 03:31:33 +02:00
parent b2ee957833
commit bbf9f247a9
10 changed files with 135 additions and 31 deletions

View File

@ -83,9 +83,9 @@ import kotlin.concurrent.thread
import kotlin.reflect.KClass import kotlin.reflect.KClass
import com.lagradost.cloudstream3.plugins.PluginManager import com.lagradost.cloudstream3.plugins.PluginManager
import com.lagradost.cloudstream3.plugins.RepositoryManager import com.lagradost.cloudstream3.plugins.RepositoryManager
import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIES
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringRepo import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.appStringRepo
import com.lagradost.cloudstream3.ui.settings.extensions.RepositoryData import com.lagradost.cloudstream3.ui.settings.extensions.RepositoryData
import com.lagradost.cloudstream3.ui.setup.SetupFragmentExtensions
import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.Coroutines.main
import com.lagradost.cloudstream3.utils.Event import com.lagradost.cloudstream3.utils.Event
@ -133,6 +133,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
companion object { companion object {
const val TAG = "MAINACT" const val TAG = "MAINACT"
val afterPluginsLoadedEvent = Event<Boolean>() val afterPluginsLoadedEvent = Event<Boolean>()
val afterRepositoryLoadedEvent = Event<Boolean>()
} }
override fun onColorSelected(dialogId: Int, color: Int) { override fun onColorSelected(dialogId: Int, color: Int) {
@ -347,6 +348,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
Toast.LENGTH_LONG Toast.LENGTH_LONG
) )
} }
afterRepositoryLoadedEvent.invoke(true)
} }
} }
@ -695,9 +697,9 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
// If no plugins bring up extensions screen // If no plugins bring up extensions screen
} else if (PluginManager.getPluginsOnline().isEmpty() } else if (PluginManager.getPluginsOnline().isEmpty()
&& PluginManager.getPluginsLocal().isEmpty() && PluginManager.getPluginsLocal().isEmpty()
&& PREBUILT_REPOSITORIES.isNotEmpty() // && PREBUILT_REPOSITORIES.isNotEmpty()
) { ) {
navController.navigate(R.id.navigation_setup_extensions) navController.navigate(R.id.navigation_setup_extensions, SetupFragmentExtensions.newInstance(false))
} }
} catch (e: Exception) { } catch (e: Exception) {
logError(e) logError(e)

View File

@ -123,11 +123,15 @@ object RepositoryManager {
} }
} }
fun getRepositories(): Array<RepositoryData> {
return getKey(REPOSITORIES_KEY) ?: emptyArray()
}
// Don't want to read before we write in another thread // Don't want to read before we write in another thread
private val repoLock = Mutex() private val repoLock = Mutex()
suspend fun addRepository(repository: RepositoryData) { suspend fun addRepository(repository: RepositoryData) {
repoLock.withLock { repoLock.withLock {
val currentRepos = getKey<Array<RepositoryData>>(REPOSITORIES_KEY) ?: emptyArray() val currentRepos = getRepositories()
// No duplicates // No duplicates
setKey(REPOSITORIES_KEY, (currentRepos + repository).distinctBy { it.url }) setKey(REPOSITORIES_KEY, (currentRepos + repository).distinctBy { it.url })
} }

View File

@ -60,6 +60,7 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.deleteAllResumeStateIds
import com.lagradost.cloudstream3.utils.DataStoreHelper.removeLastWatched import com.lagradost.cloudstream3.utils.DataStoreHelper.removeLastWatched
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultWatchState import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultWatchState
import com.lagradost.cloudstream3.utils.Event import com.lagradost.cloudstream3.utils.Event
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.HOMEPAGE_API import com.lagradost.cloudstream3.utils.HOMEPAGE_API
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showOptionSelectStringRes import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showOptionSelectStringRes
import com.lagradost.cloudstream3.utils.SubtitleHelper.getFlagFromIso import com.lagradost.cloudstream3.utils.SubtitleHelper.getFlagFromIso

View File

@ -14,6 +14,7 @@ import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import com.lagradost.cloudstream3.AcraApplication.Companion.openBrowser
import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.mvvm.Some import com.lagradost.cloudstream3.mvvm.Some
@ -25,9 +26,10 @@ import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.Coroutines.main
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
import kotlinx.android.synthetic.main.add_repo_input.* import kotlinx.android.synthetic.main.add_repo_input.*
import kotlinx.android.synthetic.main.add_repo_input.apply_btt
import kotlinx.android.synthetic.main.add_repo_input.cancel_btt
import kotlinx.android.synthetic.main.fragment_extensions.* import kotlinx.android.synthetic.main.fragment_extensions.*
import kotlinx.android.synthetic.main.fragment_extensions.list_repositories
const val PUBLIC_REPOSITORIES_LIST = "https://recloudstream.github.io/repos/"
class ExtensionsFragment : Fragment() { class ExtensionsFragment : Fragment() {
override fun onCreateView( override fun onCreateView(
@ -98,6 +100,10 @@ class ExtensionsFragment : Fragment() {
(repo_recycler_view?.adapter as? RepoAdapter)?.updateList(it) (repo_recycler_view?.adapter as? RepoAdapter)?.updateList(it)
} }
list_repositories?.setOnClickListener {
openBrowser(PUBLIC_REPOSITORIES_LIST)
}
observe(extensionViewModel.pluginStats) { observe(extensionViewModel.pluginStats) {
when (it) { when (it) {
is Some.Success -> { is Some.Success -> {
@ -154,6 +160,9 @@ class ExtensionsFragment : Fragment() {
dialog.repo_url_input?.setText(fixedUrl) dialog.repo_url_input?.setText(fixedUrl)
} }
} }
dialog.list_repositories?.setOnClickListener {
openBrowser(PUBLIC_REPOSITORIES_LIST)
}
// dialog.text2?.text = provider.name // dialog.text2?.text = provider.name
dialog.apply_btt?.setOnClickListener secondListener@{ dialog.apply_btt?.setOnClickListener secondListener@{

View File

@ -7,8 +7,12 @@ import android.view.ViewGroup
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import com.lagradost.cloudstream3.AcraApplication.Companion.openBrowser
import com.lagradost.cloudstream3.MainActivity.Companion.afterRepositoryLoadedEvent
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.plugins.RepositoryManager
import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIES import com.lagradost.cloudstream3.plugins.RepositoryManager.PREBUILT_REPOSITORIES
import com.lagradost.cloudstream3.ui.settings.extensions.PUBLIC_REPOSITORIES_LIST
import com.lagradost.cloudstream3.ui.settings.extensions.PluginsViewModel import com.lagradost.cloudstream3.ui.settings.extensions.PluginsViewModel
import com.lagradost.cloudstream3.ui.settings.extensions.RepoAdapter import com.lagradost.cloudstream3.ui.settings.extensions.RepoAdapter
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
@ -19,6 +23,10 @@ import kotlinx.android.synthetic.main.fragment_setup_media.*
class SetupFragmentExtensions : Fragment() { class SetupFragmentExtensions : Fragment() {
companion object { companion object {
const val SETUP_EXTENSION_BUNDLE_IS_SETUP = "isSetup" const val SETUP_EXTENSION_BUNDLE_IS_SETUP = "isSetup"
/**
* If false then this is treated a singular screen with a done button
* */
fun newInstance(isSetup: Boolean): Bundle { fun newInstance(isSetup: Boolean): Bundle {
return Bundle().apply { return Bundle().apply {
putBoolean(SETUP_EXTENSION_BUNDLE_IS_SETUP, isSetup) putBoolean(SETUP_EXTENSION_BUNDLE_IS_SETUP, isSetup)
@ -33,6 +41,33 @@ class SetupFragmentExtensions : Fragment() {
return inflater.inflate(R.layout.fragment_setup_extensions, container, false) return inflater.inflate(R.layout.fragment_setup_extensions, container, false)
} }
override fun onResume() {
super.onResume()
afterRepositoryLoadedEvent += ::setRepositories
}
override fun onStop() {
super.onStop()
afterRepositoryLoadedEvent -= ::setRepositories
}
private fun setRepositories(success: Boolean = true) {
val repositories = RepositoryManager.getRepositories() + PREBUILT_REPOSITORIES
val hasRepos = repositories.isNotEmpty()
repo_recycler_view?.isVisible = hasRepos
blank_repo_screen?.isVisible = !hasRepos
if (hasRepos) {
repo_recycler_view?.adapter = RepoAdapter(true, {}, {
PluginsViewModel.downloadAll(activity, it.url, null)
}).apply { updateList(repositories) }
} else {
list_repositories?.setOnClickListener {
openBrowser(PUBLIC_REPOSITORIES_LIST)
}
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
context?.fixPaddingStatusbar(setup_root) context?.fixPaddingStatusbar(setup_root)
@ -40,10 +75,7 @@ class SetupFragmentExtensions : Fragment() {
with(context) { with(context) {
if (this == null) return if (this == null) return
setRepositories()
repo_recycler_view?.adapter = RepoAdapter(true, {}, {
PluginsViewModel.downloadAll(activity, it.url, null)
}).apply { updateList(PREBUILT_REPOSITORIES) }
if (!isSetup) { if (!isSetup) {
next_btt.setText(R.string.setup_done) next_btt.setText(R.string.setup_done)

View File

@ -80,8 +80,10 @@ class SetupFragmentLanguage : Fragment() {
next_btt?.setOnClickListener { next_btt?.setOnClickListener {
// If no plugins go to plugins page // If no plugins go to plugins page
val nextDestination = if (PluginManager.getPluginsOnline() val nextDestination = if (
.isEmpty() && PREBUILT_REPOSITORIES.isNotEmpty() PluginManager.getPluginsOnline().isEmpty()
&& PluginManager.getPluginsLocal().isEmpty()
//&& PREBUILT_REPOSITORIES.isNotEmpty()
) R.id.action_navigation_global_to_navigation_setup_extensions ) R.id.action_navigation_global_to_navigation_setup_extensions
else R.id.action_navigation_setup_language_to_navigation_setup_provider_languages else R.id.action_navigation_setup_language_to_navigation_setup_provider_languages

View File

@ -6,22 +6,35 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<TextView <LinearLayout
android:id="@+id/text1"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:layout_gravity="center_vertical"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:orientation="horizontal">
android:paddingStart="?android:attr/listPreferredItemPaddingStart" <TextView
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:id="@+id/text1"
android:text="@string/add_repository" android:layout_weight="1"
android:textColor="?attr/textColor" android:layout_width="0dp"
android:textSize="20sp" android:layout_height="wrap_content"
android:textStyle="bold" /> android:layout_rowWeight="1"
android:layout_gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:text="@string/add_repository"
android:textColor="?attr/textColor"
android:textSize="20sp"
android:textStyle="bold" />
<com.google.android.material.button.MaterialButton
android:id="@+id/list_repositories"
style="@style/WhiteButton"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/view_public_repositories_button_short" />
</LinearLayout>
<TextView <TextView
android:id="@+id/text2" android:id="@+id/text2"

View File

@ -19,10 +19,11 @@
app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toTopOf="@id/download_storage_appbar" app:layout_constraintBottom_toTopOf="@id/download_storage_appbar"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/repository_item" /> tools:listitem="@layout/repository_item"
tools:visibility="visible" />
<LinearLayout <LinearLayout
android:visibility="gone" tools:visibility="gone"
android:id="@+id/blank_repo_screen" android:id="@+id/blank_repo_screen"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -31,17 +32,24 @@
android:orientation="vertical"> android:orientation="vertical">
<ImageView <ImageView
android:layout_margin="10dp"
android:layout_width="30dp" android:layout_width="30dp"
android:layout_height="30dp" android:layout_height="30dp"
android:layout_margin="10dp"
android:src="@drawable/ic_baseline_extension_24" /> android:src="@drawable/ic_baseline_extension_24" />
<TextView <TextView
android:layout_marginBottom="20dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:text="@string/blank_repo_message" android:text="@string/blank_repo_message"
android:textSize="16sp" /> android:textSize="16sp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/list_repositories"
style="@style/WhiteButton"
android:layout_width="wrap_content"
android:text="@string/view_public_repositories_button" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/setup_root" android:id="@+id/setup_root"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -21,12 +21,43 @@
android:gravity="center" android:gravity="center"
android:text="@string/setup_extensions_subtext" /> android:text="@string/setup_extensions_subtext" />
<androidx.recyclerview.widget.RecyclerView <LinearLayout
android:id="@+id/repo_recycler_view" android:id="@+id/blank_repo_screen"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:listitem="@layout/repository_item" /> android:layout_margin="20dp"
android:gravity="center"
android:orientation="vertical"
tools:visibility="gone">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:src="@drawable/ic_baseline_extension_24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:gravity="center"
android:text="@string/blank_repo_message"
android:textSize="16sp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/list_repositories"
style="@style/WhiteButton"
android:layout_width="wrap_content"
android:text="@string/view_public_repositories_button" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/repo_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/repository_item"
tools:visibility="visible" />
<LinearLayout <LinearLayout
android:id="@+id/apply_btt_holder" android:id="@+id/apply_btt_holder"

View File

@ -596,4 +596,6 @@
<string name="plugins_disabled" formatted="true">Disabled: %d</string> <string name="plugins_disabled" formatted="true">Disabled: %d</string>
<string name="plugins_not_downloaded" formatted="true">Not downloaded: %d</string> <string name="plugins_not_downloaded" formatted="true">Not downloaded: %d</string>
<string name="blank_repo_message">Add a repository to install site extensions</string> <string name="blank_repo_message">Add a repository to install site extensions</string>
<string name="view_public_repositories_button">View public repositories</string>
<string name="view_public_repositories_button_short">Public list</string>
</resources> </resources>