Compare commits

...

1 commit

Author SHA1 Message Date
firelight
94850f2a77
Fix: Sync delay, Progress on sync button and runOnMainThreadNative fix 2026-07-08 14:37:07 +00:00
4 changed files with 17 additions and 4 deletions

View file

@ -171,6 +171,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.UIHelper.navigate
import com.lagradost.cloudstream3.utils.UIHelper.requestRW import com.lagradost.cloudstream3.utils.UIHelper.requestRW
import com.lagradost.cloudstream3.utils.UIHelper.setNavigationBarColorCompat import com.lagradost.cloudstream3.utils.UIHelper.setNavigationBarColorCompat
import com.lagradost.cloudstream3.utils.UIHelper.showProgress
import com.lagradost.cloudstream3.utils.UIHelper.toPx import com.lagradost.cloudstream3.utils.UIHelper.toPx
import com.lagradost.cloudstream3.utils.USER_PROVIDER_API import com.lagradost.cloudstream3.utils.USER_PROVIDER_API
import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API
@ -1428,8 +1429,9 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
else -> { else -> {
resultviewPreviewBookmark.isEnabled = false resultviewPreviewBookmark.isEnabled = false
resultviewPreviewBookmark.setIconResource(R.drawable.ic_baseline_bookmark_border_24) resultviewPreviewBookmark.showProgress()
resultviewPreviewBookmark.setText(R.string.loading) //resultviewPreviewBookmark.setIconResource(R.drawable.ic_baseline_bookmark_border_24)
//resultviewPreviewBookmark.setText(R.string.loading)
} }
} }
} }

View file

@ -182,6 +182,7 @@ class SyncViewModel : ViewModel() {
fun publishUserData() = ioSafe { fun publishUserData() = ioSafe {
Log.i(TAG, "publishUserData") Log.i(TAG, "publishUserData")
val user = userData.value val user = userData.value
_userDataResponse.postValue(Resource.Loading())
if (user is Resource.Success) { if (user is Resource.Success) {
syncs.forEach { (prefix, id) -> syncs.forEach { (prefix, id) ->
repos.firstOrNull { it.idPrefix == prefix }?.updateStatus(id, user.value) repos.firstOrNull { it.idPrefix == prefix }?.updateStatus(id, user.value)

View file

@ -597,6 +597,10 @@ object UIHelper {
fun MaterialButton.showProgress(@ColorInt tintColor: Int = this.iconTint.defaultColor) = fun MaterialButton.showProgress(@ColorInt tintColor: Int = this.iconTint.defaultColor) =
// Use runOnMainThreadNative to allow process on io threads, to make the code a bit cleaner // Use runOnMainThreadNative to allow process on io threads, to make the code a bit cleaner
runOnMainThreadNative { runOnMainThreadNative {
// No need to set it again, as then it will reset the animation
if(this.icon is IndeterminateDrawable<*>) {
return@runOnMainThreadNative
}
val spec = CircularProgressIndicatorSpec( val spec = CircularProgressIndicatorSpec(
context, null, 0, context, null, 0,
com.google.android.material.R.style.Widget_Material3_CircularProgressIndicator_ExtraSmall com.google.android.material.R.style.Widget_Material3_CircularProgressIndicator_ExtraSmall

View file

@ -1,14 +1,20 @@
package com.lagradost.cloudstream3.utils package com.lagradost.cloudstream3.utils
import android.annotation.SuppressLint
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import androidx.annotation.AnyThread import androidx.annotation.AnyThread
import androidx.annotation.MainThread import androidx.annotation.MainThread
@SuppressLint("ThreadConstraint") // mainLooper.isCurrentThread does not switch the context
@AnyThread @AnyThread
actual fun runOnMainThreadNative(@MainThread work: () -> Unit) { actual fun runOnMainThreadNative(@MainThread work: () -> Unit) {
val mainHandler = Handler(Looper.getMainLooper()) val mainLooper = Looper.getMainLooper()
mainHandler.post { if (mainLooper.isCurrentThread) {
// Do the work directly if we already are on the main thread, no need to enqueue it
work() work()
} else {
// Otherwise post it to the other main thread
Handler(mainLooper).post(work)
} }
} }