mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
rewrite the mediapicker dialog, make it work like picking directories
This commit is contained in:
parent
906168c6b5
commit
021a1cbf74
5 changed files with 88 additions and 24 deletions
|
@ -18,7 +18,6 @@ import com.bumptech.glide.request.RequestOptions
|
|||
import com.bumptech.glide.request.target.SimpleTarget
|
||||
import com.bumptech.glide.request.transition.Transition
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
|
@ -343,8 +342,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
return
|
||||
|
||||
mIsGettingMedia = true
|
||||
val token = object : TypeToken<List<Medium>>() {}.type
|
||||
val media = Gson().fromJson<ArrayList<Medium>>(config.loadFolderMedia(mPath), token) ?: ArrayList(1)
|
||||
val media = getCachedMedia(mPath)
|
||||
if (media.isNotEmpty() && !mLoadedInitialPhotos) {
|
||||
gotMedia(media, true)
|
||||
} else {
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.simplemobiletools.gallery.dialogs
|
|||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.widget.GridLayoutManager
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.extensions.beGoneIf
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
|
@ -22,8 +21,8 @@ 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
|
||||
var shownDirectories: ArrayList<Directory> = ArrayList()
|
||||
var view: View = LayoutInflater.from(activity).inflate(R.layout.dialog_directory_picker, null)
|
||||
var shownDirectories = ArrayList<Directory>()
|
||||
var view = LayoutInflater.from(activity).inflate(R.layout.dialog_directory_picker, null)
|
||||
var isGridViewType = activity.config.viewTypeFolders == VIEW_TYPE_GRID
|
||||
|
||||
init {
|
||||
|
|
|
@ -1,27 +1,32 @@
|
|||
package com.simplemobiletools.gallery.dialogs
|
||||
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.support.v7.widget.GridLayoutManager
|
||||
import android.view.LayoutInflater
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.extensions.beGoneIf
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
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.extensions.getCachedMedia
|
||||
import com.simplemobiletools.gallery.helpers.VIEW_TYPE_GRID
|
||||
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()
|
||||
var shownMedia = ArrayList<Medium>()
|
||||
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_medium_picker, null)
|
||||
var isGridViewType = activity.config.viewTypeFiles == VIEW_TYPE_GRID
|
||||
|
||||
init {
|
||||
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_medium_picker, null)
|
||||
mediaGrid = view.media_grid
|
||||
(view.media_grid.layoutManager as GridLayoutManager).apply {
|
||||
orientation = if (activity.config.scrollHorizontally && isGridViewType) GridLayoutManager.HORIZONTAL else GridLayoutManager.VERTICAL
|
||||
spanCount = if (isGridViewType) activity.config.mediaColumnCnt else 1
|
||||
}
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
|
@ -29,10 +34,7 @@ class PickMediumDialog(val activity: SimpleActivity, val path: String, val callb
|
|||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.select_photo)
|
||||
|
||||
val token = object : TypeToken<List<Medium>>() {}.type
|
||||
var media = Gson().fromJson<ArrayList<Medium>>(activity.config.loadFolderMedia(path), token) ?: ArrayList(1)
|
||||
media = media.filter { !it.video } as ArrayList
|
||||
|
||||
val media = activity.getCachedMedia(path).filter { !it.video } as ArrayList
|
||||
if (media.isNotEmpty()) {
|
||||
gotMedia(media)
|
||||
}
|
||||
|
@ -52,6 +54,22 @@ class PickMediumDialog(val activity: SimpleActivity, val path: String, val callb
|
|||
callback(it.path)
|
||||
dialog.dismiss()
|
||||
}
|
||||
mediaGrid.adapter = adapter
|
||||
|
||||
val scrollHorizontally = activity.config.scrollHorizontally && isGridViewType
|
||||
view.apply {
|
||||
media_grid.adapter = adapter
|
||||
|
||||
media_vertical_fastscroller.isHorizontal = false
|
||||
media_vertical_fastscroller.beGoneIf(scrollHorizontally)
|
||||
|
||||
media_horizontal_fastscroller.isHorizontal = true
|
||||
media_horizontal_fastscroller.beVisibleIf(scrollHorizontally)
|
||||
|
||||
if (scrollHorizontally) {
|
||||
media_horizontal_fastscroller.setViews(media_grid)
|
||||
} else {
|
||||
media_vertical_fastscroller.setViews(media_grid)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -337,3 +337,8 @@ fun Activity.getCachedDirectories(): ArrayList<Directory> {
|
|||
val token = object : TypeToken<List<Directory>>() {}.type
|
||||
return Gson().fromJson<ArrayList<Directory>>(config.directories, token) ?: ArrayList<Directory>(1)
|
||||
}
|
||||
|
||||
fun Activity.getCachedMedia(path: String): ArrayList<Medium> {
|
||||
val token = object : TypeToken<List<Medium>>() {}.type
|
||||
return Gson().fromJson<ArrayList<Medium>>(config.loadFolderMedia(path), token) ?: ArrayList(1)
|
||||
}
|
||||
|
|
|
@ -1,10 +1,54 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.RecyclerView
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/media_grid"
|
||||
android:id="@+id/media_grid_holder"
|
||||
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_vertical_scroll"/>
|
||||
android:paddingTop="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyScalableRecyclerView
|
||||
android:id="@+id/media_grid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="android.support.v7.widget.GridLayoutManager"
|
||||
app:spanCount="@integer/media_columns_vertical_scroll"/>
|
||||
|
||||
<com.simplemobiletools.commons.views.FastScroller
|
||||
android:id="@+id/media_vertical_fastscroller"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:paddingLeft="@dimen/normal_margin"
|
||||
android:paddingStart="@dimen/normal_margin">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/fastscroller_handle_vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:alpha="0"
|
||||
android:background="@drawable/fastscroller_handle_vertical"/>
|
||||
|
||||
</com.simplemobiletools.commons.views.FastScroller>
|
||||
|
||||
<com.simplemobiletools.commons.views.FastScroller
|
||||
android:id="@+id/media_horizontal_fastscroller"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:paddingTop="@dimen/normal_margin">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/fastscroller_handle_horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:alpha="0"
|
||||
android:background="@drawable/fastscroller_handle_horizontal"/>
|
||||
|
||||
</com.simplemobiletools.commons.views.FastScroller>
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in a new issue