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
164becfe
Commit
164becfe
authored
Dec 25, 2015
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement dragging to move profiles
parent
eed7ec6e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
7 deletions
+55
-7
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
...scala/com/github/shadowsocks/ProfileManagerActivity.scala
+24
-2
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+4
-3
src/main/scala/com/github/shadowsocks/database/DBHelper.scala
...main/scala/com/github/shadowsocks/database/DBHelper.scala
+10
-1
src/main/scala/com/github/shadowsocks/database/Profile.scala
src/main/scala/com/github/shadowsocks/database/Profile.scala
+3
-0
src/main/scala/com/github/shadowsocks/database/ProfileManager.scala
...cala/com/github/shadowsocks/database/ProfileManager.scala
+14
-1
No files found.
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
View file @
164becfe
...
...
@@ -111,6 +111,24 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
notifyItemInserted
(
pos
)
}
def
move
(
from
:
Int
,
to
:
Int
)
{
val
step
=
if
(
from
<
to
)
1
else
-
1
val
first
=
profiles
(
from
)
var
previousOrder
=
profiles
(
from
).
userOrder
for
(
i
<-
from
until
to
by
step
)
{
val
next
=
profiles
(
i
+
step
)
val
order
=
next
.
userOrder
next
.
userOrder
=
previousOrder
previousOrder
=
order
profiles
(
i
)
=
next
ShadowsocksApplication
.
profileManager
.
updateProfile
(
next
)
}
first
.
userOrder
=
previousOrder
profiles
(
to
)
=
first
ShadowsocksApplication
.
profileManager
.
updateProfile
(
first
)
notifyItemMoved
(
from
,
to
)
}
def
remove
(
pos
:
Int
)
{
recycleBin
.
append
((
pos
,
profiles
(
pos
)))
profiles
.
remove
(
pos
)
...
...
@@ -169,12 +187,16 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
def
onViewDetachedFromWindow
(
v
:
View
)
=
profilesAdapter
.
commitRemoves
def
onViewAttachedToWindow
(
v
:
View
)
=
()
})
new
ItemTouchHelper
(
new
SimpleCallback
(
0
,
ItemTouchHelper
.
START
|
ItemTouchHelper
.
END
)
{
new
ItemTouchHelper
(
new
SimpleCallback
(
ItemTouchHelper
.
UP
|
ItemTouchHelper
.
DOWN
,
ItemTouchHelper
.
START
|
ItemTouchHelper
.
END
)
{
def
onSwiped
(
viewHolder
:
ViewHolder
,
direction
:
Int
)
=
{
profilesAdapter
.
remove
(
viewHolder
.
getAdapterPosition
)
removedSnackbar
.
show
}
def
onMove
(
recyclerView
:
RecyclerView
,
viewHolder
:
ViewHolder
,
target
:
ViewHolder
)
=
false
// TODO?
def
onMove
(
recyclerView
:
RecyclerView
,
viewHolder
:
ViewHolder
,
target
:
ViewHolder
)
=
{
profilesAdapter
.
move
(
viewHolder
.
getAdapterPosition
,
target
.
getAdapterPosition
)
true
}
}).
attachToRecyclerView
(
profilesList
)
attachService
(
new
IShadowsocksServiceCallback
.
Stub
{
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
164becfe
...
...
@@ -438,9 +438,10 @@ class Shadowsocks
currentProfile
=
ShadowsocksApplication
.
currentProfile
match
{
case
Some
(
profile
)
=>
profile
// updated
case
None
=>
// removed
val
profiles
=
ShadowsocksApplication
.
profileManager
.
getAllProfiles
.
getOrElse
(
List
[
Profile
]())
if
(
profiles
.
isEmpty
)
ShadowsocksApplication
.
profileManager
.
createDefault
()
else
ShadowsocksApplication
.
switchProfile
(
profiles
.
head
.
id
)
ShadowsocksApplication
.
profileManager
.
getFirstProfile
match
{
case
Some
(
first
)
=>
ShadowsocksApplication
.
switchProfile
(
first
.
id
)
case
None
=>
ShadowsocksApplication
.
profileManager
.
createDefault
()
}
}
updatePreferenceScreen
()
...
...
src/main/scala/com/github/shadowsocks/database/DBHelper.scala
View file @
164becfe
...
...
@@ -64,7 +64,7 @@ object DBHelper {
}
class
DBHelper
(
val
context
:
Context
)
extends
OrmLiteSqliteOpenHelper
(
context
,
DBHelper
.
PROFILE
,
null
,
1
4
)
{
extends
OrmLiteSqliteOpenHelper
(
context
,
DBHelper
.
PROFILE
,
null
,
1
5
)
{
import
DBHelper._
lazy
val
profileDao
:
Dao
[
Profile
,
Int
]
=
getDao
(
classOf
[
Profile
])
...
...
@@ -116,6 +116,15 @@ class DBHelper(val context: Context)
profileDao
.
update
(
profile
)
}
}
if
(
oldVersion
<
15
)
{
profileDao
.
executeRawNoArgs
(
"ALTER TABLE `profile` ADD COLUMN userOrder LONG;"
)
var
i
=
0
for
(
profile
<-
profileDao
.
queryForAll
.
asScala
)
{
profile
.
userOrder
=
i
profileDao
.
update
(
profile
)
i
+=
1
}
}
}
}
}
src/main/scala/com/github/shadowsocks/database/Profile.scala
View file @
164becfe
...
...
@@ -92,4 +92,7 @@ class Profile {
@DatabaseField
val
date
:
java.util.Date
=
new
java
.
util
.
Date
()
@DatabaseField
var
userOrder
:
Long
=
_
}
src/main/scala/com/github/shadowsocks/database/ProfileManager.scala
View file @
164becfe
...
...
@@ -64,6 +64,9 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
profile
.
udpdns
=
oldProfile
.
udpdns
case
_
=>
}
val
last
=
dbHelper
.
profileDao
.
queryRaw
(
dbHelper
.
profileDao
.
queryBuilder
.
selectRaw
(
"MAX(userOrder)"
)
.
prepareStatementString
).
getFirstResult
if
(
last
!=
null
&&
last
.
length
==
1
)
profile
.
userOrder
=
last
(
0
).
toInt
+
1
dbHelper
.
profileDao
.
createOrUpdate
(
profile
)
if
(
profileAddedListener
!=
null
)
profileAddedListener
(
profile
)
profile
...
...
@@ -109,10 +112,20 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
}
}
def
getFirstProfile
=
{
try
{
Option
(
dbHelper
.
profileDao
.
query
(
dbHelper
.
profileDao
.
queryBuilder
.
limit
(
1L
).
prepare
).
get
(
0
))
}
catch
{
case
ex
:
Exception
=>
Log
.
e
(
Shadowsocks
.
TAG
,
"getAllProfiles"
,
ex
)
None
}
}
def
getAllProfiles
:
Option
[
List
[
Profile
]]
=
{
try
{
import
scala.collection.JavaConversions._
Option
(
dbHelper
.
profileDao
.
query
ForAll
(
).
toList
)
Option
(
dbHelper
.
profileDao
.
query
(
dbHelper
.
profileDao
.
queryBuilder
.
orderBy
(
"userOrder"
,
true
).
prepare
).
toList
)
}
catch
{
case
ex
:
Exception
=>
Log
.
e
(
Shadowsocks
.
TAG
,
"getAllProfiles"
,
ex
)
...
...
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