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
41adfb58
Commit
41adfb58
authored
Jul 03, 2018
by
divyanshu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
requested changes
parent
5a2445c4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
45 deletions
+42
-45
UriInteractor.kt
...java/chat/rocket/android/chatroom/domain/UriInteractor.kt
+6
-0
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+24
-0
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+9
-41
ImageHelper.kt
app/src/main/java/chat/rocket/android/helper/ImageHelper.kt
+2
-2
DrawingActivity.kt
...src/main/java/chat/rocket/android/draw/DrawingActivity.kt
+1
-2
No files found.
app/src/main/java/chat/rocket/android/chatroom/domain/UriInteractor.kt
View file @
41adfb58
...
...
@@ -3,6 +3,7 @@ package chat.rocket.android.chatroom.domain
import
android.content.Context
import
android.net.Uri
import
chat.rocket.android.util.extensions.*
import
java.io.File
import
javax.inject.Inject
class
UriInteractor
@Inject
constructor
(
private
val
context
:
Context
)
{
...
...
@@ -33,4 +34,9 @@ class UriInteractor @Inject constructor(private val context: Context) {
* Note: It should be an image.
*/
fun
getBitmap
(
uri
:
Uri
)
=
uri
.
getBitmpap
(
context
)
/**
* Returns the Uri from the [File].
*/
fun
getUri
(
file
:
File
)
=
Uri
.
fromFile
(
file
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
41adfb58
package
chat.rocket.android.chatroom.presentation
import
android.graphics.Bitmap
import
android.graphics.BitmapFactory
import
android.net.Uri
import
android.os.Environment
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.adapter.AutoCompleteType
import
chat.rocket.android.chatroom.adapter.PEOPLE
...
...
@@ -77,6 +80,8 @@ import timber.log.Timber
import
java.io.ByteArrayInputStream
import
java.io.ByteArrayOutputStream
import
java.io.InputStream
import
java.io.File
import
java.io.FileOutputStream
import
java.util.*
import
javax.inject.Inject
...
...
@@ -898,6 +903,12 @@ class ChatRoomPresenter @Inject constructor(
}
}
fun
getDrawingImageUri
(
byteArray
:
ByteArray
):
Uri
{
val
bitmap
=
BitmapFactory
.
decodeByteArray
(
byteArray
,
0
,
byteArray
.
size
)
val
file
=
saveDrawingImage
(
bitmap
)
return
uriInteractor
.
getUri
(
file
)
}
private
suspend
fun
subscribeTypingStatus
()
{
launch
(
CommonPool
+
strategy
.
jobs
)
{
client
.
subscribeTypingStatus
(
chatRoomId
.
toString
())
{
_
,
id
->
...
...
@@ -963,4 +974,17 @@ class ChatRoomPresenter @Inject constructor(
}
}
}
private
fun
saveDrawingImage
(
bitmap
:
Bitmap
):
File
{
val
imageDir
=
"${Environment.DIRECTORY_PICTURES}/Rocket.Chat Images/"
val
path
=
Environment
.
getExternalStoragePublicDirectory
(
imageDir
)
val
file
=
File
(
path
,
UUID
.
randomUUID
().
toString
()+
".png"
)
path
.
mkdirs
()
file
.
createNewFile
()
val
outputStream
=
FileOutputStream
(
file
)
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
PNG
,
100
,
outputStream
)
outputStream
.
flush
()
outputStream
.
close
()
return
file
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
41adfb58
package
chat.rocket.android.chatroom.ui
import
android.Manifest
import
android.app.Activity
import
android.content.ClipData
import
android.content.ClipboardManager
import
android.content.Context
import
android.content.Intent
import
android.graphics.Bitmap
import
android.graphics.BitmapFactory
import
android.net.Uri
import
android.os.Bundle
import
android.os.Environment
import
android.os.Handler
import
android.text.SpannableStringBuilder
import
android.view.KeyEvent
import
android.view.LayoutInflater
import
android.view.Menu
import
android.view.MenuInflater
import
android.view.MenuItem
import
android.view.View
import
android.view.ViewGroup
...
...
@@ -48,10 +43,10 @@ import chat.rocket.android.emoji.EmojiKeyboardPopup
import
chat.rocket.android.emoji.EmojiParser
import
chat.rocket.android.emoji.EmojiPickerPopup
import
chat.rocket.android.emoji.EmojiReactionListener
import
chat.rocket.android.helper.AndroidPermissionsHelper
import
chat.rocket.android.helper.EndlessRecyclerViewScrollListener
import
chat.rocket.android.helper.KeyboardHelper
import
chat.rocket.android.helper.MessageParser
import
chat.rocket.android.helper.ImageHelper
import
chat.rocket.android.util.extensions.asObservable
import
chat.rocket.android.util.extensions.circularRevealOrUnreveal
import
chat.rocket.android.util.extensions.fadeIn
...
...
@@ -74,9 +69,6 @@ import kotlinx.android.synthetic.main.fragment_chat_room.*
import
kotlinx.android.synthetic.main.message_attachment_options.*
import
kotlinx.android.synthetic.main.message_composer.*
import
kotlinx.android.synthetic.main.message_list.*
import
java.io.File
import
java.io.FileOutputStream
import
java.util.UUID
import
java.util.concurrent.TimeUnit
import
java.util.concurrent.atomic.AtomicInteger
import
javax.inject.Inject
...
...
@@ -243,27 +235,13 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
REQUEST_CODE_FOR_DRAW
->
{
val
result
=
resultData
.
getByteArrayExtra
(
"bitmap"
)
val
bitmap
=
BitmapFactory
.
decodeByteArray
(
result
,
0
,
result
.
size
)
val
uri
=
saveImage
(
bitmap
)
val
uri
=
presenter
.
getDrawingImageUri
(
result
)
uploadFile
(
uri
)
}
}
}
}
private
fun
saveImage
(
bitmap
:
Bitmap
):
Uri
{
val
imageDir
=
"${Environment.DIRECTORY_PICTURES}/Rocket.Chat Images/"
val
path
=
Environment
.
getExternalStoragePublicDirectory
(
imageDir
)
val
file
=
File
(
path
,
UUID
.
randomUUID
().
toString
()+
".png"
)
path
.
mkdirs
()
file
.
createNewFile
()
val
outputStream
=
FileOutputStream
(
file
)
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
PNG
,
100
,
outputStream
)
outputStream
.
flush
()
outputStream
.
close
()
return
Uri
.
fromFile
(
file
)
}
override
fun
onPrepareOptionsMenu
(
menu
:
Menu
)
{
menu
.
clear
()
if
(
isFavorite
)
{
...
...
@@ -825,11 +803,13 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
button_drawing
.
setOnClickListener
{
if
(!
canWriteToExternalStorage
())
{
checkWritingPermission
()
}
else
{
val
intent
=
Intent
(
activity
,
DrawingActivity
::
class
.
java
)
startActivityForResult
(
intent
,
REQUEST_CODE_FOR_DRAW
)
context
?.
let
{
if
(!
ImageHelper
.
canWriteToExternalStorage
(
it
))
{
ImageHelper
.
checkWritingPermission
(
it
)
}
else
{
val
intent
=
Intent
(
activity
,
DrawingActivity
::
class
.
java
)
startActivityForResult
(
intent
,
REQUEST_CODE_FOR_DRAW
)
}
}
handler
.
postDelayed
({
hideAttachmentOptions
()
...
...
@@ -838,18 +818,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
private
fun
canWriteToExternalStorage
():
Boolean
{
return
context
?.
let
{
AndroidPermissionsHelper
.
checkPermission
(
it
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
}
!!
}
private
fun
checkWritingPermission
()
{
activity
?.
let
{
AndroidPermissionsHelper
.
requestPermission
(
it
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
AndroidPermissionsHelper
.
WRITE_EXTERNAL_STORAGE_CODE
)
}
}
private
fun
setupSuggestionsView
()
{
suggestions_view
.
anchorTo
(
text_message
)
.
setMaximumHeight
(
resources
.
getDimensionPixelSize
(
R
.
dimen
.
suggestions_box_max_height
))
...
...
app/src/main/java/chat/rocket/android/helper/ImageHelper.kt
View file @
41adfb58
...
...
@@ -147,14 +147,14 @@ object ImageHelper {
return
true
}
private
fun
canWriteToExternalStorage
(
context
:
Context
):
Boolean
{
fun
canWriteToExternalStorage
(
context
:
Context
):
Boolean
{
return
AndroidPermissionsHelper
.
checkPermission
(
context
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
}
private
fun
checkWritingPermission
(
context
:
Context
)
{
fun
checkWritingPermission
(
context
:
Context
)
{
if
(
context
is
ContextThemeWrapper
&&
context
.
baseContext
is
Activity
)
{
val
activity
=
context
.
baseContext
as
Activity
AndroidPermissionsHelper
.
requestPermission
(
...
...
draw/src/main/java/chat/rocket/android/draw/DrawingActivity.kt
View file @
41adfb58
...
...
@@ -14,7 +14,6 @@ import kotlinx.android.synthetic.main.activity_drawing.*
import
kotlinx.android.synthetic.main.color_palette_view.*
import
java.io.ByteArrayOutputStream
class
DrawingActivity
:
AppCompatActivity
()
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
...
...
@@ -27,7 +26,7 @@ class DrawingActivity : AppCompatActivity() {
image_send_drawing
.
setOnClickListener
{
val
bStream
=
ByteArrayOutputStream
()
val
bitmap
=
custom_draw_view
.
getBitmap
()
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
PNG
,
10
0
,
bStream
)
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
PNG
,
7
0
,
bStream
)
val
byteArray
=
bStream
.
toByteArray
()
val
returnIntent
=
Intent
()
returnIntent
.
putExtra
(
"bitmap"
,
byteArray
)
...
...
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