Skip to content

Commit f28924f

Browse files
Fix intent launches (#2554)
1 parent b510942 commit f28924f

File tree

4 files changed

+50
-25
lines changed

4 files changed

+50
-25
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,31 @@
108108
android:launchMode="singleTask"
109109
is a bit experimental, it makes loading repositories from browser still stay on the same page
110110
no idea about side effects
111+
112+
Not exported to prevent bypassing the AccountSelectActivity
111113
-->
112114
<activity
113115
android:name=".MainActivity"
114116
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden|navigation|uiMode"
115-
android:exported="true"
117+
android:exported="false"
116118
android:launchMode="singleTask"
117119
android:resizeableActivity="true"
118-
android:supportsPictureInPicture="true">
120+
android:supportsPictureInPicture="true" />
121+
122+
<activity
123+
android:name=".ui.account.AccountSelectActivity"
124+
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden"
125+
android:exported="true">
126+
<intent-filter android:exported="true">
127+
<action android:name="android.intent.action.MAIN" />
128+
129+
<category android:name="android.intent.category.LAUNCHER" />
130+
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
131+
</intent-filter>
132+
<intent-filter>
133+
<action android:name="android.intent.action.VIEW" />
134+
<category android:name="android.intent.category.DEFAULT" />
135+
</intent-filter>
119136

120137
<!-- cloudstreamplayer://encodedUrl?name=Dune -->
121138
<intent-filter>
@@ -173,7 +190,7 @@
173190
<data android:scheme="cloudstreamcontinuewatching" />
174191
</intent-filter>
175192

176-
<intent-filter>
193+
<intent-filter android:autoVerify="false">
177194
<action android:name="android.intent.action.VIEW" />
178195

179196
<category android:name="android.intent.category.DEFAULT" />
@@ -186,21 +203,6 @@
186203
</intent-filter>
187204
</activity>
188205

189-
<activity
190-
android:name=".ui.account.AccountSelectActivity"
191-
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden"
192-
android:exported="true">
193-
<intent-filter android:exported="true">
194-
<action android:name="android.intent.action.MAIN" />
195-
<category android:name="android.intent.category.LAUNCHER" />
196-
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
197-
</intent-filter>
198-
<intent-filter>
199-
<action android:name="android.intent.action.VIEW" />
200-
<category android:name="android.intent.category.DEFAULT" />
201-
</intent-filter>
202-
</activity>
203-
204206
<receiver
205207
android:name=".receivers.VideoDownloadRestartReceiver"
206208
android:enabled="false"

app/src/main/java/com/lagradost/cloudstream3/ui/account/AccountSelectActivity.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,24 @@ import com.lagradost.cloudstream3.utils.UIHelper.setNavigationBarColorCompat
3838

3939
class AccountSelectActivity : FragmentActivity(), BiometricCallback {
4040

41+
companion object {
42+
var hasLoggedIn: Boolean = false
43+
}
44+
4145
val accountViewModel: AccountViewModel by viewModels()
4246

4347
@SuppressLint("NotifyDataSetChanged")
4448
override fun onCreate(savedInstanceState: Bundle?) {
4549
super.onCreate(savedInstanceState)
50+
51+
// Sometimes we start this activity when we have already logged in
52+
// For example when using cloudstreamsearch://
53+
// In those cases we want to just go to the main activity instantly
54+
if (hasLoggedIn) {
55+
navigateToMainActivity()
56+
return
57+
}
58+
4659
loadThemes(this)
4760

4861
enableEdgeToEdgeCompat()
@@ -188,8 +201,11 @@ class AccountSelectActivity : FragmentActivity(), BiometricCallback {
188201
askBiometricAuth()
189202
}
190203

204+
@SuppressLint("UnsafeIntentLaunch")
191205
private fun navigateToMainActivity() {
192-
openActivity(MainActivity::class.java)
206+
hasLoggedIn = true
207+
// We want to propagate any intent we get here to MainActivity since this is just an intermediary
208+
openActivity(MainActivity::class.java, baseIntent = intent)
193209
finish() // Finish the account selection activity
194210
}
195211

app/src/main/java/com/lagradost/cloudstream3/ui/search/SearchFragment.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.preference.PreferenceManager
2323
import androidx.recyclerview.widget.GridLayoutManager
2424
import androidx.recyclerview.widget.LinearLayoutManager
2525
import androidx.activity.result.contract.ActivityResultContracts
26+
import androidx.core.view.doOnLayout
2627
import com.google.android.material.bottomsheet.BottomSheetBehavior
2728
import com.google.android.material.bottomsheet.BottomSheetDialog
2829
import com.google.android.material.button.MaterialButton
@@ -414,7 +415,7 @@ class SearchFragment : BaseFragment<FragmentSearchBinding>(
414415
binding.searchFilter.isFocusable = true
415416
binding.searchFilter.isFocusableInTouchMode = true
416417
}
417-
418+
418419
// Hide suggestions when search view loses focus (phone only)
419420
if (isLayout(PHONE)) {
420421
binding.mainSearch.setOnQueryTextFocusChangeListener { _, hasFocus ->
@@ -572,7 +573,7 @@ class SearchFragment : BaseFragment<FragmentSearchBinding>(
572573
removeKey("$currentAccount/$SEARCH_HISTORY_KEY", searchItem.key)
573574
searchViewModel.updateHistory()
574575
}
575-
576+
576577
SEARCH_HISTORY_CLEAR -> {
577578
// Show confirmation dialog (from footer button)
578579
activity?.let { ctx ->
@@ -653,7 +654,11 @@ class SearchFragment : BaseFragment<FragmentSearchBinding>(
653654

654655
sq?.let { query ->
655656
if (query.isBlank()) return@let
656-
mainSearch.setQuery(query, true)
657+
658+
// Queries are dropped if you are submitted before layout finishes
659+
mainSearch.doOnLayout {
660+
mainSearch.setQuery(query, true)
661+
}
657662
// Clear the query as to not make it request the same query every time the page is opened
658663
arguments?.remove(SEARCH_QUERY)
659664
savedInstanceState?.remove(SEARCH_QUERY)
@@ -674,7 +679,7 @@ class SearchFragment : BaseFragment<FragmentSearchBinding>(
674679
val hasSuggestions = suggestions.isNotEmpty()
675680
binding.searchSuggestionsRecycler.isVisible = hasSuggestions
676681
(binding.searchSuggestionsRecycler.adapter as? SearchSuggestionAdapter?)?.submitList(suggestions)
677-
682+
678683
// On non-phone layouts, redirect focus and handle back button
679684
if (!isLayout(PHONE)) {
680685
if (hasSuggestions) {

app/src/main/java/com/lagradost/cloudstream3/utils/UIHelper.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,12 @@ object UIHelper {
259259
}
260260

261261
// Open activities from an activity outside the nav graph
262-
fun Context.openActivity(activity: Class<*>, args: Bundle? = null) {
262+
fun Context.openActivity(activity: Class<*>, args: Bundle? = null, baseIntent: Intent? = null) {
263263
val tag = "NavComponent"
264264
try {
265-
val intent = Intent(this, activity)
265+
val intent = baseIntent ?: Intent()
266+
intent.setClass(this, activity)
267+
266268
if (args != null) {
267269
intent.putExtras(args)
268270
}

0 commit comments

Comments
 (0)