splitting photo and video thumbnails to remove redundant views

This commit is contained in:
tibbi 2021-02-19 18:51:43 +01:00
parent 2cf4735767
commit b0c664842f
6 changed files with 167 additions and 54 deletions

View file

@ -77,7 +77,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:5.33.33' implementation 'com.simplemobiletools:commons:5.33.34'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.22' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.22'

View file

@ -31,18 +31,24 @@ import com.simplemobiletools.gallery.pro.interfaces.MediaOperationsListener
import com.simplemobiletools.gallery.pro.models.Medium import com.simplemobiletools.gallery.pro.models.Medium
import com.simplemobiletools.gallery.pro.models.ThumbnailItem import com.simplemobiletools.gallery.pro.models.ThumbnailItem
import com.simplemobiletools.gallery.pro.models.ThumbnailSection import com.simplemobiletools.gallery.pro.models.ThumbnailSection
import kotlinx.android.synthetic.main.photo_video_item_grid.view.* import kotlinx.android.synthetic.main.photo_item_grid.view.*
import kotlinx.android.synthetic.main.thumbnail_section.view.* import kotlinx.android.synthetic.main.thumbnail_section.view.*
import kotlinx.android.synthetic.main.video_item_grid.view.*
import kotlinx.android.synthetic.main.video_item_grid.view.media_item_holder
import kotlinx.android.synthetic.main.video_item_grid.view.medium_check
import kotlinx.android.synthetic.main.video_item_grid.view.medium_name
import kotlinx.android.synthetic.main.video_item_grid.view.medium_thumbnail
import java.util.* import java.util.*
class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailItem>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailItem>, val listener: MediaOperationsListener?, val isAGetIntent: Boolean,
val allowMultiplePicks: Boolean, val path: String, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) : val allowMultiplePicks: Boolean, val path: String, recyclerView: MyRecyclerView, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) :
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
private val INSTANT_LOAD_DURATION = 2000L private val INSTANT_LOAD_DURATION = 2000L
private val IMAGE_LOAD_DELAY = 100L private val IMAGE_LOAD_DELAY = 100L
private val ITEM_SECTION = 0 private val ITEM_SECTION = 0
private val ITEM_MEDIUM = 1 private val ITEM_MEDIUM_VIDEO_PORTRAIT = 1
private val ITEM_MEDIUM_PHOTO = 2
private val config = activity.config private val config = activity.config
private val viewType = config.getFolderViewType(if (config.showAll) SHOW_ALL else path) private val viewType = config.getFolderViewType(if (config.showAll) SHOW_ALL else path)
@ -72,9 +78,17 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
R.layout.thumbnail_section R.layout.thumbnail_section
} else { } else {
if (isListViewType) { if (isListViewType) {
R.layout.photo_video_item_list if (viewType == ITEM_MEDIUM_PHOTO) {
R.layout.photo_item_list
} else {
R.layout.video_item_list
}
} else { } else {
R.layout.photo_video_item_grid if (viewType == ITEM_MEDIUM_PHOTO) {
R.layout.photo_item_grid
} else {
R.layout.video_item_grid
}
} }
} }
return createViewHolder(layoutType, parent) return createViewHolder(layoutType, parent)
@ -101,10 +115,10 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
override fun getItemViewType(position: Int): Int { override fun getItemViewType(position: Int): Int {
val tmbItem = media[position] val tmbItem = media[position]
return if (tmbItem is ThumbnailSection) { return when {
ITEM_SECTION tmbItem is ThumbnailSection -> ITEM_SECTION
} else { (tmbItem as Medium).isVideo() || tmbItem.isPortrait() -> ITEM_MEDIUM_VIDEO_PORTRAIT
ITEM_MEDIUM else -> ITEM_MEDIUM_PHOTO
} }
} }
@ -507,13 +521,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
media_item_holder.setPadding(padding, padding, padding, padding) media_item_holder.setPadding(padding, padding, padding, padding)
play_outline.beVisibleIf(medium.isVideo() || medium.isPortrait()) play_portrait_outline?.beVisibleIf(medium.isVideo() || medium.isPortrait())
if (medium.isVideo()) { if (medium.isVideo()) {
play_outline.setImageResource(R.drawable.ic_play_outline_vector) play_portrait_outline?.setImageResource(R.drawable.ic_play_outline_vector)
play_outline.beVisible() play_portrait_outline?.beVisible()
} else if (medium.isPortrait()) { } else if (medium.isPortrait()) {
play_outline.setImageResource(R.drawable.ic_portrait_photo_vector) play_portrait_outline?.setImageResource(R.drawable.ic_portrait_photo_vector)
play_outline.beVisibleIf(showFileTypes) play_portrait_outline?.beVisibleIf(showFileTypes)
} }
if (showFileTypes && (medium.isGIF() || medium.isRaw() || medium.isSVG())) { if (showFileTypes && (medium.isGIF() || medium.isRaw() || medium.isSVG())) {
@ -524,7 +538,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
}) })
file_type.beVisible() file_type.beVisible()
} else { } else {
file_type.beGone() file_type?.beGone()
} }
medium_name.beVisibleIf(displayFilenames || isListViewType) medium_name.beVisibleIf(displayFilenames || isListViewType)
@ -533,9 +547,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
val showVideoDuration = medium.isVideo() && config.showThumbnailVideoDuration val showVideoDuration = medium.isVideo() && config.showThumbnailVideoDuration
if (showVideoDuration) { if (showVideoDuration) {
video_duration.text = medium.videoDuration.getFormattedDuration() video_duration?.text = medium.videoDuration.getFormattedDuration()
} }
video_duration.beVisibleIf(showVideoDuration) video_duration?.beVisibleIf(showVideoDuration)
medium_check?.beVisibleIf(isSelected) medium_check?.beVisibleIf(isSelected)
if (isSelected) { if (isSelected) {
@ -575,7 +589,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
if (isListViewType) { if (isListViewType) {
medium_name.setTextColor(textColor) medium_name.setTextColor(textColor)
play_outline.applyColorFilter(textColor) play_portrait_outline?.applyColorFilter(textColor)
} }
} }
} }

