From 6fc45f61802d6eea1799f5c6ee6686378361ba41 Mon Sep 17 00:00:00 2001 From: CranberrySoup <142951702+CranberrySoup@users.noreply.github.com> Date: Tue, 31 Oct 2023 22:33:01 +0100 Subject: [PATCH] Fix merge issues --- .../cloudstream3/syncproviders/BackupAPI.kt | 6 +- .../cloudstream3/ui/home/HomeFragment.kt | 61 ------------------- .../ui/library/LibraryFragment.kt | 13 ++-- .../cloudstream3/utils/BackupUtils.kt | 16 +++-- .../lagradost/cloudstream3/utils/Scheduler.kt | 7 +-- app/src/main/res/values/strings.xml | 4 -- 6 files changed, 22 insertions(+), 85 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/BackupAPI.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/BackupAPI.kt index a01d6d2e..1891db2e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/BackupAPI.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/BackupAPI.kt @@ -162,7 +162,7 @@ abstract class BackupAPI(defIndex: Int) : IBackupAPI, return } - val keysToUpdate = getKeysToUpdate(context.getBackup(), newData) + val keysToUpdate = getKeysToUpdate(getBackup(context), newData) if (keysToUpdate.isEmpty()) { Log.d(LOG_KEY, "remote data is up to date, sync not needed") return @@ -267,7 +267,7 @@ abstract class BackupAPI(defIndex: Int) : IBackupAPI, private fun shouldUploadBackup(): Boolean { val ctx = AcraApplication.context ?: return false - val newBackup = ctx.getBackup().toJson() + val newBackup = getBackup(ctx).toJson() return compareJson(lastBackupJson ?: "", newBackup).failed } @@ -322,7 +322,7 @@ abstract class BackupAPI(defIndex: Int) : IBackupAPI, return } - val backupFile = context.getBackup().toJson() + val backupFile = getBackup(context).toJson() lastBackupJson = backupFile Log.d(LOG_KEY, "${this.name}: uploadFile is now running") uploadFile(context, backupFile, loginData) 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 541b128f..4d940123 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 @@ -28,10 +28,6 @@ import com.lagradost.cloudstream3.APIHolder.apis import com.lagradost.cloudstream3.APIHolder.filterProviderByPreferredMedia import com.lagradost.cloudstream3.APIHolder.getApiProviderLangSettings import com.lagradost.cloudstream3.CommonActivity.showToast -import com.lagradost.cloudstream3.MainActivity.Companion.afterBackupRestoreEvent -import com.lagradost.cloudstream3.MainActivity.Companion.afterPluginsLoadedEvent -import com.lagradost.cloudstream3.MainActivity.Companion.bookmarksUpdatedEvent -import com.lagradost.cloudstream3.MainActivity.Companion.mainPluginsLoadedEvent import com.lagradost.cloudstream3.databinding.FragmentHomeBinding import com.lagradost.cloudstream3.databinding.HomeEpisodesExpandedBinding import com.lagradost.cloudstream3.databinding.HomeSelectMainpageBinding @@ -42,7 +38,6 @@ import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.mvvm.observeNullable import com.lagradost.cloudstream3.ui.APIRepository.Companion.noneApi import com.lagradost.cloudstream3.ui.APIRepository.Companion.randomApi -import com.lagradost.cloudstream3.ui.WatchType import com.lagradost.cloudstream3.ui.result.txt import com.lagradost.cloudstream3.ui.search.* import com.lagradost.cloudstream3.ui.search.SearchHelper.handleSearchClickCallback @@ -55,7 +50,6 @@ import com.lagradost.cloudstream3.utils.AppUtils.ownShow import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus import com.lagradost.cloudstream3.utils.Coroutines.ioSafe import com.lagradost.cloudstream3.utils.DataStoreHelper -import com.lagradost.cloudstream3.utils.DataStoreHelper.currentHomePage import com.lagradost.cloudstream3.utils.Event import com.lagradost.cloudstream3.utils.SubtitleHelper.getFlagFromIso import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe @@ -485,61 +479,6 @@ class HomeFragment : Fragment() { fixGrid() } - fun bookmarksUpdated(_data : Boolean) { - reloadStored() - } - - override fun onResume() { - super.onResume() - reloadStored() - bookmarksUpdatedEvent += ::bookmarksUpdated - afterPluginsLoadedEvent += ::afterPluginsLoaded - mainPluginsLoadedEvent += ::afterMainPluginsLoaded - afterBackupRestoreEvent += ::reloadStored - } - - override fun onStop() { - bookmarksUpdatedEvent -= ::bookmarksUpdated - afterPluginsLoadedEvent -= ::afterPluginsLoaded - mainPluginsLoadedEvent -= ::afterMainPluginsLoaded - afterBackupRestoreEvent -= ::reloadStored - super.onStop() - } - - private fun reloadStored(unused: Unit = Unit) { - homeViewModel.reloadStored() - val list = EnumSet.noneOf(WatchType::class.java) - getKey(HOME_BOOKMARK_VALUE_LIST)?.map { WatchType.fromInternalId(it) }?.let { - list.addAll(it) - } - homeViewModel.loadStoredData(list) - } - - private fun afterMainPluginsLoaded(unused: Boolean = false) { - loadHomePage(false) - } - - private fun afterPluginsLoaded(forceReload: Boolean) { - loadHomePage(forceReload) - } - - private fun loadHomePage(forceReload: Boolean) { - val apiName = currentHomePage - - if (homeViewModel.apiName.value != apiName || apiName == null || forceReload) { - //println("Caught home: " + homeViewModel.apiName.value + " at " + apiName) - homeViewModel.loadAndCancel(apiName, forceReload) - } - } - - private fun homeHandleSearch(callback: SearchClickCallback) { - if (callback.action == SEARCH_ACTION_FOCUSED) { - //focusCallback(callback.card) - } else { - handleSearchClickCallback(callback) - } - } - private var currentApiName: String? = null private var toggleRandomButton = false diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt index 85e7468a..25d21b1a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt @@ -145,7 +145,8 @@ class LibraryFragment : Fragment() { } // Set the color for the search exit icon to the correct theme text color - val searchExitIcon = binding?.mainSearch?.findViewById(androidx.appcompat.R.id.search_close_btn) + val searchExitIcon = + binding?.mainSearch?.findViewById(androidx.appcompat.R.id.search_close_btn) val searchExitIconColor = TypedValue() activity?.theme?.resolveAttribute(android.R.attr.textColor, searchExitIconColor, true) @@ -481,6 +482,7 @@ class LibraryFragment : Fragment() { } }) } + override fun onConfigurationChanged(newConfig: Configuration) { (binding?.viewpager?.adapter as? ViewpagerAdapter)?.rebind() super.onConfigurationChanged(newConfig) @@ -499,6 +501,7 @@ class LibraryFragment : Fragment() { private fun onNewSyncData(unused: Unit) { Log.d(BackupAPI.LOG_KEY, "will reload pages") libraryViewModel.reloadPages(true) + } private val sortChangeClickListener = View.OnClickListener { view -> val methods = libraryViewModel.sortingMethods.map { @@ -515,10 +518,10 @@ class LibraryFragment : Fragment() { libraryViewModel.sort(method) }) } -} -class MenuSearchView(context: Context) : SearchView(context) { - override fun onActionViewCollapsed() { - super.onActionViewCollapsed() + class MenuSearchView(context: Context) : SearchView(context) { + override fun onActionViewCollapsed() { + super.onActionViewCollapsed() + } } } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt index 1a946b5e..38387553 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/BackupUtils.kt @@ -151,10 +151,8 @@ object BackupUtils { } @Suppress("UNCHECKED_CAST") - private fun getBackup(context: Context?): BackupFile? { - if (context == null) return null - - val syncDataPrefs = getSyncPrefs().all.filter { it.key.isTransferable() } + fun getBackup(context: Context): BackupFile { + val syncDataPrefs = context.getSyncPrefs().all.filter { it.key.isTransferable() } val allData = context.getSharedPrefs().all.filter { it.key.isTransferable() } val allSettings = context.getDefaultSharedPrefs().all.filter { it.key.isTransferable() } @@ -216,9 +214,15 @@ object BackupUtils { // we must remove keys that are not present if (!restoreKeys.isNullOrEmpty()) { - Log.d(BackupAPI.LOG_KEY, "successfulRestore for src=[${restoreSource.name}]: ${restoreData.successfulRestore}") + Log.d( + BackupAPI.LOG_KEY, + "successfulRestore for src=[${restoreSource.name}]: ${restoreData.successfulRestore}" + ) val removedKeys = restoreData.wantToRestore - restoreData.successfulRestore - Log.d(BackupAPI.LOG_KEY, "removed keys for src=[${restoreSource.name}]: $removedKeys") + Log.d( + BackupAPI.LOG_KEY, + "removed keys for src=[${restoreSource.name}]: $removedKeys" + ) removedKeys.forEach { removeKeyRaw(it, restoreSource) } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/Scheduler.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/Scheduler.kt index 319f09cc..e004b11f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/Scheduler.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/Scheduler.kt @@ -7,9 +7,6 @@ import android.util.Log import com.lagradost.cloudstream3.syncproviders.AccountManager import com.lagradost.cloudstream3.syncproviders.BackupAPI import com.lagradost.cloudstream3.syncproviders.BackupAPI.Companion.logHistoryChanged -import com.lagradost.cloudstream3.ui.home.HOME_BOOKMARK_VALUE_LIST -import com.lagradost.cloudstream3.ui.player.PLAYBACK_SPEED_KEY -import com.lagradost.cloudstream3.ui.player.RESIZE_MODE_KEY import com.lagradost.cloudstream3.utils.BackupUtils.nonTransferableKeys import com.lagradost.cloudstream3.utils.Coroutines.ioSafe @@ -27,9 +24,6 @@ class Scheduler( *nonTransferableKeys.toTypedArray(), VideoDownloadManager.KEY_DOWNLOAD_INFO, DOWNLOAD_HEADER_CACHE, - PLAYBACK_SPEED_KEY, - HOME_BOOKMARK_VALUE_LIST, - RESIZE_MODE_KEY, ) private val invalidUploadTriggerKeysRegex = listOf( // These trigger automatically every time a show is opened, way too often. @@ -100,6 +94,7 @@ class Scheduler( var lastValue = all registerOnSharedPreferenceChangeListener { sharedPreferences, storeKey -> + if (storeKey == null) return@registerOnSharedPreferenceChangeListener ioSafe { scheduler.work( BackupAPI.PreferencesSchedulerData( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ff03d1fb..d6b02463 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -696,8 +696,6 @@ Qualities Profile background UI was unable to be created correctly, this is a MAJOR BUG and should be reported immediately %s - tv_no_focus_tag - You have already voted Sync file name (optional) Oauth redirect url (optional) https://recloudstream.github.io/cloudstream-sync/google-drive @@ -732,8 +730,6 @@ tv_no_focus_tag - - Enter PIN Enter Current PIN Lock Profile