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
b91de115
Commit
b91de115
authored
May 01, 2019
by
Hussein El Feky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reformatted code
parent
1f56cb65
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
31 deletions
+50
-31
SettingsPresenter.kt
...rocket/android/settings/presentation/SettingsPresenter.kt
+11
-2
SettingsFragment.kt
.../java/chat/rocket/android/settings/ui/SettingsFragment.kt
+39
-29
No files found.
app/src/main/java/chat/rocket/android/settings/presentation/SettingsPresenter.kt
View file @
b91de115
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
...
...
@@ -41,7 +43,6 @@ class SettingsPresenter @Inject constructor(
private
val
permissions
:
PermissionsInteractor
,
private
val
rocketChatClientFactory
:
RocketChatClientFactory
,
private
val
saveLanguageInteractor
:
SaveCurrentLanguageInteractor
,
val
getCurrentLanguageInteractor
:
GetCurrentLanguageInteractor
,
getCurrentServerInteractor
:
GetCurrentServerInteractor
,
removeAccountInteractor
:
RemoveAccountInteractor
,
databaseManagerFactory
:
DatabaseManagerFactory
,
...
...
@@ -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 @
b91de115
...
...
@@ -165,33 +165,41 @@ class SettingsFragment : Fragment(), SettingsView, AppLanguageView {
private
fun
changeLanguage
()
{
context
?.
let
{
val
locales
=
ArrayList
<
Pair
<
String
,
String
>>()
with
(
locales
)
{
add
(
Pair
(
"en"
,
""
))
add
(
Pair
(
"ar"
,
""
))
add
(
Pair
(
"de"
,
""
))
add
(
Pair
(
"es"
,
""
))
add
(
Pair
(
"fa"
,
""
))
add
(
Pair
(
"fr"
,
""
))
add
(
Pair
(
"hi"
,
"IN"
))
add
(
Pair
(
"it"
,
""
))
add
(
Pair
(
"ja"
,
""
))
add
(
Pair
(
"pt"
,
"BR"
))
add
(
Pair
(
"pt"
,
"PT"
))
add
(
Pair
(
"ru"
,
"RU"
))
add
(
Pair
(
"tr"
,
""
))
add
(
Pair
(
"uk"
,
""
))
add
(
Pair
(
"zh"
,
"CN"
))
add
(
Pair
(
"zh"
,
"TW"
))
}
val
selectedLanguage
=
presenter
.
getCurrentLanguageInteractor
.
getLanguage
(
)
val
selected
Country
=
presenter
.
getCurrentLanguageInteractor
.
getCountry
(
)
// Add [String] for locales without specified countries, and
// add [Pair] for locales with specified countries.
val
locales
=
arrayOf
(
"en"
,
"ar"
,
"de"
,
"es"
,
"fa"
,
"fr"
,
Pair
(
"hi"
,
"IN"
),
"it"
,
"ja"
,
Pair
(
"pt"
,
"BR"
),
Pair
(
"pt"
,
"PT"
),
Pair
(
"ru"
,
"RU"
),
"tr"
,
"uk"
,
Pair
(
"zh"
,
"CN"
),
Pair
(
"zh"
,
"TW"
)
)
val
selected
Locale
=
presenter
.
getCurrentLocale
(
it
)
var
localeIndex
=
-
1
locales
.
forEachIndexed
{
index
,
locale
->
// If country is specified, then return the respective locale, else return the
// first locale found if the language is as specified regardless of the country.
if
(
locale
.
first
==
selectedLanguage
)
{
if
(
locale
.
second
==
selectedCountry
)
{
var
language
:
String
?
=
null
var
country
=
""
if
(
locale
is
String
)
{
language
=
locale
}
else
if
(
locale
is
Pair
<*,
*>)
{
language
=
locale
.
first
as
String
country
=
locale
.
second
as
String
}
// 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
)
{
...
...
@@ -199,15 +207,17 @@ class SettingsFragment : Fragment(), SettingsView, AppLanguageView {
}
}
}
// This is needed if none of the device locales is implemented in the app.
// By default, set locale will be English
if
(
localeIndex
==
-
1
)
localeIndex
=
0
AlertDialog
.
Builder
(
it
)
.
setTitle
(
R
.
string
.
title_choose_language
)
.
setSingleChoiceItems
(
resources
.
getStringArray
(
R
.
array
.
languages
),
localeIndex
)
{
dialog
,
option
->
updateLanguage
(
locales
[
option
].
first
,
locales
[
option
].
second
)
if
(
locales
[
option
]
is
String
)
{
updateLanguage
(
locales
[
option
]
as
String
)
}
else
if
(
locales
[
option
]
is
Pair
<*,
*>)
{
updateLanguage
((
locales
[
option
]
as
Pair
<*,
*>).
first
as
String
,
(
locales
[
option
]
as
Pair
<*,
*>).
second
as
String
)
}
dialog
.
dismiss
()
}
.
create
()
...
...
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