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
9bcc0f5c
Commit
9bcc0f5c
authored
Apr 27, 2019
by
Hussein El Feky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Showed the selected locale in Language setter
parent
521f0a8b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
26 deletions
+45
-26
SharedPrefsCurrentLanguageRepository.kt
...er/infrastructure/SharedPrefsCurrentLanguageRepository.kt
+3
-2
SettingsPresenter.kt
...rocket/android/settings/presentation/SettingsPresenter.kt
+3
-3
SettingsFragment.kt
.../java/chat/rocket/android/settings/ui/SettingsFragment.kt
+39
-21
No files found.
app/src/main/java/chat/rocket/android/server/infrastructure/SharedPrefsCurrentLanguageRepository.kt
View file @
9bcc0f5c
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 @
9bcc0f5c
...
...
@@ -40,11 +40,12 @@ class SettingsPresenter @Inject constructor(
private
val
tokenRepository
:
TokenRepository
,
private
val
permissions
:
PermissionsInteractor
,
private
val
rocketChatClientFactory
:
RocketChatClientFactory
,
private
val
saveLanguageInteractor
:
SaveCurrentLanguageInteractor
,
val
getCurrentLanguageInteractor
:
GetCurrentLanguageInteractor
,
getCurrentServerInteractor
:
GetCurrentServerInteractor
,
removeAccountInteractor
:
RemoveAccountInteractor
,
databaseManagerFactory
:
DatabaseManagerFactory
,
connectionManagerFactory
:
ConnectionManagerFactory
,
private
val
saveLanguageInteractor
:
SaveCurrentLanguageInteractor
connectionManagerFactory
:
ConnectionManagerFactory
)
:
CheckServerPresenter
(
strategy
=
strategy
,
factory
=
rocketChatClientFactory
,
...
...
@@ -92,7 +93,6 @@ class SettingsPresenter @Inject constructor(
fun
enableAnalyticsTracking
(
isEnabled
:
Boolean
)
{
analyticsTrackingInteractor
.
save
(
isEnabled
)
}
fun
logout
()
{
...
...
app/src/main/java/chat/rocket/android/settings/ui/SettingsFragment.kt
View file @
9bcc0f5c
...
...
@@ -35,8 +35,10 @@ 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
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -163,29 +165,45 @@ 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
selectedCountry
=
presenter
.
getCurrentLanguageInteractor
.
getCountry
()
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
&&
(
localeIndex
==
-
1
||
locale
.
second
==
selectedCountry
))
{
localeIndex
=
index
if
(
locale
.
second
==
selectedCountry
)
return
@forEachIndexed
}
}
// 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
),
-
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"
)
}
updateLanguage
(
locales
[
option
].
first
,
locales
[
option
].
second
)
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