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
c448359d
Unverified
Commit
c448359d
authored
Jun 20, 2018
by
Lucio Maciel
Committed by
GitHub
Jun 20, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1384 from RocketChat/feature/compress-image
[NEW] Compress image
parents
18e06ae0
590aedde
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
209 additions
and
122 deletions
+209
-122
UriInteractor.kt
...java/chat/rocket/android/chatroom/domain/UriInteractor.kt
+13
-7
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+152
-74
Animation.kt
...ain/java/chat/rocket/android/util/extensions/Animation.kt
+15
-9
Image.kt
...rc/main/java/chat/rocket/android/util/extensions/Image.kt
+11
-0
Ui.kt
app/src/main/java/chat/rocket/android/util/extensions/Ui.kt
+5
-16
Uri.kt
app/src/main/java/chat/rocket/android/util/extensions/Uri.kt
+13
-16
No files found.
app/src/main/java/chat/rocket/android/chatroom/domain/UriInteractor.kt
View file @
c448359d
...
@@ -5,26 +5,32 @@ import android.net.Uri
...
@@ -5,26 +5,32 @@ import android.net.Uri
import
chat.rocket.android.util.extensions.*
import
chat.rocket.android.util.extensions.*
import
javax.inject.Inject
import
javax.inject.Inject
class
UriInteractor
@Inject
constructor
(
private
val
context
:
Context
)
{
class
UriInteractor
@Inject
constructor
(
private
val
context
:
Context
)
{
/**
/**
*
Gets the file name from an
[Uri].
*
Returns the file name from the
[Uri].
*/
*/
fun
getFileName
(
uri
:
Uri
):
String
?
=
uri
.
getFileName
(
context
)
fun
getFileName
(
uri
:
Uri
):
String
?
=
uri
.
getFileName
(
context
)
/**
/**
*
Gets the MimeType of an [Uri]
*
Returns the MimeType from the [Uri].
*/
*/
fun
getMimeType
(
uri
:
Uri
):
String
=
uri
.
getMimeType
(
context
)
fun
getMimeType
(
uri
:
Uri
):
String
=
uri
.
getMimeType
(
context
)
/**
/**
*
Gets the real path of an [Uri]
*
Returns the file size from the [Uri].
*/
*/
fun
getRealPath
(
uri
:
Uri
):
String
?
=
uri
.
getRealPathFromURI
(
context
)
fun
getFileSize
(
uri
:
Uri
)
=
uri
.
getFileSize
(
context
)
fun
getFileSize
(
uri
:
Uri
)
=
uri
.
getFileSize
(
context
)
/**
* Returns the InputStream from the [Uri].
*/
fun
getInputStream
(
uri
:
Uri
)
=
uri
.
getInputStream
(
context
)
fun
getInputStream
(
uri
:
Uri
)
=
uri
.
getInputStream
(
context
)
/**
* Returns the Bitmap from the [Uri].
*
* Note: It should be an image.
*/
fun
getBitmap
(
uri
:
Uri
)
=
uri
.
getBitmpap
(
context
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
c448359d
This diff is collapsed.
Click to expand it.
app/src/main/java/chat/rocket/android/util/extensions/Animation.kt
View file @
c448359d
...
@@ -8,11 +8,11 @@ import android.content.Context
...
@@ -8,11 +8,11 @@ import android.content.Context
import
android.os.Build
import
android.os.Build
import
android.os.VibrationEffect
import
android.os.VibrationEffect
import
android.os.Vibrator
import
android.os.Vibrator
import
androidx.fragment.app.Fragment
import
android.view.View
import
android.view.View
import
android.view.ViewAnimationUtils
import
android.view.ViewAnimationUtils
import
android.view.animation.AccelerateInterpolator
import
android.view.animation.AccelerateInterpolator
import
android.view.animation.DecelerateInterpolator
import
android.view.animation.DecelerateInterpolator
import
androidx.fragment.app.Fragment
fun
View
.
rotateBy
(
value
:
Float
,
duration
:
Long
=
100
)
{
fun
View
.
rotateBy
(
value
:
Float
,
duration
:
Long
=
100
)
{
animate
()
animate
()
...
@@ -31,12 +31,12 @@ fun View.fadeIn(startValue: Float = 0f, finishValue: Float = 1f, duration: Long
...
@@ -31,12 +31,12 @@ fun View.fadeIn(startValue: Float = 0f, finishValue: Float = 1f, duration: Long
.
alpha
(
startValue
)
.
alpha
(
startValue
)
.
setDuration
(
duration
/
2
)
.
setDuration
(
duration
/
2
)
.
setInterpolator
(
DecelerateInterpolator
())
.
setInterpolator
(
DecelerateInterpolator
())
.
withEndAction
(
{
.
withEndAction
{
animate
()
animate
()
.
alpha
(
finishValue
)
.
alpha
(
finishValue
)
.
setDuration
(
duration
/
2
)
.
setDuration
(
duration
/
2
)
.
setInterpolator
(
AccelerateInterpolator
()).
start
()
.
setInterpolator
(
AccelerateInterpolator
()).
start
()
}
)
.
start
()
}.
start
()
setVisible
(
true
)
setVisible
(
true
)
}
}
...
@@ -51,18 +51,25 @@ fun View.fadeOut(startValue: Float = 1f, finishValue: Float = 0f, duration: Long
...
@@ -51,18 +51,25 @@ fun View.fadeOut(startValue: Float = 1f, finishValue: Float = 0f, duration: Long
.
alpha
(
startValue
)
.
alpha
(
startValue
)
.
setDuration
(
duration
)
.
setDuration
(
duration
)
.
setInterpolator
(
DecelerateInterpolator
())
.
setInterpolator
(
DecelerateInterpolator
())
.
withEndAction
(
{
.
withEndAction
{
animate
()
animate
()
.
alpha
(
finishValue
)
.
alpha
(
finishValue
)
.
setDuration
(
duration
)
.
setDuration
(
duration
)
.
setInterpolator
(
AccelerateInterpolator
()).
start
()
.
setInterpolator
(
AccelerateInterpolator
()).
start
()
}
)
.
start
()
}.
start
()
setVisible
(
false
)
setVisible
(
false
)
}
}
fun
View
.
circularRevealOrUnreveal
(
centerX
:
Int
,
centerY
:
Int
,
startRadius
:
Float
,
endRadius
:
Float
,
duration
:
Long
=
200
)
{
fun
View
.
circularRevealOrUnreveal
(
val
anim
=
ViewAnimationUtils
.
createCircularReveal
(
this
,
centerX
,
centerY
,
startRadius
,
endRadius
)
centerX
:
Int
,
centerY
:
Int
,
startRadius
:
Float
,
endRadius
:
Float
,
duration
:
Long
=
200
)
{
val
anim
=
ViewAnimationUtils
.
createCircularReveal
(
this
,
centerX
,
centerY
,
startRadius
,
endRadius
)
anim
.
duration
=
duration
anim
.
duration
=
duration
if
(
startRadius
<
endRadius
)
{
if
(
startRadius
<
endRadius
)
{
...
@@ -74,7 +81,7 @@ fun View.circularRevealOrUnreveal(centerX: Int, centerY: Int, startRadius: Float
...
@@ -74,7 +81,7 @@ fun View.circularRevealOrUnreveal(centerX: Int, centerY: Int, startRadius: Float
anim
.
start
()
anim
.
start
()
}
}
fun
View
.
shake
(
x
:
Float
=
2F
,
num
:
Int
=
0
){
fun
View
.
shake
(
x
:
Float
=
2F
,
num
:
Int
=
0
)
{
if
(
num
==
6
)
{
if
(
num
==
6
)
{
this
.
translationX
=
0
.
toFloat
()
this
.
translationX
=
0
.
toFloat
()
return
return
...
@@ -104,5 +111,4 @@ fun Fragment.vibrateSmartPhone() {
...
@@ -104,5 +111,4 @@ fun Fragment.vibrateSmartPhone() {
}
else
{
}
else
{
vibrator
.
vibrate
(
200
)
vibrator
.
vibrate
(
200
)
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/util/extensions/Image.kt
0 → 100644
View file @
c448359d
package
chat.rocket.android.util.extensions
import
android.graphics.Bitmap
fun
Bitmap
.
getCompressFormat
(
mimeType
:
String
):
Bitmap
.
CompressFormat
{
return
when
{
mimeType
.
contains
(
"jpeg"
)
->
Bitmap
.
CompressFormat
.
JPEG
mimeType
.
contains
(
"webp"
)
->
Bitmap
.
CompressFormat
.
WEBP
else
->
Bitmap
.
CompressFormat
.
PNG
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/util/extensions/Ui.kt
View file @
c448359d
...
@@ -2,17 +2,15 @@ package chat.rocket.android.util.extensions
...
@@ -2,17 +2,15 @@ package chat.rocket.android.util.extensions
import
android.app.Activity
import
android.app.Activity
import
android.content.Context
import
android.content.Context
import
androidx.annotation.LayoutRes
import
androidx.annotation.StringRes
import
androidx.fragment.app.Fragment
import
androidx.appcompat.app.AppCompatActivity
import
androidx.recyclerview.widget.LinearLayoutManager
import
androidx.recyclerview.widget.RecyclerView
import
android.view.LayoutInflater
import
android.view.LayoutInflater
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.view.inputmethod.InputMethodManager
import
android.view.inputmethod.InputMethodManager
import
android.widget.Toast
import
android.widget.Toast
import
androidx.annotation.LayoutRes
import
androidx.annotation.StringRes
import
androidx.appcompat.app.AppCompatActivity
import
androidx.fragment.app.Fragment
import
chat.rocket.android.R
import
chat.rocket.android.R
// TODO: Remove. Use KTX instead.
// TODO: Remove. Use KTX instead.
...
@@ -88,13 +86,4 @@ fun Fragment.showToast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SH
...
@@ -88,13 +86,4 @@ fun Fragment.showToast(@StringRes resource: Int, duration: Int = Toast.LENGTH_SH
showToast
(
getString
(
resource
),
duration
)
showToast
(
getString
(
resource
),
duration
)
fun
Fragment
.
showToast
(
message
:
String
,
duration
:
Int
=
Toast
.
LENGTH_SHORT
)
=
fun
Fragment
.
showToast
(
message
:
String
,
duration
:
Int
=
Toast
.
LENGTH_SHORT
)
=
activity
?.
showToast
(
message
,
duration
)
activity
?.
showToast
(
message
,
duration
)
\ No newline at end of file
fun
RecyclerView
.
isAtBottom
():
Boolean
{
val
manager
:
RecyclerView
.
LayoutManager
?
=
layoutManager
if
(
manager
is
LinearLayoutManager
)
{
return
manager
.
findFirstVisibleItemPosition
()
==
0
}
return
false
// or true??? we can't determine the first visible item.
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/util/extensions/Uri.kt
View file @
c448359d
...
@@ -3,6 +3,7 @@ package chat.rocket.android.util.extensions
...
@@ -3,6 +3,7 @@ package chat.rocket.android.util.extensions
import
android.annotation.TargetApi
import
android.annotation.TargetApi
import
android.content.ContentResolver
import
android.content.ContentResolver
import
android.content.Context
import
android.content.Context
import
android.graphics.Bitmap
import
android.net.Uri
import
android.net.Uri
import
android.os.Build
import
android.os.Build
import
android.provider.DocumentsContract
import
android.provider.DocumentsContract
...
@@ -57,25 +58,17 @@ fun Uri.getMimeType(context: Context): String {
...
@@ -57,25 +58,17 @@ fun Uri.getMimeType(context: Context): String {
}
}
}
}
fun
Uri
.
getRealPathFromURI
(
context
:
Context
):
String
?
{
val
cursor
=
context
.
contentResolver
.
query
(
this
,
arrayOf
(
MediaStore
.
Images
.
Media
.
DATA
),
null
,
null
,
null
)
cursor
.
use
{
cursor
->
val
columnIndex
=
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Images
.
Media
.
DATA
)
cursor
.
moveToFirst
()
return
cursor
.
getString
(
columnIndex
)
}
}
@TargetApi
(
Build
.
VERSION_CODES
.
N
)
@TargetApi
(
Build
.
VERSION_CODES
.
N
)
fun
Uri
.
isVirtualFile
(
context
:
Context
):
Boolean
{
fun
Uri
.
isVirtualFile
(
context
:
Context
):
Boolean
{
if
(!
DocumentsContract
.
isDocumentUri
(
context
,
this
))
{
if
(!
DocumentsContract
.
isDocumentUri
(
context
,
this
))
{
return
false
return
false
}
}
val
cursor
=
context
.
contentResolver
.
query
(
this
,
val
cursor
=
context
.
contentResolver
.
query
(
arrayOf
(
DocumentsContract
.
Document
.
COLUMN_FLAGS
),
this
,
null
,
null
,
null
)
arrayOf
(
DocumentsContract
.
Document
.
COLUMN_FLAGS
),
null
,
null
,
null
)
var
flags
=
0
var
flags
=
0
if
(
cursor
.
moveToFirst
())
{
if
(
cursor
.
moveToFirst
())
{
...
@@ -97,8 +90,8 @@ fun Uri.getInputStreamForVirtualFile(context: Context, mimeTypeFilter: String):
...
@@ -97,8 +90,8 @@ fun Uri.getInputStreamForVirtualFile(context: Context, mimeTypeFilter: String):
throw
FileNotFoundException
()
throw
FileNotFoundException
()
}
}
return
resolver
.
openTypedAssetFileDescriptor
(
this
,
openableMimeTypes
[
0
],
return
resolver
.
openTypedAssetFileDescriptor
(
this
,
openableMimeTypes
[
0
],
null
)
null
)
?.
createInputStream
()
?.
createInputStream
()
}
}
fun
Uri
.
getInputStream
(
context
:
Context
):
InputStream
?
{
fun
Uri
.
getInputStream
(
context
:
Context
):
InputStream
?
{
...
@@ -107,4 +100,8 @@ fun Uri.getInputStream(context: Context): InputStream? {
...
@@ -107,4 +100,8 @@ fun Uri.getInputStream(context: Context): InputStream? {
}
}
return
context
.
contentResolver
.
openInputStream
(
this
)
return
context
.
contentResolver
.
openInputStream
(
this
)
}
}
\ No newline at end of file
fun
Uri
.
getBitmpap
(
context
:
Context
):
Bitmap
?
{
return
MediaStore
.
Images
.
Media
.
getBitmap
(
context
.
contentResolver
,
this
)
}
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