mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 00:17:58 +01:00
replace directory baseadapter with recyclerview adapter
This commit is contained in:
parent
613ab2bb10
commit
6c4ec53cc1
8 changed files with 72 additions and 114 deletions
|
@ -17,17 +17,13 @@ import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.AdapterView
|
import android.widget.AdapterView
|
||||||
import android.widget.GridView
|
|
||||||
import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask
|
|
||||||
import com.simplemobiletools.filepicker.extensions.*
|
import com.simplemobiletools.filepicker.extensions.*
|
||||||
import com.simplemobiletools.fileproperties.dialogs.PropertiesDialog
|
|
||||||
import com.simplemobiletools.gallery.Constants
|
import com.simplemobiletools.gallery.Constants
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.Utils
|
import com.simplemobiletools.gallery.Utils
|
||||||
import com.simplemobiletools.gallery.adapters.DirectoryAdapter
|
import com.simplemobiletools.gallery.adapters.DirectoryAdapter
|
||||||
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
||||||
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
|
import com.simplemobiletools.gallery.dialogs.ChangeSortingDialog
|
||||||
import com.simplemobiletools.gallery.dialogs.CopyDialog
|
|
||||||
import com.simplemobiletools.gallery.dialogs.RenameDirectoryDialog
|
import com.simplemobiletools.gallery.dialogs.RenameDirectoryDialog
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
@ -109,14 +105,14 @@ class MainActivity : SimpleActivity(), AdapterView.OnItemClickListener, SwipeRef
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
tryloadGallery()
|
tryloadGallery()
|
||||||
if (mState != null)
|
/*if (mState != null)
|
||||||
directories_grid.onRestoreInstanceState(mState)
|
directories_grid.onRestoreInstanceState(mState)*/
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
deleteDirs()
|
deleteDirs()
|
||||||
mState = directories_grid.onSaveInstanceState()
|
//mState = directories_grid.onSaveInstanceState()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
@ -164,7 +160,7 @@ class MainActivity : SimpleActivity(), AdapterView.OnItemClickListener, SwipeRef
|
||||||
|
|
||||||
private fun prepareForDeleting() {
|
private fun prepareForDeleting() {
|
||||||
toast(R.string.deleting)
|
toast(R.string.deleting)
|
||||||
val items = directories_grid.checkedItemPositions
|
/*val items = directories_grid.checkedItemPositions
|
||||||
val cnt = items.size()
|
val cnt = items.size()
|
||||||
var deletedCnt = 0
|
var deletedCnt = 0
|
||||||
for (i in 0..cnt - 1) {
|
for (i in 0..cnt - 1) {
|
||||||
|
@ -182,7 +178,7 @@ class MainActivity : SimpleActivity(), AdapterView.OnItemClickListener, SwipeRef
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyDeletion(deletedCnt)
|
notifyDeletion(deletedCnt)*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun notifyDeletion(cnt: Int) {
|
private fun notifyDeletion(cnt: Int) {
|
||||||
|
@ -245,7 +241,7 @@ class MainActivity : SimpleActivity(), AdapterView.OnItemClickListener, SwipeRef
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showProperties() {
|
private fun showProperties() {
|
||||||
val items = directories_grid.checkedItemPositions
|
/*val items = directories_grid.checkedItemPositions
|
||||||
if (items.size() == 1) {
|
if (items.size() == 1) {
|
||||||
PropertiesDialog(this, selectedPaths.toTypedArray()[0], false)
|
PropertiesDialog(this, selectedPaths.toTypedArray()[0], false)
|
||||||
} else {
|
} else {
|
||||||
|
@ -259,11 +255,11 @@ class MainActivity : SimpleActivity(), AdapterView.OnItemClickListener, SwipeRef
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertiesDialog(this, paths, false)
|
PropertiesDialog(this, paths, false)
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun editDirectory() {
|
private fun editDirectory() {
|
||||||
val items = directories_grid.checkedItemPositions
|
/*val items = directories_grid.checkedItemPositions
|
||||||
val cnt = items.size()
|
val cnt = items.size()
|
||||||
for (i in 0..cnt - 1) {
|
for (i in 0..cnt - 1) {
|
||||||
if (items.valueAt(i)) {
|
if (items.valueAt(i)) {
|
||||||
|
@ -272,7 +268,7 @@ class MainActivity : SimpleActivity(), AdapterView.OnItemClickListener, SwipeRef
|
||||||
renameDir(path)
|
renameDir(path)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renameDir(path: String) {
|
private fun renameDir(path: String) {
|
||||||
|
@ -292,7 +288,7 @@ class MainActivity : SimpleActivity(), AdapterView.OnItemClickListener, SwipeRef
|
||||||
|
|
||||||
private fun displayCopyDialog() {
|
private fun displayCopyDialog() {
|
||||||
val files = ArrayList<File>()
|
val files = ArrayList<File>()
|
||||||
val items = directories_grid.checkedItemPositions
|
/*val items = directories_grid.checkedItemPositions
|
||||||
val cnt = items.size()
|
val cnt = items.size()
|
||||||
for (i in 0..cnt - 1) {
|
for (i in 0..cnt - 1) {
|
||||||
if (items.valueAt(i)) {
|
if (items.valueAt(i)) {
|
||||||
|
@ -315,7 +311,7 @@ class MainActivity : SimpleActivity(), AdapterView.OnItemClickListener, SwipeRef
|
||||||
override fun copyFailed() {
|
override fun copyFailed() {
|
||||||
toast(R.string.copy_move_failed)
|
toast(R.string.copy_move_failed)
|
||||||
}
|
}
|
||||||
})
|
})*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isPickImageIntent(intent: Intent) = isPickIntent(intent) && (hasImageContentData(intent) || isImageType(intent))
|
private fun isPickImageIntent(intent: Intent) = isPickIntent(intent) && (hasImageContentData(intent) || isImageType(intent))
|
||||||
|
@ -487,7 +483,8 @@ class MainActivity : SimpleActivity(), AdapterView.OnItemClickListener, SwipeRef
|
||||||
|
|
||||||
private val selectedPaths: Set<String>
|
private val selectedPaths: Set<String>
|
||||||
get() {
|
get() {
|
||||||
val items = directories_grid.checkedItemPositions
|
return HashSet<String>()
|
||||||
|
/*val items = directories_grid.checkedItemPositions
|
||||||
val selectedPaths = HashSet<String>()
|
val selectedPaths = HashSet<String>()
|
||||||
val cnt = items.size()
|
val cnt = items.size()
|
||||||
for (i in 0..cnt - 1) {
|
for (i in 0..cnt - 1) {
|
||||||
|
@ -496,7 +493,7 @@ class MainActivity : SimpleActivity(), AdapterView.OnItemClickListener, SwipeRef
|
||||||
selectedPaths.add(mDirs[id].path)
|
selectedPaths.add(mDirs[id].path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return selectedPaths
|
return selectedPaths*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun scanCompleted(path: String) {
|
private fun scanCompleted(path: String) {
|
||||||
|
@ -520,13 +517,9 @@ class MainActivity : SimpleActivity(), AdapterView.OnItemClickListener, SwipeRef
|
||||||
}
|
}
|
||||||
mDirs = dirs
|
mDirs = dirs
|
||||||
|
|
||||||
val adapter = DirectoryAdapter(this, mDirs)
|
val adapter = DirectoryAdapter(this, mDirs) {
|
||||||
directories_grid.apply {
|
|
||||||
this@apply.adapter = adapter
|
|
||||||
onItemClickListener = this@MainActivity
|
|
||||||
//setMultiChoiceModeListener(this)
|
|
||||||
//setOnTouchListener(this)
|
|
||||||
choiceMode = GridView.CHOICE_MODE_MULTIPLE_MODAL
|
|
||||||
}
|
}
|
||||||
|
directories_grid.adapter = adapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package com.simplemobiletools.gallery.adapters
|
package com.simplemobiletools.gallery.adapters
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.support.v7.widget.RecyclerView
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.BaseAdapter
|
import com.bignerdranch.android.multiselector.MultiSelector
|
||||||
import android.widget.ImageView
|
import com.bignerdranch.android.multiselector.SwappingHolder
|
||||||
import android.widget.TextView
|
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import com.bumptech.glide.signature.StringSignature
|
import com.bumptech.glide.signature.StringSignature
|
||||||
|
@ -15,59 +15,36 @@ 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.*
|
||||||
|
|
||||||
class DirectoryAdapter(private val mContext: Context, private val mDirs: MutableList<Directory>) : BaseAdapter() {
|
class DirectoryAdapter(val mContext: Context, val mDirs: MutableList<Directory>, val itemClick: (Directory) -> Unit) :
|
||||||
private val mInflater: LayoutInflater
|
RecyclerView.Adapter<DirectoryAdapter.ViewHolder>() {
|
||||||
|
|
||||||
init {
|
override fun getItemCount() = mDirs.size
|
||||||
mInflater = mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
|
||||||
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
holder.bindView(mContext, mDirs[position])
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getView(position: Int, view: View?, parent: ViewGroup): View {
|
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
|
||||||
var convertView = view
|
val view = LayoutInflater.from(parent?.context).inflate(R.layout.directory_item, parent, false)
|
||||||
val viewHolder: ViewHolder
|
return ViewHolder(view, itemClick)
|
||||||
if (convertView == null) {
|
|
||||||
convertView = mInflater.inflate(R.layout.directory_item, parent, false)
|
|
||||||
viewHolder = ViewHolder(convertView)
|
|
||||||
convertView!!.tag = viewHolder
|
|
||||||
} else {
|
|
||||||
viewHolder = convertView.tag as ViewHolder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val dir = mDirs[position]
|
class ViewHolder(view: View, val itemClick: (Directory) -> (Unit)) : SwappingHolder(view, MultiSelector()) {
|
||||||
viewHolder.dirName.text = formatDirectoryName(dir)
|
fun bindView(context: Context, directory: Directory) {
|
||||||
viewHolder.photoCnt.text = dir.mediaCnt.toString()
|
itemView.dir_name.text = directory.name
|
||||||
val tmb = dir.thumbnail
|
itemView.photo_cnt.text = directory.mediaCnt.toString()
|
||||||
val timestampSignature = StringSignature(dir.timestamp.toString())
|
|
||||||
|
val tmb = directory.thumbnail
|
||||||
|
val timestampSignature = StringSignature(directory.timestamp.toString())
|
||||||
if (tmb.endsWith(".gif")) {
|
if (tmb.endsWith(".gif")) {
|
||||||
Glide.with(mContext).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
|
Glide.with(context).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
|
||||||
.placeholder(R.color.tmb_background).centerCrop().crossFade().into(viewHolder.dirThumbnail)
|
.placeholder(R.color.tmb_background).centerCrop().crossFade().into(itemView.dir_thumbnail)
|
||||||
} else {
|
} else {
|
||||||
Glide.with(mContext).load(tmb).diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature)
|
Glide.with(context).load(tmb).diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature)
|
||||||
.placeholder(R.color.tmb_background).centerCrop().crossFade().into(viewHolder.dirThumbnail)
|
.placeholder(R.color.tmb_background).centerCrop().crossFade().into(itemView.dir_thumbnail)
|
||||||
}
|
}
|
||||||
|
|
||||||
return convertView
|
itemView.setOnClickListener { itemClick(directory) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatDirectoryName(dir: Directory): String {
|
|
||||||
return dir.name
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getCount(): Int {
|
|
||||||
return mDirs.size
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItem(position: Int): Any {
|
|
||||||
return mDirs[position]
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItemId(position: Int): Long {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class ViewHolder(view: View) {
|
|
||||||
val dirName: TextView = view.dir_name
|
|
||||||
val photoCnt: TextView = view.photo_cnt
|
|
||||||
val dirThumbnail: ImageView = view.dir_thumbnail
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,50 +3,36 @@ package com.simplemobiletools.gallery.dialogs
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.widget.AdapterView
|
|
||||||
import android.widget.GridView
|
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.adapters.DirectoryAdapter
|
import com.simplemobiletools.gallery.adapters.DirectoryAdapter
|
||||||
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
import kotlinx.android.synthetic.main.activity_main.view.*
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class PickAlbumDialog(val activity: Activity, val listener: OnPickAlbumListener) : AdapterView.OnItemClickListener, GetDirectoriesAsynctask.GetDirectoriesListener {
|
class PickAlbumDialog(val activity: Activity, val listener: OnPickAlbumListener) : GetDirectoriesAsynctask.GetDirectoriesListener {
|
||||||
val context = activity.applicationContext
|
val context = activity.applicationContext
|
||||||
var grid: GridView? = null
|
var dialog: AlertDialog
|
||||||
var dirs = ArrayList<Directory>()
|
|
||||||
var dialog: AlertDialog? = null
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val view = LayoutInflater.from(context).inflate(R.layout.dialog_album_picker, null)
|
val view = LayoutInflater.from(context).inflate(R.layout.dialog_album_picker, null)
|
||||||
grid = view.directories_grid
|
|
||||||
|
|
||||||
dialog = AlertDialog.Builder(activity)
|
dialog = AlertDialog.Builder(activity)
|
||||||
.setTitle(context.resources.getString(R.string.select_destination))
|
.setTitle(context.resources.getString(R.string.select_destination))
|
||||||
.setView(view)
|
.setView(view)
|
||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.create().apply {
|
.create()
|
||||||
show()
|
|
||||||
}
|
dialog.show()
|
||||||
|
|
||||||
GetDirectoriesAsynctask(context, false, false, ArrayList<String>(), this).execute()
|
GetDirectoriesAsynctask(context, false, false, ArrayList<String>(), this).execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
|
||||||
listener.onSuccess(dirs[position].path)
|
|
||||||
dialog?.dismiss()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun gotDirectories(dirs: ArrayList<Directory>) {
|
override fun gotDirectories(dirs: ArrayList<Directory>) {
|
||||||
this.dirs = dirs
|
DirectoryAdapter(context, dirs) {
|
||||||
|
listener.onSuccess(it.path)
|
||||||
val adapter = DirectoryAdapter(context, dirs)
|
dialog.dismiss()
|
||||||
|
}
|
||||||
grid?.adapter = adapter
|
|
||||||
grid?.onItemClickListener = this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OnPickAlbumListener {
|
interface OnPickAlbumListener {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<android.support.design.widget.CoordinatorLayout
|
<android.support.design.widget.CoordinatorLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/coordinator_layout"
|
android:id="@+id/coordinator_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
@ -10,15 +11,12 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<GridView
|
<android.support.v7.widget.RecyclerView
|
||||||
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:columnWidth="@dimen/dir_tmb_size"
|
app:layoutManager="android.support.v7.widget.GridLayoutManager"
|
||||||
android:horizontalSpacing="1dp"
|
app:spanCount="@integer/columns"/>
|
||||||
android:numColumns="auto_fit"
|
|
||||||
android:stretchMode="columnWidth"
|
|
||||||
android:verticalSpacing="1dp"/>
|
|
||||||
|
|
||||||
</android.support.v4.widget.SwipeRefreshLayout>
|
</android.support.v4.widget.SwipeRefreshLayout>
|
||||||
</android.support.design.widget.CoordinatorLayout>
|
</android.support.design.widget.CoordinatorLayout>
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<GridView
|
<android.support.v7.widget.RecyclerView
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
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:columnWidth="@dimen/dir_tmb_size"
|
app:layoutManager="android.support.v7.widget.GridLayoutManager"
|
||||||
android:horizontalSpacing="1dp"
|
app:spanCount="@integer/columns"/>
|
||||||
android:numColumns="auto_fit"
|
|
||||||
android:paddingTop="@dimen/activity_margin"
|
|
||||||
android:stretchMode="columnWidth"
|
|
||||||
android:verticalSpacing="1dp"/>
|
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/dir_holder"
|
android:id="@+id/dir_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="1px">
|
||||||
|
|
||||||
<include layout="@layout/directory_tmb"/>
|
<include layout="@layout/directory_tmb"/>
|
||||||
|
|
||||||
|
|
3
app/src/main/res/values-land/integers.xml
Normal file
3
app/src/main/res/values-land/integers.xml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<resources>
|
||||||
|
<integer name="columns">4</integer>
|
||||||
|
</resources>
|
3
app/src/main/res/values/integers.xml
Normal file
3
app/src/main/res/values/integers.xml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<resources>
|
||||||
|
<integer name="columns">2</integer>
|
||||||
|
</resources>
|
Loading…
Reference in a new issue