mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Only reload the home page if the API has changed (performance)
This commit is contained in:
parent
19d9034e65
commit
42a1f272a2
4 changed files with 11 additions and 8 deletions
|
@ -68,7 +68,7 @@ object AccountHelper {
|
||||||
DataStoreHelper.accounts = currentAccounts.toTypedArray()
|
DataStoreHelper.accounts = currentAccounts.toTypedArray()
|
||||||
|
|
||||||
// Update UI
|
// Update UI
|
||||||
setAccount(getDefaultAccount(context), true)
|
setAccount(getDefaultAccount(context))
|
||||||
callback.invoke(null)
|
callback.invoke(null)
|
||||||
dialog?.dismissSafe()
|
dialog?.dismissSafe()
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import com.lagradost.cloudstream3.ui.AutofitRecyclerView
|
||||||
import com.lagradost.cloudstream3.ui.account.AccountAdapter.Companion.VIEW_TYPE_EDIT_ACCOUNT
|
import com.lagradost.cloudstream3.ui.account.AccountAdapter.Companion.VIEW_TYPE_EDIT_ACCOUNT
|
||||||
import com.lagradost.cloudstream3.ui.account.AccountAdapter.Companion.VIEW_TYPE_SELECT_ACCOUNT
|
import com.lagradost.cloudstream3.ui.account.AccountAdapter.Companion.VIEW_TYPE_SELECT_ACCOUNT
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAccounts
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAccounts
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.setAccount
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.setAccount
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
|
||||||
|
@ -80,7 +79,7 @@ class AccountSelectActivity : AppCompatActivity() {
|
||||||
// We came from MainActivity, return there
|
// We came from MainActivity, return there
|
||||||
// and switch to the edited account
|
// and switch to the edited account
|
||||||
if (isEditingFromMainActivity) {
|
if (isEditingFromMainActivity) {
|
||||||
setAccount(it, it.keyIndex != DataStoreHelper.selectedKeyIndex)
|
setAccount(it)
|
||||||
navigateToMainActivity()
|
navigateToMainActivity()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -53,7 +53,7 @@ class AccountViewModel : ViewModel() {
|
||||||
|
|
||||||
val currentHomePage = DataStoreHelper.currentHomePage
|
val currentHomePage = DataStoreHelper.currentHomePage
|
||||||
|
|
||||||
setAccount(account, false)
|
setAccount(account)
|
||||||
|
|
||||||
DataStoreHelper.currentHomePage = currentHomePage
|
DataStoreHelper.currentHomePage = currentHomePage
|
||||||
DataStoreHelper.accounts = currentAccounts.toTypedArray()
|
DataStoreHelper.accounts = currentAccounts.toTypedArray()
|
||||||
|
@ -78,13 +78,13 @@ class AccountViewModel : ViewModel() {
|
||||||
// Pin is correct, proceed
|
// Pin is correct, proceed
|
||||||
_isAllowedLogin.postValue(true)
|
_isAllowedLogin.postValue(true)
|
||||||
_selectedKeyIndex.postValue(account.keyIndex)
|
_selectedKeyIndex.postValue(account.keyIndex)
|
||||||
setAccount(account, true)
|
setAccount(account)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No PIN set for the selected account, proceed
|
// No PIN set for the selected account, proceed
|
||||||
_isAllowedLogin.postValue(true)
|
_isAllowedLogin.postValue(true)
|
||||||
_selectedKeyIndex.postValue(account.keyIndex)
|
_selectedKeyIndex.postValue(account.keyIndex)
|
||||||
setAccount(account, true)
|
setAccount(account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -149,12 +149,16 @@ object DataStoreHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setAccount(account: Account, refreshHomePage: Boolean) {
|
fun setAccount(account: Account) {
|
||||||
|
val homepage = currentHomePage
|
||||||
|
|
||||||
selectedKeyIndex = account.keyIndex
|
selectedKeyIndex = account.keyIndex
|
||||||
showToast(context?.getString(R.string.logged_account, account.name) ?: account.name)
|
showToast(context?.getString(R.string.logged_account, account.name) ?: account.name)
|
||||||
MainActivity.bookmarksUpdatedEvent(true)
|
MainActivity.bookmarksUpdatedEvent(true)
|
||||||
MainActivity.reloadLibraryEvent(true)
|
MainActivity.reloadLibraryEvent(true)
|
||||||
if (refreshHomePage) {
|
val oldAccount = accounts.find { it.keyIndex == account.keyIndex }
|
||||||
|
if (oldAccount != null && currentHomePage != homepage) {
|
||||||
|
// This is not a new account, and the homepage has changed, reload it
|
||||||
MainActivity.reloadHomeEvent(true)
|
MainActivity.reloadHomeEvent(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue