Skip to content

Commit bff9727

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents a82059c + 627c1bb commit bff9727

File tree

12 files changed

+250
-131
lines changed

12 files changed

+250
-131
lines changed

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
128128
import com.lagradost.cloudstream3.utils.Coroutines.main
129129
import com.lagradost.cloudstream3.utils.DataStore.getKey
130130
import com.lagradost.cloudstream3.utils.DataStore.setKey
131+
import com.lagradost.cloudstream3.utils.DataStoreHelper
131132
import com.lagradost.cloudstream3.utils.DataStoreHelper.migrateResumeWatching
132133
import com.lagradost.cloudstream3.utils.Event
133134
import com.lagradost.cloudstream3.utils.IOnBackPressed
@@ -305,6 +306,10 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
305306

306307
// kinda shitty solution, but cant com main->home otherwise for popups
307308
val bookmarksUpdatedEvent = Event<Boolean>()
309+
/**
310+
* Used by data store helper to fully reload home when switching accounts
311+
*/
312+
val reloadHomeEvent = Event<Boolean>()
308313

309314

310315
/**
@@ -539,6 +544,10 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
539544
val isTrueTv = isTrueTvSettings()
540545
navView.menu.findItem(R.id.navigation_library)?.isVisible = !isTrueTv
541546
navRailView.menu.findItem(R.id.navigation_library)?.isVisible = !isTrueTv
547+
548+
// Hide downloads on TV
549+
navView.menu.findItem(R.id.navigation_downloads)?.isVisible = !isTrueTv
550+
navRailView.menu.findItem(R.id.navigation_downloads)?.isVisible = !isTrueTv
542551
}
543552
}
544553

@@ -1092,15 +1101,19 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
10921101
updateTv()
10931102

10941103
// backup when we update the app, I don't trust myself to not boot lock users, might want to make this a setting?
1095-
try {
1104+
normalSafeApiCall {
10961105
val appVer = BuildConfig.VERSION_NAME
10971106
val lastAppAutoBackup: String = getKey("VERSION_NAME") ?: ""
10981107
if (appVer != lastAppAutoBackup) {
10991108
setKey("VERSION_NAME", BuildConfig.VERSION_NAME)
1100-
backup()
1109+
normalSafeApiCall {
1110+
backup()
1111+
}
1112+
normalSafeApiCall {
1113+
// Recompile oat on new version
1114+
PluginManager.deleteAllOatFiles(this)
1115+
}
11011116
}
1102-
} catch (t: Throwable) {
1103-
logError(t)
11041117
}
11051118

11061119
// just in case, MAIN SHOULD *NEVER* BOOT LOOP CRASH
@@ -1112,16 +1125,17 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
11121125
newLocalBinding.root.viewTreeObserver.addOnGlobalFocusChangeListener { _, newFocus ->
11131126
// println("refocus $oldFocus -> $newFocus")
11141127
try {
1115-
val r = Rect(0,0,0,0)
1128+
val r = Rect(0, 0, 0, 0)
11161129
newFocus.getDrawingRect(r)
11171130
val x = r.centerX()
11181131
val y = r.centerY()
11191132
val dx = 0 //screenWidth / 2
11201133
val dy = screenHeight / 2
1121-
val r2 = Rect(x-dx,y-dy,x+dx,y+dy)
1134+
val r2 = Rect(x - dx, y - dy, x + dx, y + dy)
11221135
newFocus.requestRectangleOnScreen(r2, false)
1123-
// TvFocus.current =TvFocus.current.copy(y=y.toFloat())
1124-
} catch (_ : Throwable) { }
1136+
// TvFocus.current =TvFocus.current.copy(y=y.toFloat())
1137+
} catch (_: Throwable) {
1138+
}
11251139
TvFocus.updateFocusView(newFocus)
11261140
/*var focus = newFocus
11271141
@@ -1182,7 +1196,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
11821196
}
11831197
} else if (lastError == null) {
11841198
ioSafe {
1185-
getKey<String>(USER_SELECTED_HOMEPAGE_API)?.let { homeApi ->
1199+
DataStoreHelper.currentHomePage?.let { homeApi ->
11861200
mainPluginsLoadedEvent.invoke(loadSinglePlugin(this@MainActivity, homeApi))
11871201
} ?: run {
11881202
mainPluginsLoadedEvent.invoke(false)
@@ -1543,6 +1557,11 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
15431557
migrateResumeWatching()
15441558
}
15451559

1560+
getKey<String>(USER_SELECTED_HOMEPAGE_API)?.let { homepage ->
1561+
DataStoreHelper.currentHomePage = homepage
1562+
removeKey(USER_SELECTED_HOMEPAGE_API)
1563+
}
1564+
15461565
try {
15471566
if (getKey(HAS_DONE_SETUP_KEY, false) != true) {
15481567
navController.navigate(R.id.navigation_setup_language)

app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ object PluginManager {
137137
}
138138
}
139139

140+
/**
141+
* Deletes all generated oat files which will force Android to recompile the dex extensions.
142+
* This might fix unrecoverable SIGSEGV exceptions when old oat files are loaded in a new app update.
143+
*/
144+
fun deleteAllOatFiles(context: Context) {
145+
File("${context.filesDir}/${ONLINE_PLUGINS_FOLDER}").listFiles()?.forEach { repo ->
146+
repo.listFiles { file -> file.name == "oat" && file.isDirectory }?.forEach { file ->
147+
val success = file.deleteRecursively()
148+
Log.i(TAG, "Deleted oat directory: ${file.absolutePath} Success=$success")
149+
}
150+
}
151+
}
152+
153+
140154
fun getPluginsOnline(): Array<PluginData> {
141155
return getKey(PLUGINS_KEY) ?: emptyArray()
142156
}

