diff --git a/app/src/main/java/dev/kuylar/lighttube/ui/VideoPlayerManager.kt b/app/src/main/java/dev/kuylar/lighttube/ui/VideoPlayerManager.kt index 69c2561..6b7cc3d 100644 --- a/app/src/main/java/dev/kuylar/lighttube/ui/VideoPlayerManager.kt +++ b/app/src/main/java/dev/kuylar/lighttube/ui/VideoPlayerManager.kt @@ -4,22 +4,18 @@ import android.content.pm.ActivityInfo import android.os.Handler import android.util.Log import android.view.View -import android.widget.ImageView import android.widget.ProgressBar import android.widget.TextView import android.widget.Toast import androidx.appcompat.content.res.AppCompatResources import androidx.core.content.ContextCompat import androidx.core.os.bundleOf -import com.bumptech.glide.Glide -import com.bumptech.glide.load.resource.bitmap.CenterCrop import com.github.vkay94.dtpv.DoubleTapPlayerView import com.github.vkay94.dtpv.youtube.YouTubeOverlay import com.github.vkay94.timebar.LibTimeBar import com.github.vkay94.timebar.YouTubeChapter import com.github.vkay94.timebar.YouTubeSegment import com.github.vkay94.timebar.YouTubeTimeBar -import com.github.vkay94.timebar.YouTubeTimeBarPreview import com.google.android.exoplayer2.C import com.google.android.exoplayer2.ExoPlayer import com.google.android.exoplayer2.MediaItem @@ -44,7 +40,7 @@ import java.io.IOException import kotlin.concurrent.thread class VideoPlayerManager(private val activity: MainActivity) : Player.Listener, - YouTubeTimeBarPreview.Listener, LibTimeBar.SegmentListener { + LibTimeBar.SegmentListener { private var videoTracks: Tracks? = null private val playerHandler: Handler private val exoplayerView: DoubleTapPlayerView = activity.findViewById(R.id.player) @@ -56,7 +52,7 @@ class VideoPlayerManager(private val activity: MainActivity) : Player.Listener, private val player: ExoPlayer = ExoPlayer.Builder(activity).apply { setHandleAudioBecomingNoisy(true) }.build() - private val api: LightTubeApi = activity.api + private lateinit var api: LightTubeApi private val fragmentManager = activity.supportFragmentManager private val miniplayerTitle: TextView = activity.findViewById(R.id.miniplayer_video_title) @@ -82,6 +78,8 @@ class VideoPlayerManager(private val activity: MainActivity) : Player.Listener, ) playerHandler = Handler(player.applicationLooper) + api = activity.getApi() + // im sorry for this monstrosity var r = Runnable {} r = Runnable { @@ -129,10 +127,6 @@ class VideoPlayerManager(private val activity: MainActivity) : Player.Listener, val timeBar = view.findViewById(com.google.android.exoplayer2.ui.R.id.exo_progress) timeBar.addSegmentListener(this) - val preview = view.findViewById(R.id.player_preview) - view.findViewById(com.google.android.exoplayer2.ui.R.id.exo_progress) - .timeBarPreview(preview) - preview.previewListener(this) if (isFullscreen) { fullscreenDoubleTapView @@ -334,8 +328,9 @@ class VideoPlayerManager(private val activity: MainActivity) : Player.Listener, } private fun setStoryboards(levels: String?, recommendedLevel: String?, length: Long?) { - if (levels == null || length == null || recommendedLevel == null) storyboard = null - storyboard = StoryboardInfo(levels!!, recommendedLevel!!, length!!) + return //FIXME: disabled until i write a working storyboard view + // if (levels == null || length == null || recommendedLevel == null) storyboard = null + // storyboard = StoryboardInfo(levels!!, recommendedLevel!!, length!!) } private fun setSponsors(videoId: String) { @@ -470,21 +465,6 @@ class VideoPlayerManager(private val activity: MainActivity) : Player.Listener, } } - override fun loadThumbnail(imageView: ImageView, position: Long) { - try { - storyboard!!.throttle(position) // the library fails throttling, so we do it ourselves - Glide.with(activity) - .load(storyboard!!.getImageUrl(position)) - .transform(storyboard!!.getTransformation(position), CenterCrop()) - .into(imageView) - } catch (e: Exception) { - if (e.message != "throttle") - Glide.with(activity) - .load("https://i.ytimg.com/vi/${player.currentMediaItem?.mediaId}/maxresdefault.jpg") - .into(imageView) - } - } - override fun onChapterChanged(timeBar: LibTimeBar, newChapter: YouTubeChapter, drag: Boolean) { // todo: show current chapter on UI } diff --git a/app/src/main/java/dev/kuylar/lighttube/ui/activity/MainActivity.kt b/app/src/main/java/dev/kuylar/lighttube/ui/activity/MainActivity.kt index b770948..c4e8bbd 100644 --- a/app/src/main/java/dev/kuylar/lighttube/ui/activity/MainActivity.kt +++ b/app/src/main/java/dev/kuylar/lighttube/ui/activity/MainActivity.kt @@ -40,7 +40,7 @@ class MainActivity : AppCompatActivity() { lateinit var miniplayer: BottomSheetBehavior private lateinit var miniplayerScene: MotionLayout lateinit var player: VideoPlayerManager - lateinit var api: LightTubeApi + private lateinit var api: LightTubeApi private var loadingSuggestions = false override fun onCreate(savedInstanceState: Bundle?) { @@ -58,7 +58,7 @@ class MainActivity : AppCompatActivity() { return } - api = LightTubeApi(this) + setApi() binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) @@ -151,6 +151,16 @@ class MainActivity : AppCompatActivity() { } } + private fun setApi() { + api = LightTubeApi(this) + } + + fun getApi(): LightTubeApi { + if (!this::api.isInitialized) + setApi() + return api + } + private fun minimizePlayer(): Boolean { return if (miniplayer.state == BottomSheetBehavior.STATE_EXPANDED) { miniplayer.state = BottomSheetBehavior.STATE_COLLAPSED diff --git a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/ChannelFragment.kt b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/ChannelFragment.kt index 065f4a6..f7b6756 100644 --- a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/ChannelFragment.kt +++ b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/ChannelFragment.kt @@ -34,7 +34,7 @@ class ChannelFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { (activity as MainActivity).apply { thread { - val channel = api.getChannel(id, "about") + val channel = getApi().getChannel(id, "about") val channelAdapter = ChannelAdapter(childFragmentManager, id, ArrayList(channel.data!!.enabledTabs.filter { it.lowercase() != "search" })) val viewPager = binding.channelPager diff --git a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/HomeFragment.kt b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/HomeFragment.kt index b5af26a..8951d85 100644 --- a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/HomeFragment.kt +++ b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/HomeFragment.kt @@ -34,7 +34,7 @@ class HomeFragment : Fragment() { a.setLoading(true) thread { try { - val info = a.api.getInstanceInfo() + val info = a.getApi().getInstanceInfo() a.runOnUiThread { a.setLoading(false) binding.homeMotd.text = info.motd diff --git a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/LibraryFragment.kt b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/LibraryFragment.kt index 9f2b148..e69fe4d 100644 --- a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/LibraryFragment.kt +++ b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/LibraryFragment.kt @@ -41,6 +41,7 @@ class LibraryFragment : Fragment() { val adapter = RendererRecyclerAdapter(items) binding.recyclerLibrary.layoutManager = LinearLayoutManager(context) binding.recyclerLibrary.adapter = adapter + binding.recyclerLibrary.itemAnimator = null if (items.size == 0) loadData() } diff --git a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/PlaylistFragment.kt b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/PlaylistFragment.kt index 3480da3..77b2356 100644 --- a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/PlaylistFragment.kt +++ b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/PlaylistFragment.kt @@ -46,6 +46,7 @@ class PlaylistFragment : Fragment() { val adapter = RendererRecyclerAdapter(items) binding.recyclerPlaylist.layoutManager = LinearLayoutManager(context) binding.recyclerPlaylist.adapter = adapter + binding.recyclerPlaylist.itemAnimator = null binding.recyclerPlaylist.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { super.onScrollStateChanged(recyclerView, newState) diff --git a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/SearchFragment.kt b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/SearchFragment.kt index ddb0dbc..cfe17c1 100644 --- a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/SearchFragment.kt +++ b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/SearchFragment.kt @@ -47,6 +47,7 @@ class SearchFragment : Fragment() { val adapter = RendererRecyclerAdapter(items) binding.recyclerSearch.layoutManager = LinearLayoutManager(context) binding.recyclerSearch.adapter = adapter + binding.recyclerSearch.itemAnimator = null binding.recyclerSearch.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { super.onScrollStateChanged(recyclerView, newState) diff --git a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/VideoCommentsFragment.kt b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/VideoCommentsFragment.kt index efe9e36..43e0e08 100644 --- a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/VideoCommentsFragment.kt +++ b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/VideoCommentsFragment.kt @@ -36,7 +36,7 @@ class VideoCommentsFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { - api = (activity as MainActivity).api + api = (activity as MainActivity).getApi() binding = FragmentVideoCommentsBinding.inflate(inflater) return binding.root } @@ -46,6 +46,7 @@ class VideoCommentsFragment : Fragment() { val adapter = RendererRecyclerAdapter(items) binding.recyclerComments.layoutManager = LinearLayoutManager(context) binding.recyclerComments.adapter = adapter + binding.recyclerComments.itemAnimator = null binding.recyclerComments.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { super.onScrollStateChanged(recyclerView, newState) diff --git a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/VideoInfoFragment.kt b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/VideoInfoFragment.kt index ff35cb0..1b6e014 100644 --- a/app/src/main/java/dev/kuylar/lighttube/ui/fragment/VideoInfoFragment.kt +++ b/app/src/main/java/dev/kuylar/lighttube/ui/fragment/VideoInfoFragment.kt @@ -35,7 +35,7 @@ class VideoInfoFragment : Fragment() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - api = (requireActivity() as MainActivity).api + api = (requireActivity() as MainActivity).getApi() player = (requireActivity() as MainActivity).player arguments?.let { id = it.getString("id")!! @@ -93,10 +93,10 @@ class VideoInfoFragment : Fragment() { val adapter = RendererRecyclerAdapter(items) binding.recyclerRecommended.layoutManager = LinearLayoutManager(context) binding.recyclerRecommended.adapter = adapter + binding.recyclerRecommended.itemAnimator = null requireActivity().supportFragmentManager.beginTransaction().apply { replace(R.id.video_info_fragment, VideoDetailsFragment::class.java, bundleOf(Pair("video", Gson().toJson(video)))) - replace(R.id.comments_fragment, VideoCommentsFragment::class.java, bundleOf(Pair("commentsContinuation", video.commentsContinuation))) }.commit() diff --git a/app/src/main/res/layout/exo_playback_control_view.xml b/app/src/main/res/layout/exo_playback_control_view.xml index d796a95..e680ad4 100644 --- a/app/src/main/res/layout/exo_playback_control_view.xml +++ b/app/src/main/res/layout/exo_playback_control_view.xml @@ -196,13 +196,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - -