Skip to content

Commit

Permalink
AddFragment: extract OnAddingShowEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Oct 17, 2024
1 parent dea7b5a commit 5a8aa46
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ import org.greenrobot.eventbus.ThreadMode
*/
abstract class AddFragment : Fragment() {

class OnAddingShowEvent(
/**
* Is -1 if adding all shows this lists.
*/
val showTmdbId: Int
) {
/**
* Sets TMDB id to -1 to indicate all shows of this are added.
*/
internal constructor() : this(-1)
}

protected var searchResults: List<SearchResult>? = null
private set
protected lateinit var adapter: AddAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class AddShowDialogFragment : AppCompatDialogFragment() {
// Not added, offer to add.
binding.buttonPositive.setText(R.string.action_shows_add)
binding.buttonPositive.setOnClickListener {
EventBus.getDefault().post(AddFragment.OnAddingShowEvent(showTmdbId))
EventBus.getDefault().post(OnAddingShowEvent(showTmdbId))
addShowListener.onAddShow(SearchResult().also {
it.tmdbId = showTmdbId
it.title = show.title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.view.MenuItem
import android.view.View
import androidx.appcompat.widget.PopupMenu
import com.battlelancer.seriesguide.R
import com.battlelancer.seriesguide.shows.search.discover.AddFragment.OnAddingShowEvent
import com.battlelancer.seriesguide.util.TaskManager
import com.battlelancer.seriesguide.util.tasks.AddShowToWatchlistTask
import com.battlelancer.seriesguide.util.tasks.RemoveShowFromWatchlistTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class BaseAddShowsFragment : Fragment() {
* actually added, yet.
*/
@Subscribe(threadMode = ThreadMode.MAIN)
fun onEventAddingShow(event: AddFragment.OnAddingShowEvent) {
fun onEventAddingShow(event: OnAddingShowEvent) {
if (event.showTmdbId > 0) {
setStateForTmdbId(event.showTmdbId, SearchResult.STATE_ADDING)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ open class ItemAddShowClickListener(
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 Uwe Trottmann

package com.battlelancer.seriesguide.shows.search.discover

/**
* Event posted when a show is about to be added to the database.
*/
class OnAddingShowEvent(
/**
* Is -1 if adding all shows this lists.
*/
val showTmdbId: Int
) {
/**
* Sets TMDB id to -1 to indicate all shows of this are added.
*/
constructor() : this(-1)
}

0 comments on commit 5a8aa46

Please sign in to comment.