diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index d94c863d..bc7d0c10 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -1,23 +1,59 @@ package com.simplemobiletools.filemanager.adapters import android.content.Context -import android.content.res.Resources +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.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import com.simplemobiletools.filemanager.R -import com.simplemobiletools.filemanager.extensions.formatSize +import com.simplemobiletools.filepicker.extensions.formatSize import com.simplemobiletools.filepicker.extensions.isGif import com.simplemobiletools.filepicker.models.FileDirItem import kotlinx.android.synthetic.main.list_item.view.* import java.io.File -class ItemsAdapter(context: Context, private val mItems: List) : BaseAdapter() { +class ItemsAdapter(val context: Context, private val mItems: List, val itemClick: (FileDirItem) -> Unit) : + RecyclerView.Adapter() { + + override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { + val view = LayoutInflater.from(parent?.context).inflate(R.layout.list_item, parent, false) + return ViewHolder(context, view, itemClick) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + holder.bindView(mItems[position]) + } + + override fun getItemCount() = mItems.size + + class ViewHolder(val context: Context, view: View, val itemClick: (FileDirItem) -> (Unit)) : RecyclerView.ViewHolder(view) { + fun bindView(fileDirItem: FileDirItem) { + itemView.item_name.text = fileDirItem.name + + if (fileDirItem.isDirectory) { + Glide.with(context).load(R.mipmap.directory).diskCacheStrategy(getCacheStrategy(fileDirItem)).centerCrop().crossFade().into(itemView.item_icon) + itemView.item_details.text = getChildrenCnt(fileDirItem) + } else { + Glide.with(context).load(fileDirItem.path).diskCacheStrategy(getCacheStrategy(fileDirItem)).error(R.mipmap.file).centerCrop().crossFade().into(itemView.item_icon) + itemView.item_details.text = fileDirItem.size.formatSize() + } + + itemView.setOnClickListener { itemClick(fileDirItem) } + } + + private fun getCacheStrategy(item: FileDirItem) = if (File(item.path).isGif()) DiskCacheStrategy.NONE else DiskCacheStrategy.RESULT + + private fun getChildrenCnt(item: FileDirItem): String { + val children = item.children + return context.resources.getQuantityString(R.plurals.items, children, children) + } + } +} + + +/*class ItemsAdapter(context: Context, private val mItems: List) : BaseAdapter() { private val mInflater: LayoutInflater private val mRes: Resources private val mContext: Context @@ -78,3 +114,4 @@ class ItemsAdapter(context: Context, private val mItems: List) : Ba val details: TextView = view.item_details } } +*/ \ No newline at end of file diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt index 221a41e9..15b771c4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt @@ -23,6 +23,7 @@ import com.simplemobiletools.filemanager.dialogs.RenameItemDialog import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask import com.simplemobiletools.filepicker.extensions.* import com.simplemobiletools.filepicker.models.FileDirItem +import com.simplemobiletools.filepicker.views.RecyclerViewDivider import com.simplemobiletools.fileproperties.dialogs.PropertiesDialog import kotlinx.android.synthetic.main.items_fragment.* import java.io.File @@ -78,9 +79,11 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick mItems = newItems - val adapter = ItemsAdapter(context, mItems) + val adapter = ItemsAdapter(context, mItems) { + + } items_list.adapter = adapter - items_list.onItemClickListener = this + items_list.addItemDecoration(RecyclerViewDivider(context)) items_list.setOnTouchListener(this) } @@ -315,17 +318,18 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick } private fun getSelectedItemIndexes(): List { - val items = items_list.checkedItemPositions + /*val items = items_list.checkedItemPositions val cnt = items.size() val selectedItems = (0..cnt - 1) .filter { items.valueAt(it) } .map { items.keyAt(it) } - return selectedItems + return selectedItems*/ + return ArrayList() } private fun prepareForDeleting() { mToBeDeleted.clear() - val items = items_list.checkedItemPositions + /*val items = items_list.checkedItemPositions val cnt = items.size() var deletedCnt = 0 for (i in 0..cnt - 1) { @@ -337,7 +341,7 @@ class ItemsFragment : android.support.v4.app.Fragment(), AdapterView.OnItemClick } } - notifyDeletion(deletedCnt) + notifyDeletion(deletedCnt)*/ } private fun notifyDeletion(cnt: Int) { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/views/RecyclerViewDivider.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/views/RecyclerViewDivider.kt new file mode 100644 index 00000000..dc58ce26 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/views/RecyclerViewDivider.kt @@ -0,0 +1,33 @@ +package com.simplemobiletools.filemanager.views + +import android.content.Context +import android.graphics.Canvas +import android.graphics.drawable.Drawable +import android.support.v7.widget.RecyclerView +import com.simplemobiletools.filemanager.R + +class RecyclerViewDivider(context: Context) : RecyclerView.ItemDecoration() { + private val mDivider: Drawable + + init { + mDivider = context.resources.getDrawable(R.drawable.divider) + } + + override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) { + val left = parent.paddingLeft + val right = parent.width - parent.paddingRight + + val childCount = parent.childCount + for (i in 0..childCount - 1) { + val child = parent.getChildAt(i) + + val params = child.layoutParams as RecyclerView.LayoutParams + + val top = child.bottom + params.bottomMargin + val bottom = top + mDivider.intrinsicHeight + + mDivider.setBounds(left, top, right, bottom) + mDivider.draw(c) + } + } +} diff --git a/app/src/main/res/drawable/divider.xml b/app/src/main/res/drawable/divider.xml new file mode 100644 index 00000000..50b3dc49 --- /dev/null +++ b/app/src/main/res/drawable/divider.xml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/app/src/main/res/layout/items_fragment.xml b/app/src/main/res/layout/items_fragment.xml index dce29add..6639baa6 100644 --- a/app/src/main/res/layout/items_fragment.xml +++ b/app/src/main/res/layout/items_fragment.xml @@ -1,7 +1,8 @@ @@ -10,13 +11,13 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + android:paddingLeft="@dimen/activity_margin" + app:layoutManager="android.support.v7.widget.LinearLayoutManager"/> diff --git a/app/src/main/res/layout/list_item.xml b/app/src/main/res/layout/list_item.xml index b668a57a..4aee3a47 100644 --- a/app/src/main/res/layout/list_item.xml +++ b/app/src/main/res/layout/list_item.xml @@ -2,7 +2,8 @@ #33000000 #08000000 #44888888 + #44cccccc