View file

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/media_item_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true">
<com.simplemobiletools.gallery.pro.views.MySquareImageView
android:id="@+id/medium_thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/file_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="@dimen/small_margin"
android:fontFamily="sans-serif-medium"
android:shadowColor="@color/default_background_color"
android:shadowRadius="4"
android:text="@string/gif"
android:textColor="@android:color/white"
android:textSize="@dimen/bigger_text_size"
android:visibility="gone" />
<ImageView
android:id="@+id/medium_check"
android:layout_width="@dimen/selection_check_size"
android:layout_height="@dimen/selection_check_size"
android:layout_alignEnd="@+id/medium_name"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_margin="@dimen/medium_margin"
android:background="@drawable/circle_background"
android:contentDescription="@null"
android:padding="@dimen/tiny_margin"
android:src="@drawable/ic_check_vector"
android:visibility="gone" />
<TextView
android:id="@+id/medium_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/medium_thumbnail"
android:layout_alignEnd="@+id/medium_thumbnail"
android:layout_alignParentBottom="true"
android:background="@drawable/gradient_background"
android:ellipsize="end"
android:gravity="bottom"
android:maxLines="3"
android:paddingLeft="@dimen/small_margin"
android:paddingRight="@dimen/small_margin"
android:paddingBottom="@dimen/small_margin"
android:shadowColor="@color/default_background_color"
android:shadowRadius="4"
android:textColor="@android:color/white"
android:textSize="@dimen/smaller_text_size"
tools:text="My photo" />
</RelativeLayout>

