Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ package com.battlelancer.seriesguide.people

import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.ViewGroup
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuProvider
import androidx.lifecycle.Lifecycle
import com.battlelancer.seriesguide.R
import com.battlelancer.seriesguide.databinding.ActivityPeopleBinding
import com.battlelancer.seriesguide.people.PeopleFragment.OnShowPersonListener
Expand All @@ -15,7 +21,7 @@ import com.battlelancer.seriesguide.util.commitReorderingAllowed

/**
* Displays a list of people, and on wide enough screens person details.
* Otherwise lets [PersonActivity] show details.
* Otherwise, lets [PersonActivity] show details.
*/
class PeopleActivity : BaseActivity(), OnShowPersonListener {

Expand Down Expand Up @@ -49,6 +55,7 @@ class PeopleActivity : BaseActivity(), OnShowPersonListener {
setContentView(binding.root)
ThemeUtils.configureForEdgeToEdge(binding.root as ViewGroup)
setupActionBar()
setupMenu()
binding.sgAppBarLayout.sgAppBarLayout.liftOnScrollTargetViewId =
PeopleFragment.liftOnScrollTargetViewId

Expand Down Expand Up @@ -105,6 +112,45 @@ class PeopleActivity : BaseActivity(), OnShowPersonListener {
}
}

private fun setupMenu() {
addMenuProvider(object : MenuProvider {

override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
menuInflater.inflate(R.menu.people_menu, menu)

val peopleType = PeopleType.valueOf(
intent.getStringExtra(InitBundle.PEOPLE_TYPE)!!
)

val searchItem = menu.findItem(R.id.menu_search)
val searchView = searchItem.actionView as SearchView

searchView.queryHint = if (peopleType == PeopleType.CAST) {
getString(R.string.people_search_cast_hint)
} else {
getString(R.string.people_search_crew_hint)
}

searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
return true
}

override fun onQueryTextChange(newText: String): Boolean {
val peopleFragment =
supportFragmentManager.findFragmentById(R.id.containerPeople) as PeopleFragment?
peopleFragment?.search(newText)
return true
}
})
}

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
return false // BaseActivity (BaseThemeActivity) handles the home button
}
}, this, Lifecycle.State.RESUMED)
}

override fun showPerson(tmdbId: Int) {
if (isTwoPane) {
// show inline
Expand All @@ -120,7 +166,3 @@ class PeopleActivity : BaseActivity(), OnShowPersonListener {
}
}
}

interface PeopleActivityInterface {
val isTwoPane: Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class PeopleFragment : Fragment() {
ListView.CHOICE_MODE_NONE
}


return rootView
}

Expand Down Expand Up @@ -134,7 +133,6 @@ class PeopleFragment : Fragment() {

override fun onDetach() {
super.onDetach()

onShowPersonListener = sDummyListener
}

Expand Down Expand Up @@ -186,8 +184,13 @@ class PeopleFragment : Fragment() {
}

private fun setEmptyMessage() {
// display error message if we are offline
if (!AndroidUtils.isNetworkConnected(requireContext())) {

emptyView.setContentVisibility(View.VISIBLE)
if (model.isSearchOngoing()) {
emptyView.setMessage(R.string.empty_no_results)
emptyView.setButtonGone(true)
} else if (!AndroidUtils.isNetworkConnected(requireContext())) {
// display error message if we are offline
emptyView.setMessage(R.string.offline)
} else {
emptyView.setMessage(
Expand All @@ -197,7 +200,10 @@ class PeopleFragment : Fragment() {
)
)
}
emptyView.setContentVisibility(View.VISIBLE)
}

fun search(query: String) {
model.filter(query)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class PeopleViewModel(
private val peopleType: PeopleActivity.PeopleType
) : AndroidViewModel(application) {

private var originalCredits = emptyList<Person>()
val credits = MutableLiveData<List<Person>>()

init {
Expand All @@ -40,10 +41,26 @@ class PeopleViewModel(
newCredits?.crew
}

credits.postValue(castOrCrewOrNull ?: emptyList())
originalCredits = castOrCrewOrNull ?: emptyList()
credits.postValue(originalCredits)
}
}

fun filter(query: String) {
viewModelScope.launch(Dispatchers.IO) {
val filterResult = originalCredits.filter { person ->
if (person.description != null) {
person.name.contains(query, ignoreCase = true) ||
person.description.contains(query, ignoreCase = true)
} else {
person.name.contains(query, ignoreCase = true)
}
}
credits.postValue(filterResult)
}
}

fun isSearchOngoing() = credits.value?.size != originalCredits.size
}

class PeopleViewModelFactory(
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/menu/people_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Apache-2.0 -->
<!-- Copyright © 2026 Uwe Trottmann <uwe@uwetrottmann.com> -->

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_search"
android:icon="@drawable/ic_search_white_24dp"
android:title="@string/search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView" />
</menu>
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@
<string name="description_extension_web_search">Nach Webseiten und Bildern suchen</string>
<!-- People -->
<string name="person_biography">Biografie</string>
<string name="people_search_crew_hint">Suche nach Crew</string>
<string name="people_search_cast_hint">Suche nach Besetzung</string>
<!-- Feedback -->
<string name="feedback_question_enjoy">Gefällt Ihnen SeriesGuide?</string>
<string name="feedback_action_yes">Ja!</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@

<!-- People -->
<string name="person_biography">Biography</string>
<string name="people_search_crew_hint">Search for crew</string>
<string name="people_search_cast_hint">Search for cast</string>

<!-- Feedback -->
<string name="feedback_question_enjoy">Are you enjoying SeriesGuide?</string>
Expand Down