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
49fbfcc2
Commit
49fbfcc2
authored
Jan 09, 2017
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine an issue mentioned in #1064
parent
c2930bfe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
16 deletions
+20
-16
src/main/scala/com/github/shadowsocks/acl/CustomRulesFragment.scala
...cala/com/github/shadowsocks/acl/CustomRulesFragment.scala
+20
-16
No files found.
src/main/scala/com/github/shadowsocks/acl/CustomRulesFragment.scala
View file @
49fbfcc2
...
@@ -4,7 +4,7 @@ import java.net.IDN
...
@@ -4,7 +4,7 @@ import java.net.IDN
import
java.util.Locale
import
java.util.Locale
import
android.content.
{
ClipData
,
ClipboardManager
,
Context
,
DialogInterface
}
import
android.content.
{
ClipData
,
ClipboardManager
,
Context
,
DialogInterface
}
import
android.os.
{
Bundle
,
Handler
}
import
android.os.
Bundle
import
android.support.design.widget.Snackbar
import
android.support.design.widget.Snackbar
import
android.support.v7.app.AlertDialog
import
android.support.v7.app.AlertDialog
import
android.support.v7.widget.RecyclerView.ViewHolder
import
android.support.v7.widget.RecyclerView.ViewHolder
...
@@ -62,7 +62,6 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
...
@@ -62,7 +62,6 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
.
setView
(
view
))
.
setView
(
view
))
}
}
private
val
handler
=
new
Handler
()
private
val
selectedItems
=
new
mutable
.
HashSet
[
AnyRef
]
private
val
selectedItems
=
new
mutable
.
HashSet
[
AnyRef
]
private
def
onSelectedItemsUpdated
()
:
Unit
=
if
(
selectionItem
!=
null
)
{
private
def
onSelectedItemsUpdated
()
:
Unit
=
if
(
selectionItem
!=
null
)
{
selectionItem
.
setVisible
(
selectedItems
.
nonEmpty
)
selectionItem
.
setVisible
(
selectedItems
.
nonEmpty
)
...
@@ -95,7 +94,10 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
...
@@ -95,7 +94,10 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
undoManager
.
remove
((-
1
,
item
))
undoManager
.
remove
((-
1
,
item
))
})
:
DialogInterface.OnClickListener
)
})
:
DialogInterface.OnClickListener
)
.
setPositiveButton
(
android
.
R
.
string
.
ok
,
((
_
,
_
)
=>
.
setPositiveButton
(
android
.
R
.
string
.
ok
,
((
_
,
_
)
=>
if
(
adapter
.
addFromTemplate
(
templateSelector
.
getSelectedItemPosition
,
editText
.
getText
))
adapter
.
remove
(
item
))
adapter
.
addFromTemplate
(
templateSelector
.
getSelectedItemPosition
,
editText
.
getText
)
match
{
case
-
1
=>
adapter
.
remove
(
item
)
case
index
=>
list
.
post
(()
=>
list
.
scrollToPosition
(
index
))
})
:
DialogInterface.OnClickListener
)
:
DialogInterface.OnClickListener
)
.
create
().
show
()
.
create
().
show
()
}
}
...
@@ -112,7 +114,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
...
@@ -112,7 +114,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
private
var
savePending
:
Boolean
=
_
private
var
savePending
:
Boolean
=
_
private
def
apply
()
=
if
(!
savePending
)
{
private
def
apply
()
=
if
(!
savePending
)
{
savePending
=
true
savePending
=
true
handler
.
post
(()
=>
{
list
.
post
(()
=>
{
Acl
.
save
(
Acl
.
CUSTOM_RULES
,
acl
)
Acl
.
save
(
Acl
.
CUSTOM_RULES
,
acl
)
savePending
=
false
savePending
=
false
})
})
...
@@ -126,28 +128,30 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
...
@@ -126,28 +128,30 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
def
onCreateViewHolder
(
vg
:
ViewGroup
,
i
:
Int
)
=
new
AclRuleViewHolder
(
LayoutInflater
.
from
(
vg
.
getContext
)
def
onCreateViewHolder
(
vg
:
ViewGroup
,
i
:
Int
)
=
new
AclRuleViewHolder
(
LayoutInflater
.
from
(
vg
.
getContext
)
.
inflate
(
android
.
R
.
layout
.
simple_list_item_1
,
vg
,
false
))
.
inflate
(
android
.
R
.
layout
.
simple_list_item_1
,
vg
,
false
))
def
addSubnet
(
subnet
:
Subnet
)
:
Boolean
=
if
(
acl
.
subnets
.
add
(
subnet
))
{
def
addSubnet
(
subnet
:
Subnet
)
:
Int
=
if
(
acl
.
subnets
.
add
(
subnet
))
{
notifyItemInserted
(
acl
.
subnets
.
indexOf
(
subnet
))
val
index
=
acl
.
subnets
.
indexOf
(
subnet
)
notifyItemInserted
(
index
)
apply
()
apply
()
true
index
}
else
false
}
else
-
1
def
addHostname
(
hostname
:
String
)
:
Boolean
=
if
(
acl
.
proxyHostnames
.
add
(
hostname
))
{
def
addHostname
(
hostname
:
String
)
:
Int
=
if
(
acl
.
proxyHostnames
.
add
(
hostname
))
{
notifyItemInserted
(
acl
.
proxyHostnames
.
indexOf
(
hostname
)
+
acl
.
subnets
.
size
)
val
index
=
acl
.
proxyHostnames
.
indexOf
(
hostname
)
+
acl
.
subnets
.
size
notifyItemInserted
(
index
)
apply
()
apply
()
true
index
}
else
false
}
else
-
1
def
addToProxy
(
input
:
String
)
:
Boolean
=
try
addSubnet
(
Subnet
.
fromString
(
input
))
catch
{
def
addToProxy
(
input
:
String
)
:
Int
=
try
addSubnet
(
Subnet
.
fromString
(
input
))
catch
{
case
_:
IllegalArgumentException
=>
addHostname
(
input
)
case
_:
IllegalArgumentException
=>
addHostname
(
input
)
}
}
def
addFromTemplate
(
template
:
Int
,
text
:
CharSequence
)
:
Boolean
=
template
match
{
def
addFromTemplate
(
template
:
Int
,
text
:
CharSequence
)
:
Int
=
template
match
{
case
GENERIC
=>
addToProxy
(
text
.
toString
)
case
GENERIC
=>
addToProxy
(
text
.
toString
)
case
DOMAIN
=>
try
addHostname
(
TEMPLATE_DOMAIN
.
formatLocal
(
Locale
.
ENGLISH
,
case
DOMAIN
=>
try
addHostname
(
TEMPLATE_DOMAIN
.
formatLocal
(
Locale
.
ENGLISH
,
IDN
.
toASCII
(
text
.
toString
,
IDN
.
ALLOW_UNASSIGNED
|
IDN
.
USE_STD3_ASCII_RULES
).
replaceAll
(
"\\."
,
"\\\\."
)))
catch
{
IDN
.
toASCII
(
text
.
toString
,
IDN
.
ALLOW_UNASSIGNED
|
IDN
.
USE_STD3_ASCII_RULES
).
replaceAll
(
"\\."
,
"\\\\."
)))
catch
{
case
exc
:
IllegalArgumentException
=>
case
exc
:
IllegalArgumentException
=>
Toast
.
makeText
(
getActivity
,
exc
.
getMessage
,
Toast
.
LENGTH_SHORT
).
show
()
Toast
.
makeText
(
getActivity
,
exc
.
getMessage
,
Toast
.
LENGTH_SHORT
).
show
()
false
-
1
}
}
case
_
=>
false
case
_
=>
-
1
}
}
def
remove
(
i
:
Int
)
{
def
remove
(
i
:
Int
)
{
...
...
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