diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 4a60982f6..8aaa5cb3d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -10,6 +10,8 @@ import com.bignerdranch.android.multiselector.ModalMultiSelectorCallback import com.bignerdranch.android.multiselector.MultiSelector import com.bignerdranch.android.multiselector.SwappingHolder import com.bumptech.glide.Glide +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog @@ -20,7 +22,9 @@ import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog +import com.simplemobiletools.gallery.dialogs.PickMediumDialog import com.simplemobiletools.gallery.extensions.* +import com.simplemobiletools.gallery.models.AlbumCover import com.simplemobiletools.gallery.models.Directory import kotlinx.android.synthetic.main.directory_item.view.* import kotlinx.android.synthetic.main.directory_tmb.view.* @@ -253,10 +257,10 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList() if (selectedPositions.isEmpty()) return + val files = ArrayList() selectedPositions.forEach { val dir = File(dirs[it].path) files.addAll(dir.listFiles().filter { it.isFile && it.isImageVideoGif() }) @@ -324,6 +328,28 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList>() {}.type + var albumCovers = Gson().fromJson>(config.albumCovers, listType) ?: ArrayList(1) + + if (useDefault) { + albumCovers = albumCovers.filterNot { it.path == path } as ArrayList + storeCovers(albumCovers) + } else { + PickMediumDialog(activity, path) { + albumCovers = albumCovers.filterNot { it.path == path } as ArrayList + albumCovers.add(AlbumCover(path, it)) + storeCovers(albumCovers) + } + } + } + + private fun storeCovers(albumCovers: ArrayList) { + activity.config.albumCovers = Gson().toJson(albumCovers) + actMode?.finish() listener?.refreshItems() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt index 9c68c310f..cf384829e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt @@ -13,7 +13,7 @@ import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getCachedDirectories import com.simplemobiletools.gallery.models.Directory -import kotlinx.android.synthetic.main.dialog_album_picker.view.* +import kotlinx.android.synthetic.main.dialog_directory_picker.view.* class PickDirectoryDialog(val activity: SimpleActivity, val sourcePath: String, val callback: (path: String) -> Unit) { var dialog: AlertDialog @@ -21,7 +21,7 @@ class PickDirectoryDialog(val activity: SimpleActivity, val sourcePath: String, var shownDirectories: ArrayList = ArrayList() init { - val view = LayoutInflater.from(activity).inflate(R.layout.dialog_album_picker, null) + val view = LayoutInflater.from(activity).inflate(R.layout.dialog_directory_picker, null) directoriesGrid = view.directories_grid dialog = AlertDialog.Builder(activity) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt new file mode 100644 index 000000000..8d2bacf2b --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -0,0 +1,56 @@ +package com.simplemobiletools.gallery.dialogs + +import android.support.v7.app.AlertDialog +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import com.simplemobiletools.commons.extensions.setupDialogStuff +import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.activities.SimpleActivity +import com.simplemobiletools.gallery.adapters.MediaAdapter +import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask +import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.models.Medium +import kotlinx.android.synthetic.main.dialog_medium_picker.view.* + +class PickMediumDialog(val activity: SimpleActivity, val path: String, val callback: (path: String) -> Unit) { + var dialog: AlertDialog + var mediaGrid: RecyclerView + var shownMedia: ArrayList = ArrayList() + + init { + val view = LayoutInflater.from(activity).inflate(R.layout.dialog_medium_picker, null) + mediaGrid = view.media_grid + + dialog = AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok, null) + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this, R.string.select_photo) + + val token = object : TypeToken>() {}.type + val media = Gson().fromJson>(activity.config.loadFolderMedia(path), token) ?: ArrayList(1) + + if (media.isNotEmpty()) { + gotMedia(media) + } + + GetMediaAsynctask(activity, path, false, true, false) { + gotMedia(it) + }.execute() + } + } + + private fun gotMedia(media: ArrayList) { + if (media.hashCode() == shownMedia.hashCode()) + return + + shownMedia = media + val adapter = MediaAdapter(activity, media, null) { + callback(it.path) + dialog.dismiss() + } + mediaGrid.adapter = adapter + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index e84570f46..d35a981bf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -167,4 +167,8 @@ class Config(context: Context) : BaseConfig(context) { var directories: String get() = prefs.getString(DIRECTORIES, "") set(directories) = prefs.edit().putString(DIRECTORIES, directories).apply() + + var albumCovers: String + get() = prefs.getString(ALBUM_COVERS, "") + set(albumCovers) = prefs.edit().putString(ALBUM_COVERS, albumCovers).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 0a3b1ef3e..21dc7c6de 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -17,12 +17,13 @@ val DARK_BACKGROUND = "dark_background" val PINNED_FOLDERS = "pinned_folders" val DIR_COLUMN_CNT = "dir_column_cnt" val MEDIA_COLUMN_CNT = "media_column_cnt" -val SHOW_ALL = "show_all" // display images and videos from all folders together +val SHOW_ALL = "show_all" // display images and videos from all folders together val SHOW_MEDIA = "show_media" val SAVE_FOLDER_PREFIX = "folder2_" val HIDE_FOLDER_TOOLTIP_SHOWN = "hide_folder_tooltip_shown" val EXCLUDED_FOLDERS = "excluded_folders" val INCLUDED_FOLDERS = "included_folders" +val ALBUM_COVERS = "album_covers" val NOMEDIA = ".nomedia" diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/AlbumCover.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/AlbumCover.kt new file mode 100644 index 000000000..f5937ad08 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/AlbumCover.kt @@ -0,0 +1,3 @@ +package com.simplemobiletools.gallery.models + +data class AlbumCover(val path: String, val tmb: String) diff --git a/app/src/main/res/layout/dialog_album_picker.xml b/app/src/main/res/layout/dialog_directory_picker.xml similarity index 90% rename from app/src/main/res/layout/dialog_album_picker.xml rename to app/src/main/res/layout/dialog_directory_picker.xml index 079c72fa4..0feb6bf5a 100644 --- a/app/src/main/res/layout/dialog_album_picker.xml +++ b/app/src/main/res/layout/dialog_directory_picker.xml @@ -5,5 +5,6 @@ android:id="@+id/directories_grid" android:layout_width="match_parent" android:layout_height="wrap_content" + android:paddingTop="@dimen/activity_margin" app:layoutManager="android.support.v7.widget.GridLayoutManager" app:spanCount="@integer/directory_columns"/> diff --git a/app/src/main/res/layout/dialog_medium_picker.xml b/app/src/main/res/layout/dialog_medium_picker.xml new file mode 100644 index 000000000..f2aebbd17 --- /dev/null +++ b/app/src/main/res/layout/dialog_medium_picker.xml @@ -0,0 +1,10 @@ + +