Skip to content

Commit

Permalink
Kotlin: convert TaskManager
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Oct 17, 2024
1 parent 07c8004 commit 715c7d9
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 Uwe Trottmann
// SPDX-License-Identifier: Apache-2.0
// Copyright 2013-2024 Uwe Trottmann

package com.battlelancer.seriesguide.dataliberation

Expand Down Expand Up @@ -63,7 +63,7 @@ class AutoBackupFragment : Fragment() {
}

binding.buttonAutoBackupNow.setOnClickListener {
if (TaskManager.getInstance().tryBackupTask(requireContext())) {
if (TaskManager.tryBackupTask(requireContext())) {
setProgressLock(true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class JsonExportTask(
}

private fun onPostExecute(result: Int) {
TaskManager.getInstance().releaseBackupTaskRef()
TaskManager.releaseBackupTaskRef()

if (!isAutoBackupMode) {
val messageId: Int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 Uwe Trottmann
// SPDX-License-Identifier: Apache-2.0
// Copyright 2013-2024 Uwe Trottmann

package com.battlelancer.seriesguide.dataliberation

Expand Down Expand Up @@ -120,8 +120,7 @@ class JsonImportTask(

private fun doInBackground(coroutineScope: CoroutineScope): Int {
// Ensure no large database ops are running
val tm = TaskManager.getInstance()
if (SgSyncAdapter.isSyncActive(context, false) || tm.isAddTaskRunning) {
if (SgSyncAdapter.isSyncActive(context, false) || TaskManager.isAddTaskRunning) {
return ERROR_LARGE_DB_OP
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class HistoryActivity : BaseActivity(), OnAddShowListener {
* Called if the user adds a show from a trakt stream fragment.
*/
override fun onAddShow(show: SearchResult) {
TaskManager.getInstance().performAddTask(this, show)
TaskManager.performAddTask(this, show)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 Uwe Trottmann
// SPDX-License-Identifier: Apache-2.0
// Copyright 2018-2024 Uwe Trottmann

package com.battlelancer.seriesguide.shows

Expand Down Expand Up @@ -63,7 +63,7 @@ class FirstRunView @JvmOverloads constructor(context: Context, attrs: AttributeS
putBoolean(DisplaySettings.KEY_PREVENT_SPOILERS, noSpoilers)
}
// update next episode strings right away
TaskManager.getInstance().tryNextEpisodeUpdateTask(v.context)
TaskManager.tryNextEpisodeUpdateTask(v.context)
// show
binding.checkboxNoSpoilers.isChecked = noSpoilers
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ open class ShowsActivityImpl : BaseTopActivity(), AddShowDialogFragment.OnAddSho
}

// update next episodes
TaskManager.getInstance().tryNextEpisodeUpdateTask(this)
TaskManager.tryNextEpisodeUpdateTask(this)
}

override fun onPause() {
Expand All @@ -336,7 +336,7 @@ open class ShowsActivityImpl : BaseTopActivity(), AddShowDialogFragment.OnAddSho
* Called if the user adds a show from a trakt stream fragment.
*/
override fun onAddShow(show: SearchResult) {
TaskManager.getInstance().performAddTask(this, show)
TaskManager.performAddTask(this, show)
}

override val snackbarParentView: View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class ShowsDistillationFragment : AppCompatDialogFragment() {

override fun onNoReleasedChanged(value: Boolean) {
DisplaySettings.setNoReleasedEpisodes(requireContext(), value)
TaskManager.getInstance().tryNextEpisodeUpdateTask(requireContext())
TaskManager.tryNextEpisodeUpdateTask(requireContext())
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ open class SearchActivityImpl : BaseMessageActivity(), AddShowDialogFragment.OnA
}

override fun onAddShow(show: SearchResult) {
TaskManager.getInstance().performAddTask(this, show)
TaskManager.performAddTask(this, show)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AddShowPopupMenu(
R.id.menu_action_add_show_add -> {
// post so other fragments can display a progress indicator for that show
EventBus.getDefault().post(OnAddingShowEvent(show.tmdbId))
TaskManager.getInstance().performAddTask(context, show)
TaskManager.performAddTask(context, show)
true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ open class ItemAddShowClickListener(

override fun onAddClick(item: SearchResult) {
EventBus.getDefault().post(OnAddingShowEvent(item.tmdbId))
TaskManager.getInstance().performAddTask(context, item)
TaskManager.performAddTask(context, item)
}

override fun onMoreOptionsClick(view: View, show: SearchResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ShowsDiscoverPagingActivity : BaseMessageActivity(), AddShowDialogFragment
}

override fun onAddShow(show: SearchResult) {
TaskManager.getInstance().performAddTask(this, show)
TaskManager.performAddTask(this, show)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ShowsTraktActivity : BaseMessageActivity(), AddShowDialogFragment.OnAddSho
}

override fun onAddShow(show: SearchResult) {
TaskManager.getInstance().performAddTask(this, show)
TaskManager.performAddTask(this, show)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ class TraktAddFragment : Fragment() {
}
}
EventBus.getDefault().post(OnAddingShowEvent())
TaskManager.getInstance()
.performAddTask(context, showsToAdd, false, false)
TaskManager.performAddTask(requireContext(), showsToAdd,
isSilentMode = false,
isMergingShows = false
)
}
// disable the item so the user has to come back
menuItem.isEnabled = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 Uwe Trottmann
// SPDX-License-Identifier: Apache-2.0
// Copyright 2019-2024 Uwe Trottmann

package com.battlelancer.seriesguide.shows.search.similar

Expand Down Expand Up @@ -30,7 +30,7 @@ class SimilarShowsActivity : BaseSimilarActivity(), AddShowDialogFragment.OnAddS
}

override fun onAddShow(show: SearchResult) {
TaskManager.getInstance().performAddTask(this, show)
TaskManager.performAddTask(this, show)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 Uwe Trottmann
// SPDX-License-Identifier: Apache-2.0
// Copyright 2011-2024 Uwe Trottmann

package com.battlelancer.seriesguide.shows.tools

Expand Down Expand Up @@ -321,7 +321,7 @@ class AddShowTask(

@Deprecated("Deprecated in Java")
override fun onPostExecute(aVoid: Void?) {
TaskManager.getInstance().releaseAddTaskRef()
TaskManager.releaseAddTaskRef()
}

private fun publishProgress(result: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 Uwe Trottmann
// SPDX-License-Identifier: Apache-2.0
// Copyright 2014-2024 Uwe Trottmann

package com.battlelancer.seriesguide.shows.tools;

Expand Down Expand Up @@ -32,7 +32,7 @@ protected Void doInBackground(Integer... params) {

@Override
protected void onPostExecute(Void aVoid) {
TaskManager.getInstance().releaseNextEpisodeUpdateTaskRef();
TaskManager.releaseNextEpisodeUpdateTaskRef();
}

public static void updateLatestEpisodeFor(Context context, Long showId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 Uwe Trottmann
// SPDX-License-Identifier: Apache-2.0
// Copyright 2017-2024 Uwe Trottmann

package com.battlelancer.seriesguide.sync;

Expand Down Expand Up @@ -156,7 +156,7 @@ private HexagonResult syncShows(Map<Integer, Long> tmdbIdsToShowIds) {
boolean addNewShows = !newShows.isEmpty();
if (addNewShows) {
List<SearchResult> newShowsList = new LinkedList<>(newShows.values());
TaskManager.getInstance().performAddTask(context, newShowsList, true, !hasMergedShows);
TaskManager.performAddTask(context, newShowsList, true, !hasMergedShows);
} else if (!hasMergedShows) {
// set shows as merged
HexagonSettings.setHasMergedShows(context, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class SgSyncAdapter(context: Context) : AbstractThreadedSyncAdapter(context, tru
if (Thread.interrupted()) throw InterruptedException()

// update next episodes for all shows
TaskManager.getInstance().tryNextEpisodeUpdateTask(context)
TaskManager.tryNextEpisodeUpdateTask(context)

updateTimeAndFailedCounter(prefs, resultCode)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2023 Uwe Trottmann
// SPDX-License-Identifier: Apache-2.0
// Copyright 2011-2024 Uwe Trottmann

package com.battlelancer.seriesguide.ui

Expand Down Expand Up @@ -93,7 +93,7 @@ abstract class BaseActivity : BaseThemeActivity() {
if (!BackupSettings.isTimeForAutoBackup(this)) {
return false
}
TaskManager.getInstance().tryBackupTask(this)
TaskManager.tryBackupTask(this)
return true
}

Expand Down
Loading

0 comments on commit 715c7d9

Please sign in to comment.