mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 00:17:58 +01:00
show the cached folders immediately as possible copy/move destinations at the dialog
This commit is contained in:
parent
69a8a35016
commit
5a954febf4
4 changed files with 40 additions and 20 deletions
|
@ -13,7 +13,6 @@ import android.support.v7.widget.GridLayoutManager
|
|||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.models.Release
|
||||
import com.simplemobiletools.gallery.BuildConfig
|
||||
|
@ -21,10 +20,7 @@ import com.simplemobiletools.gallery.R
|
|||
import com.simplemobiletools.gallery.adapters.DirectoryAdapter
|
||||
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
||||
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
|
||||
import com.simplemobiletools.gallery.extensions.config
|
||||
import com.simplemobiletools.gallery.extensions.launchAbout
|
||||
import com.simplemobiletools.gallery.extensions.launchCamera
|
||||
import com.simplemobiletools.gallery.extensions.launchSettings
|
||||
import com.simplemobiletools.gallery.extensions.*
|
||||
import com.simplemobiletools.gallery.helpers.*
|
||||
import com.simplemobiletools.gallery.models.Directory
|
||||
import com.simplemobiletools.gallery.views.MyScalableRecyclerView
|
||||
|
@ -159,9 +155,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
return
|
||||
|
||||
mIsGettingDirs = true
|
||||
val token = object : TypeToken<List<Directory>>() {}.type
|
||||
val dirs = Gson().fromJson<ArrayList<Directory>>(config.directories, token) ?: ArrayList<Directory>(1)
|
||||
if (dirs.size != 0 && !mLoadedInitialPhotos) {
|
||||
val dirs = getCachedDirectories()
|
||||
if (dirs.isNotEmpty() && !mLoadedInitialPhotos) {
|
||||
gotDirectories(dirs)
|
||||
}
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
mIsGettingMedia = true
|
||||
val token = object : TypeToken<List<Medium>>() {}.type
|
||||
val media = Gson().fromJson<ArrayList<Medium>>(config.loadFolderMedia(mPath), token) ?: ArrayList<Medium>(1)
|
||||
if (media.size == 0 && !mLoadedInitialPhotos) {
|
||||
if (media.isNotEmpty() && !mLoadedInitialPhotos) {
|
||||
gotMedia(media)
|
||||
}
|
||||
|
||||
|
|
|
@ -11,33 +11,33 @@ import com.simplemobiletools.gallery.activities.SimpleActivity
|
|||
import com.simplemobiletools.gallery.adapters.DirectoryAdapter
|
||||
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.*
|
||||
|
||||
class PickAlbumDialog(val activity: SimpleActivity, val sourcePath: String, val callback: (path: String) -> Unit) {
|
||||
var dialog: AlertDialog
|
||||
var directoriesGrid: RecyclerView
|
||||
var shownDirectories: ArrayList<Directory> = ArrayList()
|
||||
|
||||
init {
|
||||
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_album_picker, null)
|
||||
directoriesGrid = view.directories_grid
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
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_destination)
|
||||
|
||||
val dirs = activity.getCachedDirectories()
|
||||
if (dirs.isNotEmpty()) {
|
||||
gotDirectories(dirs)
|
||||
}
|
||||
|
||||
GetDirectoriesAsynctask(activity, false, false) {
|
||||
val adapter = DirectoryAdapter(activity, it, null) {
|
||||
if (it.path.trimEnd('/') == sourcePath) {
|
||||
activity.toast(R.string.source_and_destination_same)
|
||||
return@DirectoryAdapter
|
||||
} else {
|
||||
callback.invoke(it.path)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
directoriesGrid.adapter = adapter
|
||||
gotDirectories(it)
|
||||
}.execute()
|
||||
}
|
||||
}
|
||||
|
@ -48,4 +48,21 @@ class PickAlbumDialog(val activity: SimpleActivity, val sourcePath: String, val
|
|||
callback.invoke(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun gotDirectories(directories: ArrayList<Directory>) {
|
||||
if (directories.hashCode() == shownDirectories.hashCode())
|
||||
return
|
||||
|
||||
shownDirectories = directories
|
||||
val adapter = DirectoryAdapter(activity, directories, null) {
|
||||
if (it.path.trimEnd('/') == sourcePath) {
|
||||
activity.toast(R.string.source_and_destination_same)
|
||||
return@DirectoryAdapter
|
||||
} else {
|
||||
callback.invoke(it.path)
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
directoriesGrid.adapter = adapter
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ import com.bumptech.glide.Glide
|
|||
import com.bumptech.glide.load.DecodeFormat
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.signature.StringSignature
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.gallery.BuildConfig
|
||||
|
@ -22,6 +24,7 @@ import com.simplemobiletools.gallery.activities.SimpleActivity
|
|||
import com.simplemobiletools.gallery.helpers.NOMEDIA
|
||||
import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE
|
||||
import com.simplemobiletools.gallery.helpers.REQUEST_SET_WALLPAPER
|
||||
import com.simplemobiletools.gallery.models.Directory
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import com.simplemobiletools.gallery.views.MySquareImageView
|
||||
import java.io.File
|
||||
|
@ -253,3 +256,8 @@ fun Activity.loadStaticGif(path: String, target: MySquareImageView) {
|
|||
if (config.cropThumbnails) builder.centerCrop() else builder.fitCenter()
|
||||
builder.into(target)
|
||||
}
|
||||
|
||||
fun Activity.getCachedDirectories(): ArrayList<Directory> {
|
||||
val token = object : TypeToken<List<Directory>>() {}.type
|
||||
return Gson().fromJson<ArrayList<Directory>>(config.directories, token) ?: ArrayList<Directory>(1)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue