added settings to disable HD, SUB, DUB & Title. Now stop complaining

This commit is contained in:
LagradOst 2022-05-05 18:16:41 +02:00
parent a114c8658e
commit 1499b2be40
9 changed files with 180 additions and 71 deletions

View file

@ -36,7 +36,7 @@ android {
targetSdkVersion 30
versionCode 47
versionName "2.9.24"
versionName "2.9.25"
resValue "string", "app_version",
"${defaultConfig.versionName}${versionNameSuffix ?: ""}"

View file

@ -44,6 +44,7 @@ import com.lagradost.cloudstream3.syncproviders.OAuth2API.Companion.appString
import com.lagradost.cloudstream3.ui.APIRepository
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
import com.lagradost.cloudstream3.ui.result.ResultFragment
import com.lagradost.cloudstream3.ui.search.SearchResultBuilder
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isEmulatorSettings
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
import com.lagradost.cloudstream3.utils.AppUtils.isCastApiAvailable
@ -109,7 +110,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
super.onConfigurationChanged(newConfig)
updateLocale() // android fucks me by chaining lang when rotating the phone
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
navHostFragment.navController.currentDestination?.let { updateNavBar(it) }
}
@ -349,6 +351,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
api.init()
}
SearchResultBuilder.updateCache(this)
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
val downloadFromGithub = try {
settingsManager.getBoolean(getString(R.string.killswitch_key), true)
@ -365,57 +369,68 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
e.printStackTrace()
false
}
fun addNginxToJson(data: java.util.HashMap<String, ProvidersInfoJson>): java.util.HashMap<String, ProvidersInfoJson>? {
try {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
val nginxUrl =
settingsManager.getString(getString(R.string.nginx_url_key), "nginx_url_key").toString()
val nginxCredentials =
settingsManager.getString(getString(R.string.nginx_credentials), "nginx_credentials")
.toString()
val StoredNginxProvider = NginxProvider()
if (nginxUrl == "nginx_url_key" || nginxUrl == "") { // if key is default value, or empty:
data[StoredNginxProvider.javaClass.simpleName] = ProvidersInfoJson(
url = nginxUrl,
name = StoredNginxProvider.name,
status = PROVIDER_STATUS_DOWN, // the provider will not be display
credentials = nginxCredentials
)
} else { // valid url
data[StoredNginxProvider.javaClass.simpleName] = ProvidersInfoJson(
url = nginxUrl,
name = StoredNginxProvider.name,
status = PROVIDER_STATUS_OK,
credentials = nginxCredentials
)
}
return data
} catch (e: Exception) {
logError(e)
return data
}
}
fun createNginxJson() : ProvidersInfoJson? { //java.util.HashMap<String, ProvidersInfoJson>
return try {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
val nginxUrl = settingsManager.getString(getString(R.string.nginx_url_key), "nginx_url_key").toString()
val nginxCredentials = settingsManager.getString(getString(R.string.nginx_credentials), "nginx_credentials").toString()
if (nginxUrl == "nginx_url_key" || nginxUrl == "") { // if key is default value or empty:
null // don't overwrite anything
} else {
ProvidersInfoJson(
url = nginxUrl,
name = NginxProvider().name,
status = PROVIDER_STATUS_OK,
credentials = nginxCredentials
)
fun addNginxToJson(data: java.util.HashMap<String, ProvidersInfoJson>): java.util.HashMap<String, ProvidersInfoJson>? {
try {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
val nginxUrl =
settingsManager.getString(getString(R.string.nginx_url_key), "nginx_url_key")
.toString()
val nginxCredentials =
settingsManager.getString(
getString(R.string.nginx_credentials),
"nginx_credentials"
)
.toString()
val StoredNginxProvider = NginxProvider()
if (nginxUrl == "nginx_url_key" || nginxUrl == "") { // if key is default value, or empty:
data[StoredNginxProvider.javaClass.simpleName] = ProvidersInfoJson(
url = nginxUrl,
name = StoredNginxProvider.name,
status = PROVIDER_STATUS_DOWN, // the provider will not be display
credentials = nginxCredentials
)
} else { // valid url
data[StoredNginxProvider.javaClass.simpleName] = ProvidersInfoJson(
url = nginxUrl,
name = StoredNginxProvider.name,
status = PROVIDER_STATUS_OK,
credentials = nginxCredentials
)
}
return data
} catch (e: Exception) {
logError(e)
return data
}
}
fun createNginxJson(): ProvidersInfoJson? { //java.util.HashMap<String, ProvidersInfoJson>
return try {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
val nginxUrl =
settingsManager.getString(getString(R.string.nginx_url_key), "nginx_url_key")
.toString()
val nginxCredentials = settingsManager.getString(
getString(R.string.nginx_credentials),
"nginx_credentials"
).toString()
if (nginxUrl == "nginx_url_key" || nginxUrl == "") { // if key is default value or empty:
null // don't overwrite anything
} else {
ProvidersInfoJson(
url = nginxUrl,
name = NginxProvider().name,
status = PROVIDER_STATUS_OK,
credentials = nginxCredentials
)
}
} catch (e: Exception) {
logError(e)
null
}
} catch (e: Exception) {
logError(e)
null
}
}
// this pulls the latest data so ppl don't have to update to simply change provider url
if (downloadFromGithub) {
@ -435,13 +450,15 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
tryParseJson<HashMap<String, ProvidersInfoJson>>(txt)
setKey(PROVIDER_STATUS_KEY, txt)
MainAPI.overrideData = newCache // update all new providers
val newUpdatedCache = newCache?.let { addNginxToJson(it) ?: it }
for (api in apis) { // update current providers
newUpdatedCache?.get(api.javaClass.simpleName)?.let { data ->
api.overrideWithNewData(data)
}
val newUpdatedCache =
newCache?.let { addNginxToJson(it) ?: it }
for (api in apis) { // update current providers
newUpdatedCache?.get(api.javaClass.simpleName)
?.let { data ->
api.overrideWithNewData(data)
}
}
} catch (e: Exception) {
logError(e)
@ -456,7 +473,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
newCache
}?.let { providersJsonMap ->
MainAPI.overrideData = providersJsonMap
val providersJsonMapUpdated = addNginxToJson(providersJsonMap)?: providersJsonMap // if return null, use unchanged one
val providersJsonMapUpdated = addNginxToJson(providersJsonMap)
?: providersJsonMap // if return null, use unchanged one
val acceptableProviders =
providersJsonMapUpdated.filter { it.value.status == PROVIDER_STATUS_OK || it.value.status == PROVIDER_STATUS_SLOW }
.map { it.key }.toSet()
@ -524,7 +542,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
setUpBackup()
CommonActivity.init(this)
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
//val navController = findNavController(R.id.nav_host_fragment)

View file

@ -1,11 +1,13 @@
package com.lagradost.cloudstream3.ui.search
import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.core.view.isVisible
import androidx.preference.PreferenceManager
import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
import com.lagradost.cloudstream3.utils.AppUtils.getNameFull
@ -15,6 +17,17 @@ import com.lagradost.cloudstream3.utils.UIHelper.setImage
import kotlinx.android.synthetic.main.home_result_grid.view.*
object SearchResultBuilder {
private val showCache: MutableMap<String, Boolean> = mutableMapOf()
fun updateCache(context: Context?) {
if (context == null) return
val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
for (k in context.resources.getStringArray(R.array.poster_ui_options_values)) {
showCache[k] = settingsManager.getBoolean(k, showCache[k] ?: true)
}
}
/**
* @param nextFocusBehavior True if first, False if last, Null if between.
* Used to prevent escaping the adapter horizontally (focus wise).
@ -34,6 +47,7 @@ object SearchResultBuilder {
val textIsDub: TextView? = itemView.text_is_dub
val textIsSub: TextView? = itemView.text_is_sub
val textQuality: TextView? = itemView.text_quality
val shadow: View? = itemView.title_shadow
val bg: CardView = itemView.background_card
@ -47,6 +61,13 @@ object SearchResultBuilder {
textIsDub?.isVisible = false
textIsSub?.isVisible = false
val showSub = showCache[textIsDub?.context?.getString(R.string.show_sub_key)] ?: false
val showDub = showCache[textIsDub?.context?.getString(R.string.show_dub_key)] ?: false
val showTitle = showCache[cardText?.context?.getString(R.string.show_title_key)] ?: false
val showHd = showCache[textQuality?.context?.getString(R.string.show_title_key)] ?: false
shadow?.isVisible = showTitle
when (card.quality) {
SearchQuality.BlueRay -> R.string.quality_blueray
SearchQuality.Cam -> R.string.quality_cam
@ -67,14 +88,15 @@ object SearchResultBuilder {
null -> null
}?.let { textRes ->
textQuality?.setText(textRes)
textQuality?.isVisible = true
textQuality?.isVisible = showHd
} ?: run {
textQuality?.isVisible = false
}
cardText?.text = card.name
cardText?.isVisible = showTitle
cardView.isVisible = true
if (!cardView.setImage(card.posterUrl, card.posterHeaders)) {
cardView.setImageResource(R.drawable.default_cover)
}
@ -185,10 +207,10 @@ object SearchResultBuilder {
val dubStatus = card.dubStatus
if (!dubStatus.isNullOrEmpty()) {
if (dubStatus.contains(DubStatus.Dubbed)) {
textIsDub?.visibility = View.VISIBLE
textIsDub?.isVisible = showDub
}
if (dubStatus.contains(DubStatus.Subbed)) {
textIsSub?.visibility = View.VISIBLE
textIsSub?.isVisible = showSub
}
}

View file

@ -39,6 +39,7 @@ import com.lagradost.cloudstream3.syncproviders.OAuth2API
import com.lagradost.cloudstream3.syncproviders.OAuth2API.Companion.aniListApi
import com.lagradost.cloudstream3.syncproviders.OAuth2API.Companion.malApi
import com.lagradost.cloudstream3.ui.APIRepository
import com.lagradost.cloudstream3.ui.search.SearchResultBuilder
import com.lagradost.cloudstream3.ui.subtitles.ChromecastSubtitlesFragment
import com.lagradost.cloudstream3.ui.subtitles.SubtitlesFragment
import com.lagradost.cloudstream3.utils.BackupUtils.backup
@ -339,6 +340,34 @@ class SettingsFragment : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true
}
getPref(R.string.poster_ui_key)?.setOnPreferenceClickListener {
val prefNames = resources.getStringArray(R.array.poster_ui_options)
val keys = resources.getStringArray(R.array.poster_ui_options_values)
val prefValues = keys.map {
settingsManager.getBoolean(it, true)
}.mapIndexedNotNull { index, b ->
if (b) {
index
} else null
}
activity?.showMultiDialog(
prefNames.toList(),
prefValues,
getString(R.string.poster_ui_settings),
{}) { list ->
val edit = settingsManager.edit()
for ((i, key) in keys.withIndex()) {
edit.putBoolean(key, list.contains(i))
}
edit.apply()
SearchResultBuilder.updateCache(it.context)
}
return@setOnPreferenceClickListener true
}
val syncApis =
listOf(Pair(R.string.mal_key, malApi), Pair(R.string.anilist_key, aniListApi))
for ((key, api) in syncApis) {
@ -487,28 +516,34 @@ class SettingsFragment : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true
}
getPref(R.string.nginx_url_key)?.setOnPreferenceClickListener {
getPref(R.string.nginx_url_key)?.setOnPreferenceClickListener {
activity?.showNginxTextInputDialog(
settingsManager.getString(getString(R.string.nginx_url_pref), "Nginx server url").toString(),
settingsManager.getString(getString(R.string.nginx_url_key), "").toString(), // key: the actual you use rn
settingsManager.getString(getString(R.string.nginx_url_pref), "Nginx server url")
.toString(),
settingsManager.getString(getString(R.string.nginx_url_key), "")
.toString(), // key: the actual you use rn
android.text.InputType.TYPE_TEXT_VARIATION_URI, // uri
{}) {
settingsManager.edit()
.putString(getString(R.string.nginx_url_key), it).apply() // change the stored url in nginx_url_key to it
.putString(getString(R.string.nginx_url_key), it)
.apply() // change the stored url in nginx_url_key to it
}
return@setOnPreferenceClickListener true
}
getPref(R.string.nginx_credentials)?.setOnPreferenceClickListener {
activity?.showNginxTextInputDialog(
settingsManager.getString(getString(R.string.nginx_credentials_title), "Nginx Credentials").toString(),
settingsManager.getString(getString(R.string.nginx_credentials), "").toString(), // key: the actual you use rn
settingsManager.getString(
getString(R.string.nginx_credentials_title),
"Nginx Credentials"
).toString(),
settingsManager.getString(getString(R.string.nginx_credentials), "")
.toString(), // key: the actual you use rn
android.text.InputType.TYPE_TEXT_VARIATION_URI,
{}) {
settingsManager.edit()
.putString(getString(R.string.nginx_credentials), it).apply() // change the stored url in nginx_url_key to it
.putString(getString(R.string.nginx_credentials), it)
.apply() // change the stored url in nginx_url_key to it
}
return@setOnPreferenceClickListener true
}

View file

@ -30,6 +30,7 @@
android:clickable="false"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/title_shadow"
android:src="@drawable/title_shadow"
android:layout_gravity="bottom"
tools:ignore="ContentDescription" />

View file

@ -36,6 +36,7 @@
android:clickable="false"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/title_shadow"
android:src="@drawable/title_shadow"
android:layout_gravity="bottom"
tools:ignore="ContentDescription" />
@ -55,6 +56,7 @@
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:ellipsize="end" />
<TextView
tools:text="@string/quality_hd"
android:id="@+id/text_quality"
@ -67,6 +69,7 @@
android:layout_gravity="end"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="@string/app_dubbed_text"
android:id="@+id/text_is_dub"

View file

@ -143,6 +143,20 @@
<item>500</item>
</array>
<array name="poster_ui_options">
<item>@string/show_hd</item>
<item>@string/show_dub</item>
<item>@string/show_sub</item>
<item>@string/show_title</item>
</array>
<array name="poster_ui_options_values">
<item>@string/show_hd_key</item>
<item>@string/show_dub_key</item>
<item>@string/show_sub_key</item>
<item>@string/show_title_key</item>
</array>
<array name="episode_long_click_options">
<item>@string/episode_action_chromecast_episode</item>
<item>@string/episode_action_chromecast_mirror</item>

View file

@ -48,6 +48,7 @@
<string name="log_enabled_key" translatable="false">log_enabled_key</string>
<string name="show_logcat_key" translatable="false">show_logcat_key</string>
<string name="bottom_title_key" translatable="false">bottom_title_key</string>
<string name="poster_ui_key" translatable="false">poster_ui_key</string>
<!-- FORMAT MIGHT TRANSLATE, WILL CAUSE CRASH IF APPLIED WRONG -->
<string name="extra_info_format" translatable="false" formatted="true">%d %s | %sMB</string>
@ -342,6 +343,16 @@
<string name="episode_action_reload_links">Reload links</string>
<string name="episode_action_download_subtitle">Download subtitles</string>
<string name="show_hd">Quality label</string>
<string name="show_dub">Dub label</string>
<string name="show_sub">Sub label</string>
<string name="show_title">Title</string>
<string name="show_hd_key" translatable="false">show_hd_key</string>
<string name="show_dub_key" translatable="false">show_dub_key</string>
<string name="show_sub_key" translatable="false">show_sub_key</string>
<string name="show_title_key" translatable="false">show_title_key</string>
<string name="poster_ui_settings">Toggle UI elements on poster</string>
<string name="no_update_found">No Update Found</string>
<string name="check_for_update">Check for Update</string>

View file

@ -166,6 +166,10 @@
android:key="@string/bottom_title_key"
android:summary="@string/bottom_title_settings_des"
android:title="@string/bottom_title_settings" />
<Preference
android:icon="@drawable/ic_baseline_tv_24"
android:key="@string/poster_ui_key"
android:title="@string/poster_ui_settings" />
</PreferenceCategory>
<PreferenceCategory
android:key="search"