Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions app/src/main/assets/licenses/Inter-OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter)

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL

-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION AND CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ object CommonActivity {
"Dracula" -> R.style.DraculaMode
"Lavender" -> R.style.LavenderMode
"SilentBlue" -> R.style.SilentBlueMode
"TvOS" -> R.style.TvOSMode

else -> R.style.AppTheme
}
Expand All @@ -381,6 +382,7 @@ object CommonActivity {
"Party" -> R.style.OverlayPrimaryColorParty
"Pink" -> R.style.OverlayPrimaryColorPink
"Lavender" -> R.style.OverlayPrimaryColorLavender
"AppleBlue" -> R.style.OverlayPrimaryColorAppleBlue
"Monet" -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
R.style.OverlayPrimaryColorMonet else R.style.OverlayPrimaryColorNormal

Expand Down
79 changes: 77 additions & 2 deletions app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.localLi
import com.lagradost.cloudstream3.syncproviders.SyncAPI
import com.lagradost.cloudstream3.ui.APIRepository
import com.lagradost.cloudstream3.ui.SyncWatchType
import com.lagradost.cloudstream3.ui.TvLiftFocus
import com.lagradost.cloudstream3.ui.WatchType
import com.lagradost.cloudstream3.ui.account.AccountHelper.showAccountSelectLinear
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
Expand Down Expand Up @@ -490,6 +491,27 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
navHostFragment.navController.currentDestination?.let { updateNavBar(it) }
}

private var isTabBarShown = true

/** The tab bar scrolls away with the home page, called on every scrolled frame */
private fun updateTabBarVisibility() {
val tabBar = tvTabBarBinding?.navTopBar ?: return
if (!tabBar.isVisible) return

val homeRecycler = binding?.root?.findViewById<RecyclerView?>(R.id.home_master_recycler)
val show = tabBar.hasFocus() || homeRecycler == null ||
homeRecycler.computeVerticalScrollOffset() < 40.toPx
if (show == isTabBarShown) return
isTabBarShown = show

tabBar.animate().cancel()
tabBar.animate()
.translationY(if (show) 0.0f else -(tabBar.bottom + 10.toPx).toFloat())
.alpha(if (show) 1.0f else 0.0f)
.setDuration(200)
.start()
}

private fun updateNavBar(destination: NavDestination) {
this.hideKeyboard()

Expand Down Expand Up @@ -557,17 +579,31 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
}*/

