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
010a714e
Commit
010a714e
authored
Mar 20, 2019
by
Govind Dixit
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Add multi language support to app
parent
c83e48dd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
96 additions
and
64 deletions
+96
-64
AppModule.kt
.../main/java/chat/rocket/android/dagger/module/AppModule.kt
+8
-0
MainActivity.kt
...src/main/java/chat/rocket/android/main/ui/MainActivity.kt
+17
-62
GetCurrentLanguageInteractor.kt
...ket/android/server/domain/GetCurrentLanguageInteractor.kt
+11
-0
SaveCurrentLanguageInteractor.kt
...et/android/server/domain/SaveCurrentLanguageInteractor.kt
+10
-0
SettingsFragment.kt
.../java/chat/rocket/android/settings/ui/SettingsFragment.kt
+50
-2
No files found.
app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt
View file @
010a714e
...
...
@@ -43,6 +43,8 @@ import chat.rocket.android.server.domain.UsersRepository
import
chat.rocket.android.server.domain.BasicAuthRepository
import
chat.rocket.android.server.domain.GetBasicAuthInteractor
import
chat.rocket.android.server.domain.SaveBasicAuthInteractor
import
chat.rocket.android.server.infraestructure.CurrentLanguageRepository
import
chat.rocket.android.server.infraestructure.SharedPrefsCurrentLanguageRepository
import
chat.rocket.android.server.infraestructure.SharedPrefsBasicAuthRepository
import
chat.rocket.android.server.infraestructure.DatabaseMessageMapper
import
chat.rocket.android.server.infraestructure.DatabaseMessagesRepository
...
...
@@ -201,6 +203,12 @@ class AppModule {
return
SharedPrefsConnectingServerRepository
(
prefs
)
}
@Provides
@Singleton
fun
provideCurrentLanguageRepository
(
prefs
:
SharedPreferences
):
CurrentLanguageRepository
{
return
SharedPrefsCurrentLanguageRepository
(
prefs
)
}
@Provides
@Singleton
fun
provideSettingsRepository
(
localRepository
:
LocalRepository
):
SettingsRepository
{
...
...
app/src/main/java/chat/rocket/android/main/ui/MainActivity.kt
View file @
010a714e
...
...
@@ -39,14 +39,17 @@ import dagger.android.support.HasSupportFragmentInjector
import
kotlinx.android.synthetic.main.activity_main.*
import
kotlinx.android.synthetic.main.app_bar.*
import
kotlinx.android.synthetic.main.nav_header.view.*
import
java.util.Locale
import
javax.inject.Inject
import
android.app.NotificationManager
import
chat.rocket.android.server.domain.GetCurrentLanguageInteractor
import
chat.rocket.android.server.domain.SaveCurrentLanguageInteractor
import
java.util.Locale
private
const
val
CURRENT_STATE
=
"current_state"
private
const
val
SETTING
=
"Settings"
private
const
val
MY_LANG
=
"My_Lang"
private
const
val
SETTING
=
"settings"
private
const
val
MY_LANG
=
"my_lang"
class
MainActivity
:
AppCompatActivity
(),
MainView
,
HasActivityInjector
,
HasSupportFragmentInjector
{
...
...
@@ -58,6 +61,10 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
lateinit
var
presenter
:
MainPresenter
@Inject
lateinit
var
permissions
:
PermissionsInteractor
@Inject
lateinit
var
getLanguageInteractor
:
GetCurrentLanguageInteractor
@Inject
lateinit
var
saveLanguageInteractor
:
SaveCurrentLanguageInteractor
private
var
isFragmentAdded
:
Boolean
=
false
private
var
expanded
=
false
private
val
headerLayout
by
lazy
{
view_navigation
.
getHeaderView
(
0
)
}
...
...
@@ -285,78 +292,26 @@ class MainActivity : AppCompatActivity(), MainView, HasActivityInjector,
progressDialog
=
null
}
fun
changeLanguage
()
{
val
languages
=
resources
.
getStringArray
(
R
.
array
.
languages
)
val
builder
=
AlertDialog
.
Builder
(
this
)
builder
.
setTitle
(
R
.
string
.
title_choose_language
)
builder
.
setSingleChoiceItems
(
languages
,
-
1
)
{
dialog
,
which
->
when
(
which
){
0
->{
setLocale
(
"en"
)
recreate
()
}
1
->{
setLocale
(
"hi"
)
recreate
()
}
2
->{
setLocale
(
"ja"
)
recreate
()
}
3
->{
setLocale
(
"ru"
)
recreate
()
}
4
->{
setLocale
(
"it"
)
recreate
()
}
5
->{
setLocaleWithRegion
(
"pt"
,
"BR"
)
recreate
()
}
6
->{
setLocaleWithRegion
(
"pt"
,
"PT"
)
recreate
()
}
7
->{
setLocale
(
"zh"
)
recreate
()
}
}
dialog
.
dismiss
()
}
builder
.
create
().
show
()
private
fun
loadLocale
()
{
val
currentLanguage
=
getLanguageInteractor
.
get
()
!!
setLocale
(
currentLanguage
)
}
private
fun
setLocale
(
lang
:
String
)
{
fun
setLocale
(
lang
:
String
)
{
val
locale
=
Locale
(
lang
)
Locale
.
setDefault
(
locale
)
val
config
=
Configuration
()
config
.
locale
=
locale
baseContext
.
resources
.
updateConfiguration
(
config
,
baseContext
.
resources
.
displayMetrics
)
val
editor
=
getSharedPreferences
(
SETTING
,
Context
.
MODE_PRIVATE
).
edit
()
editor
.
putString
(
MY_LANG
,
lang
)
editor
.
apply
()
saveLanguageInteractor
.
save
(
lang
)
}
private
fun
setLocaleWithRegion
(
lang
:
String
,
country
:
String
)
{
fun
setLocaleWithRegion
(
lang
:
String
,
country
:
String
)
{
val
locale
=
Locale
(
lang
,
country
)
Locale
.
setDefault
(
locale
)
val
config
=
Configuration
()
config
.
locale
=
locale
baseContext
.
resources
.
updateConfiguration
(
config
,
baseContext
.
resources
.
displayMetrics
)
val
editor
=
getSharedPreferences
(
SETTING
,
Context
.
MODE_PRIVATE
).
edit
()
editor
.
putString
(
MY_LANG
,
lang
)
editor
.
apply
()
}
private
fun
loadLocale
()
{
val
sharedPreferences
=
getSharedPreferences
(
SETTING
,
Activity
.
MODE_PRIVATE
)
val
language
=
sharedPreferences
.
getString
(
MY_LANG
,
""
)
setLocale
(
language
)
saveLanguageInteractor
.
save
(
lang
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/domain/GetCurrentLanguageInteractor.kt
0 → 100644
View file @
010a714e
package
chat.rocket.android.server.domain
import
chat.rocket.android.server.infraestructure.CurrentLanguageRepository
import
javax.inject.Inject
class
GetCurrentLanguageInteractor
@Inject
constructor
(
private
val
repository
:
CurrentLanguageRepository
)
{
fun
get
():
String
?
=
repository
.
get
()
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/domain/SaveCurrentLanguageInteractor.kt
0 → 100644
View file @
010a714e
package
chat.rocket.android.server.domain
import
chat.rocket.android.server.infraestructure.CurrentLanguageRepository
import
javax.inject.Inject
class
SaveCurrentLanguageInteractor
@Inject
constructor
(
private
val
repository
:
CurrentLanguageRepository
)
{
fun
save
(
language
:
String
)
=
repository
.
save
(
language
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/settings/ui/SettingsFragment.kt
View file @
010a714e
...
...
@@ -8,6 +8,7 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.AdapterView
import
androidx.appcompat.app.AlertDialog
import
androidx.appcompat.app.AppCompatActivity
import
androidx.core.net.toUri
import
androidx.fragment.app.Fragment
...
...
@@ -24,7 +25,6 @@ import chat.rocket.android.settings.password.ui.PasswordActivity
import
chat.rocket.android.settings.presentation.SettingsView
import
chat.rocket.android.util.extensions.addFragmentBackStack
import
chat.rocket.android.util.extensions.inflate
import
chat.rocket.android.util.extensions.showToast
import
chat.rocket.android.webview.ui.webViewIntent
import
dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_settings.*
...
...
@@ -75,7 +75,7 @@ class SettingsFragment : Fragment(), SettingsView, AdapterView.OnItemClickListen
resources
.
getStringArray
(
R
.
array
.
settings_actions
)[
1
]
->
activity
?.
startActivity
(
Intent
(
activity
,
PasswordActivity
::
class
.
java
))
resources
.
getStringArray
(
R
.
array
.
settings_actions
)[
2
]
->
(
activity
as
?
MainActivity
)
?.
changeLanguage
()
resources
.
getStringArray
(
R
.
array
.
settings_actions
)[
2
]
->
changeLanguage
()
resources
.
getStringArray
(
R
.
array
.
settings_actions
)[
3
]
->
shareApp
()
...
...
@@ -141,6 +141,54 @@ class SettingsFragment : Fragment(), SettingsView, AdapterView.OnItemClickListen
}
}
fun
changeLanguage
()
{
val
languages
=
resources
.
getStringArray
(
R
.
array
.
languages
)
val
mainActivity
=(
activity
as
?
MainActivity
)
context
?.
let
{
AlertDialog
.
Builder
(
it
)
.
setTitle
(
R
.
string
.
title_choose_language
)
.
setSingleChoiceItems
(
languages
,
-
1
)
{
dialog
,
which
->
when
(
which
)
{
0
->
{
mainActivity
?.
setLocale
(
"en"
)
activity
?.
recreate
()
}
1
->
{
mainActivity
?.
setLocale
(
"hi"
)
activity
?.
recreate
()
}
2
->
{
mainActivity
?.
setLocale
(
"ja"
)
activity
?.
recreate
()
}
3
->
{
mainActivity
?.
setLocale
(
"ru"
)
activity
?.
recreate
()
}
4
->
{
mainActivity
?.
setLocale
(
"it"
)
activity
?.
recreate
()
}
5
->{
mainActivity
?.
setLocaleWithRegion
(
"pt"
,
"BR"
)
activity
?.
recreate
()
}
6
->{
mainActivity
?.
setLocaleWithRegion
(
"pt"
,
"PT"
)
activity
?.
recreate
()
}
7
->{
mainActivity
?.
setLocale
(
"zh"
)
activity
?.
recreate
()
}
}
dialog
.
dismiss
()
}
.
create
().
show
()
}
}
companion
object
{
fun
newInstance
()
=
SettingsFragment
()
}
...
...
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