From 837609abb92f7e21b30b2c0ec1f78f7fccf6b93c Mon Sep 17 00:00:00 2001 From: Kelvin Date: Wed, 17 Jan 2024 13:26:17 +0100 Subject: [PATCH] Remove primary client, remove play store default source, add additional flows for adding sources --- .../platformplayer/activities/MainActivity.kt | 10 ++++- .../mainactivity/main/SourcesFragment.kt | 17 ++++--- .../platformplayer/states/StatePlatform.kt | 45 ++----------------- app/src/main/res/layout/fragment_sources.xml | 44 ++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + app/src/playstore/res/raw/plugin_config.json | 4 +- 6 files changed, 69 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/com/futo/platformplayer/activities/MainActivity.kt b/app/src/main/java/com/futo/platformplayer/activities/MainActivity.kt index ffa86cf5..5797e0ec 100644 --- a/app/src/main/java/com/futo/platformplayer/activities/MainActivity.kt +++ b/app/src/main/java/com/futo/platformplayer/activities/MainActivity.kt @@ -536,7 +536,15 @@ class MainActivity : AppCompatActivity, IWithResultLauncher { } }; "BROWSE_PLUGINS" -> { - navigate(_fragBrowser, "https://plugins.grayjay.app"); + navigate(_fragBrowser, BrowserFragment.NavigateOptions("https://plugins.grayjay.app/", mapOf( + Pair("grayjay") { req -> + StateApp.instance.contextOrNull?.let { + if(it is MainActivity) { + it.handleUrlAll(req.url.toString()); + } + }; + } + ))); } } } diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/SourcesFragment.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/SourcesFragment.kt index c3d1230b..39c87028 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/SourcesFragment.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/SourcesFragment.kt @@ -8,6 +8,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.LinearLayout +import androidx.core.view.isVisible import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -25,6 +26,7 @@ import com.futo.platformplayer.views.adapters.DisabledSourceView import com.futo.platformplayer.views.adapters.EnabledSourceAdapter import com.futo.platformplayer.views.adapters.EnabledSourceViewHolder import com.futo.platformplayer.views.adapters.ItemMoveCallback +import com.futo.platformplayer.views.buttons.BigButton import com.futo.platformplayer.views.sources.SourceUnderConstructionView import kotlinx.coroutines.runBlocking import java.util.Collections @@ -86,6 +88,14 @@ class SourcesFragment : MainFragment() { _containerDisabledViews = findViewById(R.id.container_disabled_views); _containerConstruction = findViewById(R.id.container_construction); + if(StatePlatform.instance.getAvailableClients().isEmpty()) { + findViewById(R.id.no_sources).isVisible = true; + findViewById(R.id.plugin_disclaimer).isVisible = false; + } + findViewById(R.id.button_add_sources).onClick.subscribe { + fragment.startActivity(Intent(context, AddSourceOptionsActivity::class.java)); + }; + for(inConstructSource in StatePlugins.instance.getSourcesUnderConstruction(context)) _containerConstruction.addView(SourceUnderConstructionView(context, inConstructSource.key, inConstructSource.value)); @@ -111,8 +121,6 @@ class SourcesFragment : MainFragment() { adapterSourcesEnabled.notifyItemMoved(fromPosition, toPosition); onEnabledChanged(enabledSources); - if(toPosition == 0) - onPrimaryChanged(enabledSources.first()); StatePlatform.instance.setPlatformOrder(enabledSources.map { it.name }); }; @@ -133,8 +141,6 @@ class SourcesFragment : MainFragment() { updateContainerVisibility(); onEnabledChanged(enabledSources); - if(index == 0) - onPrimaryChanged(enabledSources.first()); if(enabledSources.size <= 1) setCanRemove(false); @@ -221,9 +227,6 @@ class SourcesFragment : MainFragment() { _adapterSourcesEnabled.canRemove = canRemove; } - private fun onPrimaryChanged(client: IPlatformClient) { - StatePlatform.instance.selectPrimaryClient(client.id); - } private fun onEnabledChanged(clients: List) { runBlocking { StatePlatform.instance.selectClients(*clients.map { it.id }.toTypedArray()); diff --git a/app/src/main/java/com/futo/platformplayer/states/StatePlatform.kt b/app/src/main/java/com/futo/platformplayer/states/StatePlatform.kt index 798e1988..1aded91e 100644 --- a/app/src/main/java/com/futo/platformplayer/states/StatePlatform.kt +++ b/app/src/main/java/com/futo/platformplayer/states/StatePlatform.kt @@ -94,11 +94,6 @@ class StatePlatform { private val _liveEventClientPool = PlatformMultiClientPool("LiveEvents", 1); //Used exclusively for live events - private val _primaryClientPersistent = FragmentedStorage.get("primaryClient"); - private var _primaryClientObj : IPlatformClient? = null; - val primaryClient : IPlatformClient get() = _primaryClientObj ?: throw IllegalStateException("PlatformState not yet initialized"); - - private val _icons : HashMap = HashMap(); val hasClients: Boolean get() = _availableClients.size > 0; @@ -207,20 +202,6 @@ class StatePlatform { .filter { id -> _availableClients.any { it.id == id } } .toTypedArray(); } - - - val primary = _primaryClientPersistent.value; - if(primary.isEmpty() || primary == StateDeveloper.DEV_ID) { - selectPrimaryClient(enabled.firstOrNull() ?: _availableClients.first().id); - } else if(!_availableClients.any { it.id == primary }) { - selectPrimaryClient(_availableClients.firstOrNull()?.id!!); - } else { - selectPrimaryClient(primary); - } - - if(!enabled.any { it == primaryClient.id }) { - enabled = enabled.concat(primaryClient.id); - } } selectClients(*enabled); }; @@ -323,8 +304,6 @@ class StatePlatform { newClient.initialize(); _enabledClients.add(newClient); } - if (_primaryClientObj == client) - _primaryClientObj = newClient; _availableClients.removeIf { it.id == id }; _availableClients.add(newClient); @@ -365,17 +344,6 @@ class StatePlatform { }; } - /** - * Selects the primary client, meaning the first target for requests. - * At the moment, since multi-client requests are not yet implemented, this is the goto client. - */ - fun selectPrimaryClient(id: String) { - synchronized(_clientsLock) { - _primaryClientObj = getClient(id); - _primaryClientPersistent.setAndSave(id); - } - } - fun getHome(): IPager { Logger.i(TAG, "Platform - getHome"); var clientIdsOngoing = mutableListOf(); @@ -448,14 +416,12 @@ class StatePlatform { toAwait.map { PlaceholderPager(5, { PlatformContentPlaceholder(it.first.id) }) }); } - fun getHomePrimary(): IPager { - return primaryClient.getHome(); - } //Search fun searchSuggestions(query: String): Array { Logger.i(TAG, "Platform - searchSuggestions"); - return primaryClient.searchSuggestions(query); + //TODO: hasSearchSuggestions + return getEnabledClients().firstOrNull()?.searchSuggestions(query) ?: arrayOf(); } fun search(query: String, type: String? = null, sort: String? = null, filters: Map> = mapOf(), clientIds: List? = null): IPager { @@ -887,7 +853,6 @@ class StatePlatform { synchronized(_clientsLock) { val enabledExisting = _enabledClients.filter { it is DevJSClient }; val isEnabled = !enabledExisting.isEmpty() - val isPrimary = _primaryClientObj is DevJSClient; for (enabled in enabledExisting) { enabled.disable(); @@ -902,11 +867,7 @@ class StatePlatform { devId = newClient.devID; try { StateDeveloper.instance.initializeDev(devId!!); - if (isPrimary) { - _primaryClientObj = newClient; - _enabledClients.add(0, newClient); - newClient.initialize(); - } else if (isEnabled) { + if (isEnabled) { _enabledClients.add(newClient); newClient.initialize(); } diff --git a/app/src/main/res/layout/fragment_sources.xml b/app/src/main/res/layout/fragment_sources.xml index 8cb41ff2..8a623422 100644 --- a/app/src/main/res/layout/fragment_sources.xml +++ b/app/src/main/res/layout/fragment_sources.xml @@ -17,6 +17,40 @@ android:orientation="vertical" android:paddingStart="20dp" android:paddingEnd="20dp"> + + + + + + + + + + + + @@ -113,6 +148,15 @@ + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ac8e4b9b..fabd85da 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -214,6 +214,7 @@ Videos Clear history Nothing to import + You have no sources installed, please add sources to use the app as intended. Enabling lots of sources can reduce the loading speed of your application. Support Membership diff --git a/app/src/playstore/res/raw/plugin_config.json b/app/src/playstore/res/raw/plugin_config.json index 87ab26d3..72fc5c5b 100644 --- a/app/src/playstore/res/raw/plugin_config.json +++ b/app/src/playstore/res/raw/plugin_config.json @@ -1,7 +1,7 @@ { "SOURCES_EMBEDDED": { - "1c291164-294c-4c2d-800d-7bc6d31d0019": "sources/peertube/PeerTubeConfig.json" + }, - "SOURCES_EMBEDDED_DEFAULT": ["1c291164-294c-4c2d-800d-7bc6d31d0019"], + "SOURCES_EMBEDDED_DEFAULT": [], "SOURCES_UNDER_CONSTRUCTION": {} }