Skip to content

Commit 6cc8b01

Browse files
authored
Feat(TV): Added network stream to downloads tab, and updated nextfocus for easier navigation. Closes #1283
1 parent b87e85b commit 6cc8b01

8 files changed

Lines changed: 241 additions & 119 deletions

File tree

app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,36 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
699699
// Check if we are already at the selected destination
700700
if (navController.currentDestination?.id == destinationId) return false
701701

702+
// Make all nav buttons focus on this specific view when nextFocusRightId
703+
val targetView = when (destinationId) {
704+
// Please note that if R.id.navigation_home is readded, then it will only take affect when
705+
// navigation to home for the second time as onNavDestinationSelected will not get called
706+
// when first loading up the app
707+
708+
// R.id.navigation_home -> R.id.home_preview_change_api
709+
R.id.navigation_search -> R.id.main_search
710+
R.id.navigation_library -> R.id.main_search
711+
R.id.navigation_downloads -> R.id.download_appbar
712+
else -> null
713+
}
714+
if (targetView != null && isLayout(TV or EMULATOR)) {
715+
val fromView = binding?.navRailView
716+
if (fromView != null) {
717+
fromView.nextFocusRightId = targetView
718+
719+
for (focusView in arrayOf(
720+
R.id.navigation_downloads,
721+
R.id.navigation_home,
722+
R.id.navigation_search,
723+
R.id.navigation_library,
724+
R.id.navigation_settings,
725+
)) {
726+
fromView.findViewById<View?>(focusView)?.nextFocusRightId = targetView
727+
}
728+
}
729+
}
730+
731+
702732
val builder = NavOptions.Builder().setLaunchSingleTop(true).setRestoreState(true)
703733
.setEnterAnim(R.anim.enter_anim)
704734
.setExitAnim(R.anim.exit_anim)

app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class DownloadFragment : Fragment() {
8787
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
8888
super.onViewCreated(view, savedInstanceState)
8989
hideKeyboard()
90-
binding?.downloadStorageAppbar?.setAppBarNoScrollFlagsOnTV()
90+
binding?.downloadAppbar?.setAppBarNoScrollFlagsOnTV()
9191
binding?.downloadDeleteAppbar?.setAppBarNoScrollFlagsOnTV()
9292

9393
/**
@@ -136,12 +136,15 @@ class DownloadFragment : Fragment() {
136136
binding?.downloadUsed
137137
)
138138

139-
// Prevent race condition and make sure
140-
// we don't display it early
141-
if (
142-
downloadsViewModel.isMultiDeleteState.value == null ||
143-
downloadsViewModel.isMultiDeleteState.value == false
144-
) binding?.downloadStorageAppbar?.isVisible = it > 0
139+
val hasBytes = it > 0
140+
if(hasBytes) {
141+
binding?.downloadLoadingBytes?.stopShimmer()
142+
} else {
143+
binding?.downloadLoadingBytes?.startShimmer()
144+
}
145+
146+
binding?.downloadBytesBar?.isVisible = hasBytes
147+
binding?.downloadLoadingBytes?.isGone = hasBytes
145148
}
146149
observe(downloadsViewModel.downloadBytes) {
147150
updateStorageInfo(
@@ -165,7 +168,7 @@ class DownloadFragment : Fragment() {
165168
// Prevent race condition and make sure
166169
// we don't display it early
167170
if (downloadsViewModel.usedBytes.value?.let { it > 0 } == true) {
168-
binding?.downloadStorageAppbar?.isVisible = true
171+
binding?.downloadAppbar?.isVisible = true
169172
}
170173
}
171174
}
@@ -218,6 +221,12 @@ class DownloadFragment : Fragment() {
218221
isGone = isLayout(TV)
219222
setOnClickListener { showStreamInputDialog(it.context) }
220223
}
224+
225+
downloadStreamButtonTv.isFocusableInTouchMode = isLayout(TV)
226+
downloadAppbar.isFocusableInTouchMode = isLayout(TV)
227+
228+
downloadStreamButtonTv.setOnClickListener { showStreamInputDialog(it.context) }
229+
steamImageviewHolder.isVisible = isLayout(TV)
221230
}
222231

223232
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@@ -252,7 +261,7 @@ class DownloadFragment : Fragment() {
252261
private fun handleSelectedChange(selected: MutableSet<Int>) {
253262
if (selected.isNotEmpty()) {
254263
binding?.downloadDeleteAppbar?.isVisible = true
255-
binding?.downloadStorageAppbar?.isVisible = false
264+
binding?.downloadAppbar?.isVisible = false
256265
activity?.attachBackPressedCallback("Downloads") {
257266
downloadsViewModel.setIsMultiDeleteState(false)
258267
}

app/src/main/res/layout/fragment_child_downloads.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
android:contentDescription="@string/cancel"
3333
android:padding="8dp"
3434
android:layout_gravity="center_vertical"
35-
android:nextFocusLeft="@id/nav_rail_view"
35+
android:nextFocusLeft="@id/navigation_downloads"
3636
app:tint="@android:color/white" />
3737

3838
<Button
@@ -87,7 +87,7 @@
8787
android:layout_width="match_parent"
8888
android:layout_height="match_parent"
8989
android:background="?attr/primaryBlackBackground"
90-
android:nextFocusLeft="@id/nav_rail_view"
90+
android:nextFocusLeft="@id/navigation_downloads"
9191
android:nextFocusUp="@id/download_child_toolbar"
9292
android:padding="10dp"
9393
app:layout_behavior="@string/appbar_scrolling_view_behavior"

0 commit comments

Comments
 (0)