binding?.apply {
navRailView.isVisible = isNavVisible && isLandscape()
// On TV the top tab bar replaces the nav rail
navRailView.isVisible = isNavVisible && isLandscape() && !isLayout(TV)
navView.isVisible = isNavVisible && !isLandscape()
navHostFragment.apply {
val marginPx = resources.getDimensionPixelSize(R.dimen.nav_rail_view_width)
layoutParams =
(navHostFragment.layoutParams as ViewGroup.MarginLayoutParams).apply {
marginStart =
if (isNavVisible && isLandscape() && isLayout(TV or EMULATOR)) marginPx else 0
if (isNavVisible && isLandscape() && isLayout(EMULATOR)) marginPx else 0
}
}

tvTabBarBinding?.apply {
navTopBar.isVisible = destination.id == R.id.navigation_home
if (navTopBar.isVisible) {
updateTabBarVisibility()
// Focus "Home" on app start and whenever nothing is focused
val isFirstFocus = !hasDoneInitialTvFocus
hasDoneInitialTvFocus = true
navTopBar.postDelayed({
if (isFirstFocus || currentFocus?.isShown != true) navTopHome.requestFocus()
}, 500)
}
}

/**
* We need to make sure if we return to a sub-fragment,
* the correct navigation item is selected so that it does not
Expand Down Expand Up @@ -908,6 +944,10 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa

var binding: ActivityMainBinding? = null

/** Only set on TV, holds the top tab bar */
private var tvTabBarBinding: ActivityMainTvBinding? = null
private var hasDoneInitialTvFocus = false

object TvFocus {
data class FocusTarget(
val width: Int,
Expand Down Expand Up @@ -1251,6 +1291,16 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
}

if (isLayout(TV)) {
tvTabBarBinding = newLocalBinding
newLocalBinding.navTopHome.isSelected = true
newLocalBinding.root.viewTreeObserver.addOnGlobalFocusChangeListener { _, newFocus ->
TvLiftFocus.onFocusChanged(newFocus)
updateTabBarVisibility()
}
newLocalBinding.root.viewTreeObserver.addOnScrollChangedListener {
updateTabBarVisibility()
}

// Put here any button you don't want focusing it to center the view
val exceptionButtons = listOf(
//R.id.home_preview_play_btt,
Expand Down Expand Up @@ -1837,6 +1887,31 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
}
}

tvTabBarBinding?.apply {
for ((tab, destinationId) in listOf(
navTopHome to R.id.navigation_home,
navTopSearch to R.id.navigation_search,
navTopLibrary to R.id.navigation_library,
navTopDownloads to R.id.navigation_downloads,
navTopSettings to R.id.navigation_settings,
)) {
tab.setOnClickListener {
binding?.navRailView?.menu?.findItem(destinationId)?.let { item ->
onNavDestinationSelected(item, navController)
}
}
}

navTopProfileCard.setOnClickListener {
showAccountSelectLinear()
}
val homeViewModel = ViewModelProvider(this@MainActivity)[HomeViewModel::class.java]
observe(homeViewModel.currentAccount) { currentAccount ->
navTopProfileCard.isVisible = currentAccount != null
if (currentAccount != null) navTopProfilePic.loadImage(currentAccount.image)
}
}

// Navigation button long click functionality to scroll to top
for (view in listOf(binding?.navView, binding?.navRailView)) {
view?.findViewById<View?>(R.id.navigation_home)?.setOnLongClickListener {
Expand Down
78 changes: 78 additions & 0 deletions app/src/main/java/com/lagradost/cloudstream3/ui/TvLiftFocus.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.lagradost.cloudstream3.ui

import android.graphics.drawable.Drawable
import android.view.View
import android.view.animation.DecelerateInterpolator
import androidx.recyclerview.widget.RecyclerView
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.utils.UIHelper.toPx
import java.lang.ref.WeakReference

/**
* tvOS-like focus: the focused view is scaled up with a shadow instead of being outlined.
* Large views would overflow the screen, so they keep their focus drawable.
* The lifted view must fit in the padding of its parent (tv_lift_room), as unclipping
* the parents doubles the GPU time of every frame.
*/
object TvLiftFocus {
private const val CARD_SCALE = 1.10f
private const val BUTTON_SCALE = 1.06f
private const val DURATION = 180L

/** Max size of a liftable view, relative to the screen */
private const val MAX_WIDTH_FRACTION = 0.4f
private const val MAX_HEIGHT_FRACTION = 0.6f

private val interpolator = DecelerateInterpolator(1.5f)
private var lifted: WeakReference<View> = WeakReference(null)
private var liftedForeground: Drawable? = null

/** Hides the title below [card] until it is focused, like the posters on tvOS */
fun hideTitleUntilFocused(card: View) {
val title = card.findViewById<View>(R.id.imageText) ?: return
card.setTag(R.id.tv_hide_title, true)
title.animate().cancel()
title.alpha = if (card.hasFocus()) 1.0f else 0.0f
}

fun onFocusChanged(newFocus: View?) {
lifted.get()?.let { old -> if (old != newFocus) lower(old) }
lifted = WeakReference(null)
if (newFocus == null || !canLift(newFocus)) return

// RecyclerView items are cards (posters, episodes), everything else is a button
animate(newFocus, if (newFocus.parent is RecyclerView) CARD_SCALE else BUTTON_SCALE, 12.toPx)
lifted = WeakReference(newFocus)
liftedForeground = newFocus.foreground
newFocus.foreground = null
}

private fun lower(view: View) {
if (view.foreground == null) view.foreground = liftedForeground
animate(view, 1.0f, 0)
}

private fun animate(view: View, scale: Float, elevation: Int) {
view.animate()
.scaleX(scale)
.scaleY(scale)
.translationZ(elevation.toFloat())
.setDuration(DURATION)
.setInterpolator(interpolator)
.start()
if (view.getTag(R.id.tv_hide_title) == true) {
view.findViewById<View>(R.id.imageText)?.animate()
?.alpha(if (scale > 1.0f) 1.0f else 0.0f)
?.setDuration(DURATION)
?.start()
}
}

private fun canLift(view: View): Boolean {
if (view.tag == view.context.getString(R.string.tv_no_focus_tag)) return false
val root = view.rootView ?: return false
return view.width > 0 && view.height > 0 &&
view.width <= root.width * MAX_WIDTH_FRACTION &&
view.height <= root.height * MAX_HEIGHT_FRACTION
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.lagradost.cloudstream3.databinding.HomeResultGridBinding
import com.lagradost.cloudstream3.databinding.HomeResultGridExpandedBinding
import com.lagradost.cloudstream3.ui.BaseAdapter
import com.lagradost.cloudstream3.ui.BaseDiffCallback
import com.lagradost.cloudstream3.ui.TvLiftFocus
import com.lagradost.cloudstream3.ui.ViewHolderState
import com.lagradost.cloudstream3.ui.newSharedPool
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_LOAD
Expand Down Expand Up @@ -226,5 +227,6 @@ open class HomeChildItemAdapter(
)

holder.itemView.tag = position
if (isLayout(TV)) TvLiftFocus.hideTitleUntilFocused(holder.itemView)
}
}
Loading
Loading