Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.dokka)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.compose.multiplatform)
alias(libs.plugins.compose.compiler)
}

val javaTarget = JvmTarget.fromTarget(libs.versions.jvmTarget.get())
Expand Down Expand Up @@ -288,7 +290,11 @@ dependencies {
implementation(libs.work.runtime.ktx)
implementation(libs.nicehttp) // HTTP Lib

implementation(libs.bundles.compose)
implementation(libs.activity.compose)

implementation(project(":library"))
implementation(project(":shared"))
}

tasks.register<Jar>("androidSourcesJar") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ object VideoClickActionHolder {
?.second
}

fun getPlayers(activity: Activity? = null) = allVideoClickActions.filter { it.isPlayer && it.shouldShowSafe(activity, null) }
fun getPlayers(context: Context? = null) = allVideoClickActions.filter { it.isPlayer && it.shouldShowSafe(context, null) }
}

abstract class VideoClickAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fun buildDefaultClient(context: Context, ignoreSSL: Boolean = false): OkHttpClie
safe { Security.insertProviderAt(Conscrypt.newProvider(), 1) }

val settingsManager = PreferenceManager.getDefaultSharedPreferences(context)
val dns = settingsManager.getInt(context.getString(R.string.dns_pref), 0)
val dns = settingsManager.getInt(context.getString(R.string.dns_key), 0)
val baseClient = OkHttpClient.Builder()
.followRedirects(true)
.followSslRedirects(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lagradost.cloudstream3.ui.player.source_priority

import android.app.Activity
import android.app.Dialog
import androidx.annotation.StyleRes
import androidx.core.view.isVisible
Expand All @@ -26,23 +27,23 @@ data class LinkSource(


class QualityProfileDialog private constructor(
val activity: FragmentActivity,
val activity: Activity,
@StyleRes val themeRes: Int,
private val links: List<LinkSource>,
private val usedProfile: Int?,
private val profileSelectionCallback: ((QualityDataHelper.QualityProfile) -> Unit)?,
private val useProfileSelection: Boolean
) : Dialog(activity, themeRes) {
constructor(
activity: FragmentActivity,
activity: Activity,
@StyleRes themeRes: Int,
links: List<LinkSource>,
usedProfile: Int,
profileSelectionCallback: ((QualityDataHelper.QualityProfile) -> Unit),
) : this(activity, themeRes, links, usedProfile, profileSelectionCallback, true)

constructor(
activity: FragmentActivity,
activity: Activity,
@StyleRes themeRes: Int,
links: List<LinkSource>
) : this(activity, themeRes, links, null, null, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.ui.settings
import android.content.Context
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
Expand All @@ -17,6 +18,7 @@ import com.lagradost.cloudstream3.CloudStreamApp
import com.lagradost.cloudstream3.CloudStreamApp.Companion.getKey
import com.lagradost.cloudstream3.CloudStreamApp.Companion.setKey
import com.lagradost.cloudstream3.CommonActivity
import com.lagradost.cloudstream3.CommonActivity.activity
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.MainActivity
import com.lagradost.cloudstream3.R
Expand Down Expand Up @@ -175,68 +177,25 @@ class SettingsGeneral : BasePreferenceFragmentCompat() {
putString(context.getString(R.string.download_path_key_visual), visual)
}
}
}

private val pathPicker = getChooseFolderLauncher { uri, path ->
pickDownloadPath(uri, path)
}

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
hideKeyboard()
setPreferencesFromResource(R.xml.settings_general, rootKey)
val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext())

fun getCurrent(): MutableList<CustomSite> {
return getKey<Array<CustomSite>>(USER_PROVIDER_API)?.toMutableList()
?: mutableListOf()
}

getPref(R.string.locale_key)?.setOnPreferenceClickListener { pref ->
val current = getCurrentLocale(pref.context)
val languageTagsIETF = appLanguages.map { it.second }
val languageNames = appLanguages.map { it.nameNextToFlagEmoji() }
val currentIndex = languageTagsIETF.indexOf(current)

activity?.showDialog(
languageNames, currentIndex, getString(R.string.app_language), true, { }
) { selectedLangIndex ->
try {
val langTagIETF = languageTagsIETF[selectedLangIndex]
CommonActivity.setLocale(activity, langTagIETF)
settingsManager.edit {
putString(getString(R.string.locale_key), langTagIETF)
}
activity?.recreate()
} catch (e: Exception) {
logError(e)
}
}
return@setOnPreferenceClickListener true
}

getPref(R.string.battery_optimisation_key)?.hideOn(TV or EMULATOR)?.setOnPreferenceClickListener {
val ctx = context ?: return@setOnPreferenceClickListener false

if (isAppRestricted(ctx)) {
ctx.showBatteryOptimizationDialog()
} else {
showToast(R.string.app_unrestricted_toast)
}

true
}

fun showAdd() {
val providers = allProviders.distinctBy { it::class }.sortedBy { it.name }
activity?.showDialog(
val context = activity
context?.showDialog(
providers.map { "${it.name} (${it.mainUrl})" },
-1,
context?.getString(R.string.add_site_pref) ?: return,
context.getString(R.string.add_site_pref) ?: return,
true,
{}) { selection ->
val provider = providers.getOrNull(selection) ?: return@showDialog

val binding : AddSiteInputBinding = AddSiteInputBinding.inflate(layoutInflater,null,false)
val binding : AddSiteInputBinding = AddSiteInputBinding.inflate(LayoutInflater.from(
context
),null,false)

val builder =
AlertDialog.Builder(context ?: return@showDialog, R.style.AlertDialogCustom)
Expand Down Expand Up @@ -274,19 +233,24 @@ class SettingsGeneral : BasePreferenceFragmentCompat() {

fun showDelete() {
val current = getCurrent()

activity?.showMultiDialog(
val context = activity
context?.showMultiDialog(
current.map { it.name },
listOf(),
context?.getString(R.string.remove_site_pref) ?: return,
context.getString(R.string.remove_site_pref),
{}) { indexes ->
current.removeAll(indexes.map { current[it] })
setKey(USER_PROVIDER_API, current.toTypedArray())
}
}

fun showAddOrDelete() {
val binding : AddRemoveSitesBinding = AddRemoveSitesBinding.inflate(layoutInflater,null,false)
val context = activity

val binding : AddRemoveSitesBinding = AddRemoveSitesBinding.inflate(
LayoutInflater.from(
context
),null,false)
val builder =
AlertDialog.Builder(context ?: return, R.style.AlertDialogCustom)
.setView(binding.root)
Expand All @@ -303,6 +267,54 @@ class SettingsGeneral : BasePreferenceFragmentCompat() {
dialog.dismissSafe(activity)
}
}
}

private val pathPicker = getChooseFolderLauncher { uri, path ->
pickDownloadPath(uri, path)
}

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
hideKeyboard()
setPreferencesFromResource(R.xml.settings_general, rootKey)
val settingsManager = PreferenceManager.getDefaultSharedPreferences(requireContext())


getPref(R.string.locale_key)?.setOnPreferenceClickListener { pref ->
val current = getCurrentLocale(pref.context)
val languageTagsIETF = appLanguages.map { it.second }
val languageNames = appLanguages.map { it.nameNextToFlagEmoji() }
val currentIndex = languageTagsIETF.indexOf(current)

activity?.showDialog(
languageNames, currentIndex, getString(R.string.app_language), true, { }
) { selectedLangIndex ->
try {
val langTagIETF = languageTagsIETF[selectedLangIndex]
CommonActivity.setLocale(activity, langTagIETF)
settingsManager.edit {
putString(getString(R.string.locale_key), langTagIETF)
}
activity?.recreate()
} catch (e: Exception) {
logError(e)
}
}
return@setOnPreferenceClickListener true
}

getPref(R.string.battery_optimisation_key)?.hideOn(TV or EMULATOR)?.setOnPreferenceClickListener {
val ctx = context ?: return@setOnPreferenceClickListener false

if (isAppRestricted(ctx)) {
ctx.showBatteryOptimizationDialog()
} else {
showToast(R.string.app_unrestricted_toast)
}

true
}



getPref(R.string.override_site_key)?.setOnPreferenceClickListener { _ ->

Expand All @@ -329,15 +341,15 @@ class SettingsGeneral : BasePreferenceFragmentCompat() {
val prefValues = resources.getIntArray(R.array.dns_pref_values)

val currentDns =
settingsManager.getInt(getString(R.string.dns_pref), 0)
settingsManager.getInt(getString(R.string.dns_key), 0)

activity?.showBottomDialog(
prefNames.toList(),
prefValues.indexOf(currentDns),
getString(R.string.dns_pref),
true,
{}) {
settingsManager.edit { putInt(getString(R.string.dns_pref), prefValues[it]) }
settingsManager.edit { putInt(getString(R.string.dns_key), prefValues[it]) }
(context ?: CloudStreamApp.context)?.let { ctx -> app.initClient(ctx) }
}
return@setOnPreferenceClickListener true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.lagradost.cloudstream3.ui.settings

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.lagradost.cloudstream4.compose.createComposeView
import com.mihon.presentation.settings.SearchableSettings

/** Empty glue code to connect the old navigation graph to Compose */
class SettingsGeneral2 : Fragment(), SearchableSettings by SettingsGeneralScreen() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View = createComposeView(inflater, container, savedInstanceState)
}
Loading