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
cc83b9ea
Unverified
Commit
cc83b9ea
authored
May 14, 2019
by
Filipe Brito
Committed by
GitHub
May 14, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into viewpager-rtl
parents
8f8cb4c8
556733e8
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
136 additions
and
68 deletions
+136
-68
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+40
-10
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+15
-11
SharedPrefsCurrentLanguageRepository.kt
...er/infrastructure/SharedPrefsCurrentLanguageRepository.kt
+3
-2
SettingsPresenter.kt
...rocket/android/settings/presentation/SettingsPresenter.kt
+13
-4
SettingsFragment.kt
.../java/chat/rocket/android/settings/ui/SettingsFragment.kt
+46
-21
strings.xml
app/src/main/res/values-de/strings.xml
+19
-20
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
cc83b9ea
...
...
@@ -124,6 +124,7 @@ class ChatRoomPresenter @Inject constructor(
private
var
lastState
=
manager
.
state
private
var
typingStatusList
=
arrayListOf
<
String
>()
private
val
roomChangesChannel
=
Channel
<
Room
>(
Channel
.
CONFLATED
)
private
var
lastMessageId
:
String
?
=
null
private
lateinit
var
draftKey
:
String
fun
setupChatRoom
(
...
...
@@ -223,6 +224,7 @@ class ChatRoomPresenter @Inject constructor(
isBroadcast
=
chatIsBroadcast
,
isRoom
=
true
)
)
lastMessageId
=
localMessages
.
firstOrNull
()
?.
id
val
lastSyncDate
=
messagesRepository
.
getLastSyncDate
(
chatRoomId
)
if
(
oldMessages
.
isNotEmpty
()
&&
lastSyncDate
!=
null
)
{
view
.
showMessages
(
oldMessages
,
clearDataSet
)
...
...
@@ -235,7 +237,7 @@ class ChatRoomPresenter @Inject constructor(
}
// TODO: For now we are marking the room as read if we can get the messages (I mean, no exception occurs)
// but should mark only when the user see the first unread message.
// but should mark only when the user see
s
the first unread message.
markRoomAsRead
(
chatRoomId
)
subscribeMessages
(
chatRoomId
)
...
...
@@ -371,6 +373,7 @@ class ChatRoomPresenter @Inject constructor(
throw
ex
}
}
lastMessageId
=
id
}
else
{
client
.
updateMessage
(
chatRoomId
,
messageId
,
text
)
}
...
...
@@ -1089,6 +1092,31 @@ class ChatRoomPresenter @Inject constructor(
}
}
fun
reactToLastMessage
(
text
:
String
,
roomId
:
String
)
{
launchUI
(
strategy
)
{
lastMessageId
?.
let
{
messageId
->
val
emoji
=
text
.
substring
(
1
).
trimEnd
()
if
(
emoji
.
length
>=
2
&&
emoji
.
startsWith
(
":"
)
&&
emoji
.
endsWith
(
":"
))
{
try
{
retryIO
(
"toggleEmoji($messageId, $emoji)"
)
{
client
.
toggleReaction
(
messageId
,
emoji
.
removeSurrounding
(
":"
))
}
logReactionEvent
()
view
.
clearMessageComposition
(
true
)
}
catch
(
ex
:
RocketChatException
)
{
Timber
.
e
(
ex
)
// emoji is not valid, post it
sendMessage
(
roomId
,
text
,
null
)
}
}
else
{
sendMessage
(
roomId
,
text
,
null
)
}
}.
ifNull
{
sendMessage
(
roomId
,
text
,
null
)
}
}
}
private
fun
logReactionEvent
()
{
when
{
roomTypeOf
(
chatRoomType
)
is
RoomType
.
DirectMessage
->
...
...
@@ -1162,18 +1190,19 @@ class ChatRoomPresenter @Inject constructor(
sendMessage
(
roomId
,
text
,
null
)
}
else
{
view
.
disableSendMessageButton
()
val
command
=
text
.
split
(
" "
)
va
l
name
=
command
[
0
].
substring
(
1
)
val
index
=
text
.
indexOf
(
" "
)
va
r
name
=
""
var
params
=
""
command
.
forEachIndexed
{
index
,
param
->
if
(
index
>
0
)
{
params
+=
"$param "
}
if
(
index
>=
1
)
{
name
=
text
.
substring
(
1
,
index
)
params
=
text
.
substring
(
index
+
1
).
trim
()
}
val
result
=
retryIO
(
"runCommand($name, $params, $roomId)"
)
{
client
.
runCommand
(
Command
(
name
,
params
),
roomId
)
}
if
(!
result
)
{
if
(
result
)
{
view
.
clearMessageComposition
(
true
)
}
else
{
// failed, command is not valid so post it
sendMessage
(
roomId
,
text
,
null
)
}
...
...
@@ -1286,6 +1315,7 @@ class ChatRoomPresenter @Inject constructor(
fun
clearDraftMessage
()
{
localRepository
.
clear
(
draftKey
)
}
/**
* Get unfinished message from local repository, when user left chat room without
* sending a message and now the user is back.
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
cc83b9ea
...
...
@@ -148,10 +148,14 @@ private const val BUNDLE_CHAT_ROOM_MESSAGE = "chat_room_message"
class
ChatRoomFragment
:
Fragment
(),
ChatRoomView
,
EmojiKeyboardListener
,
EmojiReactionListener
,
ChatRoomAdapter
.
OnActionSelected
,
Drawable
.
Callback
{
@Inject
lateinit
var
presenter
:
ChatRoomPresenter
@Inject
lateinit
var
parser
:
MessageParser
@Inject
lateinit
var
analyticsManager
:
AnalyticsManager
@Inject
lateinit
var
navigator
:
ChatRoomNavigator
@Inject
lateinit
var
presenter
:
ChatRoomPresenter
@Inject
lateinit
var
parser
:
MessageParser
@Inject
lateinit
var
analyticsManager
:
AnalyticsManager
@Inject
lateinit
var
navigator
:
ChatRoomNavigator
private
lateinit
var
adapter
:
ChatRoomAdapter
internal
lateinit
var
chatRoomId
:
String
private
lateinit
var
chatRoomName
:
String
...
...
@@ -472,14 +476,15 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
override
fun
sendMessage
(
text
:
String
)
{
ui
{
if
(!
text
.
isBlank
())
{
if
(!
text
.
startsWith
(
"/"
))
{
presenter
.
sendMessage
(
chatRoomId
,
text
,
editingMessageId
)
}
else
{
if
(
text
.
startsWith
(
"/"
))
{
presenter
.
runCommand
(
text
,
chatRoomId
)
}
else
if
(
text
.
startsWith
(
"+"
))
{
presenter
.
reactToLastMessage
(
text
,
chatRoomId
)
}
else
{
presenter
.
sendMessage
(
chatRoomId
,
text
,
editingMessageId
)
}
}
}
...
...
@@ -524,7 +529,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
override
fun
clearMessageComposition
(
deleteMessage
:
Boolean
)
{
ui
{
citation
=
null
...
...
@@ -896,7 +900,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
button_take_a_photo
.
setOnClickListener
{
// Check for camera permission
context
?.
let
{
if
(
hasCameraPermission
(
it
))
{
if
(
hasCameraPermission
(
it
))
{
dispatchTakePictureIntent
()
}
else
{
getCameraPermission
(
this
)
...
...
@@ -964,7 +968,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
grantResults
:
IntArray
)
{
super
.
onRequestPermissionsResult
(
requestCode
,
permissions
,
grantResults
)
when
(
requestCode
)
{
when
(
requestCode
)
{
AndroidPermissionsHelper
.
CAMERA_CODE
->
{
if
(
grantResults
.
isNotEmpty
()
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
// permission was granted
...
...
app/src/main/java/chat/rocket/android/server/infrastructure/SharedPrefsCurrentLanguageRepository.kt
View file @
cc83b9ea
package
chat.rocket.android.server.infrastructure
import
android.content.SharedPreferences
import
java.util.*
private
const
val
CURRENT_LANGUAGE
=
"current_language"
private
const
val
CURRENT_LANGUAGE_COUNTRY
=
"current_language_country"
...
...
@@ -16,10 +17,10 @@ class SharedPrefsCurrentLanguageRepository(private val preferences: SharedPrefer
}
override
fun
getLanguage
():
String
?
{
return
preferences
.
getString
(
CURRENT_LANGUAGE
,
""
)
return
preferences
.
getString
(
CURRENT_LANGUAGE
,
Locale
.
getDefault
().
language
)
}
override
fun
getCountry
():
String
?
{
return
preferences
.
getString
(
CURRENT_LANGUAGE_COUNTRY
,
""
)
return
preferences
.
getString
(
CURRENT_LANGUAGE_COUNTRY
,
Locale
.
getDefault
().
country
)
}
}
app/src/main/java/chat/rocket/android/settings/presentation/SettingsPresenter.kt
View file @
cc83b9ea
package
chat.rocket.android.settings.presentation
import
android.content.Context
import
android.os.Build
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.db.DatabaseManagerFactory
import
chat.rocket.android.helper.UserHelper
import
chat.rocket.android.main.presentation.MainNavigator
import
chat.rocket.android.server.domain.AnalyticsTrackingInteractor
import
chat.rocket.android.server.domain.GetCurrentLanguageInteractor
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.server.domain.PermissionsInteractor
import
chat.rocket.android.server.domain.RemoveAccountInteractor
...
...
@@ -27,6 +28,7 @@ import chat.rocket.core.internal.rest.serverInfo
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.withContext
import
timber.log.Timber
import
java.util.*
import
javax.inject.Inject
import
javax.inject.Named
...
...
@@ -40,11 +42,11 @@ class SettingsPresenter @Inject constructor(
private
val
tokenRepository
:
TokenRepository
,
private
val
permissions
:
PermissionsInteractor
,
private
val
rocketChatClientFactory
:
RocketChatClientFactory
,
private
val
saveLanguageInteractor
:
SaveCurrentLanguageInteractor
,
getCurrentServerInteractor
:
GetCurrentServerInteractor
,
removeAccountInteractor
:
RemoveAccountInteractor
,
databaseManagerFactory
:
DatabaseManagerFactory
,
connectionManagerFactory
:
ConnectionManagerFactory
,
private
val
saveLanguageInteractor
:
SaveCurrentLanguageInteractor
connectionManagerFactory
:
ConnectionManagerFactory
)
:
CheckServerPresenter
(
strategy
=
strategy
,
factory
=
rocketChatClientFactory
,
...
...
@@ -93,7 +95,6 @@ class SettingsPresenter @Inject constructor(
fun
enableAnalyticsTracking
(
isEnabled
:
Boolean
)
{
analyticsTrackingInteractor
.
save
(
isEnabled
)
}
fun
logout
()
{
...
...
@@ -127,6 +128,14 @@ class SettingsPresenter @Inject constructor(
}
}
fun
getCurrentLocale
(
context
:
Context
):
Locale
{
return
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
{
context
.
resources
.
configuration
.
locales
.
get
(
0
)
}
else
{
context
.
resources
.
configuration
.
locale
}
}
fun
saveLocale
(
language
:
String
,
country
:
String
?
=
null
)
{
saveLanguageInteractor
.
save
(
language
,
country
)
}
...
...
app/src/main/java/chat/rocket/android/settings/ui/SettingsFragment.kt
View file @
cc83b9ea
...
...
@@ -35,8 +35,28 @@ internal const val TAG_SETTINGS_FRAGMENT = "SettingsFragment"
fun
newInstance
():
Fragment
=
SettingsFragment
()
class
SettingsFragment
:
Fragment
(),
SettingsView
,
AppLanguageView
{
@Inject
lateinit
var
analyticsManager
:
AnalyticsManager
@Inject
lateinit
var
presenter
:
SettingsPresenter
@Inject
lateinit
var
analyticsManager
:
AnalyticsManager
@Inject
lateinit
var
presenter
:
SettingsPresenter
private
val
locales
=
arrayListOf
(
"en"
,
"ar"
,
"de"
,
"es"
,
"fa"
,
"fr"
,
"hi,IN"
,
"it"
,
"ja"
,
"pt,BR"
,
"pt,PT"
,
"ru,RU"
,
"tr"
,
"uk"
,
"zh,CN"
,
"zh,TW"
)
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -163,28 +183,33 @@ class SettingsFragment : Fragment(), SettingsView, AppLanguageView {
private
fun
changeLanguage
()
{
context
?.
let
{
val
selectedLocale
=
presenter
.
getCurrentLocale
(
it
)
var
localeIndex
=
-
1
locales
.
forEachIndexed
{
index
,
locale
->
val
array
=
locale
.
split
(
","
)
val
language
=
array
[
0
]
val
country
=
if
(
array
.
size
>
1
)
array
[
1
]
else
""
// If language and country are specified, return the respective locale, else return
// the first locale found if the language is as specified regardless of the country.
if
(
language
==
selectedLocale
.
language
)
{
if
(
country
==
selectedLocale
.
country
)
{
localeIndex
=
index
return
@forEachIndexed
}
else
if
(
localeIndex
==
-
1
)
{
localeIndex
=
index
}
}
}
AlertDialog
.
Builder
(
it
)
.
setTitle
(
R
.
string
.
title_choose_language
)
.
setSingleChoiceItems
(
resources
.
getStringArray
(
R
.
array
.
languages
),
-
1
resources
.
getStringArray
(
R
.
array
.
languages
),
localeIndex
)
{
dialog
,
option
->
when
(
option
)
{
0
->
updateLanguage
(
"en"
)
1
->
updateLanguage
(
"ar"
)
2
->
updateLanguage
(
"de"
)
3
->
updateLanguage
(
"es"
)
4
->
updateLanguage
(
"fa"
)
5
->
updateLanguage
(
"fr"
)
6
->
updateLanguage
(
"hi"
,
"IN"
)
7
->
updateLanguage
(
"it"
)
8
->
updateLanguage
(
"ja"
)
9
->
updateLanguage
(
"pt"
,
"BR"
)
10
->
updateLanguage
(
"pt"
,
"PT"
)
11
->
updateLanguage
(
"ru"
,
"RU"
)
12
->
updateLanguage
(
"tr"
)
13
->
updateLanguage
(
"uk"
)
14
->
updateLanguage
(
"zh"
,
"CN"
)
15
->
updateLanguage
(
"zh"
,
"TW"
)
val
array
=
locales
[
option
].
split
(
","
)
if
(
array
.
size
>
1
)
{
updateLanguage
(
array
[
0
],
array
[
1
])
}
else
{
updateLanguage
(
array
[
0
])
}
dialog
.
dismiss
()
}
...
...
app/src/main/res/values-de/strings.xml
View file @
cc83b9ea
...
...
@@ -9,7 +9,7 @@
<string
name=
"title_authentication"
>
Login Daten prüfen
</string>
<string
name=
"title_legal_terms"
>
Legal Terms
</string>
<string
name=
"title_chats"
>
Chats
</string>
<string
name=
"title_choose_language"
>
Choose Language
</string>
<!-- TODO Add translation --
>
<string
name=
"title_choose_language"
>
Sprache wählen
</string
>
<string
name=
"title_profile"
>
Profil
</string>
<string
name=
"title_members"
>
Benutzer
</string>
<string
name=
"title_counted_members"
>
Benutzer (%d)
</string>
...
...
@@ -77,23 +77,23 @@
<string
name=
"msg_delete_account"
>
Konto löschen
</string>
<string
name=
"msg_change_status"
>
Status ändern
</string>
<string-array
name=
"languages"
>
<!-- TODO Add translations -->
<item>
English
</item>
<item>
Arabi
c
</item>
<item>
German
</item>
<item>
Spanish
</item>
<item>
Persi
an
</item>
<item>
Fr
en
ch
</item>
<string-array
name=
"languages"
>
<item>
Englis
c
h
</item>
<item>
Arabi
sch
</item>
<item>
Deutsch
</item>
<item>
Spanis
c
h
</item>
<item>
Persi
sch
</item>
<item>
Fr
anzösis
ch
</item>
<item>
Hindi (IN)
</item>
<item>
Itali
an
</item>
<item>
Japan
ese
</item>
<item>
Portug
uese
(BR)
</item>
<item>
Portug
uese
(PT)
</item>
<item>
Russi
an
(RU)
</item>
<item>
T
urkis
h
</item>
<item>
Ukraini
an
</item>
<item>
Chines
e
(CN)
</item>
<item>
Chines
e
(TW)
</item>
<item>
Itali
enisch
</item>
<item>
Japan
isch
</item>
<item>
Portug
iesisch
(BR)
</item>
<item>
Portug
iesisch
(PT)
</item>
<item>
Russi
sch
(RU)
</item>
<item>
T
ürkisc
h
</item>
<item>
Ukraini
sch
</item>
<item>
Chines
isch
(CN)
</item>
<item>
Chines
isch
(TW)
</item>
</string-array>
<!-- Regular information messages -->
...
...
@@ -360,9 +360,8 @@
<!-- User Details -->
<string
name=
"timezone"
>
Zeitzone
</string>
<string
name=
"status"
>
Status: %1$s
</string>
<!-- TODO Translate -->
<string
name=
"user_detail_status"
>
Status
</string>
<!-- TODO Translate -->
<string
name=
"status"
>
Status: %1$s
</string>
<string
name=
"user_detail_status"
>
Status
</string>
<!-- Report -->
<string
name=
"submit"
>
Senden
</string>
<string
name=
"required"
>
*erforderlich
</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