Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
fe99fd89
Commit
fe99fd89
authored
Mar 13, 2018
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removes SVG support and requests the avatars image as jpeg or png
parent
d5ffd2a9
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
5 additions
and
288 deletions
+5
-288
build.gradle
app/build.gradle
+1
-6
ColorImage.kt
...src/main/java/chat/rocket/android/app/utils/ColorImage.kt
+0
-134
CustomImageFormatConfigurator.kt
...rocket/android/app/utils/CustomImageFormatConfigurator.kt
+0
-24
SvgDecoder.kt
...src/main/java/chat/rocket/android/app/utils/SvgDecoder.kt
+0
-111
AppModule.kt
.../main/java/chat/rocket/android/dagger/module/AppModule.kt
+1
-7
UrlHelper.kt
app/src/main/java/chat/rocket/android/helper/UrlHelper.kt
+2
-1
MemberViewModel.kt
.../chat/rocket/android/members/viewmodel/MemberViewModel.kt
+1
-1
dependencies.gradle
dependencies.gradle
+0
-4
No files found.
app/build.gradle
View file @
fe99fd89
...
...
@@ -95,14 +95,9 @@ dependencies {
implementation
libraries
.
kotshiApi
implementation
libraries
.
frescoImageViewer
implementation
(
libraries
.
androidSvg
)
{
exclude
group:
'org.jetbrains'
,
module:
'annotations-java5'
}
implementation
libraries
.
markwon
implementation
(
libraries
.
markwonImageLoader
)
{
exclude
group:
'com.caverock'
,
module:
'androidsvg'
}
implementation
libraries
.
markwonImageLoader
implementation
libraries
.
sheetMenu
...
...
app/src/main/java/chat/rocket/android/app/utils/ColorImage.kt
deleted
100644 → 0
View file @
d5ffd2a9
package
chat.rocket.android.app.utils
import
android.graphics.drawable.ColorDrawable
import
android.graphics.drawable.Drawable
import
android.support.annotation.ColorInt
import
android.support.annotation.Nullable
import
android.support.v4.graphics.ColorUtils
import
com.facebook.common.internal.ByteStreams
import
com.facebook.imageformat.ImageFormat
import
com.facebook.imageformat.ImageFormatCheckerUtils
import
com.facebook.imagepipeline.common.ImageDecodeOptions
import
com.facebook.imagepipeline.decoder.ImageDecoder
import
com.facebook.imagepipeline.drawable.DrawableFactory
import
com.facebook.imagepipeline.image.CloseableImage
import
com.facebook.imagepipeline.image.EncodedImage
import
com.facebook.imagepipeline.image.QualityInfo
import
java.io.IOException
/**
* Simple decoder that can decode color images that have the following format: <color>#FF5722</color>.
*
* @see {https://github.com/facebook/fresco/blob/master/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/imageformat/color/ColorImageExample.java}
*/
object
ColorImage
{
// Custom ImageFormat for color images.
private
val
imageFormatColor
=
ImageFormat
(
"IMAGE_FORMAT_COLOR"
,
"color"
)
// XML color tag that our colors must start with.
val
colorTag
=
"<color>"
/**
* Creates a new image format checker for [ColorImage.imageFormatColor].
*
* @return the image format checker.
*/
fun
createFormatChecker
():
ImageFormat
.
FormatChecker
=
ColorFormatChecker
()
/**
* Creates a new decoder that can decode [ColorImage.imageFormatColor] images.
*
* @return the decoder.
*/
fun
createDecoder
():
ImageDecoder
=
ColorDecoder
()
fun
createDrawableFactory
():
ColorDrawableFactory
=
ColorDrawableFactory
()
/**
* Custom color format checker that verifies that the header of the file corresponds to our [ColorImage.colorTag].
*/
class
ColorFormatChecker
:
ImageFormat
.
FormatChecker
{
private
val
header
=
ImageFormatCheckerUtils
.
asciiBytes
(
colorTag
)
override
fun
getHeaderSize
():
Int
{
return
header
.
size
}
@Nullable
override
fun
determineFormat
(
headerBytes
:
ByteArray
,
headerSize
:
Int
):
ImageFormat
?
{
if
(
headerSize
>
getHeaderSize
())
{
if
(
ImageFormatCheckerUtils
.
startsWithPattern
(
headerBytes
,
header
))
{
return
imageFormatColor
}
}
return
null
}
}
/**
* Custom closeable color image that holds a single color int value.
*/
class
CloseableColorImage
(
@field
:
ColorInt
@get
:
ColorInt
val
color
:
Int
)
:
CloseableImage
()
{
private
var
isClosed
=
false
override
fun
close
()
{
isClosed
=
true
}
override
fun
getSizeInBytes
():
Int
=
0
override
fun
isClosed
():
Boolean
=
isClosed
override
fun
getWidth
():
Int
=
0
override
fun
getHeight
():
Int
=
0
}
/**
* Decodes a color XML tag: <color>#rrggbb</color>.
*/
class
ColorDecoder
:
ImageDecoder
{
@Nullable
override
fun
decode
(
encodedImage
:
EncodedImage
,
length
:
Int
,
qualityInfo
:
QualityInfo
,
options
:
ImageDecodeOptions
):
CloseableImage
?
{
try
{
// Read the file as a string
val
text
=
String
(
ByteStreams
.
toByteArray
(
encodedImage
.
inputStream
))
// Check if the string matches "<color>#"
if
(!
text
.
startsWith
(
colorTag
+
"#"
))
{
return
null
}
// Parse the int value between # and <
val
startIndex
=
colorTag
.
length
+
1
val
endIndex
=
text
.
lastIndexOf
(
'<'
)
var
color
=
Integer
.
parseInt
(
text
.
substring
(
startIndex
,
endIndex
),
16
)
// Add the alpha component so that we actually see the color
color
=
ColorUtils
.
setAlphaComponent
(
color
,
255
)
// Return the CloseableImage
return
CloseableColorImage
(
color
)
}
catch
(
e
:
IOException
)
{
// TODO: are we using the android.util.Log for logging that type of errors? or should we use the SDK logger?
e
.
printStackTrace
()
}
// Return nothing if an error occurred
return
null
}
}
/**
* Color drawable factory that is able to render a [CloseableColorImage] by creating a new [ColorDrawable] for the given color.
*/
class
ColorDrawableFactory
:
DrawableFactory
{
override
fun
supportsImageType
(
image
:
CloseableImage
):
Boolean
{
// We can only handle CloseableColorImages.
return
image
is
CloseableColorImage
}
@Nullable
override
fun
createDrawable
(
image
:
CloseableImage
):
Drawable
?
{
// Just return a simple ColorDrawable with the given color value.
return
ColorDrawable
((
image
as
CloseableColorImage
).
color
)
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/app/utils/CustomImageFormatConfigurator.kt
deleted
100644 → 0
View file @
d5ffd2a9
package
chat.rocket.android.app.utils
import
com.facebook.drawee.backends.pipeline.DraweeConfig
import
com.facebook.imagepipeline.decoder.ImageDecoderConfig
/**
* Utility class to add custom decoders and drawable factories.
*
* @see {https://github.com/facebook/fresco/blob/master/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/CustomImageFormatConfigurator.java}
*/
object
CustomImageFormatConfigurator
{
fun
createImageDecoderConfig
()
:
ImageDecoderConfig
{
return
ImageDecoderConfig
.
newBuilder
()
.
addDecodingCapability
(
SvgDecoder
.
svgFormat
,
SvgDecoder
.
SvgFormatChecker
(),
SvgDecoder
.
Decoder
())
.
build
()
}
fun
addCustomDrawableFactories
(
draweeConfigBuilder
:
DraweeConfig
.
Builder
)
{
// We always add the color drawable factory so that it can be used for image decoder overrides.
draweeConfigBuilder
.
addCustomDrawableFactory
(
ColorImage
.
createDrawableFactory
())
draweeConfigBuilder
.
addCustomDrawableFactory
(
SvgDecoder
.
SvgDrawableFactory
())
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/app/utils/SvgDecoder.kt
deleted
100644 → 0
View file @
d5ffd2a9
package
chat.rocket.android.app.utils
import
android.graphics.Rect
import
android.graphics.drawable.Drawable
import
android.graphics.drawable.PictureDrawable
import
android.support.annotation.Nullable
import
com.caverock.androidsvg.SVG
import
com.caverock.androidsvg.SVGParseException
import
com.facebook.imageformat.ImageFormat
import
com.facebook.imageformat.ImageFormatCheckerUtils
import
com.facebook.imagepipeline.common.ImageDecodeOptions
import
com.facebook.imagepipeline.decoder.ImageDecoder
import
com.facebook.imagepipeline.drawable.DrawableFactory
import
com.facebook.imagepipeline.image.CloseableImage
import
com.facebook.imagepipeline.image.EncodedImage
import
com.facebook.imagepipeline.image.QualityInfo
/**
* SVG example that defines all classes required to decode and render SVG images.
*
* @see {https://github.com/facebook/fresco/blob/master/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/imageformat/svg/SvgDecoderExample.java}
*/
object
SvgDecoder
{
val
svgFormat
=
ImageFormat
(
"SVG_FORMAT"
,
"svg"
)
// We do not include the closing ">" since there can be additional information.
private
val
headerTag
=
"<svg"
private
val
possibleHeaderTags
=
arrayOf
(
ImageFormatCheckerUtils
.
asciiBytes
(
"<?xml"
))
/**
* Custom SVG format checker that verifies that the header of the file corresponds to our [SvgDecoder.headerTag] or [SvgDecoder.possibleHeaderTags].
*/
class
SvgFormatChecker
:
ImageFormat
.
FormatChecker
{
private
val
header
=
ImageFormatCheckerUtils
.
asciiBytes
(
headerTag
)
override
fun
getHeaderSize
():
Int
{
return
header
.
size
}
@Nullable
override
fun
determineFormat
(
headerBytes
:
ByteArray
,
headerSize
:
Int
):
ImageFormat
?
{
if
(
headerSize
>
getHeaderSize
())
{
if
(
ImageFormatCheckerUtils
.
startsWithPattern
(
headerBytes
,
header
))
{
return
svgFormat
}
if
(
possibleHeaderTags
.
any
{
ImageFormatCheckerUtils
.
startsWithPattern
(
headerBytes
,
it
)
&&
ImageFormatCheckerUtils
.
indexOfPattern
(
headerBytes
,
headerBytes
.
size
,
header
,
header
.
size
)
>
-
1
})
{
return
svgFormat
}
}
return
null
}
}
/**
* Custom closeable SVG image that holds a single SVG.
*/
class
CloseableSvgImage
(
val
svg
:
SVG
)
:
CloseableImage
()
{
private
var
isClose
=
false
override
fun
close
()
{
isClose
=
true
}
override
fun
getSizeInBytes
():
Int
=
0
override
fun
isClosed
():
Boolean
=
isClose
override
fun
getWidth
():
Int
=
0
override
fun
getHeight
():
Int
=
0
}
/**
* Decodes a [SvgDecoder.svgFormat] image.
*/
class
Decoder
:
ImageDecoder
{
@Nullable
override
fun
decode
(
encodedImage
:
EncodedImage
,
length
:
Int
,
qualityInfo
:
QualityInfo
,
options
:
ImageDecodeOptions
):
CloseableImage
?
{
try
{
val
svg
=
SVG
.
getFromInputStream
(
encodedImage
.
inputStream
)
return
CloseableSvgImage
(
svg
)
}
catch
(
e
:
SVGParseException
)
{
// TODO: are we using the android.util.Log for logging that type of errors? or should we use the SDK logger?
e
.
printStackTrace
()
}
// Return nothing if an error occurred
return
null
}
}
/**
* SVG drawable factory that creates [PictureDrawable]s for SVG images.
*/
class
SvgDrawableFactory
:
DrawableFactory
{
override
fun
supportsImageType
(
image
:
CloseableImage
):
Boolean
{
return
image
is
CloseableSvgImage
}
@Nullable
override
fun
createDrawable
(
image
:
CloseableImage
):
Drawable
?
{
return
SvgPictureDrawable
((
image
as
CloseableSvgImage
).
svg
)
}
}
class
SvgPictureDrawable
(
private
val
svg
:
SVG
)
:
PictureDrawable
(
null
)
{
override
fun
onBoundsChange
(
bounds
:
Rect
)
{
super
.
onBoundsChange
(
bounds
)
picture
=
svg
.
renderToPicture
(
bounds
.
width
(),
bounds
.
height
())
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt
View file @
fe99fd89
...
...
@@ -7,7 +7,6 @@ import android.content.SharedPreferences
import
chat.rocket.android.BuildConfig
import
chat.rocket.android.R
import
chat.rocket.android.app.RocketChatDatabase
import
chat.rocket.android.app.utils.CustomImageFormatConfigurator
import
chat.rocket.android.authentication.infraestructure.MemoryTokenRepository
import
chat.rocket.android.authentication.infraestructure.SharedPreferencesMultiServerTokenRepository
import
chat.rocket.android.dagger.qualifier.ForFresco
...
...
@@ -131,7 +130,6 @@ class AppModule {
listeners
.
add
(
RequestLoggingListener
())
return
OkHttpImagePipelineConfigFactory
.
newBuilder
(
context
,
okHttpClient
)
.
setImageDecoderConfig
(
CustomImageFormatConfigurator
.
createImageDecoderConfig
())
.
setRequestListeners
(
listeners
)
.
setDownsampleEnabled
(
true
)
//.experiment().setBitmapPrepareToDraw(true).experiment()
...
...
@@ -141,11 +139,7 @@ class AppModule {
@Provides
@Singleton
fun
provideDraweeConfig
():
DraweeConfig
{
val
draweeConfigBuilder
=
DraweeConfig
.
newBuilder
()
CustomImageFormatConfigurator
.
addCustomDrawableFactories
(
draweeConfigBuilder
)
return
draweeConfigBuilder
.
build
()
return
DraweeConfig
.
newBuilder
().
build
()
}
@Provides
...
...
app/src/main/java/chat/rocket/android/helper/UrlHelper.kt
View file @
fe99fd89
...
...
@@ -11,7 +11,8 @@ object UrlHelper {
* @param avatarName The avatar name.
* @return The avatar URL.
*/
fun
getAvatarUrl
(
serverUrl
:
String
,
avatarName
:
String
):
String
=
removeTrailingSlash
(
serverUrl
)
+
"/avatar/"
+
avatarName
fun
getAvatarUrl
(
serverUrl
:
String
,
avatarName
:
String
,
format
:
String
=
"jpeg"
):
String
=
removeTrailingSlash
(
serverUrl
)
+
"/avatar/"
+
removeTrailingSlash
(
avatarName
)
+
"?format=$format"
/**
* Returns the CAS URL.
...
...
app/src/main/java/chat/rocket/android/members/viewmodel/MemberViewModel.kt
View file @
fe99fd89
...
...
@@ -25,7 +25,7 @@ class MemberViewModel(private val member: User, private val settings: Map<String
private
fun
getUserAvatar
():
String
?
{
val
username
=
member
.
username
?:
"?"
return
baseUrl
?.
let
{
UrlHelper
.
getAvatarUrl
(
baseUrl
,
username
)
UrlHelper
.
getAvatarUrl
(
baseUrl
,
username
,
"png"
)
}
}
...
...
dependencies.gradle
View file @
fe99fd89
...
...
@@ -26,7 +26,6 @@ ext {
fresco
:
'1.8.1'
,
kotshi
:
'0.3.0'
,
frescoImageViewer
:
'0.5.0'
,
androidSvg
:
'master-SNAPSHOT'
,
markwon
:
'1.0.3'
,
sheetMenu
:
'1.3.3'
,
aVLoadingIndicatorView
:
'2.1.3'
,
...
...
@@ -87,7 +86,6 @@ ext {
kotshiCompiler
:
"se.ansman.kotshi:compiler:${versions.kotshi}"
,
frescoImageViewer
:
"com.github.stfalcon:frescoimageviewer:${versions.frescoImageViewer}"
,
androidSvg
:
"com.github.BigBadaboom:androidsvg:${versions.androidSvg}"
,
markwon
:
"ru.noties:markwon:${versions.markwon}"
,
markwonImageLoader
:
"ru.noties:markwon-image-loader:${versions.markwon}"
,
...
...
@@ -96,8 +94,6 @@ ext {
aVLoadingIndicatorView
:
"com.wang.avi:library:${versions.aVLoadingIndicatorView}"
,
swipeBackLayout
:
"me.imid.swipebacklayout.lib:library:${versions.swipeBackLayout}"
,
// For testing
junit
:
"junit:junit:$versions.junit"
,
expressoCore
:
"com.android.support.test.espresso:espresso-core:${versions.expresso}"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment