mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-18 06:17:59 +01:00
allow setting up custom album covers
This commit is contained in:
parent
866b8b77b4
commit
add3320c4a
8 changed files with 105 additions and 4 deletions
|
@ -10,6 +10,8 @@ import com.bignerdranch.android.multiselector.ModalMultiSelectorCallback
|
||||||
import com.bignerdranch.android.multiselector.MultiSelector
|
import com.bignerdranch.android.multiselector.MultiSelector
|
||||||
import com.bignerdranch.android.multiselector.SwappingHolder
|
import com.bignerdranch.android.multiselector.SwappingHolder
|
||||||
import com.bumptech.glide.Glide
|
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.ConfirmationDialog
|
||||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
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.R
|
||||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||||
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
|
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
|
||||||
|
import com.simplemobiletools.gallery.dialogs.PickMediumDialog
|
||||||
import com.simplemobiletools.gallery.extensions.*
|
import com.simplemobiletools.gallery.extensions.*
|
||||||
|
import com.simplemobiletools.gallery.models.AlbumCover
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
import kotlinx.android.synthetic.main.directory_item.view.*
|
import kotlinx.android.synthetic.main.directory_item.view.*
|
||||||
import kotlinx.android.synthetic.main.directory_tmb.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) {
|
private fun copyMoveTo(isCopyOperation: Boolean) {
|
||||||
val files = ArrayList<File>()
|
|
||||||
if (selectedPositions.isEmpty())
|
if (selectedPositions.isEmpty())
|
||||||
return
|
return
|
||||||
|
|
||||||
|
val files = ArrayList<File>()
|
||||||
selectedPositions.forEach {
|
selectedPositions.forEach {
|
||||||
val dir = File(dirs[it].path)
|
val dir = File(dirs[it].path)
|
||||||
files.addAll(dir.listFiles().filter { it.isFile && it.isImageVideoGif() })
|
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) {
|
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()
|
listener?.refreshItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
import com.simplemobiletools.gallery.extensions.getCachedDirectories
|
import com.simplemobiletools.gallery.extensions.getCachedDirectories
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
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) {
|
class PickDirectoryDialog(val activity: SimpleActivity, val sourcePath: String, val callback: (path: String) -> Unit) {
|
||||||
var dialog: AlertDialog
|
var dialog: AlertDialog
|
||||||
|
@ -21,7 +21,7 @@ class PickDirectoryDialog(val activity: SimpleActivity, val sourcePath: String,
|
||||||
var shownDirectories: ArrayList<Directory> = ArrayList()
|
var shownDirectories: ArrayList<Directory> = ArrayList()
|
||||||
|
|
||||||
init {
|
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
|
directoriesGrid = view.directories_grid
|
||||||
|
|
||||||
dialog = AlertDialog.Builder(activity)
|
dialog = AlertDialog.Builder(activity)
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
|
@ -167,4 +167,8 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
var directories: String
|
var directories: String
|
||||||
get() = prefs.getString(DIRECTORIES, "")
|
get() = prefs.getString(DIRECTORIES, "")
|
||||||
set(directories) = prefs.edit().putString(DIRECTORIES, directories).apply()
|
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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ val SAVE_FOLDER_PREFIX = "folder2_"
|
||||||
val HIDE_FOLDER_TOOLTIP_SHOWN = "hide_folder_tooltip_shown"
|
val HIDE_FOLDER_TOOLTIP_SHOWN = "hide_folder_tooltip_shown"
|
||||||
val EXCLUDED_FOLDERS = "excluded_folders"
|
val EXCLUDED_FOLDERS = "excluded_folders"
|
||||||
val INCLUDED_FOLDERS = "included_folders"
|
val INCLUDED_FOLDERS = "included_folders"
|
||||||
|
val ALBUM_COVERS = "album_covers"
|
||||||
|
|
||||||
val NOMEDIA = ".nomedia"
|
val NOMEDIA = ".nomedia"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package com.simplemobiletools.gallery.models
|
||||||
|
|
||||||
|
data class AlbumCover(val path: String, val tmb: String)
|
|
@ -5,5 +5,6 @@
|
||||||
android:id="@+id/directories_grid"
|
android:id="@+id/directories_grid"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="@dimen/activity_margin"
|
||||||
app:layoutManager="android.support.v7.widget.GridLayoutManager"
|
app:layoutManager="android.support.v7.widget.GridLayoutManager"
|
||||||
app:spanCount="@integer/directory_columns"/>
|
app:spanCount="@integer/directory_columns"/>
|
10
app/src/main/res/layout/dialog_medium_picker.xml
Normal file
10
app/src/main/res/layout/dialog_medium_picker.xml
Normal 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"/>
|
Loading…
Reference in a new issue