Skip to content

Commit

Permalink
Merge pull request #11938 from nextcloud/fix/imagedetail-addresses
Browse files Browse the repository at this point in the history
Improve address appearance in ImageDetailFragment
  • Loading branch information
AndyScherzinger authored Sep 4, 2023
2 parents e1df0b9 + e9d14e1 commit 57326ea
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 40 deletions.
29 changes: 8 additions & 21 deletions app/src/main/java/com/nextcloud/ui/ImageDetailFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import android.graphics.drawable.LayerDrawable
import android.net.Uri
import android.os.Bundle
import android.os.Parcelable
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -130,7 +129,7 @@ class ImageDetailFragment : Fragment(), Injectable {

// detailed file information
val fileInformation = mutableListOf<String>()
if (metadata.length != null && metadata.width != null && metadata.length!! > 0 && metadata.width!! > 0) {
if ((metadata.length ?: 0) > 0 && (metadata.width ?: 0) > 0) {
try {
@Suppress("MagicNumber")
val pxlCount = when (val res = metadata.length!! * metadata.width!!.toLong()) {
Expand Down Expand Up @@ -246,7 +245,7 @@ class ImageDetailFragment : Fragment(), Injectable {
}

val markerOverlay = ItemizedIconOverlay(
mutableListOf(OverlayItem("Location", "", location)),
mutableListOf(OverlayItem(null, null, location)),
imagePinDrawable(context),
markerOnGestureListener(latitude, longitude),
context
Expand Down Expand Up @@ -291,7 +290,7 @@ class ImageDetailFragment : Fragment(), Injectable {
}

// determine size if not contained in exif data
if (width == null || length == null || width <= 0 || length <= 0) {
if ((width ?: 0) <= 0 || (length ?: 0) <= 0) {
val res = BitmapUtils.getImageResolution(file.storagePath)
width = res[0]
length = res[1]
Expand Down Expand Up @@ -340,28 +339,16 @@ class ImageDetailFragment : Fragment(), Injectable {
}
}

@Suppress("MagicNumber")
private fun imagePinDrawable(context: Context): LayerDrawable {
val drawable = ContextCompat.getDrawable(context, R.drawable.photo_pin) as LayerDrawable

val bitmap =
ThumbnailsCacheManager.getBitmapFromDiskCache(ThumbnailsCacheManager.PREFIX_THUMBNAIL + file.remoteId)
val foreground = BitmapUtils.bitmapToCircularBitmapDrawable(resources, bitmap)
val background = ContextCompat.getDrawable(context, R.drawable.photo_pin)

val layerDrawable = if (foreground != null) {
LayerDrawable(arrayOf(background, foreground))
} else {
val d = ContextCompat.getDrawable(context, R.drawable.file_image)
LayerDrawable(arrayOf(background, d))
BitmapUtils.bitmapToCircularBitmapDrawable(resources, bitmap)?.let {
drawable.setDrawable(1, it)
}

val dp = DisplayUtils.convertDpToPixel(2f, context)
layerDrawable.apply {
setLayerSize(1, 38 * dp, 38 * dp)
setLayerSize(0, 40 * dp, 47 * dp)
setLayerInsetTop(1, dp)
setLayerGravity(1, Gravity.CENTER_HORIZONTAL)
}
return layerDrawable
return drawable
}

/**
Expand Down
30 changes: 14 additions & 16 deletions app/src/main/res/drawable/photo_pin.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Nextcloud Android client application
Expand All @@ -18,19 +19,16 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="46.61dp"
android:viewportWidth="40"
android:viewportHeight="46.61">
<path
android:fillColor="@color/grey_600"
android:pathData="M1.523,20a18.477,18.477 0,1 0,36.954 0a18.477,18.477 0,1 0,-36.954 0z"
android:strokeWidth="3.0454"
android:strokeColor="@color/grey_600" />
<path
android:fillColor="@color/grey_600"
android:pathData="m1.5,20c0,17.795 18.5,25 18.5,25s18.5,-7.205 18.5,-25"
android:strokeWidth="3"
android:strokeColor="@color/grey_600" />
</vector>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="80dp"
android:height="94dp"
android:drawable="@drawable/photo_pin_background" />
<item
android:id="@+id/photo_pin_image"
android:width="76dp"
android:height="76dp"
android:drawable="@drawable/outline_image_24"
android:gravity="center_horizontal"
android:top="2dp" />
</layer-list>
36 changes: 36 additions & 0 deletions app/src/main/res/drawable/photo_pin_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
Nextcloud Android client application
@author ZetaTom
Copyright (C) 2023 ZetaTom
Copyright (C) 2023 Nextcloud GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="46.61dp"
android:viewportWidth="40"
android:viewportHeight="46.61">
<path
android:fillColor="@color/grey_600"
android:pathData="M1.523,20a18.477,18.477 0,1 0,36.954 0a18.477,18.477 0,1 0,-36.954 0z"
android:strokeWidth="3.0454"
android:strokeColor="@color/grey_600" />
<path
android:fillColor="@color/grey_600"
android:pathData="m1.5,20c0,17.795 18.5,25 18.5,25s18.5,-7.205 18.5,-25"
android:strokeWidth="3"
android:strokeColor="@color/grey_600" />
</vector>
9 changes: 6 additions & 3 deletions app/src/main/res/layout/preview_image_details_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,13 @@

<TextView
android:id="@+id/imageLocation_text"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="6dp"
android:ellipsize="end"
android:maxLines="2"
android:paddingHorizontal="12dp"
android:paddingVertical="6dp"
android:textAlignment="center"
android:textStyle="bold"
android:visibility="gone"
tools:text="Mitte, Berlin, Germany"
Expand Down

0 comments on commit 57326ea

Please sign in to comment.