app/src/main/java/com/lagradost/cloudstream3/ui/AutofitRecyclerView.kt renamed to app/src/main/java/com/lagradost/cloudstream3/ui/CustomRecyclerViews.kt

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.ui
33
import android.content.Context
44
import android.util.AttributeSet
55
import android.view.View
6+
import androidx.core.view.children
67
import androidx.recyclerview.widget.GridLayoutManager
78
import androidx.recyclerview.widget.RecyclerView
89
import kotlin.math.abs
@@ -70,8 +71,8 @@ class GrdLayoutManager(val context: Context, _spanCount: Int) :
7071
val orientation = this.orientation
7172

7273
// fixes arabic by inverting left and right layout focus
73-
val correctDirection = if(this.isLayoutRTL) {
74-
when(direction) {
74+
val correctDirection = if (this.isLayoutRTL) {
75+
when (direction) {
7576
View.FOCUS_RIGHT -> View.FOCUS_LEFT
7677
View.FOCUS_LEFT -> View.FOCUS_RIGHT
7778
else -> direction
@@ -83,12 +84,15 @@ class GrdLayoutManager(val context: Context, _spanCount: Int) :
8384
View.FOCUS_DOWN -> {
8485
return spanCount
8586
}
87+
8688
View.FOCUS_UP -> {
8789
return -spanCount
8890
}
91+
8992
View.FOCUS_RIGHT -> {
9093
return 1
9194
}
95+
9296
View.FOCUS_LEFT -> {
9397
return -1
9498
}
@@ -98,12 +102,15 @@ class GrdLayoutManager(val context: Context, _spanCount: Int) :
98102
View.FOCUS_DOWN -> {
99103
return 1
100104
}
105+
101106
View.FOCUS_UP -> {
102107
return -1
103108
}
109+
104110
View.FOCUS_RIGHT -> {
105111
return spanCount
106112
}
113+
107114
View.FOCUS_LEFT -> {
108115
return -spanCount
109116
}
@@ -155,4 +162,32 @@ class AutofitRecyclerView @JvmOverloads constructor(context: Context, attrs: Att
155162

156163
layoutManager = manager
157164
}
165+
}
166+
167+
/**
168+
* Recyclerview wherein the max item width or height is set by the biggest view to prevent inconsistent view sizes.
169+
*/
170+
class MaxRecyclerView(ctx: Context, attrs: AttributeSet) : RecyclerView(ctx, attrs) {
171+
private var biggestObserved: Int = 0
172+
private val orientation = LayoutManager.getProperties(context, attrs, 0, 0).orientation
173+
private val isHorizontal = orientation == HORIZONTAL
174+
private fun View.updateMaxSize() {
175+
if (isHorizontal) {
176+
this.minimumHeight = biggestObserved
177+
} else {
178+
this.minimumWidth = biggestObserved
179+
}
180+
}
181+
182+
override fun onChildAttachedToWindow(child: View) {
183+
child.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED)
184+
val observed = if (isHorizontal) child.measuredHeight else child.measuredWidth
185+
if (observed > biggestObserved) {
186+
biggestObserved = observed
187+
children.forEach { it.updateMaxSize() }
188+
} else {
189+
child.updateMaxSize()
190+
}
191+
super.onChildAttachedToWindow(child)
192+
}
158193
}

app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
6969
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
7070
import com.lagradost.cloudstream3.utils.UIHelper.getSpanCount
7171
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIconsAndNoStringRes
72-
import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API
7372

7473
import java.util.*
7574

@@ -669,7 +668,7 @@ class HomeFragment : Fragment() {
669668
}
670669

671670
homeViewModel.reloadStored()
672-
homeViewModel.loadAndCancel(getKey(USER_SELECTED_HOMEPAGE_API), false)
671+
homeViewModel.loadAndCancel(DataStoreHelper.currentHomePage, false)
673672
//loadHomePage(false)
674673

675674
// nice profile pic on homepage

app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.getBookmarkedData
4949
import com.lagradost.cloudstream3.utils.DataStoreHelper.getLastWatched
5050
import com.lagradost.cloudstream3.utils.DataStoreHelper.getResultWatchState
5151
import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
52-
import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API
5352
import com.lagradost.cloudstream3.utils.VideoDownloadHelper
5453
import kotlinx.coroutines.Dispatchers
5554
import kotlinx.coroutines.Job
@@ -426,23 +425,29 @@ class HomeViewModel : ViewModel() {
426425
}
427426

428427
private fun afterPluginsLoaded(forceReload: Boolean) {
429-
loadAndCancel(getKey(USER_SELECTED_HOMEPAGE_API), forceReload)
428+
loadAndCancel(DataStoreHelper.currentHomePage, forceReload)
430429
}
431430

432431
private fun afterMainPluginsLoaded(unused: Boolean = false) {
433-
loadAndCancel(getKey(USER_SELECTED_HOMEPAGE_API), false)
432+
loadAndCancel(DataStoreHelper.currentHomePage, false)
433+
}
434+
435+
private fun reloadHome(unused: Boolean = false) {
436+
loadAndCancel(DataStoreHelper.currentHomePage, true)
434437
}
435438

436439
init {
437440
MainActivity.bookmarksUpdatedEvent += ::bookmarksUpdated
438441
MainActivity.afterPluginsLoadedEvent += ::afterPluginsLoaded
439442
MainActivity.mainPluginsLoadedEvent += ::afterMainPluginsLoaded
443+
MainActivity.reloadHomeEvent += ::reloadHome
440444
}
441445

442446
override fun onCleared() {
443447
MainActivity.bookmarksUpdatedEvent -= ::bookmarksUpdated
444448
MainActivity.afterPluginsLoadedEvent -= ::afterPluginsLoaded
445449
MainActivity.mainPluginsLoadedEvent -= ::afterMainPluginsLoaded
450+
MainActivity.reloadHomeEvent -= ::reloadHome
446451
super.onCleared()
447452
}
448453

@@ -495,7 +500,7 @@ class HomeViewModel : ViewModel() {
495500
val api = getApiFromNameNull(preferredApiName)
496501
if (preferredApiName == noneApi.name) {
497502
// just set to random
498-
if (fromUI) setKey(USER_SELECTED_HOMEPAGE_API, noneApi.name)
503+
if (fromUI) DataStoreHelper.currentHomePage = noneApi.name
499504
loadAndCancel(noneApi)
500505
} else if (preferredApiName == randomApi.name) {
501506
// randomize the api, if none exist like if not loaded or not installed
@@ -506,7 +511,7 @@ class HomeViewModel : ViewModel() {
506511
} else {
507512
val apiRandom = validAPIs.random()
508513
loadAndCancel(apiRandom)
509-
if (fromUI) setKey(USER_SELECTED_HOMEPAGE_API, apiRandom.name)
514+
if (fromUI) DataStoreHelper.currentHomePage = apiRandom.name
510515
}
511516
} else if (api == null) {
512517
// API is not found aka not loaded or removed, post the loading
@@ -520,7 +525,7 @@ class HomeViewModel : ViewModel() {
520525
}
521526
} else {
522527
// if the api is found, then set it to it and save key
523-
if (fromUI) setKey(USER_SELECTED_HOMEPAGE_API, api.name)
528+
if (fromUI) DataStoreHelper.currentHomePage = api.name
524529
loadAndCancel(api)
525530
}
526531
}

app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentTv.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class ResultFragmentTv : Fragment() {
177177
isVisible = true
178178
}
179179

180-
this.animate().alpha(if (turnVisible) 1.0f else 0.0f).apply {
180+
this.animate().alpha(if (turnVisible) 0.97f else 0.0f).apply {
181181
duration = 200
182182
interpolator = DecelerateInterpolator()
183183
setListener(object : Animator.AnimatorListener {
@@ -294,9 +294,9 @@ class ResultFragmentTv : Fragment() {
294294
toggleEpisodes(true)
295295
binding?.apply {
296296
val views = listOf(
297+
resultDubSelection,
297298
resultSeasonSelection,
298299
resultRangeSelection,
299-
resultDubSelection,
300300
resultEpisodes,
301301
resultPlayTrailer,
302302
)

app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ class ResultViewModel2 : ViewModel() {
518518
val episodeNumber = episodes[currentIndex].episode
519519
if (episodeNumber < currentMin) {
520520
currentMin = episodeNumber
521-
} else if (episodeNumber > currentMax) {
521+
}
522+
if (episodeNumber > currentMax) {
522523
currentMax = episodeNumber
523524
}
524525
++currentIndex

app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsProviders.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import com.lagradost.cloudstream3.ui.APIRepository
1414
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
1515
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom
1616
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
17-
import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API
17+
import com.lagradost.cloudstream3.utils.DataStoreHelper
1818
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog
1919
import com.lagradost.cloudstream3.utils.SubtitleHelper
2020
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
@@ -96,7 +96,7 @@ class SettingsProviders : PreferenceFragmentCompat() {
9696
this.getString(R.string.prefer_media_type_key),
9797
selectedList.map { it.toString() }.toMutableSet()
9898
).apply()
99-
removeKey(USER_SELECTED_HOMEPAGE_API)
99+
DataStoreHelper.currentHomePage = null
100100
//(context ?: AcraApplication.context)?.let { ctx -> app.initClient(ctx) }
101101
}
102102

app/src/main/java/com/lagradost/cloudstream3/ui/setup/SetupFragmentMedia.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import com.lagradost.cloudstream3.R
1515
import com.lagradost.cloudstream3.TvType
1616
import com.lagradost.cloudstream3.databinding.FragmentSetupMediaBinding
1717
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
18+
import com.lagradost.cloudstream3.utils.DataStoreHelper
1819
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
19-
import com.lagradost.cloudstream3.utils.USER_SELECTED_HOMEPAGE_API
2020

2121

2222
class SetupFragmentMedia : Fragment() {
@@ -77,7 +77,7 @@ class SetupFragmentMedia : Fragment() {
7777
.apply()
7878

7979
// Regenerate set homepage
80-
removeKey(USER_SELECTED_HOMEPAGE_API)
80+
DataStoreHelper.currentHomePage = null
8181
}
8282
}
8383

0 commit comments

Comments
 (0)