Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
7f13b622
Commit
7f13b622
authored
Mar 29, 2018
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Fix SQLiteDatabaseLockedException"
This reverts commit
3c532f1a
.
parent
9960f87a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
133 deletions
+60
-133
mobile/src/main/java/com/github/shadowsocks/database/LockUtils.kt
...rc/main/java/com/github/shadowsocks/database/LockUtils.kt
+0
-61
mobile/src/main/java/com/github/shadowsocks/database/PrivateDatabase.kt
...n/java/com/github/shadowsocks/database/PrivateDatabase.kt
+35
-35
mobile/src/main/java/com/github/shadowsocks/database/ProfileManager.kt
...in/java/com/github/shadowsocks/database/ProfileManager.kt
+7
-15
mobile/src/main/java/com/github/shadowsocks/database/PublicDatabase.kt
...in/java/com/github/shadowsocks/database/PublicDatabase.kt
+5
-6
mobile/src/main/java/com/github/shadowsocks/preference/OrmLitePreferenceDataStore.kt
...thub/shadowsocks/preference/OrmLitePreferenceDataStore.kt
+13
-16
No files found.
mobile/src/main/java/com/github/shadowsocks/database/LockUtils.kt
deleted
100644 → 0
View file @
9960f87a
/*******************************************************************************
* *
* Copyright (C) 2017 by Max Lv <max.c.lv@gmail.com> *
* Copyright (C) 2017 by Mygod Studio <contact-shadowsocks-android@mygod.be> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
package
com.github.shadowsocks.database
import
android.database.sqlite.SQLiteDatabaseLockedException
import
com.j256.ormlite.dao.Dao
import
com.j256.ormlite.support.ConnectionSource
import
com.j256.ormlite.table.TableUtils
import
java.sql.SQLException
private
val
Throwable
.
ultimateCause
:
Throwable
get
()
{
var
result
=
this
while
(
true
)
{
val
cause
=
result
.
cause
?:
return
result
result
=
cause
}
}
@Throws
(
SQLException
::
class
)
fun
<
T
>
safeWrapper
(
func
:
()
->
T
):
T
{
while
(
true
)
{
try
{
return
func
()
}
catch
(
e
:
SQLException
)
{
if
(
e
.
ultimateCause
!
is
SQLiteDatabaseLockedException
)
throw
e
}
}
}
@Throws
(
SQLException
::
class
)
inline
fun
<
reified
T
>
ConnectionSource
.
createTableSafe
()
=
safeWrapper
{
TableUtils
.
createTable
(
this
,
T
::
class
.
java
)
}
@Throws
(
SQLException
::
class
)
fun
<
T
,
ID
>
Dao
<
T
,
ID
>.
queryAllSafe
():
MutableList
<
T
>
=
safeWrapper
{
queryForAll
()
}
@Throws
(
SQLException
::
class
)
fun
<
T
,
ID
>
Dao
<
T
,
ID
>.
queryByIdSafe
(
id
:
ID
?):
T
?
=
safeWrapper
{
queryForId
(
id
)
}
@Throws
(
SQLException
::
class
)
fun
<
T
,
ID
>
Dao
<
T
,
ID
>.
updateSafe
(
data
:
T
?):
Int
=
safeWrapper
{
update
(
data
)
}
@Throws
(
SQLException
::
class
)
fun
<
T
,
ID
>
Dao
<
T
,
ID
>.
replaceSafe
(
data
:
T
?):
Dao
.
CreateOrUpdateStatus
?
=
safeWrapper
{
createOrUpdate
(
data
)
}
@Throws
(
SQLException
::
class
)
fun
<
T
,
ID
>
Dao
<
T
,
ID
>.
deleteByIdSafe
(
id
:
ID
?)
=
safeWrapper
{
deleteById
(
id
)
}
@Throws
(
SQLException
::
class
)
fun
<
T
,
ID
>
Dao
<
T
,
ID
>.
executeSafe
(
statement
:
String
?)
=
safeWrapper
{
executeRawNoArgs
(
statement
)
}
mobile/src/main/java/com/github/shadowsocks/database/PrivateDatabase.kt
View file @
7f13b622
...
...
@@ -37,18 +37,18 @@ object PrivateDatabase : OrmLiteSqliteOpenHelper(app, Key.DB_PROFILE, null, 25)
@Suppress
(
"UNCHECKED_CAST"
)
val
kvPairDao
:
Dao
<
KeyValuePair
,
String
?
>
by
lazy
{
getDao
(
KeyValuePair
::
class
.
java
)
as
Dao
<
KeyValuePair
,
String
?
>
}
override
fun
onCreate
(
database
:
SQLiteDatabase
?,
connectionSource
:
ConnectionSource
)
{
connectionSource
.
createTableSafe
<
Profile
>(
)
connectionSource
.
createTableSafe
<
KeyValuePair
>(
)
override
fun
onCreate
(
database
:
SQLiteDatabase
?,
connectionSource
:
ConnectionSource
?
)
{
TableUtils
.
createTable
(
connectionSource
,
Profile
::
class
.
java
)
TableUtils
.
createTable
(
connectionSource
,
KeyValuePair
::
class
.
java
)
}
private
fun
recreate
(
database
:
SQLiteDatabase
?,
connectionSource
:
ConnectionSource
)
{
private
fun
recreate
(
database
:
SQLiteDatabase
?,
connectionSource
:
ConnectionSource
?
)
{
TableUtils
.
dropTable
<
Profile
,
Int
>(
connectionSource
,
Profile
::
class
.
java
,
true
)
TableUtils
.
dropTable
<
KeyValuePair
,
String
?>(
connectionSource
,
KeyValuePair
::
class
.
java
,
true
)
onCreate
(
database
,
connectionSource
)
}
override
fun
onUpgrade
(
database
:
SQLiteDatabase
?,
connectionSource
:
ConnectionSource
,
override
fun
onUpgrade
(
database
:
SQLiteDatabase
?,
connectionSource
:
ConnectionSource
?
,
oldVersion
:
Int
,
newVersion
:
Int
)
{
if
(
oldVersion
<
7
)
{
recreate
(
database
,
connectionSource
)
...
...
@@ -57,38 +57,38 @@ object PrivateDatabase : OrmLiteSqliteOpenHelper(app, Key.DB_PROFILE, null, 25)
try
{
if
(
oldVersion
<
8
)
{
profileDao
.
execute
Safe
(
"ALTER TABLE `profile` ADD COLUMN udpdns SMALLINT;"
)
profileDao
.
execute
RawNoArgs
(
"ALTER TABLE `profile` ADD COLUMN udpdns SMALLINT;"
)
}
if
(
oldVersion
<
9
)
{
profileDao
.
execute
Safe
(
"ALTER TABLE `profile` ADD COLUMN route VARCHAR DEFAULT 'all';"
)
profileDao
.
execute
RawNoArgs
(
"ALTER TABLE `profile` ADD COLUMN route VARCHAR DEFAULT 'all';"
)
}
else
if
(
oldVersion
<
19
)
{
profileDao
.
execute
Safe
(
"UPDATE `profile` SET route = 'all' WHERE route IS NULL;"
)
profileDao
.
execute
RawNoArgs
(
"UPDATE `profile` SET route = 'all' WHERE route IS NULL;"
)
}
if
(
oldVersion
<
11
)
{
profileDao
.
execute
Safe
(
"ALTER TABLE `profile` ADD COLUMN ipv6 SMALLINT;"
)
profileDao
.
execute
RawNoArgs
(
"ALTER TABLE `profile` ADD COLUMN ipv6 SMALLINT;"
)
}
if
(
oldVersion
<
12
)
{
profileDao
.
execute
Safe
(
"BEGIN TRANSACTION;"
)
profileDao
.
execute
Safe
(
"ALTER TABLE `profile` RENAME TO `tmp`;"
)
connectionSource
.
createTableSafe
<
Profile
>(
)
profileDao
.
execute
Safe
(
profileDao
.
execute
RawNoArgs
(
"BEGIN TRANSACTION;"
)
profileDao
.
execute
RawNoArgs
(
"ALTER TABLE `profile` RENAME TO `tmp`;"
)
TableUtils
.
createTable
(
connectionSource
,
Profile
::
class
.
java
)
profileDao
.
execute
RawNoArgs
(
"INSERT INTO `profile`(id, name, host, localPort, remotePort, password, method, route,"
+
" proxyApps, bypass, udpdns, ipv6, individual) "
+
"SELECT id, name, host, localPort, remotePort, password, method, route, 1 - global,"
+
" bypass, udpdns, ipv6, individual FROM `tmp`;"
)
profileDao
.
execute
Safe
(
"DROP TABLE `tmp`;"
)
profileDao
.
execute
Safe
(
"COMMIT;"
)
profileDao
.
execute
RawNoArgs
(
"DROP TABLE `tmp`;"
)
profileDao
.
execute
RawNoArgs
(
"COMMIT;"
)
}
else
if
(
oldVersion
<
13
)
{
profileDao
.
execute
Safe
(
"ALTER TABLE `profile` ADD COLUMN tx LONG;"
)
profileDao
.
execute
Safe
(
"ALTER TABLE `profile` ADD COLUMN rx LONG;"
)
profileDao
.
execute
Safe
(
"ALTER TABLE `profile` ADD COLUMN date VARCHAR;"
)
profileDao
.
execute
RawNoArgs
(
"ALTER TABLE `profile` ADD COLUMN tx LONG;"
)
profileDao
.
execute
RawNoArgs
(
"ALTER TABLE `profile` ADD COLUMN rx LONG;"
)
profileDao
.
execute
RawNoArgs
(
"ALTER TABLE `profile` ADD COLUMN date VARCHAR;"
)
}
if
(
oldVersion
<
15
)
{
if
(
oldVersion
>=
12
)
profileDao
.
execute
Safe
(
"ALTER TABLE `profile` ADD COLUMN userOrder LONG;"
)
if
(
oldVersion
>=
12
)
profileDao
.
execute
RawNoArgs
(
"ALTER TABLE `profile` ADD COLUMN userOrder LONG;"
)
var
i
=
0L
val
apps
by
lazy
{
app
.
packageManager
.
getInstalledApplications
(
0
)
}
for
(
profile
in
profileDao
.
query
AllSafe
())
{
for
(
profile
in
profileDao
.
query
ForAll
())
{
if
(
oldVersion
<
14
)
{
val
uidSet
=
profile
.
individual
.
split
(
'|'
).
filter
(
TextUtils
::
isDigitsOnly
)
.
map
(
String
::
toInt
).
toSet
()
...
...
@@ -96,28 +96,28 @@ object PrivateDatabase : OrmLiteSqliteOpenHelper(app, Key.DB_PROFILE, null, 25)
.
joinToString
(
"\n"
)
{
it
.
packageName
}
}
profile
.
userOrder
=
i
profileDao
.
update
Safe
(
profile
)
profileDao
.
update
(
profile
)
i
+=
1
}
}
if
(
oldVersion
<
16
)
{
profileDao
.
execute
Safe
(
profileDao
.
execute
RawNoArgs
(
"UPDATE `profile` SET route = 'bypass-lan-china' WHERE route = 'bypass-china'"
)
}
if
(
oldVersion
<
21
)
{
profileDao
.
execute
Safe
(
"ALTER TABLE `profile` ADD COLUMN remoteDns VARCHAR DEFAULT '8.8.8.8';"
)
profileDao
.
execute
RawNoArgs
(
"ALTER TABLE `profile` ADD COLUMN remoteDns VARCHAR DEFAULT '8.8.8.8';"
)
}
if
(
oldVersion
<
17
)
{
profileDao
.
execute
Safe
(
"ALTER TABLE `profile` ADD COLUMN plugin VARCHAR;"
)
profileDao
.
execute
RawNoArgs
(
"ALTER TABLE `profile` ADD COLUMN plugin VARCHAR;"
)
}
else
if
(
oldVersion
<
22
)
{
// upgrade kcptun to SIP003 plugin
profileDao
.
execute
Safe
(
"BEGIN TRANSACTION;"
)
profileDao
.
execute
Safe
(
"ALTER TABLE `profile` RENAME TO `tmp`;"
)
connectionSource
.
createTableSafe
<
Profile
>(
)
profileDao
.
execute
Safe
(
profileDao
.
execute
RawNoArgs
(
"BEGIN TRANSACTION;"
)
profileDao
.
execute
RawNoArgs
(
"ALTER TABLE `profile` RENAME TO `tmp`;"
)
TableUtils
.
createTable
(
connectionSource
,
Profile
::
class
.
java
)
profileDao
.
execute
RawNoArgs
(
"INSERT INTO `profile`(id, name, host, localPort, remotePort, password, method, route, "
+
"remoteDns, proxyApps, bypass, udpdns, ipv6, individual, tx, rx, date, userOrder, "
+
"plugin) "
+
...
...
@@ -125,17 +125,17 @@ object PrivateDatabase : OrmLiteSqliteOpenHelper(app, Key.DB_PROFILE, null, 25)
"CASE WHEN kcp = 1 THEN kcpPort ELSE remotePort END, password, method, route, "
+
"remoteDns, proxyApps, bypass, udpdns, ipv6, individual, tx, rx, date, userOrder, "
+
"CASE WHEN kcp = 1 THEN 'kcptun ' || kcpcli ELSE NULL END FROM `tmp`;"
)
profileDao
.
execute
Safe
(
"DROP TABLE `tmp`;"
)
profileDao
.
execute
Safe
(
"COMMIT;"
)
profileDao
.
execute
RawNoArgs
(
"DROP TABLE `tmp`;"
)
profileDao
.
execute
RawNoArgs
(
"COMMIT;"
)
}
if
(
oldVersion
<
23
)
{
profileDao
.
execute
Safe
(
"BEGIN TRANSACTION;"
)
connectionSource
.
createTableSafe
<
KeyValuePair
>(
)
profileDao
.
execute
Safe
(
"COMMIT;"
)
profileDao
.
execute
RawNoArgs
(
"BEGIN TRANSACTION;"
)
TableUtils
.
createTable
(
connectionSource
,
KeyValuePair
::
class
.
java
)
profileDao
.
execute
RawNoArgs
(
"COMMIT;"
)
val
old
=
PreferenceManager
.
getDefaultSharedPreferences
(
app
)
PublicDatabase
.
kvPairDao
.
replaceSaf
e
(
KeyValuePair
(
Key
.
id
).
put
(
old
.
getInt
(
Key
.
id
,
0
)))
PublicDatabase
.
kvPairDao
.
replaceSaf
e
(
KeyValuePair
(
Key
.
tfo
).
put
(
old
.
getBoolean
(
Key
.
tfo
,
false
)))
PublicDatabase
.
kvPairDao
.
createOrUpdat
e
(
KeyValuePair
(
Key
.
id
).
put
(
old
.
getInt
(
Key
.
id
,
0
)))
PublicDatabase
.
kvPairDao
.
createOrUpdat
e
(
KeyValuePair
(
Key
.
tfo
).
put
(
old
.
getBoolean
(
Key
.
tfo
,
false
)))
}
if
(
oldVersion
<
25
)
{
...
...
mobile/src/main/java/com/github/shadowsocks/database/ProfileManager.kt
View file @
7f13b622
...
...
@@ -48,12 +48,10 @@ object ProfileManager {
profile
.
individual
=
oldProfile
.
individual
profile
.
udpdns
=
oldProfile
.
udpdns
}
val
last
=
safeWrapper
{
PrivateDatabase
.
profileDao
.
queryRaw
(
PrivateDatabase
.
profileDao
.
queryBuilder
()
val
last
=
PrivateDatabase
.
profileDao
.
queryRaw
(
PrivateDatabase
.
profileDao
.
queryBuilder
()
.
selectRaw
(
"MAX(userOrder)"
).
prepareStatementString
()).
firstResult
}
if
(
last
!=
null
&&
last
.
size
==
1
&&
last
[
0
]
!=
null
)
profile
.
userOrder
=
last
[
0
].
toLong
()
+
1
PrivateDatabase
.
profileDao
.
replaceSaf
e
(
profile
)
PrivateDatabase
.
profileDao
.
createOrUpdat
e
(
profile
)
ProfilesFragment
.
instance
?.
profilesAdapter
?.
add
(
profile
)
return
profile
}
...
...
@@ -62,10 +60,10 @@ object ProfileManager {
* Note: It's caller's responsibility to update DirectBoot profile if necessary.
*/
@Throws
(
SQLException
::
class
)
fun
updateProfile
(
profile
:
Profile
)
=
PrivateDatabase
.
profileDao
.
update
Safe
(
profile
)
fun
updateProfile
(
profile
:
Profile
)
=
PrivateDatabase
.
profileDao
.
update
(
profile
)
fun
getProfile
(
id
:
Int
):
Profile
?
=
try
{
PrivateDatabase
.
profileDao
.
query
ByIdSafe
(
id
)
PrivateDatabase
.
profileDao
.
query
ForId
(
id
)
}
catch
(
ex
:
SQLException
)
{
Log
.
e
(
TAG
,
"getProfile"
,
ex
)
app
.
track
(
ex
)
...
...
@@ -74,16 +72,13 @@ object ProfileManager {
@Throws
(
SQLException
::
class
)
fun
delProfile
(
id
:
Int
)
{
PrivateDatabase
.
profileDao
.
deleteById
Safe
(
id
)
PrivateDatabase
.
profileDao
.
deleteById
(
id
)
ProfilesFragment
.
instance
?.
profilesAdapter
?.
removeId
(
id
)
if
(
id
==
DataStore
.
profileId
&&
DataStore
.
directBootAware
)
DirectBoot
.
clean
()
}
fun
getFirstProfile
():
Profile
?
=
try
{
safeWrapper
{
PrivateDatabase
.
profileDao
.
query
(
PrivateDatabase
.
profileDao
.
queryBuilder
().
limit
(
1L
).
prepare
()).
singleOrNull
()
}
PrivateDatabase
.
profileDao
.
query
(
PrivateDatabase
.
profileDao
.
queryBuilder
().
limit
(
1L
).
prepare
()).
singleOrNull
()
}
catch
(
ex
:
SQLException
)
{
Log
.
e
(
TAG
,
"getFirstProfile"
,
ex
)
app
.
track
(
ex
)
...
...
@@ -91,10 +86,7 @@ object ProfileManager {
}
fun
getAllProfiles
():
List
<
Profile
>?
=
try
{
safeWrapper
{
PrivateDatabase
.
profileDao
.
query
(
PrivateDatabase
.
profileDao
.
queryBuilder
().
orderBy
(
"userOrder"
,
true
).
prepare
())
}
PrivateDatabase
.
profileDao
.
query
(
PrivateDatabase
.
profileDao
.
queryBuilder
().
orderBy
(
"userOrder"
,
true
).
prepare
())
}
catch
(
ex
:
SQLException
)
{
Log
.
e
(
TAG
,
"getAllProfiles"
,
ex
)
app
.
track
(
ex
)
...
...
mobile/src/main/java/com/github/shadowsocks/database/PublicDatabase.kt
View file @
7f13b622
...
...
@@ -34,21 +34,20 @@ object PublicDatabase : OrmLiteSqliteOpenHelper(app.deviceContext, Key.DB_PUBLIC
@Suppress
(
"UNCHECKED_CAST"
)
val
kvPairDao
:
Dao
<
KeyValuePair
,
String
?
>
by
lazy
{
getDao
(
KeyValuePair
::
class
.
java
)
as
Dao
<
KeyValuePair
,
String
?
>
}
override
fun
onCreate
(
database
:
SQLiteDatabase
?,
connectionSource
:
ConnectionSource
)
{
connectionSource
.
createTableSafe
<
KeyValuePair
>(
)
override
fun
onCreate
(
database
:
SQLiteDatabase
?,
connectionSource
:
ConnectionSource
?
)
{
TableUtils
.
createTable
(
connectionSource
,
KeyValuePair
::
class
.
java
)
}
override
fun
onUpgrade
(
database
:
SQLiteDatabase
?,
connectionSource
:
ConnectionSource
?,
oldVersion
:
Int
,
newVersion
:
Int
)
{
if
(
oldVersion
<
1
)
{
safeWrapper
{
PrivateDatabase
.
kvPairDao
.
queryBuilder
().
where
().
`in`
(
"key"
,
PrivateDatabase
.
kvPairDao
.
queryBuilder
().
where
().
`in`
(
"key"
,
Key
.
id
,
Key
.
tfo
,
Key
.
serviceMode
,
Key
.
portProxy
,
Key
.
portLocalDns
,
Key
.
portTransproxy
).
query
()
}.
forEach
{
kvPairDao
.
replaceSaf
e
(
it
)
}
.
forEach
{
kvPairDao
.
createOrUpdat
e
(
it
)
}
}
if
(
oldVersion
<
2
)
{
kvPairDao
.
replaceSaf
e
(
KeyValuePair
(
Acl
.
CUSTOM_RULES
).
put
(
Acl
().
fromId
(
Acl
.
CUSTOM_RULES
).
toString
()))
kvPairDao
.
createOrUpdat
e
(
KeyValuePair
(
Acl
.
CUSTOM_RULES
).
put
(
Acl
().
fromId
(
Acl
.
CUSTOM_RULES
).
toString
()))
}
}
...
...
mobile/src/main/java/com/github/shadowsocks/preference/OrmLitePreferenceDataStore.kt
View file @
7f13b622
...
...
@@ -22,20 +22,17 @@ package com.github.shadowsocks.preference
import
android.support.v7.preference.PreferenceDataStore
import
com.github.shadowsocks.database.KeyValuePair
import
com.github.shadowsocks.database.deleteByIdSafe
import
com.github.shadowsocks.database.queryByIdSafe
import
com.github.shadowsocks.database.replaceSafe
import
com.j256.ormlite.dao.Dao
import
java.util.HashSet
@Suppress
(
"MemberVisibilityCanPrivate"
,
"unused"
)
open
class
OrmLitePreferenceDataStore
(
private
val
kvPairDao
:
Dao
<
KeyValuePair
,
String
?
>)
:
PreferenceDataStore
()
{
fun
getBoolean
(
key
:
String
?)
=
kvPairDao
.
query
ByIdSafe
(
key
)
?.
boolean
fun
getFloat
(
key
:
String
?)
=
kvPairDao
.
query
ByIdSafe
(
key
)
?.
float
fun
getInt
(
key
:
String
?)
=
kvPairDao
.
query
ByIdSafe
(
key
)
?.
int
fun
getLong
(
key
:
String
?)
=
kvPairDao
.
query
ByIdSafe
(
key
)
?.
long
fun
getString
(
key
:
String
?)
=
kvPairDao
.
query
ByIdSafe
(
key
)
?.
string
fun
getStringSet
(
key
:
String
?)
=
kvPairDao
.
query
ByIdSafe
(
key
)
?.
stringSet
fun
getBoolean
(
key
:
String
?)
=
kvPairDao
.
query
ForId
(
key
)
?.
boolean
fun
getFloat
(
key
:
String
?)
=
kvPairDao
.
query
ForId
(
key
)
?.
float
fun
getInt
(
key
:
String
?)
=
kvPairDao
.
query
ForId
(
key
)
?.
int
fun
getLong
(
key
:
String
?)
=
kvPairDao
.
query
ForId
(
key
)
?.
long
fun
getString
(
key
:
String
?)
=
kvPairDao
.
query
ForId
(
key
)
?.
string
fun
getStringSet
(
key
:
String
?)
=
kvPairDao
.
query
ForId
(
key
)
?.
stringSet
override
fun
getBoolean
(
key
:
String
?,
defValue
:
Boolean
)
=
getBoolean
(
key
)
?:
defValue
override
fun
getFloat
(
key
:
String
?,
defValue
:
Float
)
=
getFloat
(
key
)
?:
defValue
...
...
@@ -49,32 +46,32 @@ open class OrmLitePreferenceDataStore(private val kvPairDao: Dao<KeyValuePair, S
fun
putInt
(
key
:
String
?,
value
:
Int
?)
=
if
(
value
==
null
)
remove
(
key
)
else
putInt
(
key
,
value
)
fun
putLong
(
key
:
String
?,
value
:
Long
?)
=
if
(
value
==
null
)
remove
(
key
)
else
putLong
(
key
,
value
)
override
fun
putBoolean
(
key
:
String
?,
value
:
Boolean
)
{
kvPairDao
.
replaceSaf
e
(
KeyValuePair
(
key
).
put
(
value
))
kvPairDao
.
createOrUpdat
e
(
KeyValuePair
(
key
).
put
(
value
))
fireChangeListener
(
key
)
}
override
fun
putFloat
(
key
:
String
?,
value
:
Float
)
{
kvPairDao
.
replaceSaf
e
(
KeyValuePair
(
key
).
put
(
value
))
kvPairDao
.
createOrUpdat
e
(
KeyValuePair
(
key
).
put
(
value
))
fireChangeListener
(
key
)
}
override
fun
putInt
(
key
:
String
?,
value
:
Int
)
{
kvPairDao
.
replaceSaf
e
(
KeyValuePair
(
key
).
put
(
value
))
kvPairDao
.
createOrUpdat
e
(
KeyValuePair
(
key
).
put
(
value
))
fireChangeListener
(
key
)
}
override
fun
putLong
(
key
:
String
?,
value
:
Long
)
{
kvPairDao
.
replaceSaf
e
(
KeyValuePair
(
key
).
put
(
value
))
kvPairDao
.
createOrUpdat
e
(
KeyValuePair
(
key
).
put
(
value
))
fireChangeListener
(
key
)
}
override
fun
putString
(
key
:
String
?,
value
:
String
?)
=
if
(
value
==
null
)
remove
(
key
)
else
{
kvPairDao
.
replaceSaf
e
(
KeyValuePair
(
key
).
put
(
value
))
kvPairDao
.
createOrUpdat
e
(
KeyValuePair
(
key
).
put
(
value
))
fireChangeListener
(
key
)
}
override
fun
putStringSet
(
key
:
String
?,
values
:
MutableSet
<
String
>?)
=
if
(
values
==
null
)
remove
(
key
)
else
{
kvPairDao
.
replaceSaf
e
(
KeyValuePair
(
key
).
put
(
values
))
kvPairDao
.
createOrUpdat
e
(
KeyValuePair
(
key
).
put
(
values
))
fireChangeListener
(
key
)
}
fun
remove
(
key
:
String
?)
{
kvPairDao
.
deleteById
Safe
(
key
)
kvPairDao
.
deleteById
(
key
)
fireChangeListener
(
key
)
}
...
...
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