View file

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/media_item_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:foreground="@drawable/selector"
android:paddingStart="@dimen/medium_margin"
android:paddingTop="@dimen/small_margin"
android:paddingBottom="@dimen/small_margin">
<com.simplemobiletools.gallery.pro.views.MySquareImageView
android:id="@+id/medium_thumbnail"
android:layout_width="@dimen/list_view_folder_thumbnail_size"
android:layout_height="@dimen/list_view_folder_thumbnail_size" />
<ImageView
android:id="@+id/medium_check"
android:layout_width="@dimen/selection_check_size"
android:layout_height="@dimen/selection_check_size"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="@dimen/small_margin"
android:layout_marginEnd="@dimen/medium_margin"
android:background="@drawable/circle_background"
android:contentDescription="@null"
android:padding="@dimen/tiny_margin"
android:src="@drawable/ic_check_vector"
android:visibility="gone" />
<TextView
android:id="@+id/medium_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="@+id/medium_thumbnail"
android:layout_alignBottom="@+id/medium_thumbnail"
android:layout_toEndOf="@+id/medium_thumbnail"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="3"
android:paddingStart="@dimen/medium_margin"
android:paddingEnd="@dimen/normal_margin"
android:textColor="@android:color/white"
android:textSize="@dimen/bigger_text_size"
tools:text="My photo" />
<TextView
android:id="@+id/file_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="@dimen/small_margin"
android:fontFamily="sans-serif-medium"
android:paddingEnd="@dimen/small_margin"
android:paddingBottom="@dimen/medium_margin"
android:shadowColor="@color/default_background_color"
android:shadowRadius="4"
android:text="@string/gif"
android:textColor="@android:color/white"
android:textSize="@dimen/normal_text_size"
android:visibility="gone" />
</RelativeLayout>

View file

@ -13,7 +13,7 @@
android:layout_height="match_parent" /> android:layout_height="match_parent" />
<ImageView <ImageView
android:id="@+id/play_outline" android:id="@+id/play_portrait_outline"
android:layout_width="@dimen/selection_check_size" android:layout_width="@dimen/selection_check_size"
android:layout_height="@dimen/selection_check_size" android:layout_height="@dimen/selection_check_size"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
@ -22,21 +22,6 @@
android:src="@drawable/ic_play_outline_vector" android:src="@drawable/ic_play_outline_vector"
android:visibility="gone" /> android:visibility="gone" />
<TextView
android:id="@+id/file_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="@dimen/small_margin"
android:fontFamily="sans-serif-medium"
android:shadowColor="@color/default_background_color"
android:shadowRadius="4"
android:text="@string/gif"
android:textColor="@android:color/white"
android:textSize="@dimen/bigger_text_size"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/video_duration" android:id="@+id/video_duration"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -48,7 +48,7 @@
tools:text="My photo" /> tools:text="My photo" />
<ImageView <ImageView
android:id="@+id/play_outline" android:id="@+id/play_portrait_outline"
android:layout_width="@dimen/play_outline_icon_size" android:layout_width="@dimen/play_outline_icon_size"
android:layout_height="@dimen/play_outline_icon_size" android:layout_height="@dimen/play_outline_icon_size"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
@ -58,30 +58,13 @@
android:src="@drawable/ic_play_outline_vector" android:src="@drawable/ic_play_outline_vector"
android:visibility="gone" /> android:visibility="gone" />
<TextView
android:id="@+id/file_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="@dimen/small_margin"
android:fontFamily="sans-serif-medium"
android:paddingEnd="@dimen/small_margin"
android:paddingBottom="@dimen/medium_margin"
android:shadowColor="@color/default_background_color"
android:shadowRadius="4"
android:text="@string/gif"
android:textColor="@android:color/white"
android:textSize="@dimen/normal_text_size"
android:visibility="gone" />
<TextView <TextView
android:id="@+id/video_duration" android:id="@+id/video_duration"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/medium_margin" android:layout_marginBottom="@dimen/medium_margin"
android:layout_toStartOf="@+id/play_outline" android:layout_toStartOf="@+id/play_portrait_outline"
android:paddingLeft="@dimen/small_margin" android:paddingLeft="@dimen/small_margin"
android:paddingRight="@dimen/small_margin" android:paddingRight="@dimen/small_margin"
android:paddingBottom="@dimen/small_margin" android:paddingBottom="@dimen/small_margin"