TIL never use requireActivity()

This commit is contained in:
IndusAryan 2024-03-21 20:32:11 +05:30
parent d6c5c69b97
commit 170442c912

View file

@ -1,6 +1,7 @@
package com.lagradost.cloudstream3.ui.settings package com.lagradost.cloudstream3.ui.settings
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -19,10 +20,6 @@ import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.databinding.MainSettingsBinding import com.lagradost.cloudstream3.databinding.MainSettingsBinding
import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.accountManagers
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.aniListApi
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.malApi
import com.lagradost.cloudstream3.syncproviders.AccountManager.Companion.simklApi
import com.lagradost.cloudstream3.syncproviders.AuthAPI
import com.lagradost.cloudstream3.ui.home.HomeFragment import com.lagradost.cloudstream3.ui.home.HomeFragment
import com.lagradost.cloudstream3.ui.result.txt import com.lagradost.cloudstream3.ui.result.txt
import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR
@ -144,19 +141,24 @@ class SettingsFragment : Fragment() {
/** used to debug leaks /** used to debug leaks
showToast(activity,"${VideoDownloadManager.downloadStatusEvent.size} : showToast(activity,"${VideoDownloadManager.downloadStatusEvent.size} :
${VideoDownloadManager.downloadProgressEvent.size}") **/ ${VideoDownloadManager.downloadProgressEvent.size}") **/
// Check login status for each OAuth2 API // Check login status for each OAuth2API
val isSyncing = simklApi.loginInfo() != null || malApi.loginInfo() != null || aniListApi.loginInfo() != null val isSyncing = accountManagers.any{ it.loginInfo() != null }
val accountPFP = accountManagers.firstOrNull{ it.loginInfo() != null }
// show local account image and pfp when not syncing with any api. // show local account image and pfp when not syncing with any api.
if (!isSyncing) { if (!isSyncing && accountPFP == null) {
val currentAccount = DataStoreHelper.accounts.firstOrNull { val activity = activity ?: return
it.keyIndex == DataStoreHelper.selectedKeyIndex val currentAccount = try {
} ?: DataStoreHelper.getDefaultAccount(activity ?: requireActivity()) DataStoreHelper.accounts.firstOrNull {
val name = currentAccount.name it.keyIndex == DataStoreHelper.selectedKeyIndex
val image = currentAccount.image } ?: activity.let { DataStoreHelper.getDefaultAccount(activity) }
} catch (e: IllegalStateException) {
Log.e("AccountManager", "Activity not found", e)
null
}
binding?.settingsProfilePic?.setImage(image) binding?.settingsProfilePic?.setImage(currentAccount?.image)
binding?.settingsProfileText?.text = name binding?.settingsProfileText?.text = currentAccount?.name
} else { } else {
for (syncApi in accountManagers) { for (syncApi in accountManagers) {
val login = syncApi.loginInfo() val login = syncApi.loginInfo()