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
9c713200
Commit
9c713200
authored
Apr 25, 2018
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add GenericFileAttachment
parent
c9c114dd
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
143 additions
and
20 deletions
+143
-20
RocketChatApplication.kt
...ain/java/chat/rocket/android/app/RocketChatApplication.kt
+17
-1
ChatRoomAdapter.kt
...a/chat/rocket/android/chatroom/adapter/ChatRoomAdapter.kt
+5
-0
GenericFileAttachmentViewHolder.kt
...droid/chatroom/adapter/GenericFileAttachmentViewHolder.kt
+34
-0
BaseViewModel.kt
...a/chat/rocket/android/chatroom/viewmodel/BaseViewModel.kt
+2
-1
GenericFileAttachmentViewModel.kt
...roid/chatroom/viewmodel/GenericFileAttachmentViewModel.kt
+24
-0
ViewModelMapper.kt
...chat/rocket/android/chatroom/viewmodel/ViewModelMapper.kt
+4
-0
AppModule.kt
.../main/java/chat/rocket/android/dagger/module/AppModule.kt
+1
-0
LocalRepository.kt
...ava/chat/rocket/android/infrastructure/LocalRepository.kt
+5
-5
SharedPrefsLocalRepository.kt
...cket/android/infrastructure/SharedPrefsLocalRepository.kt
+12
-11
item_author_attachment.xml
app/src/main/res/layout/item_author_attachment.xml
+1
-2
item_file_attachment.xml
app/src/main/res/layout/item_file_attachment.xml
+37
-0
strings.xml
app/src/main/res/values/strings.xml
+1
-0
No files found.
app/src/main/java/chat/rocket/android/app/RocketChatApplication.kt
View file @
9c713200
...
...
@@ -18,6 +18,7 @@ import chat.rocket.android.app.migration.model.RealmSession
import
chat.rocket.android.app.migration.model.RealmUser
import
chat.rocket.android.authentication.domain.model.toToken
import
chat.rocket.android.dagger.DaggerAppComponent
import
chat.rocket.android.dagger.qualifier.ForMessages
import
chat.rocket.android.helper.CrashlyticsTree
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.server.domain.*
...
...
@@ -84,6 +85,10 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
@Inject
lateinit
var
localRepository
:
LocalRepository
@Inject
@field
:
ForMessages
lateinit
var
messagesPrefs
:
SharedPreferences
override
fun
onCreate
()
{
super
.
onCreate
()
...
...
@@ -107,6 +112,13 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
setupFresco
()
setupTimber
()
if
(
localRepository
.
needOldMessagesCleanUp
())
{
messagesPrefs
.
edit
{
clear
()
}
localRepository
.
setOldMessagesCleanedUp
()
}
// TODO - remove this and all realm stuff when we got to 80% in 2.0
try
{
if
(!
localRepository
.
hasMigrated
())
{
...
...
@@ -286,5 +298,9 @@ private fun LocalRepository.setMigrated(migrated: Boolean) {
}
private
fun
LocalRepository
.
hasMigrated
()
=
getBoolean
(
LocalRepository
.
MIGRATION_FINISHED_KEY
)
private
fun
LocalRepository
.
needOldMessagesCleanUp
()
=
getBoolean
(
CLEANUP_OLD_MESSAGES_NEEDED
,
true
)
private
fun
LocalRepository
.
setOldMessagesCleanedUp
()
=
save
(
CLEANUP_OLD_MESSAGES_NEEDED
,
false
)
private
const
val
INTERNAL_TOKEN_MIGRATION_NEEDED
=
"INTERNAL_TOKEN_MIGRATION_NEEDED"
private
const
val
INTERNAL_TOKEN_MIGRATION_NEEDED
=
"INTERNAL_TOKEN_MIGRATION_NEEDED"
\ No newline at end of file
private
const
val
CLEANUP_OLD_MESSAGES_NEEDED
=
"CLEANUP_OLD_MESSAGES_NEEDED"
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/adapter/ChatRoomAdapter.kt
View file @
9c713200
...
...
@@ -61,6 +61,10 @@ class ChatRoomAdapter(
val
view
=
parent
.
inflate
(
R
.
layout
.
item_color_attachment
)
ColorAttachmentViewHolder
(
view
,
actionsListener
,
reactionListener
)
}
BaseViewModel
.
ViewType
.
GENERIC_FILE_ATTACHMENT
->
{
val
view
=
parent
.
inflate
(
R
.
layout
.
item_file_attachment
)
GenericFileAttachmentViewHolder
(
view
,
actionsListener
,
reactionListener
)
}
else
->
{
throw
InvalidParameterException
(
"TODO - implement for ${viewType.toViewType()}"
)
}
...
...
@@ -102,6 +106,7 @@ class ChatRoomAdapter(
is
MessageAttachmentViewHolder
->
holder
.
bind
(
dataSet
[
position
]
as
MessageAttachmentViewModel
)
is
AuthorAttachmentViewHolder
->
holder
.
bind
(
dataSet
[
position
]
as
AuthorAttachmentViewModel
)
is
ColorAttachmentViewHolder
->
holder
.
bind
(
dataSet
[
position
]
as
ColorAttachmentViewModel
)
is
GenericFileAttachmentViewHolder
->
holder
.
bind
(
dataSet
[
position
]
as
GenericFileAttachmentViewModel
)
}
}
...
...
app/src/main/java/chat/rocket/android/chatroom/adapter/GenericFileAttachmentViewHolder.kt
0 → 100644
View file @
9c713200
package
chat.rocket.android.chatroom.adapter
import
android.content.Intent
import
android.net.Uri
import
android.view.View
import
chat.rocket.android.chatroom.viewmodel.GenericFileAttachmentViewModel
import
chat.rocket.android.util.extensions.content
import
chat.rocket.android.widget.emoji.EmojiReactionListener
import
chat.rocket.common.util.ifNull
import
kotlinx.android.synthetic.main.item_file_attachment.view.*
class
GenericFileAttachmentViewHolder
(
itemView
:
View
,
listener
:
ActionsListener
,
reactionListener
:
EmojiReactionListener
?
=
null
)
:
BaseViewHolder
<
GenericFileAttachmentViewModel
>(
itemView
,
listener
,
reactionListener
)
{
init
{
with
(
itemView
)
{
setupActionMenu
(
file_attachment_container
)
setupActionMenu
(
text_file_name
)
}
}
override
fun
bindViews
(
data
:
GenericFileAttachmentViewModel
)
{
with
(
itemView
)
{
text_file_name
.
content
=
data
.
attachmentTitle
text_file_name
.
setOnClickListener
{
it
.
context
.
startActivity
(
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
data
.
attachmentUrl
)))
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/BaseViewModel.kt
View file @
9c713200
...
...
@@ -23,7 +23,8 @@ interface BaseViewModel<out T> {
AUDIO_ATTACHMENT
(
5
),
MESSAGE_ATTACHMENT
(
6
),
AUTHOR_ATTACHMENT
(
7
),
COLOR_ATTACHMENT
(
8
)
COLOR_ATTACHMENT
(
8
),
GENERIC_FILE_ATTACHMENT
(
9
)
}
}
...
...
app/src/main/java/chat/rocket/android/chatroom/viewmodel/GenericFileAttachmentViewModel.kt
0 → 100644
View file @
9c713200
package
chat.rocket.android.chatroom.viewmodel
import
chat.rocket.android.R
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.attachment.GenericFileAttachment
import
chat.rocket.core.model.attachment.ImageAttachment
data class
GenericFileAttachmentViewModel
(
override
val
message
:
Message
,
override
val
rawData
:
GenericFileAttachment
,
override
val
messageId
:
String
,
override
val
attachmentUrl
:
String
,
override
val
attachmentTitle
:
CharSequence
,
override
val
id
:
Long
,
override
var
reactions
:
List
<
ReactionViewModel
>,
override
var
nextDownStreamMessage
:
BaseViewModel
<*>?
=
null
,
override
var
preview
:
Message
?
=
null
,
override
var
isTemporary
:
Boolean
=
false
)
:
BaseFileAttachmentViewModel
<
GenericFileAttachment
>
{
override
val
viewType
:
Int
get
()
=
BaseViewModel
.
ViewType
.
GENERIC_FILE_ATTACHMENT
.
viewType
override
val
layoutId
:
Int
get
()
=
R
.
layout
.
item_file_attachment
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/ViewModelMapper.kt
View file @
9c713200
...
...
@@ -159,6 +159,7 @@ class ViewModelMapper @Inject constructor(private val context: Context,
is
ImageAttachment
->
context
.
getString
(
R
.
string
.
msg_preview_photo
)
is
VideoAttachment
->
context
.
getString
(
R
.
string
.
msg_preview_video
)
is
AudioAttachment
->
context
.
getString
(
R
.
string
.
msg_preview_audio
)
is
GenericFileAttachment
->
context
.
getString
(
R
.
string
.
msg_preview_file
)
else
->
attachment
.
text
?:
""
}
val
content
=
stripMessageQuotes
(
message
)
...
...
@@ -182,6 +183,9 @@ class ViewModelMapper @Inject constructor(private val context: Context,
is
AudioAttachment
->
AudioAttachmentViewModel
(
message
,
attachment
,
message
.
id
,
attachmentUrl
,
attachmentTitle
,
id
,
getReactions
(
message
),
preview
=
message
.
copy
(
message
=
context
.
getString
(
R
.
string
.
msg_preview_audio
)))
is
GenericFileAttachment
->
GenericFileAttachmentViewModel
(
message
,
attachment
,
message
.
id
,
attachmentUrl
,
attachmentTitle
,
id
,
getReactions
(
message
),
preview
=
message
.
copy
(
message
=
context
.
getString
(
R
.
string
.
msg_preview_file
)))
else
->
null
}
}
...
...
app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt
View file @
9c713200
...
...
@@ -169,6 +169,7 @@ class AppModule {
}
@Provides
@Singleton
fun
provideSharedPreferences
(
context
:
Application
)
=
context
.
getSharedPreferences
(
"rocket.chat"
,
Context
.
MODE_PRIVATE
)
...
...
app/src/main/java/chat/rocket/android/infrastructure/LocalRepository.kt
View file @
9c713200
...
...
@@ -7,11 +7,11 @@ interface LocalRepository {
fun
save
(
key
:
String
,
value
:
Int
)
fun
save
(
key
:
String
,
value
:
Long
)
fun
save
(
key
:
String
,
value
:
Float
)
fun
get
(
key
:
String
):
String
?
fun
getBoolean
(
key
:
String
):
Boolean
fun
getFloat
(
key
:
String
):
Float
fun
getInt
(
key
:
String
):
Int
fun
getLong
(
key
:
String
):
Long
fun
get
(
key
:
String
,
defValue
:
String
?
=
null
):
String
?
fun
getBoolean
(
key
:
String
,
defValue
:
Boolean
=
false
):
Boolean
fun
getFloat
(
key
:
String
,
defValue
:
Float
=
-
1f
):
Float
fun
getInt
(
key
:
String
,
defValue
:
Int
=
-
1
):
Int
fun
getLong
(
key
:
String
,
defValue
:
Long
=
-
1L
):
Long
fun
clear
(
key
:
String
)
fun
clearAllFromServer
(
server
:
String
)
...
...
app/src/main/java/chat/rocket/android/infrastructure/SharedPrefsLocalRepository.kt
View file @
9c713200
package
chat.rocket.android.infrastructure
import
android.content.SharedPreferences
import
androidx.core.content.edit
class
SharedPrefsLocalRepository
(
private
val
preferences
:
SharedPreferences
)
:
LocalRepository
{
override
fun
getBoolean
(
key
:
String
)
=
preferences
.
getBoolean
(
key
,
fals
e
)
override
fun
getBoolean
(
key
:
String
,
defValue
:
Boolean
)
=
preferences
.
getBoolean
(
key
,
defValu
e
)
override
fun
getFloat
(
key
:
String
)
=
preferences
.
getFloat
(
key
,
-
1f
)
override
fun
getFloat
(
key
:
String
,
defValue
:
Float
)
=
preferences
.
getFloat
(
key
,
defValue
)
override
fun
getInt
(
key
:
String
)
=
preferences
.
getInt
(
key
,
-
1
)
override
fun
getInt
(
key
:
String
,
defValue
:
Int
)
=
preferences
.
getInt
(
key
,
defValue
)
override
fun
getLong
(
key
:
String
)
=
preferences
.
getLong
(
key
,
-
1L
)
override
fun
getLong
(
key
:
String
,
defValue
:
Long
)
=
preferences
.
getLong
(
key
,
defValue
)
override
fun
save
(
key
:
String
,
value
:
Int
)
=
preferences
.
edit
().
putInt
(
key
,
value
).
apply
()
override
fun
save
(
key
:
String
,
value
:
Int
)
=
preferences
.
edit
{
putInt
(
key
,
value
)
}
override
fun
save
(
key
:
String
,
value
:
Float
)
=
preferences
.
edit
().
putFloat
(
key
,
value
).
apply
()
override
fun
save
(
key
:
String
,
value
:
Float
)
=
preferences
.
edit
{
putFloat
(
key
,
value
)
}
override
fun
save
(
key
:
String
,
value
:
Long
)
=
preferences
.
edit
().
putLong
(
key
,
value
).
apply
()
override
fun
save
(
key
:
String
,
value
:
Long
)
=
preferences
.
edit
{
putLong
(
key
,
value
)
}
override
fun
save
(
key
:
String
,
value
:
Boolean
)
=
preferences
.
edit
().
putBoolean
(
key
,
value
).
apply
()
override
fun
save
(
key
:
String
,
value
:
Boolean
)
=
preferences
.
edit
{
putBoolean
(
key
,
value
)
}
override
fun
save
(
key
:
String
,
value
:
String
?)
=
preferences
.
edit
().
putString
(
key
,
value
).
apply
()
override
fun
save
(
key
:
String
,
value
:
String
?)
=
preferences
.
edit
{
putString
(
key
,
value
)
}
override
fun
get
(
key
:
String
):
String
?
=
preferences
.
getString
(
key
,
null
)
override
fun
get
(
key
:
String
,
defValue
:
String
?):
String
?
=
preferences
.
getString
(
key
,
defValue
)
override
fun
clear
(
key
:
String
)
=
preferences
.
edit
().
remove
(
key
).
apply
()
override
fun
clear
(
key
:
String
)
=
preferences
.
edit
{
remove
(
key
)
}
override
fun
clearAllFromServer
(
server
:
String
)
{
clear
(
LocalRepository
.
KEY_PUSH_TOKEN
)
...
...
app/src/main/res/layout/item_author_attachment.xml
View file @
9c713200
...
...
@@ -53,8 +53,7 @@
android:layout_marginTop=
"4dp"
app:layout_constraintTop_toBottomOf=
"@id/text_author_name"
app:layout_constraintStart_toStartOf=
"@id/text_author_name"
app:layout_constraintEnd_toEndOf=
"parent"
tools:visibility=
"visible"
/>
app:layout_constraintEnd_toEndOf=
"parent"
/>
<include
layout=
"@layout/layout_reactions"
...
...
app/src/main/res/layout/item_file_attachment.xml
0 → 100644
View file @
9c713200
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/file_attachment_container"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:background=
"?android:attr/selectableItemBackground"
android:clickable=
"true"
android:focusable=
"true"
android:paddingBottom=
"@dimen/message_item_top_and_bottom_padding"
android:paddingEnd=
"@dimen/screen_edge_left_and_right_padding"
android:paddingStart=
"@dimen/screen_edge_left_and_right_padding"
>
<TextView
android:id=
"@+id/text_file_name"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"56dp"
android:textColor=
"@color/colorAccent"
android:textAppearance=
"@style/TextAppearance.AppCompat.Body2"
android:drawableStart=
"@drawable/ic_files_24dp"
android:drawablePadding=
"6dp"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
tools:text=
"This is a very, very, very long filename, to test how the layout will work on very very very long filenames.pdf"
/>
<include
layout=
"@layout/layout_reactions"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
app:layout_constraintStart_toStartOf=
"@id/text_file_name"
app:layout_constraintTop_toBottomOf=
"@id/text_file_name"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
9c713200
...
...
@@ -81,6 +81,7 @@
<string
name=
"msg_preview_video"
>
Video
</string>
<string
name=
"msg_preview_audio"
>
Audio
</string>
<string
name=
"msg_preview_photo"
>
Photo
</string>
<string
name=
"msg_preview_file"
>
File
</string>
<string
name=
"msg_no_messages_yet"
>
No messages yet
</string>
<string
name=
"msg_version"
>
Version %1$s
</string>
<string
name=
"msg_build"
>
Build %1$d
</string>
...
...
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