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
7e5b44d3
Commit
7e5b44d3
authored
Dec 25, 2015
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Scroll to selected profile
parent
2a5d8846
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
...scala/com/github/shadowsocks/ProfileManagerActivity.scala
+11
-4
No files found.
src/main/scala/com/github/shadowsocks/ProfileManagerActivity.scala
View file @
7e5b44d3
...
@@ -72,11 +72,12 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
...
@@ -72,11 +72,12 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
handler
.
post
(()
=>
text
.
setText
(
builder
))
handler
.
post
(()
=>
text
.
setText
(
builder
))
}
}
def
bind
(
item
:
Profile
)
{
def
bind
(
item
:
Profile
,
i
:
Int
)
{
this
.
item
=
item
this
.
item
=
item
updateText
()
updateText
()
if
(
item
.
id
==
ShadowsocksApplication
.
profileId
)
{
if
(
item
.
id
==
ShadowsocksApplication
.
profileId
)
{
text
.
setChecked
(
true
)
text
.
setChecked
(
true
)
selectedIndex
=
i
selectedItem
=
this
selectedItem
=
this
}
else
{
}
else
{
text
.
setChecked
(
false
)
text
.
setChecked
(
false
)
...
@@ -92,12 +93,12 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
...
@@ -92,12 +93,12 @@ 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
)]
private
val
recycleBin
=
new
ArrayBuffer
[(
Int
,
Profile
)]
private
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
])
def
getItemCount
=
profiles
.
length
def
getItemCount
=
profiles
.
length
def
onBindViewHolder
(
vh
:
ProfileViewHolder
,
i
:
Int
)
=
vh
.
bind
(
profiles
(
i
))
def
onBindViewHolder
(
vh
:
ProfileViewHolder
,
i
:
Int
)
=
vh
.
bind
(
profiles
(
i
)
,
i
)
def
onCreateViewHolder
(
vg
:
ViewGroup
,
i
:
Int
)
=
def
onCreateViewHolder
(
vg
:
ViewGroup
,
i
:
Int
)
=
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
))
...
@@ -131,6 +132,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
...
@@ -131,6 +132,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
}
}
}
}
private
var
selectedIndex
=
-
1
private
var
selectedItem
:
ProfileViewHolder
=
_
private
var
selectedItem
:
ProfileViewHolder
=
_
private
val
handler
=
new
Handler
private
val
handler
=
new
Handler
...
@@ -153,9 +155,14 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
...
@@ -153,9 +155,14 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
ShadowsocksApplication
.
profileManager
.
setProfileAddedListener
(
profilesAdapter
.
add
)
ShadowsocksApplication
.
profileManager
.
setProfileAddedListener
(
profilesAdapter
.
add
)
val
profilesList
=
findViewById
(
R
.
id
.
profilesList
).
asInstanceOf
[
RecyclerView
]
val
profilesList
=
findViewById
(
R
.
id
.
profilesList
).
asInstanceOf
[
RecyclerView
]
profilesList
.
setLayoutManager
(
new
LinearLayoutManager
(
this
))
val
layoutManager
=
new
LinearLayoutManager
(
this
)
profilesList
.
setLayoutManager
(
layoutManager
)
profilesList
.
setItemAnimator
(
new
DefaultItemAnimator
)
profilesList
.
setItemAnimator
(
new
DefaultItemAnimator
)
profilesList
.
setAdapter
(
profilesAdapter
)
profilesList
.
setAdapter
(
profilesAdapter
)
if
(
selectedIndex
<
0
)
selectedIndex
=
profilesAdapter
.
profiles
.
zipWithIndex
.
collectFirst
{
case
(
profile
,
i
)
if
profile
.
id
==
ShadowsocksApplication
.
profileId
=>
i
}.
getOrElse
(-
1
)
layoutManager
.
scrollToPosition
(
selectedIndex
)
removedSnackbar
=
Snackbar
.
make
(
profilesList
,
R
.
string
.
removed
,
Snackbar
.
LENGTH_LONG
)
removedSnackbar
=
Snackbar
.
make
(
profilesList
,
R
.
string
.
removed
,
Snackbar
.
LENGTH_LONG
)
.
setAction
(
R
.
string
.
undo
,
((
v
:
View
)
=>
profilesAdapter
.
undoRemoves
)
:
OnClickListener
)
.
setAction
(
R
.
string
.
undo
,
((
v
:
View
)
=>
profilesAdapter
.
undoRemoves
)
:
OnClickListener
)
removedSnackbar
.
getView
.
addOnAttachStateChangeListener
(
new
OnAttachStateChangeListener
{
removedSnackbar
.
getView
.
addOnAttachStateChangeListener
(
new
OnAttachStateChangeListener
{
...
...
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