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
d7946326
Commit
d7946326
authored
Feb 11, 2016
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine undo
parent
529b1a32
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
32 deletions
+70
-32
src/main/res/values-zh/strings.xml
src/main/res/values-zh/strings.xml
+4
-1
src/main/res/values/strings.xml
src/main/res/values/strings.xml
+4
-1
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
...scala/com/github/shadowsocks/ProfileManagerActivity.scala
+17
-30
src/main/scala/com/github/shadowsocks/widget/UndoSnackbarManager.scala
...a/com/github/shadowsocks/widget/UndoSnackbarManager.scala
+45
-0
No files found.
src/main/res/values-zh/strings.xml
View file @
d7946326
...
@@ -106,7 +106,10 @@
...
@@ -106,7 +106,10 @@
<string
name=
"action_import_msg"
>
导入成功
</string>
<string
name=
"action_import_msg"
>
导入成功
</string>
<string
name=
"action_import_err"
>
导入失败
</string>
<string
name=
"action_import_err"
>
导入失败
</string>
<string
name=
"removed"
>
已删除
</string>
<plurals
name=
"removed"
>
<item
quantity=
"one"
>
已删除
</item>
<item
quantity=
"other"
>
已删除 %d 项
</item>
</plurals>
<string
name=
"undo"
>
撤销
</string>
<string
name=
"undo"
>
撤销
</string>
<string
name=
"toggle_service_state"
>
启动服务
</string>
<string
name=
"toggle_service_state"
>
启动服务
</string>
<string
name=
"start_service_default"
>
连接到当前服务器
</string>
<string
name=
"start_service_default"
>
连接到当前服务器
</string>
...
...
src/main/res/values/strings.xml
View file @
d7946326
...
@@ -112,7 +112,10 @@
...
@@ -112,7 +112,10 @@
<string
name=
"add_profile_dialog"
>
Add this Shadowsocks Profile?
</string>
<string
name=
"add_profile_dialog"
>
Add this Shadowsocks Profile?
</string>
<string
name=
"add_profile_methods_scan_qr_code"
>
Scan QR code
</string>
<string
name=
"add_profile_methods_scan_qr_code"
>
Scan QR code
</string>
<string
name=
"add_profile_methods_manual_settings"
>
Manual Settings
</string>
<string
name=
"add_profile_methods_manual_settings"
>
Manual Settings
</string>
<string
name=
"removed"
>
Removed
</string>
<plurals
name=
"removed"
>
<item
quantity=
"one"
>
Removed
</item>
<item
quantity=
"other"
>
%d items removed
</item>
</plurals>
<string
name=
"undo"
>
Undo
</string>
<string
name=
"undo"
>
Undo
</string>
<!-- tasker -->
<!-- tasker -->
...
...
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
View file @
d7946326
...
@@ -2,7 +2,6 @@ package com.github.shadowsocks
...
@@ -2,7 +2,6 @@ package com.github.shadowsocks
import
android.content.Intent
import
android.content.Intent
import
android.os.
{
Bundle
,
Handler
}
import
android.os.
{
Bundle
,
Handler
}
import
android.support.design.widget.Snackbar
import
android.support.v7.app.
{
AlertDialog
,
AppCompatActivity
}
import
android.support.v7.app.
{
AlertDialog
,
AppCompatActivity
}
import
android.support.v7.widget.RecyclerView.ViewHolder
import
android.support.v7.widget.RecyclerView.ViewHolder
import
android.support.v7.widget.Toolbar.OnMenuItemClickListener
import
android.support.v7.widget.Toolbar.OnMenuItemClickListener
...
@@ -11,12 +10,12 @@ import android.support.v7.widget.helper.ItemTouchHelper.SimpleCallback
...
@@ -11,12 +10,12 @@ import android.support.v7.widget.helper.ItemTouchHelper.SimpleCallback
import
android.support.v7.widget.
{
DefaultItemAnimator
,
LinearLayoutManager
,
RecyclerView
,
Toolbar
}
import
android.support.v7.widget.
{
DefaultItemAnimator
,
LinearLayoutManager
,
RecyclerView
,
Toolbar
}
import
android.text.style.TextAppearanceSpan
import
android.text.style.TextAppearanceSpan
import
android.text.
{
SpannableStringBuilder
,
Spanned
}
import
android.text.
{
SpannableStringBuilder
,
Spanned
}
import
android.view.View.
{
OnAttachStateChangeListener
,
OnClickListener
}
import
android.view.
{
LayoutInflater
,
MenuItem
,
View
,
ViewGroup
}
import
android.view.
{
LayoutInflater
,
MenuItem
,
View
,
ViewGroup
}
import
android.widget.
{
CheckedTextView
,
ImageView
,
LinearLayout
,
Toast
}
import
android.widget.
{
CheckedTextView
,
ImageView
,
LinearLayout
,
Toast
}
import
com.github.shadowsocks.aidl.IShadowsocksServiceCallback
import
com.github.shadowsocks.aidl.IShadowsocksServiceCallback
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.utils.
{
Parser
,
TrafficMonitor
,
Utils
}
import
com.github.shadowsocks.utils.
{
Parser
,
TrafficMonitor
,
Utils
}
import
com.github.shadowsocks.widget.UndoSnackbarManager
import
com.google.zxing.integration.android.IntentIntegrator
import
com.google.zxing.integration.android.IntentIntegrator
import
net.glxn.qrgen.android.QRCode
import
net.glxn.qrgen.android.QRCode
...
@@ -33,7 +32,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
...
@@ -33,7 +32,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
import
ProfileManagerActivity._
import
ProfileManagerActivity._
private
class
ProfileViewHolder
(
val
view
:
View
)
extends
RecyclerView
.
ViewHolder
(
view
)
with
View
.
OnClickListener
{
private
class
ProfileViewHolder
(
val
view
:
View
)
extends
RecyclerView
.
ViewHolder
(
view
)
with
View
.
OnClickListener
{
private
var
item
:
Profile
=
_
var
item
:
Profile
=
_
private
val
text
=
itemView
.
findViewById
(
android
.
R
.
id
.
text1
).
asInstanceOf
[
CheckedTextView
]
private
val
text
=
itemView
.
findViewById
(
android
.
R
.
id
.
text1
).
asInstanceOf
[
CheckedTextView
]
itemView
.
setOnClickListener
(
this
)
itemView
.
setOnClickListener
(
this
)
...
@@ -95,7 +94,6 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
...
@@ -95,7 +94,6 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
}
}
private
class
ProfilesAdapter
extends
RecyclerView
.
Adapter
[
ProfileViewHolder
]
{
private
class
ProfilesAdapter
extends
RecyclerView
.
Adapter
[
ProfileViewHolder
]
{
private
val
recycleBin
=
new
ArrayBuffer
[(
Int
,
Profile
)]
var
profiles
=
new
ArrayBuffer
[
Profile
]
var
profiles
=
new
ArrayBuffer
[
Profile
]
profiles
++=
ShadowsocksApplication
.
profileManager
.
getAllProfiles
.
getOrElse
(
List
.
empty
[
Profile
])
profiles
++=
ShadowsocksApplication
.
profileManager
.
getAllProfiles
.
getOrElse
(
List
.
empty
[
Profile
])
...
@@ -107,14 +105,14 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
...
@@ -107,14 +105,14 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
new
ProfileViewHolder
(
LayoutInflater
.
from
(
vg
.
getContext
).
inflate
(
R
.
layout
.
layout_profiles_item
,
vg
,
false
))
new
ProfileViewHolder
(
LayoutInflater
.
from
(
vg
.
getContext
).
inflate
(
R
.
layout
.
layout_profiles_item
,
vg
,
false
))
def
add
(
item
:
Profile
)
{
def
add
(
item
:
Profile
)
{
removedSnackbar
.
dismiss
undoManager
.
flush
commitRemoves
val
pos
=
getItemCount
val
pos
=
getItemCount
profiles
+=
item
profiles
+=
item
notifyItemInserted
(
pos
)
notifyItemInserted
(
pos
)
}
}
def
move
(
from
:
Int
,
to
:
Int
)
{
def
move
(
from
:
Int
,
to
:
Int
)
{
undoManager
.
flush
val
step
=
if
(
from
<
to
)
1
else
-
1
val
step
=
if
(
from
<
to
)
1
else
-
1
val
first
=
profiles
(
from
)
val
first
=
profiles
(
from
)
var
previousOrder
=
profiles
(
from
).
userOrder
var
previousOrder
=
profiles
(
from
).
userOrder
...
@@ -133,31 +131,24 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
...
@@ -133,31 +131,24 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
}
}
def
remove
(
pos
:
Int
)
{
def
remove
(
pos
:
Int
)
{
recycleBin
.
append
((
pos
,
profiles
(
pos
)))
profiles
.
remove
(
pos
)
profiles
.
remove
(
pos
)
notifyItemRemoved
(
pos
)
notifyItemRemoved
(
pos
)
}
}
def
undoRemoves
{
def
undo
(
actions
:
Iterator
[(
Int
,
Profile
)])
=
for
((
index
,
item
)
<-
actions
)
{
for
((
index
,
item
)
<-
recycleBin
.
reverseIterator
)
{
profiles
.
insert
(
index
,
item
)
profiles
.
insert
(
index
,
item
)
notifyItemInserted
(
index
)
notifyItemInserted
(
index
)
}
}
recycleBin
.
clear
def
commit
(
actions
:
Iterator
[(
Int
,
Profile
)])
=
for
((
index
,
item
)
<-
actions
)
{
}
def
commitRemoves
{
for
((
index
,
item
)
<-
recycleBin
)
{
ShadowsocksApplication
.
profileManager
.
delProfile
(
item
.
id
)
ShadowsocksApplication
.
profileManager
.
delProfile
(
item
.
id
)
if
(
item
.
id
==
ShadowsocksApplication
.
profileId
)
ShadowsocksApplication
.
profileId
(-
1
)
if
(
item
.
id
==
ShadowsocksApplication
.
profileId
)
ShadowsocksApplication
.
profileId
(-
1
)
}
}
recycleBin
.
clear
}
}
}
private
var
selectedItem
:
ProfileViewHolder
=
_
private
var
selectedItem
:
ProfileViewHolder
=
_
private
val
handler
=
new
Handler
private
val
handler
=
new
Handler
private
lazy
val
profilesAdapter
=
new
ProfilesAdapter
private
lazy
val
profilesAdapter
=
new
ProfilesAdapter
private
var
removedSnackbar
:
Snackbar
=
_
private
var
undoManager
:
UndoSnackbarManager
[
Profile
]
=
_
override
def
onCreate
(
savedInstanceState
:
Bundle
)
{
override
def
onCreate
(
savedInstanceState
:
Bundle
)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
...
@@ -182,17 +173,13 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
...
@@ -182,17 +173,13 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
layoutManager
.
scrollToPosition
(
profilesAdapter
.
profiles
.
zipWithIndex
.
collectFirst
{
layoutManager
.
scrollToPosition
(
profilesAdapter
.
profiles
.
zipWithIndex
.
collectFirst
{
case
(
profile
,
i
)
if
profile
.
id
==
ShadowsocksApplication
.
profileId
=>
i
case
(
profile
,
i
)
if
profile
.
id
==
ShadowsocksApplication
.
profileId
=>
i
}.
getOrElse
(-
1
))
}.
getOrElse
(-
1
))
removedSnackbar
=
Snackbar
.
make
(
profilesList
,
R
.
string
.
removed
,
Snackbar
.
LENGTH_LONG
)
undoManager
=
new
UndoSnackbarManager
[
Profile
](
profilesList
,
profilesAdapter
.
undo
,
profilesAdapter
.
commit
)
.
setAction
(
R
.
string
.
undo
,
((
v
:
View
)
=>
profilesAdapter
.
undoRemoves
)
:
OnClickListener
)
removedSnackbar
.
getView
.
addOnAttachStateChangeListener
(
new
OnAttachStateChangeListener
{
def
onViewDetachedFromWindow
(
v
:
View
)
=
profilesAdapter
.
commitRemoves
def
onViewAttachedToWindow
(
v
:
View
)
=
()
})
new
ItemTouchHelper
(
new
SimpleCallback
(
ItemTouchHelper
.
UP
|
ItemTouchHelper
.
DOWN
,
new
ItemTouchHelper
(
new
SimpleCallback
(
ItemTouchHelper
.
UP
|
ItemTouchHelper
.
DOWN
,
ItemTouchHelper
.
START
|
ItemTouchHelper
.
END
)
{
ItemTouchHelper
.
START
|
ItemTouchHelper
.
END
)
{
def
onSwiped
(
viewHolder
:
ViewHolder
,
direction
:
Int
)
=
{
def
onSwiped
(
viewHolder
:
ViewHolder
,
direction
:
Int
)
=
{
profilesAdapter
.
remove
(
viewHolder
.
getAdapterPosition
)
val
index
=
viewHolder
.
getAdapterPosition
removedSnackbar
.
show
profilesAdapter
.
remove
(
index
)
undoManager
.
remove
(
index
,
viewHolder
.
asInstanceOf
[
ProfileViewHolder
].
item
)
}
}
def
onMove
(
recyclerView
:
RecyclerView
,
viewHolder
:
ViewHolder
,
target
:
ViewHolder
)
=
{
def
onMove
(
recyclerView
:
RecyclerView
,
viewHolder
:
ViewHolder
,
target
:
ViewHolder
)
=
{
profilesAdapter
.
move
(
viewHolder
.
getAdapterPosition
,
target
.
getAdapterPosition
)
profilesAdapter
.
move
(
viewHolder
.
getAdapterPosition
,
target
.
getAdapterPosition
)
...
@@ -224,9 +211,9 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
...
@@ -224,9 +211,9 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
override
def
onDestroy
{
override
def
onDestroy
{
deattachService
()
deattachService
()
super
.
onDestroy
undoManager
.
flush
ShadowsocksApplication
.
profileManager
.
setProfileAddedListener
(
null
)
ShadowsocksApplication
.
profileManager
.
setProfileAddedListener
(
null
)
profilesAdapter
.
commitRemoves
super
.
onDestroy
}
}
override
def
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
)
{
override
def
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
)
{
...
...
src/main/scala/com/github/shadowsocks/widget/UndoSnackbarManager.scala
0 → 100644
View file @
d7946326
package
com.github.shadowsocks.widget
import
android.support.design.widget.Snackbar
import
android.view.View
import
com.github.shadowsocks.R
import
scala.collection.mutable.ArrayBuffer
/**
* @author Mygod
* @param view The view to find a parent from.
* @param undo Callback for undoing removals.
* @param commit Callback for committing removals.
* @tparam T Item type.
*/
class
UndoSnackbarManager
[
T
](
view
:
View
,
undo
:
Iterator
[(
Int
,
T
)]
=>
Unit
,
commit
:
Iterator
[(
Int
,
T
)]
=>
Unit
=
null
)
{
private
val
recycleBin
=
new
ArrayBuffer
[(
Int
,
T
)]
private
val
removedCallback
=
new
Snackbar
.
Callback
{
override
def
onDismissed
(
snackbar
:
Snackbar
,
event
:
Int
)
=
{
event
match
{
case
Snackbar
.
Callback
.
DISMISS_EVENT_MANUAL
|
Snackbar
.
Callback
.
DISMISS_EVENT_TIMEOUT
=>
if
(
commit
!=
null
)
commit
(
recycleBin
.
iterator
)
recycleBin
.
clear
case
_
=>
}
last
=
null
}
}
private
var
last
:
Snackbar
=
_
def
remove
(
index
:
Int
,
item
:
T
)
=
{
recycleBin
.
append
((
index
,
item
))
val
count
=
recycleBin
.
length
last
=
Snackbar
.
make
(
view
,
view
.
getResources
.
getQuantityString
(
R
.
plurals
.
removed
,
count
,
count
:
Integer
),
Snackbar
.
LENGTH_LONG
)
.
setCallback
(
removedCallback
).
setAction
(
R
.
string
.
undo
,
(
_
=>
{
undo
(
recycleBin
.
reverseIterator
)
recycleBin
.
clear
})
:
View.OnClickListener
)
last
.
show
}
def
flush
=
if
(
last
!=
null
)
last
.
dismiss
}
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