updating the main screens UI, use rounded corners at thumbnails

This commit is contained in:
tibbi 2020-11-01 21:58:18 +01:00
parent 48235c629a
commit a7c1789a55
8 changed files with 99 additions and 108 deletions

View File

@ -77,7 +77,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.31.17'
implementation 'com.simplemobiletools:commons:5.31.18'
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.19'

View File

@ -166,7 +166,7 @@ class WidgetConfigureActivity : SimpleActivity() {
val path = directoryDao.getDirectoryThumbnail(folderPath)
if (path != null) {
runOnUiThread {
loadJpg(path, config_image, config.cropThumbnails)
loadJpg(path, config_image, config.cropThumbnails, true)
}
}
}

View File

@ -35,7 +35,6 @@ import kotlinx.android.synthetic.main.directory_item_grid.view.dir_lock
import kotlinx.android.synthetic.main.directory_item_grid.view.dir_name
import kotlinx.android.synthetic.main.directory_item_grid.view.dir_pin
import kotlinx.android.synthetic.main.directory_item_grid.view.dir_thumbnail
import kotlinx.android.synthetic.main.directory_item_grid.view.photo_cnt
import kotlinx.android.synthetic.main.directory_item_list.view.*
import java.io.File
@ -662,9 +661,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
private fun setupView(view: View, directory: Directory) {
val isSelected = selectedKeys.contains(directory.path.hashCode())
view.apply {
dir_name.text = if (groupDirectSubfolders && directory.subfoldersCount > 1) "${directory.name} (${directory.subfoldersCount})" else directory.name
dir_path?.text = "${directory.path.substringBeforeLast("/")}/"
photo_cnt.text = directory.subfoldersMediaCount.toString()
val thumbnailType = when {
directory.tmb.isVideoFast() -> TYPE_VIDEOS
directory.tmb.isGif() -> TYPE_GIFS
@ -684,7 +680,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
dir_lock.applyColorFilter(config.backgroundColor.getContrastColor())
} else {
dir_lock.beGone()
activity.loadImage(thumbnailType, directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
activity.loadImage(thumbnailType, directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, true)
}
dir_pin.beVisibleIf(pinnedFolders.contains(directory.path))
@ -693,14 +689,18 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
dir_location.setImageResource(if (directory.location == LOCATION_SD) R.drawable.ic_sd_card_vector else R.drawable.ic_usb_vector)
}
photo_cnt.beVisibleIf(showMediaCount)
if (isListViewType) {
dir_name.setTextColor(textColor)
dir_path.setTextColor(textColor)
if (isListViewType) {
dir_name.text = if (groupDirectSubfolders && directory.subfoldersCount > 1) "${directory.name} [${directory.subfoldersCount}]" else directory.name
dir_path.text = "${directory.path.substringBeforeLast("/")}/"
photo_cnt.setTextColor(textColor)
photo_cnt.text = directory.subfoldersMediaCount.toString()
photo_cnt.beVisibleIf(showMediaCount)
dir_path.setTextColor(textColor)
dir_pin.applyColorFilter(textColor)
dir_location.applyColorFilter(textColor)
} else {
dir_name.text = if (groupDirectSubfolders && directory.subfoldersCount > 1) "${directory.name} [${directory.subfoldersCount}]" else "${directory.name} (${directory.subfoldersMediaCount})"
}
}
}

View File

@ -543,14 +543,14 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
}
if (loadImageInstantly) {
activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, rotatedImagePaths)
activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, false, rotatedImagePaths)
} else {
medium_thumbnail.setImageDrawable(null)
medium_thumbnail.isHorizontalScrolling = scrollHorizontally
delayHandler.postDelayed({
val isVisible = visibleItemPaths.contains(medium.path)
if (isVisible) {
activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, rotatedImagePaths)
activity.loadImage(medium.type, path, medium_thumbnail, scrollHorizontally, animateGifs, cropThumbnails, false, rotatedImagePaths)
}
}, IMAGE_LOAD_DELAY)
}

View File

