mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 08:18:00 +01:00
splitting photo and video thumbnails to remove redundant views
This commit is contained in:
parent
2cf4735767
commit
b0c664842f
6 changed files with 167 additions and 54 deletions
|
@ -77,7 +77,7 @@ android {
|
|||
}
|
||||
|
||||
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 'it.sephiroth.android.exif:library:1.0.1'
|
||||
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.22'
|
||||
|
|
|
@ -31,18 +31,24 @@ import com.simplemobiletools.gallery.pro.interfaces.MediaOperationsListener
|
|||
import com.simplemobiletools.gallery.pro.models.Medium
|
||||
import com.simplemobiletools.gallery.pro.models.ThumbnailItem
|
||||
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.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.*
|
||||
|
||||
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) :
|
||||
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
|
||||
private val INSTANT_LOAD_DURATION = 2000L
|
||||
private val IMAGE_LOAD_DELAY = 100L
|
||||
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 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
|
||||
} else {
|
||||
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 {
|
||||
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)
|
||||
|
@ -101,10 +115,10 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
|
|||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
val tmbItem = media[position]
|
||||
return if (tmbItem is ThumbnailSection) {
|
||||
ITEM_SECTION
|
||||
} else {
|
||||
ITEM_MEDIUM
|
||||
return when {
|
||||
tmbItem is ThumbnailSection -> ITEM_SECTION
|
||||
(tmbItem as Medium).isVideo() || tmbItem.isPortrait() -> ITEM_MEDIUM_VIDEO_PORTRAIT
|
||||
else -> ITEM_MEDIUM_PHOTO
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -507,13 +521,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
|
|||
|
||||
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()) {
|
||||
play_outline.setImageResource(R.drawable.ic_play_outline_vector)
|
||||
play_outline.beVisible()
|
||||
play_portrait_outline?.setImageResource(R.drawable.ic_play_outline_vector)
|
||||
play_portrait_outline?.beVisible()
|
||||
} else if (medium.isPortrait()) {
|
||||
play_outline.setImageResource(R.drawable.ic_portrait_photo_vector)
|
||||
play_outline.beVisibleIf(showFileTypes)
|
||||
play_portrait_outline?.setImageResource(R.drawable.ic_portrait_photo_vector)
|
||||
play_portrait_outline?.beVisibleIf(showFileTypes)
|
||||
}
|
||||
|
||||
if (showFileTypes && (medium.isGIF() || medium.isRaw() || medium.isSVG())) {
|
||||
|
@ -524,7 +538,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
|
|||
})
|
||||
file_type.beVisible()
|
||||
} else {
|
||||
file_type.beGone()
|
||||
file_type?.beGone()
|
||||
}
|
||||
|
||||
medium_name.beVisibleIf(displayFilenames || isListViewType)
|
||||
|
@ -533,9 +547,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
|
|||
|
||||
val showVideoDuration = medium.isVideo() && config.showThumbnailVideoDuration
|
||||
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)
|
||||
if (isSelected) {
|
||||
|
@ -575,7 +589,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: ArrayList<ThumbnailI
|
|||
|
||||
if (isListViewType) {
|
||||
medium_name.setTextColor(textColor)
|
||||
play_outline.applyColorFilter(textColor)
|
||||
play_portrait_outline?.applyColorFilter(textColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
64
app/src/main/res/layout/photo_item_grid.xml
Normal file
64
app/src/main/res/layout/photo_item_grid.xml
Normal 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>
|
67
app/src/main/res/layout/photo_item_list.xml
Normal file
67
app/src/main/res/layout/photo_item_list.xml
Normal 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>
|
|
@ -13,7 +13,7 @@
|
|||
android:layout_height="match_parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/play_outline"
|
||||
android:id="@+id/play_portrait_outline"
|
||||
android:layout_width="@dimen/selection_check_size"
|
||||
android:layout_height="@dimen/selection_check_size"
|
||||
android:layout_alignParentStart="true"
|
||||
|
@ -22,21 +22,6 @@
|
|||
android:src="@drawable/ic_play_outline_vector"
|
||||
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
|
||||
android:id="@+id/video_duration"
|
||||
android:layout_width="match_parent"
|
|
@ -48,7 +48,7 @@
|
|||
tools:text="My photo" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/play_outline"
|
||||
android:id="@+id/play_portrait_outline"
|
||||
android:layout_width="@dimen/play_outline_icon_size"
|
||||
android:layout_height="@dimen/play_outline_icon_size"
|
||||
android:layout_alignParentEnd="true"
|
||||
|
@ -58,30 +58,13 @@
|
|||
android:src="@drawable/ic_play_outline_vector"
|
||||
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
|
||||
android:id="@+id/video_duration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
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:paddingRight="@dimen/small_margin"
|
||||
android:paddingBottom="@dimen/small_margin"
|
Loading…
Reference in a new issue