Skip to content

Commit e369880

Browse files
authored
feat: add support for folders on Android 9 and below (#273)
Refs: #258
1 parent 93a676c commit e369880

File tree

7 files changed

+25
-39
lines changed

7 files changed

+25
-39
lines changed

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+
### Added
9+
- Support for folders on Android 9 and below versions ([#258])
810

911
## [1.3.0] - 2025-10-09
1012
### Changed
@@ -66,6 +68,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6668
[#206]: https://github.com/FossifyOrg/Music-Player/issues/206
6769
[#209]: https://github.com/FossifyOrg/Music-Player/issues/209
6870
[#228]: https://github.com/FossifyOrg/Music-Player/issues/228
71+
[#258]: https://github.com/FossifyOrg/Music-Player/issues/258
6972
[#261]: https://github.com/FossifyOrg/Music-Player/issues/261
7073
[#269]: https://github.com/FossifyOrg/Music-Player/issues/269
7174

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import org.fossify.commons.dialogs.RadioGroupDialog
66
import org.fossify.commons.extensions.*
77
import org.fossify.commons.helpers.IS_CUSTOMIZING_COLORS
88
import org.fossify.commons.helpers.NavigationIcon
9-
import org.fossify.commons.helpers.isQPlus
109
import org.fossify.commons.helpers.isTiramisuPlus
1110
import org.fossify.commons.models.RadioItem
1211
import org.fossify.musicplayer.R
@@ -134,7 +133,6 @@ class SettingsActivity : SimpleControllerActivity() {
134133
}
135134

136135
private fun setupManageExcludedFolders() {
137-
binding.settingsManageExcludedFoldersHolder.beVisibleIf(isQPlus())
138136
binding.settingsManageExcludedFoldersHolder.setOnClickListener {
139137
startActivity(Intent(this, ExcludedFoldersActivity::class.java))
140138
}

app/src/main/kotlin/org/fossify/musicplayer/dialogs/ManageVisibleTabsDialog.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package org.fossify.musicplayer.dialogs
22

33
import org.fossify.commons.activities.BaseSimpleActivity
4-
import org.fossify.commons.extensions.beGone
54
import org.fossify.commons.extensions.getAlertDialogBuilder
65
import org.fossify.commons.extensions.setupDialogStuff
76
import org.fossify.commons.extensions.viewBinding
8-
import org.fossify.commons.helpers.isQPlus
97
import org.fossify.commons.views.MyAppCompatCheckbox
108
import org.fossify.musicplayer.databinding.DialogManageVisibleTabsBinding
119
import org.fossify.musicplayer.extensions.config
@@ -25,11 +23,6 @@ class ManageVisibleTabsDialog(val activity: BaseSimpleActivity, val callback: (r
2523
put(TAB_GENRES, binding.manageVisibleTabsGenres)
2624
}
2725

28-
if (!isQPlus()) {
29-
tabs.remove(TAB_FOLDERS)
30-
binding.manageVisibleTabsFolders.beGone()
31-
}
32-
3326
val showTabs = activity.config.showTabs
3427
for ((key, value) in tabs) {
3528
value.isChecked = showTabs and key != 0
@@ -52,7 +45,7 @@ class ManageVisibleTabsDialog(val activity: BaseSimpleActivity, val callback: (r
5245
}
5346

5447
if (result == 0) {
55-
result = allTabsMask
48+
result = ALL_TABS_MASK
5649
}
5750

5851
callback(result)

app/src/main/kotlin/org/fossify/musicplayer/extensions/Context.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,11 @@ fun Context.getPlaybackSetting(repeatMode: @Player.RepeatMode Int): PlaybackSett
297297
else -> config.playbackSetting
298298
}
299299
}
300+
301+
fun Context.getFriendlyFolder(path: String): String {
302+
return when (val parentPath = path.getParentPath()) {
303+
internalStoragePath -> getString(org.fossify.commons.R.string.internal)
304+
sdCardPath -> getString(org.fossify.commons.R.string.sd_card)
305+
else -> parentPath.getFilenameFromPath()
306+
}
307+
}

app/src/main/kotlin/org/fossify/musicplayer/helpers/Config.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.fossify.musicplayer.helpers
22

33
import android.content.Context
44
import org.fossify.commons.helpers.BaseConfig
5-
import java.util.Arrays
65

76
class Config(context: Context) : BaseConfig(context) {
87
companion object {
@@ -116,15 +115,15 @@ class Config(context: Context) : BaseConfig(context) {
116115
.apply()
117116

118117
var showTabs: Int
119-
get() = prefs.getInt(SHOW_TABS, allTabsMask)
118+
get() = prefs.getInt(SHOW_TABS, ALL_TABS_MASK)
120119
set(showTabs) = prefs.edit().putInt(SHOW_TABS, showTabs).apply()
121120

122121
var excludedFolders: MutableSet<String>
123122
get() = prefs.getStringSet(EXCLUDED_FOLDERS, HashSet())!!
124123
set(excludedFolders) = prefs.edit().remove(EXCLUDED_FOLDERS).putStringSet(EXCLUDED_FOLDERS, excludedFolders).apply()
125124

126125
fun addExcludedFolder(path: String) {
127-
addExcludedFolders(HashSet(Arrays.asList(path)))
126+
addExcludedFolders(HashSet(listOf(path)))
128127
}
129128

130129
fun addExcludedFolders(paths: Set<String>) {

app/src/main/kotlin/org/fossify/musicplayer/helpers/Constants.kt

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.fossify.musicplayer.helpers
33
import androidx.core.net.toUri
44
import org.fossify.commons.helpers.PERMISSION_READ_MEDIA_AUDIO
55
import org.fossify.commons.helpers.PERMISSION_WRITE_STORAGE
6-
import org.fossify.commons.helpers.isQPlus
76
import org.fossify.commons.helpers.isTiramisuPlus
87

98
const val ALL_TRACKS_PLAYLIST_ID = 1
@@ -83,32 +82,17 @@ const val ACTIVITY_PLAYLIST_FOLDER = 64
8382
const val FLAG_MANUAL_CACHE = 1
8483
const val FLAG_IS_CURRENT = 2
8584

86-
// show Folders tab only on Android Q+, BUCKET_DISPLAY_NAME hasn't been available before that
87-
val allTabsMask = if (isQPlus()) {
88-
TAB_PLAYLISTS or TAB_FOLDERS or TAB_ARTISTS or TAB_ALBUMS or TAB_TRACKS
89-
} else {
90-
TAB_PLAYLISTS or TAB_ARTISTS or TAB_ALBUMS or TAB_TRACKS
91-
}
85+
const val ALL_TABS_MASK = TAB_PLAYLISTS or TAB_FOLDERS or TAB_ARTISTS or TAB_ALBUMS or TAB_TRACKS
9286

9387
val tabsList: ArrayList<Int>
94-
get() = if (isQPlus()) {
95-
arrayListOf(
96-
TAB_PLAYLISTS,
97-
TAB_FOLDERS,
98-
TAB_ARTISTS,
99-
TAB_ALBUMS,
100-
TAB_TRACKS,
101-
TAB_GENRES
102-
)
103-
} else {
104-
arrayListOf(
105-
TAB_PLAYLISTS,
106-
TAB_ARTISTS,
107-
TAB_ALBUMS,
108-
TAB_TRACKS,
109-
TAB_GENRES
110-
)
111-
}
88+
get() = arrayListOf(
89+
TAB_PLAYLISTS,
90+
TAB_FOLDERS,
91+
TAB_ARTISTS,
92+
TAB_ALBUMS,
93+
TAB_TRACKS,
94+
TAB_GENRES
95+
)
11296

11397
// use custom sorting constants, there are too many app specific ones
11498
const val PLAYER_SORT_BY_TITLE = 1

app/src/main/kotlin/org/fossify/musicplayer/helpers/SimpleMediaScanner.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import org.fossify.musicplayer.models.*
1919
import java.io.File
2020
import java.io.FileInputStream
2121
import androidx.core.net.toUri
22+
import org.fossify.musicplayer.extensions.getFriendlyFolder
2223

2324
/**
2425
* This singleton class manages the process of querying [MediaStore] for new audio files, manually scanning storage for missing audio files, and removing outdated
@@ -239,7 +240,7 @@ class SimpleMediaScanner(private val context: Application) {
239240
val folderName = if (isQPlus()) {
240241
cursor.getStringValue(Audio.Media.BUCKET_DISPLAY_NAME) ?: MediaStore.UNKNOWN_STRING
241242
} else {
242-
""
243+
context.getFriendlyFolder(path).ifEmpty { MediaStore.UNKNOWN_STRING }
243244
}
244245

245246
val album = cursor.getStringValue(Audio.Media.ALBUM) ?: folderName

0 commit comments

Comments
 (0)