@ -14,6 +14,8 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.Priority
import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions
import com.simplemobiletools.commons.extensions.*
@ -396,17 +398,17 @@ fun Context.getFolderNameFromPath(path: String): String {
}
fun Context.loadImage(type: Int, path: String, target: MySquareImageView, horizontalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean,
skipMemoryCacheAtPaths: ArrayList<String>? = null) {
roundCorners: Boolean, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
target.isHorizontalScrolling = horizontalScroll
if (type == TYPE_IMAGES || type == TYPE_VIDEOS || type == TYPE_RAWS || type == TYPE_PORTRAITS) {
if (type == TYPE_IMAGES && path.isPng()) {
loadPng(path, target, cropThumbnails, skipMemoryCacheAtPaths)
loadPng(path, target, cropThumbnails, roundCorners, skipMemoryCacheAtPaths)
} else {
loadJpg(path, target, cropThumbnails, skipMemoryCacheAtPaths)
loadJpg(path, target, cropThumbnails, roundCorners, skipMemoryCacheAtPaths)
}
} else if (type == TYPE_GIFS) {
if (!animateGifs) {
loadStaticGIF(path, target, cropThumbnails, skipMemoryCacheAtPaths)
loadStaticGIF(path, target, cropThumbnails, roundCorners, skipMemoryCacheAtPaths)
return
}
@ -417,12 +419,12 @@ fun Context.loadImage(type: Int, path: String, target: MySquareImageView, horizo
target.scaleType = if (cropThumbnails) ImageView.ScaleType.CENTER_CROP else ImageView.ScaleType.FIT_CENTER
} catch (e: Exception) {
loadStaticGIF(path, target, cropThumbnails, skipMemoryCacheAtPaths)
loadStaticGIF(path, target, cropThumbnails, roundCorners, skipMemoryCacheAtPaths)
} catch (e: OutOfMemoryError) {
loadStaticGIF(path, target, cropThumbnails, skipMemoryCacheAtPaths)
loadStaticGIF(path, target, cropThumbnails, roundCorners, skipMemoryCacheAtPaths)
}
} else if (type == TYPE_SVGS) {
loadSVG(path, target, cropThumbnails)
loadSVG(path, target, cropThumbnails, roundCorners)
}
}
@ -447,7 +449,7 @@ fun Context.getPathLocation(path: String): Int {
}
}
fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boolean, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boolean, roundCorners: Boolean, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
val options = RequestOptions()
.signature(path.getFileSignature())
.skipMemoryCache(skipMemoryCacheAtPaths?.contains(path) == true)
@ -455,57 +457,79 @@ fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boo
.priority(Priority.LOW)
.format(DecodeFormat.PREFER_ARGB_8888)
val builder = Glide.with(applicationContext)
if (cropThumbnails) options.centerCrop() else options.fitCenter()
var builder = Glide.with(applicationContext)
.asBitmap()
.load(path)
.apply(options)
if (cropThumbnails) options.centerCrop() else options.fitCenter()
builder.apply(options).into(target)
if (roundCorners) {
val cornerRadius = resources.getDimension(R.dimen.rounded_corner_radius).toInt()
builder = builder.transform(CenterCrop(), RoundedCorners(cornerRadius))
}
builder.into(target)
}
fun Context.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boolean, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
fun Context.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boolean, roundCorners: Boolean, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
val options = RequestOptions()
.signature(path.getFileSignature())
.skipMemoryCache(skipMemoryCacheAtPaths?.contains(path) == true)
.priority(Priority.LOW)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
val builder = Glide.with(applicationContext)
if (cropThumbnails) options.centerCrop() else options.fitCenter()
var builder = Glide.with(applicationContext)
.load(path)
if (cropThumbnails) options.centerCrop() else options.fitCenter()
builder.apply(options)
.apply(options)
.transition(DrawableTransitionOptions.withCrossFade())
.into(target)
if (roundCorners) {
val cornerRadius = resources.getDimension(R.dimen.rounded_corner_radius).toInt()
builder = builder.transform(CenterCrop(), RoundedCorners(cornerRadius))
}
builder.into(target)
}
fun Context.loadStaticGIF(path: String, target: MySquareImageView, cropThumbnails: Boolean, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
fun Context.loadStaticGIF(path: String, target: MySquareImageView, cropThumbnails: Boolean, roundCorners: Boolean, skipMemoryCacheAtPaths: ArrayList<String>? = null) {
val options = RequestOptions()
.signature(path.getFileSignature())
.skipMemoryCache(skipMemoryCacheAtPaths?.contains(path) == true)
.priority(Priority.LOW)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
val builder = Glide.with(applicationContext)
if (cropThumbnails) options.centerCrop() else options.fitCenter()
var builder = Glide.with(applicationContext)
.asBitmap() // make sure the GIF wont animate
.load(path)
.apply(options)
if (cropThumbnails) options.centerCrop() else options.fitCenter()
builder.apply(options)
.into(target)
if (roundCorners) {
val cornerRadius = resources.getDimension(R.dimen.rounded_corner_radius).toInt()
builder = builder.transform(CenterCrop(), RoundedCorners(cornerRadius))
}
builder.into(target)
}
fun Context.loadSVG(path: String, target: MySquareImageView, cropThumbnails: Boolean) {
fun Context.loadSVG(path: String, target: MySquareImageView, cropThumbnails: Boolean, roundCorners: Boolean) {
target.scaleType = if (cropThumbnails) ImageView.ScaleType.CENTER_CROP else ImageView.ScaleType.FIT_CENTER
val options = RequestOptions().signature(path.getFileSignature())
Glide.with(applicationContext)
var builder = Glide.with(applicationContext)
.`as`(PictureDrawable::class.java)
.listener(SvgSoftwareLayerSetter())
.load(path)
.apply(options)
.transition(DrawableTransitionOptions.withCrossFade())
.into(target)
if (roundCorners) {
val cornerRadius = resources.getDimension(R.dimen.rounded_corner_radius).toInt()
builder = builder.transform(CenterCrop(), RoundedCorners(cornerRadius))
}
builder.into(target)
}
fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, forceShowHidden: Boolean = false, callback: (ArrayList<Directory>) -> Unit) {

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/directories_refresh_layout"
android:layout_width="match_parent"
@ -19,22 +18,22 @@
android:gravity="center"
android:padding="@dimen/activity_margin"
android:text="@string/switch_to_file_search"
android:visibility="gone"/>
android:visibility="gone" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/directories_empty_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/directories_switch_searching"
android:gravity="center_horizontal"
android:alpha="0.8"
android:textStyle="italic"
android:gravity="center_horizontal"
android:paddingStart="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin"
android:text="@string/no_media_with_filters"
android:textSize="@dimen/bigger_text_size"
android:visibility="gone"/>
android:textStyle="italic"
android:visibility="gone" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/directories_empty_placeholder_2"
@ -46,7 +45,7 @@
android:padding="@dimen/activity_margin"
android:text="@string/change_filters_underlined"
android:textSize="@dimen/bigger_text_size"
android:visibility="gone"/>
android:visibility="gone" />
<com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/directories_grid"
@ -55,7 +54,7 @@
android:layout_below="@+id/directories_switch_searching"
android:scrollbars="none"
app:layoutManager="com.simplemobiletools.commons.views.MyGridLayoutManager"
app:spanCount="@integer/directory_columns_vertical_scroll"/>
app:spanCount="@integer/directory_columns_vertical_scroll" />
<com.simplemobiletools.commons.views.FastScroller
android:id="@+id/directories_vertical_fastscroller"
@ -66,7 +65,7 @@
android:paddingStart="@dimen/normal_margin"
android:visibility="gone">
<include layout="@layout/fastscroller_handle_vertical"/>
<include layout="@layout/fastscroller_handle_vertical" />
</com.simplemobiletools.commons.views.FastScroller>
@ -79,7 +78,7 @@
android:paddingTop="@dimen/normal_margin"
android:visibility="gone">
<include layout="@layout/fastscroller_handle_horizontal"/>
<include layout="@layout/fastscroller_handle_horizontal" />
</com.simplemobiletools.commons.views.FastScroller>
</RelativeLayout>

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dir_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/medium_margin"
android:clickable="true"
android:focusable="true"
android:padding="1px">
android:paddingTop="@dimen/medium_margin">
<com.simplemobiletools.gallery.pro.views.MySquareImageView
android:id="@+id/dir_thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent" />
<ImageView
android:id="@+id/dir_lock"
@ -26,21 +26,20 @@
android:contentDescription="@string/lock_folder"
android:padding="@dimen/lock_padding"
android:src="@drawable/ic_lock_vector"
android:visibility="gone"/>
android:visibility="gone" />
<ImageView
android:id="@+id/dir_check"
android:layout_width="@dimen/selection_check_size"
android:layout_height="@dimen/selection_check_size"
android:layout_alignEnd="@+id/dir_shadow_holder"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_margin="@dimen/small_margin"
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"/>
android:visibility="gone" />
<ImageView
android:id="@+id/dir_pin"
@ -48,69 +47,37 @@
android:layout_height="@dimen/selection_check_size"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="@dimen/small_margin"
android:layout_margin="@dimen/medium_margin"
android:background="@drawable/circle_black_background"
android:contentDescription="@string/pin"
android:padding="@dimen/small_margin"
android:src="@drawable/ic_pin"
android:visibility="gone"/>
<ImageView
android:id="@+id/dir_shadow_holder"
android:layout_width="match_parent"
android:layout_height="@dimen/tmb_shadow_height"
android:layout_alignStart="@+id/dir_bottom_holder"
android:layout_alignEnd="@+id/dir_bottom_holder"
android:layout_alignParentBottom="true"
android:background="@drawable/gradient_background"
android:contentDescription="@null"/>
<LinearLayout
android:id="@+id/dir_bottom_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/dir_thumbnail"
android:layout_alignEnd="@+id/dir_thumbnail"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:orientation="vertical"
android:paddingLeft="@dimen/medium_margin"
android:paddingTop="@dimen/small_margin"
android:paddingRight="@dimen/medium_margin"
android:paddingBottom="@dimen/small_margin">
android:visibility="gone" />
<TextView
android:id="@+id/dir_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/dir_thumbnail"
android:layout_alignStart="@+id/dir_thumbnail"
android:layout_toStartOf="@+id/dir_location"
android:ellipsize="end"
android:maxLines="2"
android:paddingBottom="@dimen/small_margin"
android:shadowColor="@color/default_background_color"
android:shadowRadius="4"
android:paddingTop="@dimen/medium_margin"
android:textColor="@android:color/white"
android:textSize="@dimen/normal_text_size"/>
<TextView
android:id="@+id/photo_cnt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="@dimen/normal_text_size"/>
</LinearLayout>
android:textSize="@dimen/normal_text_size" />
<ImageView
android:id="@+id/dir_location"
android:layout_width="@dimen/sd_card_icon_size"
android:layout_height="@dimen/sd_card_icon_size"
android:layout_alignEnd="@+id/dir_bottom_holder"
android:layout_alignParentBottom="true"
android:layout_alignBottom="@+id/dir_name"
android:layout_alignParentEnd="true"
android:alpha="0.8"
android:contentDescription="@null"
android:paddingEnd="@dimen/small_margin"
android:paddingBottom="@dimen/small_margin"
android:paddingTop="@dimen/tiny_margin"
android:paddingBottom="@dimen/tiny_margin"
android:src="@drawable/ic_sd_card_vector"
android:visibility="gone"/>
android:visibility="gone" />
</RelativeLayout>

View File

@ -23,4 +23,5 @@
<dimen name="widget_initial_size">110dp</dimen>
<dimen name="full_brush_size">40dp</dimen>
<dimen name="lock_padding">40dp</dimen>
<dimen name="rounded_corner_radius">10dp</dimen>
</resources>