Commit b397ab2b authored by Mygod's avatar Mygod

Support pasting multiple lines

parent 33c087f1
...@@ -10,6 +10,5 @@ ...@@ -10,6 +10,5 @@
<EditText android:id="@+id/content" <EditText android:id="@+id/content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="textNoSuggestions" android:inputType="textNoSuggestions|textMultiLine"/>
android:lines="1"/>
</LinearLayout> </LinearLayout>
...@@ -20,6 +20,7 @@ import com.github.shadowsocks.widget.UndoSnackbarManager ...@@ -20,6 +20,7 @@ import com.github.shadowsocks.widget.UndoSnackbarManager
import com.github.shadowsocks.{MainActivity, R, ToolbarFragment} import com.github.shadowsocks.{MainActivity, R, ToolbarFragment}
import scala.collection.mutable import scala.collection.mutable
import scala.io.Source
/** /**
* @author Mygod * @author Mygod
...@@ -144,8 +145,12 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi ...@@ -144,8 +145,12 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
apply() apply()
index index
} else -1 } else -1
def addToProxy(input: String): Int = try addSubnet(Subnet.fromString(input)) catch { def addToProxy(input: String): Int = {
case _: IllegalArgumentException => addHostname(input) val acl = new Acl().fromSource(Source.fromString(input), defaultBypass = true)
var result = -1
for (hostname <- acl.proxyHostnames) result = addHostname(hostname)
if (acl.bypass) for (subnet <- acl.subnets) result = addSubnet(subnet)
result
} }
def addFromTemplate(template: Int, text: CharSequence): Int = template match { def addFromTemplate(template: Int, text: CharSequence): Int = template match {
case GENERIC => addToProxy(text.toString) case GENERIC => addToProxy(text.toString)
...@@ -298,13 +303,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi ...@@ -298,13 +303,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
.create().show() .create().show()
true true
case R.id.action_import => case R.id.action_import =>
try { try if (adapter.addToProxy(clipboard.getPrimaryClip.getItemAt(0).getText.toString) != -1) return true catch {
val items = clipboard.getPrimaryClip.getItemAt(0).getText.toString.split("\n")
if (items.nonEmpty) {
items.foreach(adapter.addToProxy)
return true
}
} catch {
case _: Exception => case _: Exception =>
} }
Snackbar.make(getActivity.findViewById(R.id.snackbar), R.string.action_import_err, Snackbar.LENGTH_LONG).show() Snackbar.make(getActivity.findViewById(R.id.snackbar), R.string.action_import_err, Snackbar.LENGTH_LONG).show()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment