Fixed Playlist save
This commit is contained in:
parent
7b85fce485
commit
84295eda82
3 changed files with 15 additions and 14 deletions
|
@ -21,9 +21,10 @@ fun Fragment.createNewFile(
|
||||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult())
|
registerForActivityResult(ActivityResultContracts.StartActivityForResult())
|
||||||
{ result: ActivityResult ->
|
{ result: ActivityResult ->
|
||||||
if (result.resultCode == Activity.RESULT_OK) {
|
if (result.resultCode == Activity.RESULT_OK) {
|
||||||
context?.contentResolver?.openOutputStream(result.data?.data!!)?.use { os->
|
write(
|
||||||
write(os, result.data?.data)
|
context?.contentResolver?.openOutputStream(result.data?.data!!),
|
||||||
}
|
result.data?.data
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,12 +40,12 @@ class PlaylistsFragment :
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
libraryViewModel.getPlaylists().observe(viewLifecycleOwner, {
|
libraryViewModel.getPlaylists().observe(viewLifecycleOwner) {
|
||||||
if (it.isNotEmpty())
|
if (it.isNotEmpty())
|
||||||
adapter?.swapDataSet(it)
|
adapter?.swapDataSet(it)
|
||||||
else
|
else
|
||||||
adapter?.swapDataSet(listOf())
|
adapter?.swapDataSet(listOf())
|
||||||
})
|
}
|
||||||
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) {
|
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner) {
|
||||||
remove()
|
remove()
|
||||||
requireActivity().onBackPressed()
|
requireActivity().onBackPressed()
|
||||||
|
|
|
@ -72,17 +72,17 @@ object M3UWriter : M3UConstants {
|
||||||
it.songPrimaryKey
|
it.songPrimaryKey
|
||||||
}.toSongs()
|
}.toSongs()
|
||||||
if (songs.isNotEmpty()) {
|
if (songs.isNotEmpty()) {
|
||||||
outputStream.bufferedWriter().use{ bw->
|
outputStream.use { os ->
|
||||||
bw.write(M3UConstants.HEADER)
|
os.bufferedWriter().use { bw->
|
||||||
songs.forEach {
|
bw.write(M3UConstants.HEADER)
|
||||||
bw.newLine()
|
songs.forEach {
|
||||||
bw.write(M3UConstants.ENTRY + it.duration + M3UConstants.DURATION_SEPARATOR + it.artistName + " - " + it.title)
|
bw.newLine()
|
||||||
bw.newLine()
|
bw.write(M3UConstants.ENTRY + it.duration + M3UConstants.DURATION_SEPARATOR + it.artistName + " - " + it.title)
|
||||||
bw.write(it.data)
|
bw.newLine()
|
||||||
|
bw.write(it.data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outputStream.flush()
|
|
||||||
outputStream.close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue