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
24a9b0a5
Commit
24a9b0a5
authored
Mar 29, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add check to whether app already a migration already happened
parent
a43b7c89
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
24 deletions
+49
-24
RocketChatApplication.kt
...ain/java/chat/rocket/android/app/RocketChatApplication.kt
+16
-6
TwoFAPresenter.kt
...d/authentication/twofactor/presentation/TwoFAPresenter.kt
+1
-1
LocalRepository.kt
...ava/chat/rocket/android/infrastructure/LocalRepository.kt
+14
-8
SharedPrefsLocalRepository.kt
...cket/android/infrastructure/SharedPrefsLocalRepository.kt
+18
-9
No files found.
app/src/main/java/chat/rocket/android/app/RocketChatApplication.kt
View file @
24a9b0a5
...
@@ -15,11 +15,11 @@ import chat.rocket.android.app.migration.model.RealmBasedServerInfo
...
@@ -15,11 +15,11 @@ import chat.rocket.android.app.migration.model.RealmBasedServerInfo
import
chat.rocket.android.app.migration.model.RealmPublicSetting
import
chat.rocket.android.app.migration.model.RealmPublicSetting
import
chat.rocket.android.app.migration.model.RealmSession
import
chat.rocket.android.app.migration.model.RealmSession
import
chat.rocket.android.app.migration.model.RealmUser
import
chat.rocket.android.app.migration.model.RealmUser
import
chat.rocket.android.authentication.domain.model.TokenModel
import
chat.rocket.android.authentication.domain.model.toToken
import
chat.rocket.android.authentication.domain.model.toToken
import
chat.rocket.android.dagger.DaggerAppComponent
import
chat.rocket.android.dagger.DaggerAppComponent
import
chat.rocket.android.helper.CrashlyticsTree
import
chat.rocket.android.helper.CrashlyticsTree
import
chat.rocket.android.helper.UrlHelper
import
chat.rocket.android.helper.UrlHelper
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.server.domain.*
import
chat.rocket.android.server.domain.*
import
chat.rocket.android.server.domain.model.Account
import
chat.rocket.android.server.domain.model.Account
import
chat.rocket.android.widget.emoji.EmojiRepository
import
chat.rocket.android.widget.emoji.EmojiRepository
...
@@ -76,6 +76,8 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
...
@@ -76,6 +76,8 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
lateinit
var
prefs
:
SharedPreferences
lateinit
var
prefs
:
SharedPreferences
@Inject
@Inject
lateinit
var
getAccountsInteractor
:
GetAccountsInteractor
lateinit
var
getAccountsInteractor
:
GetAccountsInteractor
@Inject
lateinit
var
localRepository
:
LocalRepository
override
fun
onCreate
()
{
override
fun
onCreate
()
{
super
.
onCreate
()
super
.
onCreate
()
...
@@ -94,10 +96,11 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
...
@@ -94,10 +96,11 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
// TODO - remove this and all realm stuff when we got to 80% in 2.0
// TODO - remove this and all realm stuff when we got to 80% in 2.0
try
{
try
{
if
(!
localRepository
.
hasMigrated
())
{
migrateFromLegacy
()
migrateFromLegacy
()
}
}
catch
(
ex
:
Exception
)
{
}
catch
(
ex
:
Exception
)
{
Timber
.
d
(
ex
,
"Error migrating old accounts"
)
Timber
.
d
(
ex
,
"Error migrating old accounts"
)
ex
.
printStackTrace
()
}
}
}
}
...
@@ -138,6 +141,7 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
...
@@ -138,6 +141,7 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
}
}
migrateCurrentServer
(
serversInfoList
)
migrateCurrentServer
(
serversInfoList
)
serverRealm
.
close
()
serverRealm
.
close
()
localRepository
.
setMigrated
(
true
)
}
}
private
fun
migrateServerInfo
(
url
:
String
,
authToken
:
String
,
settings
:
PublicSettings
,
user
:
RealmUser
)
{
private
fun
migrateServerInfo
(
url
:
String
,
authToken
:
String
,
settings
:
PublicSettings
,
user
:
RealmUser
)
{
...
@@ -151,7 +155,7 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
...
@@ -151,7 +155,7 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
}
}
val
account
=
Account
(
url
,
icon
,
logo
,
user
.
username
!!
,
avatar
)
val
account
=
Account
(
url
,
icon
,
logo
,
user
.
username
!!
,
avatar
)
launch
(
CommonPool
)
{
launch
(
CommonPool
)
{
tokenRepository
.
save
(
url
,
Token
(
userId
!!
,
authToken
))
tokenRepository
.
save
(
Token
(
userId
!!
,
authToken
))
accountRepository
.
save
(
account
)
accountRepository
.
save
(
account
)
}
}
}
}
...
@@ -210,14 +214,14 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
...
@@ -210,14 +214,14 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
getCurrentServerInteractor
.
get
()
?.
let
{
serverUrl
->
getCurrentServerInteractor
.
get
()
?.
let
{
serverUrl
->
multiServerRepository
.
get
(
serverUrl
)
?.
let
{
token
->
multiServerRepository
.
get
(
serverUrl
)
?.
let
{
token
->
tokenRepository
.
save
(
serverUrl
,
Token
(
token
.
userId
,
token
.
authToken
))
tokenRepository
.
save
(
Token
(
token
.
userId
,
token
.
authToken
))
}
}
}
}
runBlocking
{
runBlocking
{
getAccountsInteractor
.
get
().
forEach
{
account
->
getAccountsInteractor
.
get
().
forEach
{
account
->
multiServerRepository
.
get
(
account
.
serverUrl
)
?.
let
{
token
->
multiServerRepository
.
get
(
account
.
serverUrl
)
?.
let
{
token
->
tokenRepository
.
save
(
account
.
serverUrl
,
token
.
toToken
())
tokenRepository
.
save
(
token
.
toToken
())
}
}
}
}
}
}
...
@@ -255,4 +259,10 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
...
@@ -255,4 +259,10 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
}
}
}
}
private
fun
LocalRepository
.
setMigrated
(
migrated
:
Boolean
)
{
save
(
LocalRepository
.
MIGRATION_FINISHED_KEY
,
migrated
)
}
private
fun
LocalRepository
.
hasMigrated
()
=
getBoolean
(
LocalRepository
.
MIGRATION_FINISHED_KEY
)
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
app/src/main/java/chat/rocket/android/authentication/twofactor/presentation/TwoFAPresenter.kt
View file @
24a9b0a5
...
@@ -54,7 +54,7 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
...
@@ -54,7 +54,7 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
client
.
login
(
usernameOrEmail
,
password
,
twoFactorAuthenticationCode
)
client
.
login
(
usernameOrEmail
,
password
,
twoFactorAuthenticationCode
)
val
me
=
client
.
me
()
val
me
=
client
.
me
()
saveAccount
(
me
)
saveAccount
(
me
)
tokenRepository
.
save
(
server
,
token
)
tokenRepository
.
save
(
token
)
registerPushToken
()
registerPushToken
()
navigator
.
toChatList
()
navigator
.
toChatList
()
}
catch
(
exception
:
RocketChatException
)
{
}
catch
(
exception
:
RocketChatException
)
{
...
...
app/src/main/java/chat/rocket/android/infrastructure/LocalRepository.kt
View file @
24a9b0a5
...
@@ -2,18 +2,24 @@ package chat.rocket.android.infrastructure
...
@@ -2,18 +2,24 @@ package chat.rocket.android.infrastructure
interface
LocalRepository
{
interface
LocalRepository
{
fun
save
(
key
:
String
,
value
:
String
?)
fun
save
(
key
:
String
,
value
:
Boolean
)
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
clear
(
key
:
String
)
fun
clearAllFromServer
(
server
:
String
)
companion
object
{
companion
object
{
const
val
KEY_PUSH_TOKEN
=
"KEY_PUSH_TOKEN"
const
val
KEY_PUSH_TOKEN
=
"KEY_PUSH_TOKEN"
const
val
MIGRATION_FINISHED_KEY
=
"MIGRATION_FINISHED_KEY"
const
val
TOKEN_KEY
=
"token_"
const
val
TOKEN_KEY
=
"token_"
const
val
SETTINGS_KEY
=
"settings_"
const
val
SETTINGS_KEY
=
"settings_"
const
val
CURRENT_USERNAME_KEY
=
"username_"
const
val
CURRENT_USERNAME_KEY
=
"username_"
}
}
fun
save
(
key
:
String
,
value
:
String
?)
fun
get
(
key
:
String
):
String
?
fun
clear
(
key
:
String
)
fun
clearAllFromServer
(
server
:
String
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/infrastructure/SharedPrefsLocalRepository.kt
View file @
24a9b0a5
...
@@ -3,18 +3,27 @@ package chat.rocket.android.infrastructure
...
@@ -3,18 +3,27 @@ package chat.rocket.android.infrastructure
import
android.content.SharedPreferences
import
android.content.SharedPreferences
class
SharedPrefsLocalRepository
(
private
val
preferences
:
SharedPreferences
)
:
LocalRepository
{
class
SharedPrefsLocalRepository
(
private
val
preferences
:
SharedPreferences
)
:
LocalRepository
{
override
fun
getBoolean
(
key
:
String
)
=
preferences
.
getBoolean
(
key
,
false
)
override
fun
save
(
key
:
String
,
value
:
String
?)
{
override
fun
getFloat
(
key
:
String
)
=
preferences
.
getFloat
(
key
,
-
1f
)
preferences
.
edit
().
putString
(
key
,
value
).
apply
()
}
override
fun
get
(
key
:
String
):
String
?
{
override
fun
getInt
(
key
:
String
)
=
preferences
.
getInt
(
key
,
-
1
)
return
preferences
.
getString
(
key
,
null
)
}
override
fun
clear
(
key
:
String
)
{
override
fun
getLong
(
key
:
String
)
=
preferences
.
getLong
(
key
,
-
1L
)
preferences
.
edit
().
remove
(
key
).
apply
()
}
override
fun
save
(
key
:
String
,
value
:
Int
)
=
preferences
.
edit
().
putInt
(
key
,
value
).
apply
()
override
fun
save
(
key
:
String
,
value
:
Float
)
=
preferences
.
edit
().
putFloat
(
key
,
value
).
apply
()
override
fun
save
(
key
:
String
,
value
:
Long
)
=
preferences
.
edit
().
putLong
(
key
,
value
).
apply
()
override
fun
save
(
key
:
String
,
value
:
Boolean
)
=
preferences
.
edit
().
putBoolean
(
key
,
value
).
apply
()
override
fun
save
(
key
:
String
,
value
:
String
?)
=
preferences
.
edit
().
putString
(
key
,
value
).
apply
()
override
fun
get
(
key
:
String
):
String
?
=
preferences
.
getString
(
key
,
null
)
override
fun
clear
(
key
:
String
)
=
preferences
.
edit
().
remove
(
key
).
apply
()
override
fun
clearAllFromServer
(
server
:
String
)
{
override
fun
clearAllFromServer
(
server
:
String
)
{
clear
(
LocalRepository
.
KEY_PUSH_TOKEN
)
clear
(
LocalRepository
.
KEY_PUSH_TOKEN
)
...
...
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