Skip to content

Commit be1105b

Browse files
authored
fix: find current fragment using viewpager position (#240)
The `getCurrentFragment()` method doesn't always return the current fragment. This change ensures correct menu items are displayed when that happens. Refs: #65
1 parent 348a9ce commit be1105b

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- Playlist menu options now show up correctly on the playlists tab ([#65])
810

911
## [1.2.2] - 2025-08-21
1012
### Changed
@@ -46,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4648
[#18]: https://github.com/FossifyOrg/Music-Player/issues/18
4749
[#45]: https://github.com/FossifyOrg/Music-Player/issues/45
4850
[#47]: https://github.com/FossifyOrg/Music-Player/issues/47
51+
[#65]: https://github.com/FossifyOrg/Music-Player/issues/65
4952
[#206]: https://github.com/FossifyOrg/Music-Player/issues/206
5053
[#228]: https://github.com/FossifyOrg/Music-Player/issues/228
5154

app/src/main/kotlin/org/fossify/musicplayer/activities/MainActivity.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ class MainActivity : SimpleMusicActivity() {
118118
}
119119
}
120120

121-
private fun refreshMenuItems() {
121+
private fun refreshMenuItems(position: Int = binding.viewPager.currentItem) {
122122
binding.mainMenu.getToolbar().menu.apply {
123-
val isPlaylistFragment = getCurrentFragment() is PlaylistsFragment
123+
val tab = getVisibleTabs()[position]
124+
val isPlaylistFragment = tab == TAB_PLAYLISTS
124125
findItem(R.id.create_new_playlist).isVisible = isPlaylistFragment
125126
findItem(R.id.create_playlist_from_folder).isVisible = isPlaylistFragment
126127
findItem(R.id.import_playlist).isVisible = isPlaylistFragment
@@ -224,7 +225,7 @@ class MainActivity : SimpleMusicActivity() {
224225
getAllFragments().forEach {
225226
it.finishActMode()
226227
}
227-
refreshMenuItems()
228+
refreshMenuItems(position)
228229
}
229230
})
230231
binding.viewPager.currentItem = config.lastUsedViewPagerPage

0 commit comments

Comments
 (0)