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