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