allow selecting Cover photo from any folder

This commit is contained in:
tibbi 2017-10-19 18:08:37 +02:00
parent 021a1cbf74
commit 7132e09047
3 changed files with 42 additions and 23 deletions

View file

@ -215,10 +215,11 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
}
private fun pinFolders(pin: Boolean) {
if (pin)
if (pin) {
config.addPinnedFolders(getSelectedPaths())
else
} else {
config.removePinnedFolders(getSelectedPaths())
}
pinnedFolders = config.pinnedFolders
listener?.recheckPinnedFolders()
@ -302,20 +303,30 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
return
val path = dirs[selectedPositions.first()].path
var albumCovers = config.parseAlbumCovers()
if (useDefault) {
albumCovers = albumCovers.filterNot { it.path == path } as ArrayList
val albumCovers = getAlbumCoversWithout(path)
storeCovers(albumCovers)
} else {
PickMediumDialog(activity, path) {
albumCovers = albumCovers.filterNot { it.path == path } as ArrayList
albumCovers.add(AlbumCover(path, it))
pickMediumFrom(path, path)
}
}
private fun pickMediumFrom(targetFolder: String, path: String) {
PickMediumDialog(activity, path) {
if (File(it).isDirectory) {
pickMediumFrom(targetFolder, it)
} else {
val albumCovers = getAlbumCoversWithout(path)
val cover = AlbumCover(targetFolder, it)
albumCovers.add(cover)
storeCovers(albumCovers)
}
}
}
private fun getAlbumCoversWithout(path: String) = config.parseAlbumCovers().filterNot { it.path == path } as ArrayList
private fun storeCovers(albumCovers: ArrayList<AlbumCover>) {
activity.config.albumCovers = Gson().toJson(albumCovers)
actMode?.finish()

View file

@ -37,16 +37,16 @@ class PickDirectoryDialog(val activity: SimpleActivity, val sourcePath: String,
.setNeutralButton(R.string.other_folder, { dialogInterface, i -> showOtherFolder() })
.create().apply {
activity.setupDialogStuff(view, this, R.string.select_destination)
val dirs = activity.getCachedDirectories()
if (dirs.isNotEmpty()) {
gotDirectories(activity.addTempFolderIfNeeded(dirs))
}
GetDirectoriesAsynctask(activity, false, false) {
gotDirectories(activity.addTempFolderIfNeeded(it))
}.execute()
}
val dirs = activity.getCachedDirectories()
if (dirs.isNotEmpty()) {
gotDirectories(activity.addTempFolderIfNeeded(dirs))
}
GetDirectoriesAsynctask(activity, false, false) {
gotDirectories(activity.addTempFolderIfNeeded(it))
}.execute()
}
private fun showOtherFolder() {

View file

@ -31,17 +31,25 @@ class PickMediumDialog(val activity: SimpleActivity, val path: String, val callb
dialog = AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.setNeutralButton(R.string.other_folder, { dialogInterface, i -> showOtherFolder() })
.create().apply {
activity.setupDialogStuff(view, this, R.string.select_photo)
}
val media = activity.getCachedMedia(path).filter { !it.video } as ArrayList
if (media.isNotEmpty()) {
gotMedia(media)
}
val media = activity.getCachedMedia(path).filter { !it.video } as ArrayList
if (media.isNotEmpty()) {
gotMedia(media)
}
GetMediaAsynctask(activity, path, false, true, false) {
gotMedia(it)
}.execute()
GetMediaAsynctask(activity, path, false, true, false) {
gotMedia(it)
}.execute()
}
private fun showOtherFolder() {
PickDirectoryDialog(activity, path) {
callback(it)
dialog.dismiss()
}
}