Skip to content
Merged
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
4 changes: 2 additions & 2 deletions app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
}

//Automatically download not existing plugins, using mode specified.
val autoDownloadPlugin = AutoDownloadMode.getEnum(
/*val autoDownloadPlugin = AutoDownloadMode.getEnum(
settingsManager.getInt(
getString(R.string.auto_download_plugins_key),
0
Expand All @@ -1390,7 +1390,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
this@MainActivity,
autoDownloadPlugin
)
}
}*/
}

ioSafe {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ object PluginManager {
/**
* @return True if successful, false if not
* */
private suspend fun loadPlugin(context: Context, file: File, data: PluginData): Boolean {
internal suspend fun loadPlugin(context: Context, file: File, data: PluginData): Boolean {
val fileName = file.nameWithoutExtension
val filePath = file.absolutePath
currentlyLoading = fileName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ object RepositoryManager {
suspend fun parseRepository(url: String): Repository? {
return safeAsync {
// Take manifestVersion and such into account later
app.get(convertRawGitUrl(url), cacheTime = 5, cacheUnit = TimeUnit.MINUTES)
app.get(convertRawGitUrl(url), cacheTime = 15, cacheUnit = TimeUnit.MINUTES)
.parsedSafe<Repository>()
}
}

private suspend fun parsePlugins(pluginUrls: String): List<SitePlugin> {
// Take manifestVersion and such into account later
return try {
app.get(convertRawGitUrl(pluginUrls), cacheTime = 5, cacheUnit = TimeUnit.MINUTES)
app.get(convertRawGitUrl(pluginUrls), cacheTime = 15, cacheUnit = TimeUnit.MINUTES)
.parsed<Array<SitePlugin>>().toList()
} catch (t: Throwable) {
logError(t)
Expand Down Expand Up @@ -247,9 +247,16 @@ object RepositoryManager {
private val repoLock = Mutex()
suspend fun addRepository(repository: RepositoryData) {
repoLock.withLock {
val currentRepos = getRepositories()
// No duplicates
setKey(REPOSITORIES_KEY, (currentRepos + repository).distinctBy { it.url })
// No duplicates, but we want the new repository instead of the old one
var currentRepos = getRepositories()
val index = currentRepos.indexOfFirst { it.url == repository.url }
if(index == -1) {
currentRepos += repository
} else {
/** We want to keep the ordering here, as that is the addition order */
currentRepos[index] = repository
}
setKey(REPOSITORIES_KEY, currentRepos)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ object AccountScreen {
.padding(contentPadding),
horizontalAlignment = Alignment.End
) {
val (edit, accounts) = FocusRequester.createRefs()
val (edit, accounts) = remember { FocusRequester.createRefs() }

IconButton(
onClick = {
Expand Down Expand Up @@ -318,7 +318,7 @@ object AccountScreen {
)
}

val (focusRequester) = FocusRequester.createRefs()
val focusRequester = remember { FocusRequester() }
LaunchedEffect(Unit) {
focusRequester.requestFocus()
}
Expand Down Expand Up @@ -746,7 +746,7 @@ object AccountScreen {
val innerPadding by animateDpAsState(
targetValue = if (hasFocus || isLayout(PHONE or EMULATOR)) 0.dp else MaterialTheme.padding.extraSmall,
)
val (focusRequester) = FocusRequester.createRefs()
val focusRequester = remember { FocusRequester() }
LaunchedEffect(Unit) {
if (selected) {
focusRequester.requestFocus()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,58 @@ object ApkUpdater : AppUpdater {
}
}

/**
* Returns true if we have a non-null digest that matches a digest on the specified existing file
* */
suspend fun isFileDigest(file: File, digest: DigestPair?): Boolean {
if (digest == null) {
return false
}
try {
val fileDigest = calculateDigest(
digestAlgorithm = digest.algorithm,
readStream = file.inputStream()
)
return fileDigest != null && digest.digest.contentEquals(fileDigest)
} catch (_: Throwable) {
// File not found/security/read issues, not very useful errors
}
return false
}

/**
* Calculates the digest of a stream with the specified algorithm, use transfer instead if
* you already download something.
*
* Will throw read errors
* Will return null if the algorithm is null or does not exist/has some error
* */
@Throws
suspend fun calculateDigest(digestAlgorithm: String?, readStream: InputStream) =
withContext(Dispatchers.IO) {
if (digestAlgorithm == null) return@withContext null

val md =
safe {
MessageDigest.getInstance(digestAlgorithm)
} ?: return@withContext null

val context = currentCoroutineContext()
val buffer = ByteArray(DEFAULT_BUFFER_SIZE)
var read: Int
while ((readStream.read(buffer, 0, DEFAULT_BUFFER_SIZE)
.also { read = it }) >= 0
) {
try {
md.update(buffer, 0, read)
} catch (_: Throwable) {
return@withContext null
}
context.ensureActive()
}
return@withContext safe { md.digest() }
}

@Throws
suspend fun legacyDownloader(
activity: Activity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.text.input.TextFieldLineLimits
import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.foundation.verticalScroll
Expand All @@ -30,7 +31,6 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.material3.rememberSearchBarState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.Immutable
Expand All @@ -47,6 +47,11 @@ import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
Expand Down Expand Up @@ -288,25 +293,54 @@ object SettingsFragmentScreen : Screen {

@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
@Composable
fun SettingsSearch(textFieldState : TextFieldState) {
fun SettingsSearch(textFieldState: TextFieldState) {
var hasFocus by remember { mutableStateOf(false) }
var isWritable by remember { mutableStateOf(false) }
val focusProgress by animateFloatAsState(targetValue = if (hasFocus) 1.0f else 0.0f)
val focusManager = LocalFocusManager.current
val focusRequester = remember { FocusRequester() }
val isTv = isLayout(TV)
TextField(
state = textFieldState,
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Search,
// This option is bugged on compose, making it unable to open at all
// showKeyboardOnFocus = false
/**
* We do not want to pull up the keyboard when navigating to the item on TV, therefore
* we listen to when the TV user presses some key to "extra" focus it
*
* showKeyboardOnFocus is somewhat bugged, so need to change this to true when you
* press it, as otherwise no keyboard will show even with keyboardController
* */
showKeyboardOnFocus = if (isTv) isWritable else true
),
lineLimits = TextFieldLineLimits.SingleLine,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp - 12.dp * focusProgress)
.focusOutline(enabled = isLayout(TV), CircleShape)
.focusOutline(enabled = isTv, CircleShape)
.onFocusChanged { newFocus ->
hasFocus = newFocus.hasFocus
}.focusRequester(focusRequester),
/** Loss of focus -> readonly */
if (!newFocus.hasFocus) {
isWritable = false
}
}
.focusRequester(focusRequester)
.onPreviewKeyEvent { keyEvent ->
if (isWritable || !isTv || !hasFocus || keyEvent.type != KeyEventType.KeyUp) {
return@onPreviewKeyEvent false
}

/** Focus + press once -> writable */
return@onPreviewKeyEvent when (keyEvent.key) {
Key.Enter, Key.DirectionCenter, Key.NumPadEnter, Key.Spacebar -> {
isWritable = true
true
}

else -> false
}
},
placeholder = {
Text(text = stringResource(R.string.search_hint))
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ object SettingsUpdatesScreen : SearchableSettings {
preference = settings.plugins.autoUpdate,
),

Preference.PreferenceItem.ListPreference(
/*Preference.PreferenceItem.ListPreference(
title = stringResource(R.string.automatic_plugin_download),
subtitle = "%s\n" + stringResource(R.string.automatic_plugin_download_summary),
icon = painterResource(R.drawable.extention_renew2),
Expand All @@ -197,7 +197,7 @@ object SettingsUpdatesScreen : SearchableSettings {
)
}
}
),
),*/
Preference.PreferenceItem.TextPreference(
title = stringResource(R.string.test_extensions),
subtitle = stringResource(R.string.test_extensions_summary),
Expand Down
Loading
Loading