Skip to content

Commit 49af948

Browse files
committed
Previewing SVG files works
1 parent 8c46e6d commit 49af948

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

owncloudApp/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies {
2626

2727
// Image loading
2828
implementation 'com.github.bumptech.glide:glide:4.12.0'
29+
implementation 'com.github.corouteam:GlideToVectorYou:v2.0.0'
2930

3031
// CustomTabs required for OAuth2 and OIDC.
3132
implementation "androidx.browser:browser:1.4.0"

owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.kt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ package com.owncloud.android.ui.preview
2727

2828
import android.accounts.Account
2929
import android.graphics.Bitmap
30+
import android.graphics.Color
3031
import android.graphics.drawable.Drawable
3132
import android.os.Bundle
3233
import android.view.LayoutInflater
@@ -120,6 +121,8 @@ class PreviewImageFragment : FileFragment() {
120121
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
121122
super.onViewCreated(view, savedInstanceState)
122123

124+
binding.top.setBackgroundColor(getBackgroundColor(file))
125+
123126
binding.photoView.isVisible = false
124127
binding.photoView.setOnClickListener {
125128
(requireActivity() as PreviewImageActivity).toggleFullScreen()
@@ -325,18 +328,26 @@ class PreviewImageFragment : FileFragment() {
325328
return false
326329
}
327330

328-
override fun onResourceReady(
329-
resource: Drawable?, model: Any, target: Target<Drawable?>,
330-
dataSource: DataSource, isFirstResource: Boolean
331-
): Boolean {
332-
Timber.d("Loading image %s", file.fileName)
333-
return false
334-
}
335-
})
336-
.into(binding.photoView)
331+
override fun onResourceReady(
332+
resource: Drawable?, model: Any, target: Target<Drawable?>,
333+
dataSource: DataSource, isFirstResource: Boolean
334+
): Boolean {
335+
Timber.d("Loading image %s", file.fileName)
336+
binding.progressWheel.isVisible = false
337+
return false
338+
}
339+
})
340+
.into(binding.photoView)
341+
337342
binding.photoView.isVisible = true
338343
}
339344

345+
private fun isSVGFile(file: OCFile): Boolean = file.mimetype == SVG_MIMETYPE
346+
347+
private fun getBackgroundColor(file: OCFile): Int {
348+
return if (isSVGFile(file)) Color.WHITE else Color.BLACK
349+
}
350+
340351
/**
341352
* Finishes the preview
342353
*/
@@ -348,6 +359,7 @@ class PreviewImageFragment : FileFragment() {
348359
private const val ARG_FILE = "FILE"
349360
private const val ARG_ACCOUNT = "ACCOUNT"
350361
private const val ARG_IGNORE_FIRST = "IGNORE_FIRST"
362+
private const val SVG_MIMETYPE = "image/svg+xml"
351363

352364
/**
353365
* Public factory method to create a new fragment that previews an image.

owncloudApp/src/main/res/layout/preview_image_fragment.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
android:id="@+id/top"
2323
android:layout_width="match_parent"
2424
android:layout_height="match_parent"
25-
android:background="#000000"
2625
android:filterTouchesWhenObscured="true"
2726
tools:context=".ui.preview.PreviewImageFragment">
2827

@@ -46,7 +45,7 @@
4645
app:layout_constraintLeft_toLeftOf="parent"
4746
app:layout_constraintRight_toRightOf="parent"
4847
app:layout_constraintTop_toTopOf="parent"
49-
app:layout_constraintBottom_toBottomOf="parent"/>
48+
app:layout_constraintBottom_toBottomOf="parent" />
5049

5150
<TextView
5251
android:id="@+id/errorText"

0 commit comments

Comments
 (0)