mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
Use Handler.postDelayed() extension to put the lambdas outside parentheses.
This commit is contained in:
parent
f522f1e1de
commit
96c41927fd
@ -31,6 +31,7 @@ import androidx.constraintlayout.motion.widget.MotionLayout
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.os.ConfigurationCompat
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.os.postDelayed
|
||||
import androidx.core.text.parseAsHtml
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.activityViewModels
|
||||
@ -210,9 +211,9 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
PlayerEvent.Background -> {
|
||||
playOnBackground()
|
||||
// wait some time in order for the service to get started properly
|
||||
handler.postDelayed({
|
||||
handler.postDelayed(500) {
|
||||
activity?.finish()
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
@ -476,10 +477,10 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
channelId,
|
||||
true
|
||||
)
|
||||
handler.postDelayed({
|
||||
handler.postDelayed(500) {
|
||||
NavigationHelper.startAudioPlayer(requireContext())
|
||||
killPlayerFragment()
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setFullscreen() {
|
||||
|
@ -6,6 +6,7 @@ import android.os.Looper
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.os.postDelayed
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
@ -144,7 +145,7 @@ class WatchHistoryFragment : BaseFragment() {
|
||||
})
|
||||
|
||||
// add a listener for scroll end, delay needed to prevent loading new ones the first time
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
Handler(Looper.getMainLooper()).postDelayed(200) {
|
||||
binding.historyScrollView.viewTreeObserver.addOnScrollChangedListener {
|
||||
if (!binding.historyScrollView.canScrollVertically(1) && !isLoading) {
|
||||
isLoading = true
|
||||
@ -152,6 +153,6 @@ class WatchHistoryFragment : BaseFragment() {
|
||||
isLoading = false
|
||||
}
|
||||
}
|
||||
}, 200)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package com.github.libretube.ui.tools
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.Process
|
||||
import androidx.core.os.postDelayed
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
import com.github.libretube.ui.activities.MainActivity
|
||||
@ -25,38 +27,32 @@ object SleepTimer {
|
||||
""
|
||||
).ifEmpty { return }
|
||||
|
||||
handler.postDelayed(
|
||||
{
|
||||
var killApp = true
|
||||
val mainActivity = context as? MainActivity ?: return@postDelayed
|
||||
val snackBar = Snackbar.make(
|
||||
mainActivity.binding.root,
|
||||
R.string.take_a_break,
|
||||
Snackbar.LENGTH_INDEFINITE
|
||||
)
|
||||
.setAction(R.string.cancel) {
|
||||
killApp = false
|
||||
}
|
||||
snackBar.show()
|
||||
(0..REACTION_INTERVAL).forEach {
|
||||
handler.postDelayed({
|
||||
val remainingTime = " (${REACTION_INTERVAL - it})"
|
||||
snackBar.setText(context.getString(R.string.take_a_break) + remainingTime)
|
||||
}, it * 1000)
|
||||
handler.postDelayed(breakReminderPref.toLong() * 60 * 1000) {
|
||||
var killApp = true
|
||||
val mainActivity = context as? MainActivity ?: return@postDelayed
|
||||
val snackBar = Snackbar.make(
|
||||
mainActivity.binding.root,
|
||||
R.string.take_a_break,
|
||||
Snackbar.LENGTH_INDEFINITE
|
||||
)
|
||||
.setAction(R.string.cancel) {
|
||||
killApp = false
|
||||
}
|
||||
handler.postDelayed(
|
||||
killApp@{
|
||||
if (!killApp) return@killApp
|
||||
|
||||
// kill the application
|
||||
mainActivity.finishAffinity()
|
||||
mainActivity.finish()
|
||||
android.os.Process.killProcess(android.os.Process.myPid())
|
||||
},
|
||||
REACTION_INTERVAL * 1000
|
||||
)
|
||||
},
|
||||
breakReminderPref.toLong() * 60 * 1000
|
||||
)
|
||||
snackBar.show()
|
||||
for (i in 0..REACTION_INTERVAL) {
|
||||
handler.postDelayed(i * 1000) {
|
||||
val remainingTime = " (${REACTION_INTERVAL - i})"
|
||||
snackBar.setText(context.getString(R.string.take_a_break) + remainingTime)
|
||||
}
|
||||
}
|
||||
handler.postDelayed(REACTION_INTERVAL * 1000) {
|
||||
if (killApp) {
|
||||
// kill the application
|
||||
mainActivity.finishAffinity()
|
||||
mainActivity.finish()
|
||||
Process.killProcess(Process.myPid())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -439,12 +439,12 @@ internal class CustomExoPlayerView(
|
||||
.setDuration((ANIMATION_DURATION * 1.5).toLong())
|
||||
.withEndAction {
|
||||
// move the text back into the button
|
||||
handler.postDelayed({
|
||||
handler.postDelayed(100) {
|
||||
textView.animate()
|
||||
.setDuration(ANIMATION_DURATION / 2)
|
||||
.translationX(0f)
|
||||
.start()
|
||||
}, 100)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.os.postDelayed
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.constants.IntentData
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
@ -74,9 +75,9 @@ object NavigationHelper {
|
||||
channelId,
|
||||
keepQueue
|
||||
)
|
||||
handler.postDelayed({
|
||||
handler.postDelayed(500) {
|
||||
startAudioPlayer(context)
|
||||
}, 500)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user