rewriting MediaAdapter to the Commons MyRecyclerViewAdapter
This commit is contained in:
parent
ee883d3acc
commit
6f78a6e9ce
6 changed files with 124 additions and 261 deletions
|
@ -47,7 +47,7 @@ ext {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.simplemobiletools:commons:2.39.7'
|
compile 'com.simplemobiletools:commons:2.39.8'
|
||||||
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.7.2'
|
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.7.2'
|
||||||
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
|
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
|
||||||
compile 'com.android.support:multidex:1.0.2'
|
compile 'com.android.support:multidex:1.0.2'
|
||||||
|
|
|
@ -340,8 +340,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
} else {
|
} else {
|
||||||
setupListLayoutManager()
|
setupListLayoutManager()
|
||||||
}
|
}
|
||||||
getDirectoryAdapter()?.setupZoomListener(mZoomListener)
|
|
||||||
getDirectoryAdapter()?.setupDragListener(true)
|
getDirectoryAdapter()?.apply {
|
||||||
|
setupZoomListener(mZoomListener)
|
||||||
|
setupDragListener(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupGridLayoutManager() {
|
private fun setupGridLayoutManager() {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||||
import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE
|
import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE
|
||||||
import com.simplemobiletools.commons.models.RadioItem
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.adapters.MediaAdapter
|
import com.simplemobiletools.gallery.adapters.MediaAdapter
|
||||||
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
|
||||||
|
@ -57,6 +58,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
private var mLatestMediaId = 0L
|
private var mLatestMediaId = 0L
|
||||||
private var mLastMediaHandler = Handler()
|
private var mLastMediaHandler = Handler()
|
||||||
private var mCurrAsyncTask: GetMediaAsynctask? = null
|
private var mCurrAsyncTask: GetMediaAsynctask? = null
|
||||||
|
private var mZoomListener: MyRecyclerView.MyZoomListener? = null
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var mMedia = ArrayList<Medium>()
|
var mMedia = ArrayList<Medium>()
|
||||||
|
@ -174,8 +176,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
|
|
||||||
val currAdapter = media_grid.adapter
|
val currAdapter = media_grid.adapter
|
||||||
if (currAdapter == null) {
|
if (currAdapter == null) {
|
||||||
media_grid.adapter = MediaAdapter(this, mMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple) {
|
media_grid.adapter = MediaAdapter(this, mMedia, this, mIsGetImageIntent || mIsGetVideoIntent || mIsGetAnyIntent, mAllowPickingMultiple, media_grid) {
|
||||||
itemClicked(it.path)
|
itemClicked((it as Medium).path)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(currAdapter as MediaAdapter).updateMedia(mMedia)
|
(currAdapter as MediaAdapter).updateMedia(mMedia)
|
||||||
|
@ -395,12 +397,18 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
private fun getRecyclerAdapter() = (media_grid.adapter as MediaAdapter)
|
private fun getRecyclerAdapter() = (media_grid.adapter as MediaAdapter)
|
||||||
|
|
||||||
private fun setupLayoutManager() {
|
private fun setupLayoutManager() {
|
||||||
if (config.viewTypeFiles == VIEW_TYPE_GRID)
|
if (config.viewTypeFiles == VIEW_TYPE_GRID) {
|
||||||
setupGridLayoutManager()
|
setupGridLayoutManager()
|
||||||
else
|
} else {
|
||||||
setupListLayoutManager()
|
setupListLayoutManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getMediaAdapter()?.apply {
|
||||||
|
setupZoomListener(mZoomListener)
|
||||||
|
setupDragListener(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupGridLayoutManager() {
|
private fun setupGridLayoutManager() {
|
||||||
val layoutManager = media_grid.layoutManager as GridLayoutManager
|
val layoutManager = media_grid.layoutManager as GridLayoutManager
|
||||||
if (config.scrollHorizontally) {
|
if (config.scrollHorizontally) {
|
||||||
|
@ -411,42 +419,30 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
media_refresh_layout.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
media_refresh_layout.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*media_grid.isDragSelectionEnabled = true
|
|
||||||
media_grid.isZoomingEnabled = true
|
|
||||||
layoutManager.spanCount = config.mediaColumnCnt
|
layoutManager.spanCount = config.mediaColumnCnt
|
||||||
media_grid.listener = object : MyScalableRecyclerView.MyScalableRecyclerViewListener {
|
mZoomListener = object : MyRecyclerView.MyZoomListener {
|
||||||
override fun zoomIn() {
|
override fun zoomIn() {
|
||||||
if (layoutManager.spanCount > 1) {
|
if (layoutManager.spanCount > 1) {
|
||||||
reduceColumnCount()
|
reduceColumnCount()
|
||||||
getRecyclerAdapter().actMode?.finish()
|
getRecyclerAdapter().finishActMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun zoomOut() {
|
override fun zoomOut() {
|
||||||
if (layoutManager.spanCount < MAX_COLUMN_COUNT) {
|
if (layoutManager.spanCount < MAX_COLUMN_COUNT) {
|
||||||
increaseColumnCount()
|
increaseColumnCount()
|
||||||
getRecyclerAdapter().actMode?.finish()
|
getRecyclerAdapter().finishActMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun selectItem(position: Int) {
|
|
||||||
getRecyclerAdapter().selectItem(position)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun selectRange(initialSelection: Int, lastDraggedIndex: Int, minReached: Int, maxReached: Int) {
|
|
||||||
getRecyclerAdapter().selectRange(initialSelection, lastDraggedIndex, minReached, maxReached)
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupListLayoutManager() {
|
private fun setupListLayoutManager() {
|
||||||
//media_grid.isDragSelectionEnabled = true
|
|
||||||
//media_grid.isZoomingEnabled = false
|
|
||||||
|
|
||||||
val layoutManager = media_grid.layoutManager as GridLayoutManager
|
val layoutManager = media_grid.layoutManager as GridLayoutManager
|
||||||
layoutManager.spanCount = 1
|
layoutManager.spanCount = 1
|
||||||
layoutManager.orientation = GridLayoutManager.VERTICAL
|
layoutManager.orientation = GridLayoutManager.VERTICAL
|
||||||
media_refresh_layout.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
media_refresh_layout.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||||
|
mZoomListener = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun increaseColumnCount() {
|
private fun increaseColumnCount() {
|
||||||
|
@ -572,10 +568,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun itemLongClicked(position: Int) {
|
|
||||||
media_grid.setDragSelectActive(position)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun selectedPaths(paths: ArrayList<String>) {
|
override fun selectedPaths(paths: ArrayList<String>) {
|
||||||
Intent().apply {
|
Intent().apply {
|
||||||
putExtra(PICKED_PATHS, paths)
|
putExtra(PICKED_PATHS, paths)
|
||||||
|
|
|
@ -58,7 +58,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
|
||||||
val dir = dirs[position]
|
val dir = dirs[position]
|
||||||
val view = holder.bindView(dir, isPickIntent) {
|
val view = holder.bindView(dir, !isPickIntent) {
|
||||||
setupView(it, dir)
|
setupView(it, dir)
|
||||||
}
|
}
|
||||||
itemViews.put(position, view)
|
itemViews.put(position, view)
|
||||||
|
@ -87,11 +87,13 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList<Direc
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun prepareActionMode(menu: Menu) {
|
override fun prepareActionMode(menu: Menu) {
|
||||||
menu.findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1
|
menu.apply {
|
||||||
menu.findItem(R.id.cab_change_cover_image).isVisible = selectedPositions.size == 1
|
findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1
|
||||||
|
findItem(R.id.cab_change_cover_image).isVisible = selectedPositions.size == 1
|
||||||
|
|
||||||
checkHideBtnVisibility(menu)
|
checkHideBtnVisibility(this)
|
||||||
checkPinBtnVisibility(menu)
|
checkPinBtnVisibility(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkHideBtnVisibility(menu: Menu) {
|
private fun checkHideBtnVisibility(menu: Menu) {
|
||||||
|
|
|
@ -2,22 +2,19 @@ package com.simplemobiletools.gallery.adapters
|
||||||
|
|
||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.support.v7.view.ActionMode
|
|
||||||
import android.support.v7.widget.RecyclerView
|
|
||||||
import android.util.SparseArray
|
import android.util.SparseArray
|
||||||
import android.view.*
|
import android.view.Menu
|
||||||
import com.bignerdranch.android.multiselector.ModalMultiSelectorCallback
|
import android.view.View
|
||||||
import com.bignerdranch.android.multiselector.MultiSelector
|
import android.view.ViewGroup
|
||||||
import com.bignerdranch.android.multiselector.SwappingHolder
|
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
|
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||||
import com.simplemobiletools.commons.extensions.beGone
|
|
||||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||||
import com.simplemobiletools.commons.extensions.isActivityDestroyed
|
import com.simplemobiletools.commons.extensions.isActivityDestroyed
|
||||||
import com.simplemobiletools.commons.interfaces.MyAdapterListener
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog
|
import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog
|
||||||
import com.simplemobiletools.gallery.extensions.*
|
import com.simplemobiletools.gallery.extensions.*
|
||||||
|
@ -27,63 +24,52 @@ import kotlinx.android.synthetic.main.photo_video_item_grid.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList<Medium>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean,
|
class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean,
|
||||||
val allowMultiplePicks: Boolean, val itemClick: (Medium) -> Unit) : RecyclerView.Adapter<MediaAdapter.ViewHolder>() {
|
val allowMultiplePicks: Boolean, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) {
|
||||||
|
|
||||||
private val config = activity.config
|
private val config = activity.config
|
||||||
var actMode: ActionMode? = null
|
|
||||||
var primaryColor = config.primaryColor
|
|
||||||
|
|
||||||
private val multiSelector = MultiSelector()
|
|
||||||
private val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST
|
private val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST
|
||||||
private var skipConfirmationDialog = false
|
private var skipConfirmationDialog = false
|
||||||
|
|
||||||
private var itemViews = SparseArray<View>()
|
|
||||||
private val selectedPositions = HashSet<Int>()
|
|
||||||
private var scrollHorizontally = config.scrollHorizontally
|
private var scrollHorizontally = config.scrollHorizontally
|
||||||
private var animateGifs = config.animateGifs
|
private var animateGifs = config.animateGifs
|
||||||
private var cropThumbnails = config.cropThumbnails
|
private var cropThumbnails = config.cropThumbnails
|
||||||
private var textColor = config.textColor
|
|
||||||
private var displayFilenames = config.displayFileNames
|
private var displayFilenames = config.displayFileNames
|
||||||
|
|
||||||
fun toggleItemSelection(select: Boolean, pos: Int) {
|
init {
|
||||||
if (select) {
|
selectableItemCount = media.count()
|
||||||
if (itemViews[pos] != null) {
|
|
||||||
itemViews[pos].medium_check?.background?.applyColorFilter(primaryColor)
|
|
||||||
selectedPositions.add(pos)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
selectedPositions.remove(pos)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
itemViews[pos]?.medium_check?.beVisibleIf(select)
|
override fun getActionMenuId() = R.menu.cab_media
|
||||||
|
|
||||||
if (selectedPositions.isEmpty()) {
|
override fun prepareItemSelection(view: View) {
|
||||||
actMode?.finish()
|
view.medium_check?.background?.applyColorFilter(primaryColor)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTitle(selectedPositions.size)
|
override fun markItemSelection(select: Boolean, view: View?) {
|
||||||
|
view?.medium_check?.beVisibleIf(select)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateTitle(cnt: Int) {
|
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||||
actMode?.title = "$cnt / ${media.size}"
|
val layoutType = if (isListViewType) R.layout.photo_video_item_list else R.layout.photo_video_item_grid
|
||||||
actMode?.invalidate()
|
val view = activity.layoutInflater.inflate(layoutType, parent, false)
|
||||||
|
return createViewHolder(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val adapterListener = object : MyAdapterListener {
|
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
|
||||||
override fun toggleItemSelectionAdapter(select: Boolean, position: Int) {
|
val medium = media[position]
|
||||||
toggleItemSelection(select, position)
|
val view = holder.bindView(medium, !allowMultiplePicks) {
|
||||||
|
setupView(it, medium)
|
||||||
|
}
|
||||||
|
itemViews.put(position, view)
|
||||||
|
toggleItemSelection(selectedPositions.contains(position), position)
|
||||||
|
holder.itemView.tag = holder
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSelectedPositions(): HashSet<Int> = selectedPositions
|
override fun getItemCount() = media.size
|
||||||
|
|
||||||
override fun itemLongClicked(position: Int) {}
|
override fun actionItemPressed(id: Int) {
|
||||||
}
|
when (id) {
|
||||||
|
|
||||||
private val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
|
|
||||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
|
||||||
when (item.itemId) {
|
|
||||||
R.id.cab_confirm_selection -> confirmSelection()
|
R.id.cab_confirm_selection -> confirmSelection()
|
||||||
R.id.cab_properties -> showProperties()
|
R.id.cab_properties -> showProperties()
|
||||||
R.id.cab_rename -> renameFile()
|
R.id.cab_rename -> renameFile()
|
||||||
|
@ -97,38 +83,20 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList<Medi
|
||||||
R.id.cab_open_with -> activity.openFile(Uri.fromFile(getCurrentFile()), true)
|
R.id.cab_open_with -> activity.openFile(Uri.fromFile(getCurrentFile()), true)
|
||||||
R.id.cab_set_as -> activity.setAs(Uri.fromFile(getCurrentFile()))
|
R.id.cab_set_as -> activity.setAs(Uri.fromFile(getCurrentFile()))
|
||||||
R.id.cab_delete -> checkDeleteConfirmation()
|
R.id.cab_delete -> checkDeleteConfirmation()
|
||||||
else -> return false
|
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu?): Boolean {
|
override fun prepareActionMode(menu: Menu) {
|
||||||
super.onCreateActionMode(actionMode, menu)
|
menu.apply {
|
||||||
actMode = actionMode
|
findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1
|
||||||
activity.menuInflater.inflate(R.menu.cab_media, menu)
|
findItem(R.id.cab_open_with).isVisible = selectedPositions.size == 1
|
||||||
return true
|
findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedPositions.size > 0
|
||||||
|
|
||||||
|
checkHideBtnVisibility(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean {
|
private fun checkHideBtnVisibility(menu: Menu) {
|
||||||
menu.findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1
|
|
||||||
menu.findItem(R.id.cab_open_with).isVisible = selectedPositions.size == 1
|
|
||||||
menu.findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedPositions.size > 0
|
|
||||||
|
|
||||||
checkHideBtnVisibility(menu)
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroyActionMode(actionMode: ActionMode?) {
|
|
||||||
super.onDestroyActionMode(actionMode)
|
|
||||||
selectedPositions.forEach {
|
|
||||||
itemViews[it]?.medium_check?.beGone()
|
|
||||||
}
|
|
||||||
selectedPositions.clear()
|
|
||||||
actMode = null
|
|
||||||
}
|
|
||||||
|
|
||||||
fun checkHideBtnVisibility(menu: Menu) {
|
|
||||||
var hiddenCnt = 0
|
var hiddenCnt = 0
|
||||||
var unhiddenCnt = 0
|
var unhiddenCnt = 0
|
||||||
selectedPositions.mapNotNull { media.getOrNull(it) }.forEach {
|
selectedPositions.mapNotNull { media.getOrNull(it) }.forEach {
|
||||||
|
@ -142,7 +110,6 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList<Medi
|
||||||
menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0
|
menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0
|
||||||
menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0
|
menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun confirmSelection() {
|
private fun confirmSelection() {
|
||||||
val paths = getSelectedMedia().map { it.path } as ArrayList<String>
|
val paths = getSelectedMedia().map { it.path } as ArrayList<String>
|
||||||
|
@ -163,14 +130,14 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList<Medi
|
||||||
RenameItemDialog(activity, getCurrentFile().absolutePath) {
|
RenameItemDialog(activity, getCurrentFile().absolutePath) {
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
actMode?.finish()
|
finishActMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun editFile() {
|
private fun editFile() {
|
||||||
activity.openEditor(Uri.fromFile(getCurrentFile()))
|
activity.openEditor(Uri.fromFile(getCurrentFile()))
|
||||||
actMode?.finish()
|
finishActMode()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleFileVisibility(hide: Boolean) {
|
private fun toggleFileVisibility(hide: Boolean) {
|
||||||
|
@ -181,7 +148,7 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList<Medi
|
||||||
}
|
}
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
actMode?.finish()
|
finishActMode()
|
||||||
}
|
}
|
||||||
}).start()
|
}).start()
|
||||||
}
|
}
|
||||||
|
@ -203,20 +170,10 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList<Medi
|
||||||
if (!isCopyOperation) {
|
if (!isCopyOperation) {
|
||||||
listener?.refreshItems()
|
listener?.refreshItems()
|
||||||
}
|
}
|
||||||
actMode?.finish()
|
finishActMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun selectAll() {
|
|
||||||
val cnt = media.size
|
|
||||||
for (i in 0 until cnt) {
|
|
||||||
selectedPositions.add(i)
|
|
||||||
multiSelector.setSelected(i, 0, true)
|
|
||||||
notifyItemChanged(i)
|
|
||||||
}
|
|
||||||
updateTitle(cnt)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkDeleteConfirmation() {
|
private fun checkDeleteConfirmation() {
|
||||||
if (skipConfirmationDialog) {
|
if (skipConfirmationDialog) {
|
||||||
deleteConfirmed()
|
deleteConfirmed()
|
||||||
|
@ -247,7 +204,7 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList<Medi
|
||||||
val removeMedia = ArrayList<Medium>(selectedPositions.size)
|
val removeMedia = ArrayList<Medium>(selectedPositions.size)
|
||||||
|
|
||||||
if (media.size <= selectedPositions.first()) {
|
if (media.size <= selectedPositions.first()) {
|
||||||
actMode?.finish()
|
finishActMode()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +226,8 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList<Medi
|
||||||
.forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) }
|
.forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) }
|
||||||
|
|
||||||
itemViews = newItems
|
itemViews = newItems
|
||||||
actMode?.finish()
|
selectableItemCount = media.size
|
||||||
|
finishActMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,29 +237,18 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList<Medi
|
||||||
return selectedMedia
|
return selectedMedia
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
|
||||||
val layoutType = if (isListViewType) R.layout.photo_video_item_list else R.layout.photo_video_item_grid
|
|
||||||
val view = LayoutInflater.from(parent?.context).inflate(layoutType, parent, false)
|
|
||||||
return ViewHolder(view, adapterListener, activity, multiSelectorMode, multiSelector, listener, allowMultiplePicks || !isAGetIntent, itemClick)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
|
||||||
itemViews.put(position, holder.bindView(media[position], displayFilenames, scrollHorizontally, isListViewType, textColor, animateGifs, cropThumbnails))
|
|
||||||
toggleItemSelection(selectedPositions.contains(position), position)
|
|
||||||
holder.itemView.tag = holder
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewRecycled(holder: ViewHolder?) {
|
override fun onViewRecycled(holder: ViewHolder?) {
|
||||||
super.onViewRecycled(holder)
|
super.onViewRecycled(holder)
|
||||||
holder?.stopLoad()
|
if (!activity.isActivityDestroyed()) {
|
||||||
|
Glide.with(activity).clear(holder?.itemView?.medium_thumbnail)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount() = media.size
|
|
||||||
|
|
||||||
fun updateMedia(newMedia: ArrayList<Medium>) {
|
fun updateMedia(newMedia: ArrayList<Medium>) {
|
||||||
media = newMedia
|
media = newMedia
|
||||||
|
selectableItemCount = media.size
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
actMode?.finish()
|
finishActMode()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateDisplayFilenames(displayFilenames: Boolean) {
|
fun updateDisplayFilenames(displayFilenames: Boolean) {
|
||||||
|
@ -324,57 +271,8 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList<Medi
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateTextColor(textColor: Int) {
|
private fun setupView(view: View, medium: Medium) {
|
||||||
this.textColor = textColor
|
view.apply {
|
||||||
notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun selectItem(pos: Int) {
|
|
||||||
toggleItemSelection(true, pos)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun selectRange(from: Int, to: Int, min: Int, max: Int) {
|
|
||||||
if (from == to) {
|
|
||||||
(min..max).filter { it != from }
|
|
||||||
.forEach { toggleItemSelection(false, it) }
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (to < from) {
|
|
||||||
for (i in to..from)
|
|
||||||
toggleItemSelection(true, i)
|
|
||||||
|
|
||||||
if (min > -1 && min < to) {
|
|
||||||
(min until to).filter { it != from }
|
|
||||||
.forEach { toggleItemSelection(false, it) }
|
|
||||||
}
|
|
||||||
if (max > -1) {
|
|
||||||
for (i in from + 1..max)
|
|
||||||
toggleItemSelection(false, i)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (i in from..to)
|
|
||||||
toggleItemSelection(true, i)
|
|
||||||
|
|
||||||
if (max > -1 && max > to) {
|
|
||||||
(to + 1..max).filter { it != from }
|
|
||||||
.forEach { toggleItemSelection(false, it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
if (min > -1) {
|
|
||||||
for (i in min until from)
|
|
||||||
toggleItemSelection(false, i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: BaseSimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback,
|
|
||||||
val multiSelector: MultiSelector, val listener: MediaOperationsListener?, val allowMultiplePicks: Boolean,
|
|
||||||
val itemClick: (Medium) -> (Unit)) :
|
|
||||||
SwappingHolder(view, MultiSelector()) {
|
|
||||||
fun bindView(medium: Medium, displayFilenames: Boolean, scrollHorizontally: Boolean, isListViewType: Boolean, textColor: Int,
|
|
||||||
animateGifs: Boolean, cropThumbnails: Boolean): View {
|
|
||||||
itemView.apply {
|
|
||||||
play_outline.beVisibleIf(medium.video)
|
play_outline.beVisibleIf(medium.video)
|
||||||
photo_name.beVisibleIf(displayFilenames || isListViewType)
|
photo_name.beVisibleIf(displayFilenames || isListViewType)
|
||||||
photo_name.text = medium.name
|
photo_name.text = medium.name
|
||||||
|
@ -384,36 +282,6 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList<Medi
|
||||||
photo_name.setTextColor(textColor)
|
photo_name.setTextColor(textColor)
|
||||||
play_outline.setColorFilter(textColor, PorterDuff.Mode.SRC_IN)
|
play_outline.setColorFilter(textColor, PorterDuff.Mode.SRC_IN)
|
||||||
}
|
}
|
||||||
|
|
||||||
setOnClickListener { viewClicked(medium) }
|
|
||||||
setOnLongClickListener { if (allowMultiplePicks) viewLongClicked() else viewClicked(medium); true }
|
|
||||||
}
|
|
||||||
return itemView
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun viewClicked(medium: Medium) {
|
|
||||||
if (multiSelector.isSelectable) {
|
|
||||||
val isSelected = adapterListener.getSelectedPositions().contains(adapterPosition)
|
|
||||||
adapterListener.toggleItemSelectionAdapter(!isSelected, adapterPosition)
|
|
||||||
} else {
|
|
||||||
itemClick(medium)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun viewLongClicked() {
|
|
||||||
if (listener != null) {
|
|
||||||
if (!multiSelector.isSelectable) {
|
|
||||||
activity.startSupportActionMode(multiSelectorCallback)
|
|
||||||
adapterListener.toggleItemSelectionAdapter(true, adapterPosition)
|
|
||||||
}
|
|
||||||
|
|
||||||
listener.itemLongClicked(adapterPosition)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun stopLoad() {
|
|
||||||
if (!activity.isActivityDestroyed())
|
|
||||||
Glide.with(activity).clear(view.medium_thumbnail)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,8 +290,6 @@ class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList<Medi
|
||||||
|
|
||||||
fun deleteFiles(files: ArrayList<File>)
|
fun deleteFiles(files: ArrayList<File>)
|
||||||
|
|
||||||
fun itemLongClicked(position: Int)
|
|
||||||
|
|
||||||
fun selectedPaths(paths: ArrayList<String>)
|
fun selectedPaths(paths: ArrayList<String>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,8 +58,8 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c
|
||||||
return
|
return
|
||||||
|
|
||||||
shownMedia = media
|
shownMedia = media
|
||||||
val adapter = MediaAdapter(activity, media, null, true, false) {
|
val adapter = MediaAdapter(activity, media, null, true, false, view.media_grid) {
|
||||||
callback(it.path)
|
callback((it as Medium).path)
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue