From d4c75c2107f93d93cab1a7cb5927cac9e38f7ee5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 10 Nov 2016 22:57:17 +0100 Subject: [PATCH] add the actual filename visibility toggle functionality --- .../gallery/activities/MediaActivity.java | 3 +- .../gallery/adapters/MediaAdapter.kt | 31 +++++++++++++------ .../gallery/extensions/view.kt | 5 +++ 3 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/extensions/view.kt diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java index ef559c90f..c43616a99 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MediaActivity.java @@ -165,7 +165,8 @@ public class MediaActivity extends SimpleActivity } private void toggleFilenameVisibility() { - + mConfig.setDisplayFileNames(!mConfig.getDisplayFileNames()); + ((MediaAdapter)mGridView.getAdapter()).updateDisplayFilenames(mConfig.getDisplayFileNames()); } private void rescanDirectory(File dir) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index 19acb1d5e..ecca9242c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -10,21 +10,25 @@ import android.widget.TextView import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.signature.StringSignature +import com.simplemobiletools.gallery.Config import com.simplemobiletools.gallery.R +import com.simplemobiletools.gallery.extensions.beVisibleIf import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.photo_video_item.view.* import kotlinx.android.synthetic.main.photo_video_tmb.view.* -class MediaAdapter(private val mContext: Context, private val mMedia: MutableList) : BaseAdapter() { +class MediaAdapter(private val context: Context, private val media: MutableList) : BaseAdapter() { private val mInflater: LayoutInflater + var displayFilenames = false init { - mInflater = mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + mInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + displayFilenames = Config.newInstance(context).displayFileNames } override fun getView(position: Int, view: View?, parent: ViewGroup): View { var convertView = view - val medium = mMedia[position] + val medium = media[position] val viewHolder: ViewHolder if (convertView == null) { convertView = mInflater.inflate(R.layout.photo_video_item, parent, false) @@ -36,25 +40,32 @@ class MediaAdapter(private val mContext: Context, private val mMedia: MutableLis viewHolder.playOutline.visibility = if (medium.isVideo) View.VISIBLE else View.GONE - viewHolder.fileName.text = medium.name + viewHolder.fileName.beVisibleIf(displayFilenames) + if (displayFilenames) + viewHolder.fileName.text = medium.name val path = medium.path val timestampSignature = StringSignature(medium.timestamp.toString()) if (medium.isGif) { - Glide.with(mContext).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature).into(viewHolder.photoThumbnail) + Glide.with(context).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature).into(viewHolder.photoThumbnail) } else { - Glide.with(mContext).load(path).diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature) + Glide.with(context).load(path).diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature) .placeholder(R.color.tmb_background).centerCrop().crossFade().into(viewHolder.photoThumbnail) } return convertView } + fun updateDisplayFilenames(display: Boolean) { + displayFilenames = display + notifyDataSetChanged() + } + override fun getCount(): Int { - return mMedia.size + return media.size } override fun getItem(position: Int): Any { - return mMedia[position] + return media[position] } override fun getItemId(position: Int): Long { @@ -62,8 +73,8 @@ class MediaAdapter(private val mContext: Context, private val mMedia: MutableLis } fun updateItems(newPhotos: List) { - mMedia.clear() - mMedia.addAll(newPhotos) + media.clear() + media.addAll(newPhotos) notifyDataSetChanged() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/view.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/view.kt new file mode 100644 index 000000000..af208183b --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/view.kt @@ -0,0 +1,5 @@ +package com.simplemobiletools.gallery.extensions + +import android.view.View + +fun View.beVisibleIf(beVisible: Boolean) = if (beVisible) visibility = View.VISIBLE else visibility = View.GONE