From 37d402d7b39616dde2d0b767c35039cfc52d0b05 Mon Sep 17 00:00:00 2001 From: LagradOst Date: Thu, 25 Nov 2021 23:36:35 +0100 Subject: [PATCH] sflix mirror and phone layout UI update --- app/build.gradle | 4 +- app/src/main/AndroidManifest.xml | 2 +- .../lagradost/cloudstream3/AcraApplication.kt | 1 - .../com/lagradost/cloudstream3/MainAPI.kt | 4 +- .../lagradost/cloudstream3/MainActivity.kt | 16 ++-- .../movieproviders/SflixProvider.kt | 6 +- .../cloudstream3/ui/home/HomeFragment.kt | 75 +++++++++---------- .../cloudstream3/ui/home/HomeViewModel.kt | 31 +++++++- .../main/res/layout-land/activity_main.xml | 63 ++++++++++++++++ app/src/main/res/layout/activity_main.xml | 3 +- app/src/main/res/layout/activity_main_tv.xml | 16 ++-- app/src/main/res/layout/fragment_home.xml | 4 + app/src/main/res/layout/homepage_parent.xml | 3 + app/src/main/res/values/styles.xml | 6 +- 14 files changed, 164 insertions(+), 70 deletions(-) create mode 100644 app/src/main/res/layout-land/activity_main.xml diff --git a/app/build.gradle b/app/build.gradle index 9a85f3b2..933f9db7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -114,7 +114,7 @@ dependencies { implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' - implementation "androidx.leanback:leanback-paging:1.1.0-alpha09" + // implementation "androidx.leanback:leanback-paging:1.1.0-alpha09" // Exoplayer implementation 'com.google.android.exoplayer:exoplayer:2.15.1' @@ -153,5 +153,5 @@ dependencies { implementation "com.github.tachiyomiorg:unifile:17bec43" // debugImplementation because LeakCanary should only run in debug builds. - debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7' + // debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a5807a7f..5bc1eaf1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -31,7 +31,7 @@ diff --git a/app/src/main/java/com/lagradost/cloudstream3/AcraApplication.kt b/app/src/main/java/com/lagradost/cloudstream3/AcraApplication.kt index 92ed9aff..0e3f7c05 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/AcraApplication.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/AcraApplication.kt @@ -85,6 +85,5 @@ class AcraApplication : Application() { private set(value) { _context = WeakReference(value) } - } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt index 359a1174..3be39506 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainAPI.kt @@ -49,7 +49,9 @@ object APIHolder { VfSerieProvider(), AsianLoadProvider(), - SflixProvider(), + SflixProvider("https://sflix.to","Sflix"), + SflixProvider("https://dopebox.to","Dopebox"), + ZoroProvider() ) diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 677eeaa6..14d4b900 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -21,6 +21,7 @@ import androidx.navigation.findNavController import androidx.navigation.ui.setupWithNavController import androidx.preference.PreferenceManager import com.google.android.gms.cast.framework.* +import com.google.android.material.navigationrail.NavigationRailView import com.jaredrummler.android.colorpicker.ColorPickerDialogListener import com.lagradost.cloudstream3.APIHolder.apis import com.lagradost.cloudstream3.APIHolder.getApiDubstatusSettings @@ -51,8 +52,6 @@ import com.lagradost.cloudstream3.utils.UIHelper.requestRW import com.lagradost.cloudstream3.utils.UIHelper.shouldShowPIPMode import com.lagradost.cloudstream3.utils.UIHelper.toPx import kotlinx.android.synthetic.main.activity_main.* -import kotlinx.android.synthetic.main.activity_main.cast_mini_controller_holder -import kotlinx.android.synthetic.main.activity_main_tv.* import kotlinx.android.synthetic.main.fragment_result.* import java.util.* import kotlin.concurrent.thread @@ -84,7 +83,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { updateLocale() // android fucks me by chaining lang when rotating the phone } - private var mCastSession: CastSession? = null + //private var mCastSession: CastSession? = null lateinit var mSessionManager: SessionManager private val mSessionManagerListener: SessionManagerListener by lazy { SessionManagerListenerImpl() } @@ -123,7 +122,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { super.onResume() try { if (isCastApiAvailable()) { - mCastSession = mSessionManager.currentCastSession + //mCastSession = mSessionManager.currentCastSession mSessionManager.addSessionManagerListener(mSessionManagerListener) } } catch (e: Exception) { @@ -136,7 +135,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { try { if (isCastApiAvailable()) { mSessionManager.removeSessionManagerListener(mSessionManagerListener) - mCastSession = null + //mCastSession = null } } catch (e: Exception) { logError(e) @@ -448,7 +447,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { .setPopUpTo(navController.graph.startDestination, false) .build()*/ nav_view?.setupWithNavController(navController) - nav_rail_view?.setupWithNavController(navController) + val navRail = findViewById(R.id.nav_rail_view) + navRail?.setupWithNavController(navController) navController.addOnDestinationChangedListener { _, destination, _ -> this.hideKeyboard() // nav_view.hideKeyboard() @@ -473,7 +473,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { ).contains(destination.id) nav_view?.isVisible = isNavVisible - nav_rail_view?.isVisible = isNavVisible + navRail?.isVisible = isNavVisible } /*nav_view.setOnNavigationItemSelectedListener { item -> @@ -496,7 +496,7 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { val rippleColor = ColorStateList.valueOf(getResourceColor(R.attr.colorPrimary, 0.1f)) nav_view?.itemRippleColor = rippleColor - nav_rail_view?.itemRippleColor = rippleColor + navRail?.itemRippleColor = rippleColor if (!checkWrite()) { requestRW() diff --git a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SflixProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SflixProvider.kt index 2b059ec6..8da325a8 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SflixProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/movieproviders/SflixProvider.kt @@ -13,11 +13,11 @@ import org.jsoup.Jsoup import org.jsoup.nodes.Element import java.net.URI -class SflixProvider : MainAPI() { +class SflixProvider(private val providerUrl: String, private val providerName: String) : MainAPI() { override val mainUrl: String - get() = "https://sflix.to" + get() = providerUrl override val name: String - get() = "Sflix" + get() = providerName override val hasQuickSearch: Boolean get() = false diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt index 2cd36552..da514a36 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeFragment.kt @@ -119,46 +119,6 @@ class HomeFragment : Fragment() { home_main_holder.isVisible = visible } - @SuppressLint("SetTextI18n") - private fun chooseRandomMainPage() { - val home = currentHomePage - if (home != null && home.items.isNotEmpty()) { - val currentList = - home.items.shuffled().filter { !it.list.isNullOrEmpty() }.flatMap { it.list }.distinctBy { it.url } - .toList() - - if (currentList.isNullOrEmpty()) { - toggleMainVisibility(false) - } else { - val randomItems = currentList.shuffled() - val randomSize = randomItems.size - home_main_poster_recyclerview.adapter = - HomeChildItemAdapter(randomItems, R.layout.home_result_big_grid) { callback -> - handleSearchClickCallback(activity, callback) - } - home_main_poster_recyclerview.post { - (home_main_poster_recyclerview.layoutManager as CenterZoomLayoutManager?)?.let { manager -> - - manager.updateSize(forceUpdate = true) - if (randomSize > 2) { - manager.scrollToPosition(randomSize / 2) - manager.snap { dx -> - home_main_poster_recyclerview?.post { - // this is the best I can do, fuck android for not including instant scroll - home_main_poster_recyclerview?.smoothScrollBy(dx, 0) - } - } - } - } - } - - toggleMainVisibility(true) - } - } else { - toggleMainVisibility(false) - } - } - private fun fixGrid() { val compactView = activity?.getGridIsCompact() ?: false val spanCountLandscape = if (compactView) 2 else 6 @@ -239,6 +199,40 @@ class HomeFragment : Fragment() { } } + observe(homeViewModel.randomItems) { items -> + if (items.isNullOrEmpty()) { + toggleMainVisibility(false) + } else { + val tempAdapter = home_main_poster_recyclerview.adapter as HomeChildItemAdapter? + // no need to reload if it has the same data + if (tempAdapter != null && tempAdapter.cardList == items) { + toggleMainVisibility(true) + return@observe + } + + val randomSize = items.size + home_main_poster_recyclerview.adapter = + HomeChildItemAdapter(items, R.layout.home_result_big_grid) { callback -> + handleSearchClickCallback(activity, callback) + } + home_main_poster_recyclerview.post { + (home_main_poster_recyclerview.layoutManager as CenterZoomLayoutManager?)?.let { manager -> + manager.updateSize(forceUpdate = true) + if (randomSize > 2) { + manager.scrollToPosition(randomSize / 2) + manager.snap { dx -> + home_main_poster_recyclerview?.post { + // this is the best I can do, fuck android for not including instant scroll + home_main_poster_recyclerview?.smoothScrollBy(dx, 0) + } + } + } + } + } + toggleMainVisibility(true) + } + } + observe(homeViewModel.page) { data -> when (data) { is Resource.Success -> { @@ -256,7 +250,6 @@ class HomeFragment : Fragment() { } home_master_recycler?.adapter?.notifyDataSetChanged() - chooseRandomMainPage() home_loading.visibility = View.GONE home_loading_error.visibility = View.GONE diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt index e51cb088..d6fb7508 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/home/HomeViewModel.kt @@ -39,6 +39,9 @@ class HomeViewModel : ViewModel() { private val _page = MutableLiveData>() val page: LiveData> = _page + private val _randomItems = MutableLiveData?>(null) + val randomItems: LiveData?> = _randomItems + private fun autoloadRepo(): APIRepository { return APIRepository(apis.first { it.hasMainPage }) } @@ -142,7 +145,29 @@ class HomeViewModel : ViewModel() { _apiName.postValue(repo?.name) if (repo?.hasMainPage == true) { _page.postValue(Resource.Loading()) - _page.postValue(repo?.getMainPage()) + _randomItems.postValue(null) + + val data = repo?.getMainPage() + when (data) { + is Resource.Success -> { + val home = data.value + if (home.items.isNotEmpty()) { + val currentList = + home.items.shuffled().filter { !it.list.isNullOrEmpty() }.flatMap { it.list } + .distinctBy { it.url } + .toList() + + if (!currentList.isNullOrEmpty()) { + val randomItems = currentList.shuffled() + + _randomItems.postValue(randomItems) + } + } + } + else -> { + } + } + _page.postValue(data) } else { _page.postValue(Resource.Success(HomePageResponse(emptyList()))) } @@ -152,8 +177,8 @@ class HomeViewModel : ViewModel() { val api = getApiFromNameNull(preferredApiName) if (preferredApiName == noneApi.name) loadAndCancel(noneApi) - else if(preferredApiName == randomApi.name || api == null) { - var validAPIs = AppUtils.filterProviderByPreferredMedia(apis, currentPrefMedia) + else if (preferredApiName == randomApi.name || api == null) { + val validAPIs = AppUtils.filterProviderByPreferredMedia(apis, currentPrefMedia) val apiRandom = validAPIs.random() loadAndCancel(apiRandom) context?.setKey(HOMEPAGE_API, apiRandom.name) diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml new file mode 100644 index 00000000..4cd80997 --- /dev/null +++ b/app/src/main/res/layout-land/activity_main.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ae179034..4deb00ad 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -31,11 +31,12 @@ android:layout_width="match_parent" android:layout_height="0dp" app:defaultNavHost="true" - app:layout_constraintBottom_toTopOf="@+id/nav_view" + app:layout_constraintBottom_toTopOf="@+id/cast_mini_controller_holder" app:layout_constraintTop_toTopOf="parent" app:navGraph="@navigation/mobile_navigation" app:layout_constraintEnd_toEndOf="parent"/> @@ -30,17 +30,21 @@ android:id="@+id/nav_host_fragment" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="0dp" - android:layout_height="match_parent" + android:layout_height="0dp" app:defaultNavHost="true" - app:layout_constraintLeft_toRightOf="@+id/nav_view" - app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintLeft_toRightOf="parent" + app:layout_constraintBottom_toTopOf="@id/cast_mini_controller_holder" app:navGraph="@navigation/mobile_navigation" app:layout_constraintStart_toEndOf="@id/nav_rail_view" app:layout_constraintEnd_toEndOf="parent"/> diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 1bf2139a..4e15061b 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -301,6 +301,8 @@ @color/colorPrimaryRed @color/colorPrimaryRed - #D53333 - #F53B3B - #EC3838 + #B62B2B + @color/colorPrimaryRed + @color/colorPrimaryRed @color/colorPrimaryRed