Merge pull request #766 from Bnyro/master

cleanup
This commit is contained in:
Bnyro 2022-07-12 15:29:28 +00:00 committed by GitHub
commit 2c5c6654b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 40 additions and 30 deletions

View File

@ -0,0 +1,7 @@
package com.github.libretube
object Globals {
var isFullScreen = false
var isMiniPlayerVisible = false
var isCurrentViewMainSettings = true
}

View File

@ -25,11 +25,11 @@ import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.ui.setupWithNavController
import com.github.libretube.Globals
import com.github.libretube.PIPED_API_URL
import com.github.libretube.R
import com.github.libretube.databinding.ActivityMainBinding
import com.github.libretube.fragments.PlayerFragment
import com.github.libretube.fragments.isFullScreen
import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.services.ClosingService
import com.github.libretube.util.ConnectionHelper
@ -308,7 +308,7 @@ class MainActivity : AppCompatActivity() {
enableTransition(R.id.yt_transition, true)
}
findViewById<LinearLayout>(R.id.linLayout).visibility = View.VISIBLE
isFullScreen = false
Globals.isFullScreen = false
}
override fun onConfigurationChanged(newConfig: Configuration) {

View File

@ -3,14 +3,13 @@ package com.github.libretube.activities
import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.github.libretube.Globals
import com.github.libretube.R
import com.github.libretube.databinding.ActivitySettingsBinding
import com.github.libretube.preferences.MainSettings
import com.github.libretube.util.ThemeHelper
import com.google.android.material.color.DynamicColors
var isCurrentViewMainSettings = true
class SettingsActivity : AppCompatActivity() {
val TAG = "SettingsActivity"
lateinit var binding: ActivitySettingsBinding
@ -46,11 +45,11 @@ class SettingsActivity : AppCompatActivity() {
}
override fun onBackPressed() {
if (isCurrentViewMainSettings) {
if (Globals.isCurrentViewMainSettings) {
super.onBackPressed()
finishAndRemoveTask()
} else {
isCurrentViewMainSettings = true
Globals.isCurrentViewMainSettings = true
supportFragmentManager
.beginTransaction()
.replace(R.id.settings, MainSettings())

View File

@ -10,6 +10,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.Globals
import com.github.libretube.R
import com.github.libretube.adapters.PlaylistsAdapter
import com.github.libretube.databinding.FragmentLibraryBinding
@ -77,7 +78,7 @@ class LibraryFragment : Fragment() {
override fun onResume() {
// optimize CreatePlaylistFab bottom margin if miniPlayer active
val layoutParams = binding.createPlaylist.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.bottomMargin = if (isMiniPlayerVisible) 180 else 64
layoutParams.bottomMargin = if (Globals.isMiniPlayerVisible) 180 else 64
binding.createPlaylist.layoutParams = layoutParams
super.onResume()
}

View File

@ -32,6 +32,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.Globals
import com.github.libretube.R
import com.github.libretube.activities.MainActivity
import com.github.libretube.activities.hideKeyboard
@ -95,9 +96,6 @@ import java.io.IOException
import java.util.concurrent.Executors
import kotlin.math.abs
var isFullScreen = false
var isMiniPlayerVisible = false
class PlayerFragment : Fragment() {
private val TAG = "PlayerFragment"
@ -208,11 +206,11 @@ class PlayerFragment : Fragment() {
val mainMotionLayout =
mainActivity.binding.mainMotionLayout
if (currentId == eId) {
isMiniPlayerVisible = true
Globals.isMiniPlayerVisible = true
exoPlayerView.useController = false
mainMotionLayout.progress = 1F
} else if (currentId == sId) {
isMiniPlayerVisible = false
Globals.isMiniPlayerVisible = false
exoPlayerView.useController = true
mainMotionLayout.progress = 0F
}
@ -231,7 +229,7 @@ class PlayerFragment : Fragment() {
binding.playerMotionLayout.transitionToStart()
binding.closeImageView.setOnClickListener {
isMiniPlayerVisible = false
Globals.isMiniPlayerVisible = false
binding.playerMotionLayout.transitionToEnd()
val mainActivity = activity as MainActivity
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
@ -240,7 +238,7 @@ class PlayerFragment : Fragment() {
.commit()
}
playerBinding.closeImageButton.setOnClickListener {
isMiniPlayerVisible = false
Globals.isMiniPlayerVisible = false
binding.playerMotionLayout.transitionToEnd()
val mainActivity = activity as MainActivity
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
@ -273,7 +271,7 @@ class PlayerFragment : Fragment() {
playerBinding.fullscreen.setOnClickListener {
// hide player controller
exoPlayerView.hideController()
if (!isFullScreen) {
if (!Globals.isFullScreen) {
// go to fullscreen mode
setFullscreen()
} else {
@ -358,7 +356,7 @@ class PlayerFragment : Fragment() {
}
mainActivity.requestedOrientation = orientation
isFullScreen = true
Globals.isFullScreen = true
}
private fun unsetFullscreen() {
@ -378,7 +376,7 @@ class PlayerFragment : Fragment() {
val mainActivity = activity as MainActivity
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
isFullScreen = false
Globals.isFullScreen = false
}
private fun scaleControls(scaleFactor: Float) {
@ -508,7 +506,7 @@ class PlayerFragment : Fragment() {
runOnUiThread {
// set media sources for the player
setResolutionAndSubtitles(view, response)
setResolutionAndSubtitles(response)
prepareExoPlayerView()
initializePlayerView(view, response)
seekToWatchPosition()
@ -981,10 +979,15 @@ class PlayerFragment : Fragment() {
}
override fun onScrubMove(timeBar: TimeBar, position: Long) {
exoPlayer.seekTo(position)
val minTimeDiff = 10 * 1000 // 10s
// get the difference between the new and the old position
val diff = abs(exoPlayer.currentPosition - position)
// seek only when the difference is greater than 10 seconds
if (diff >= minTimeDiff) exoPlayer.seekTo(position)
}
override fun onScrubStop(timeBar: TimeBar, position: Long, canceled: Boolean) {
exoPlayer.seekTo(position)
exoPlayer.play()
Handler(Looper.getMainLooper()).postDelayed({
exoPlayerView.hideController()
@ -1012,7 +1015,7 @@ class PlayerFragment : Fragment() {
}
playerBinding.chapterLL.visibility = View.VISIBLE
playerBinding.chapterLL.setOnClickListener {
if (isFullScreen) {
if (Globals.isFullScreen) {
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.chapters)
.setItems(titles.toTypedArray()) { _, index ->
@ -1033,7 +1036,7 @@ class PlayerFragment : Fragment() {
// call the function again in 100ms
exoPlayerView.postDelayed(this::setCurrentChapterName, 100)
var chapterName = getCurrentChapterName()
val chapterName = getCurrentChapterName()
// change the chapter name textView text to the chapterName
if (chapterName != null && chapterName != playerBinding.chapterName.text) {
@ -1078,7 +1081,7 @@ class PlayerFragment : Fragment() {
exoPlayer.setMediaSource(mergeSource)
}
private fun setResolutionAndSubtitles(view: View, response: Streams) {
private fun setResolutionAndSubtitles(response: Streams) {
val videoFormatPreference =
PreferenceHelper.getString(requireContext(), "player_video_format", "WEBM")
val defres = PreferenceHelper.getString(requireContext(), "default_res", "")!!
@ -1312,7 +1315,7 @@ class PlayerFragment : Fragment() {
private fun subscribe(channel_id: String) {
fun run() {
lifecycleScope.launchWhenCreated {
val response = try {
try {
val token = PreferenceHelper.getToken(requireContext())
RetrofitInstance.authApi.subscribe(
token,
@ -1335,7 +1338,7 @@ class PlayerFragment : Fragment() {
private fun unsubscribe(channel_id: String) {
fun run() {
lifecycleScope.launchWhenCreated {
val response = try {
try {
val token = PreferenceHelper.getToken(requireContext())
RetrofitInstance.authApi.unsubscribe(
token,
@ -1435,7 +1438,7 @@ class PlayerFragment : Fragment() {
val mainActivity = activity as MainActivity
mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
isFullScreen = false
Globals.isFullScreen = false
} else {
// enable exoPlayer controls again
exoPlayerView.useController = true
@ -1450,7 +1453,7 @@ class PlayerFragment : Fragment() {
binding.playerScrollView.getHitRect(bounds)
if (SDK_INT >= Build.VERSION_CODES.O &&
exoPlayer.isPlaying && (binding.playerScrollView.getLocalVisibleRect(bounds) || isFullScreen)
exoPlayer.isPlaying && (binding.playerScrollView.getLocalVisibleRect(bounds) || Globals.isFullScreen)
) {
activity?.enterPictureInPictureMode(updatePipParams())
}

View File

@ -37,7 +37,7 @@ object ThemeHelper {
"L" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
"D" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
"O" -> {
context.setTheme(R.style.OLED)
context.setTheme(R.style.Black)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}
}

View File

@ -5,7 +5,7 @@ import android.os.Looper
import android.view.View
class DoubleClickListener(
private val doubleClickTimeLimitMills: Long = 300,
private val doubleClickTimeLimitMills: Long = 200,
private val callback: Callback
) : View.OnClickListener {
private var lastClicked: Long = -1L

View File

@ -15,7 +15,7 @@
</style>
<style name="OLED">
<style name="Black">
<item name="android:colorBackground">@android:color/black</item>
<item name="colorSurface">@android:color/black</item>
@ -116,7 +116,7 @@
<style name="PlayerButton">
<item name="android:padding">6dp</item>
<item name="android:padding">9dp</item>
<item name="android:layout_height">36dp</item>
<item name="android:layout_width">36dp</item>
<item name="android:layout_gravity">center</item>