allow setting up custom album covers

This commit is contained in:
tibbi 2017-06-06 21:16:19 +02:00
parent 866b8b77b4
commit add3320c4a
8 changed files with 105 additions and 4 deletions

View File

@ -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<Direc
}
private fun copyMoveTo(isCopyOperation: Boolean) {
val files = ArrayList<File>()
if (selectedPositions.isEmpty())
return
val files = ArrayList<File>()
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<Direc
}
private fun changeAlbumCover(useDefault: Boolean) {
if (selectedPositions.size != 1)
return
val path = dirs[selectedPositions.first()].path
val listType = object : TypeToken<List<AlbumCover>>() {}.type
var albumCovers = Gson().fromJson<ArrayList<AlbumCover>>(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<AlbumCover>) {
activity.config.albumCovers = Gson().toJson(albumCovers)
actMode?.finish()
listener?.refreshItems()
}

View File

@ -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<Directory> = 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)

View File

@ -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<Medium> = 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<List<Medium>>() {}.type
val media = Gson().fromJson<ArrayList<Medium>>(activity.config.loadFolderMedia(path), token) ?: ArrayList<Medium>(1)
if (media.isNotEmpty()) {
gotMedia(media)
}
GetMediaAsynctask(activity, path, false, true, false) {
gotMedia(it)
}.execute()
}
}
private fun gotMedia(media: ArrayList<Medium>) {
if (media.hashCode() == shownMedia.hashCode())
return
shownMedia = media
val adapter = MediaAdapter(activity, media, null) {
callback(it.path)
dialog.dismiss()
}
mediaGrid.adapter = adapter
}
}

View File

@ -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()
}

View File

@ -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"

View File

@ -0,0 +1,3 @@
package com.simplemobiletools.gallery.models
data class AlbumCover(val path: String, val tmb: String)

View File

@ -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"/>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/media_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/media_columns"/>