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
06df4227
Commit
06df4227
authored
Jun 14, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Be more informative about import errors
parent
902dfb3e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
19 deletions
+29
-19
core/src/main/java/com/github/shadowsocks/database/ProfileManager.kt
...in/java/com/github/shadowsocks/database/ProfileManager.kt
+2
-5
core/src/main/java/com/github/shadowsocks/utils/Utils.kt
core/src/main/java/com/github/shadowsocks/utils/Utils.kt
+13
-0
mobile/src/main/java/com/github/shadowsocks/ScannerActivity.kt
...e/src/main/java/com/github/shadowsocks/ScannerActivity.kt
+14
-14
No files found.
core/src/main/java/com/github/shadowsocks/database/ProfileManager.kt
View file @
06df4227
...
@@ -25,6 +25,7 @@ import android.util.LongSparseArray
...
@@ -25,6 +25,7 @@ import android.util.LongSparseArray
import
com.github.shadowsocks.Core
import
com.github.shadowsocks.Core
import
com.github.shadowsocks.preference.DataStore
import
com.github.shadowsocks.preference.DataStore
import
com.github.shadowsocks.utils.DirectBoot
import
com.github.shadowsocks.utils.DirectBoot
import
com.github.shadowsocks.utils.forEachTry
import
com.github.shadowsocks.utils.printLog
import
com.github.shadowsocks.utils.printLog
import
com.google.gson.JsonParser
import
com.google.gson.JsonParser
import
com.google.gson.stream.JsonReader
import
com.google.gson.stream.JsonReader
...
@@ -61,8 +62,7 @@ object ProfileManager {
...
@@ -61,8 +62,7 @@ object ProfileManager {
profiles
?.
values
?.
singleOrNull
{
it
.
id
==
DataStore
.
profileId
}
profiles
?.
values
?.
singleOrNull
{
it
.
id
==
DataStore
.
profileId
}
}
else
Core
.
currentProfile
?.
first
}
else
Core
.
currentProfile
?.
first
val
lazyClear
=
lazy
{
clear
()
}
val
lazyClear
=
lazy
{
clear
()
}
var
result
:
Exception
?
=
null
jsons
.
asIterable
().
forEachTry
{
json
->
for
(
json
in
jsons
)
try
{
Profile
.
parseJson
(
jsonParser
.
parse
(
JsonReader
(
json
.
bufferedReader
()).
apply
{
Profile
.
parseJson
(
jsonParser
.
parse
(
JsonReader
(
json
.
bufferedReader
()).
apply
{
isLenient
=
true
isLenient
=
true
}),
feature
)
{
}),
feature
)
{
...
@@ -76,10 +76,7 @@ object ProfileManager {
...
@@ -76,10 +76,7 @@ object ProfileManager {
}
}
createProfile
(
it
)
createProfile
(
it
)
}
}
}
catch
(
e
:
Exception
)
{
if
(
result
==
null
)
result
=
e
else
result
.
addSuppressed
(
e
)
}
}
if
(
result
!=
null
)
throw
result
}
}
fun
serializeToJson
(
profiles
:
List
<
Profile
>?
=
getAllProfiles
()):
JSONArray
?
{
fun
serializeToJson
(
profiles
:
List
<
Profile
>?
=
getAllProfiles
()):
JSONArray
?
{
if
(
profiles
==
null
)
return
null
if
(
profiles
==
null
)
return
null
...
...
core/src/main/java/com/github/shadowsocks/utils/Utils.kt
View file @
06df4227
...
@@ -45,6 +45,19 @@ import java.net.HttpURLConnection
...
@@ -45,6 +45,19 @@ import java.net.HttpURLConnection
import
java.net.InetAddress
import
java.net.InetAddress
import
kotlin.coroutines.resume
import
kotlin.coroutines.resume
fun
<
T
>
Iterable
<
T
>.
forEachTry
(
action
:
(
T
)
->
Unit
)
{
var
result
:
Exception
?
=
null
for
(
element
in
this
)
try
{
action
(
element
)
}
catch
(
e
:
Exception
)
{
if
(
result
==
null
)
result
=
e
else
result
.
addSuppressed
(
e
)
}
if
(
result
!=
null
)
{
result
.
printStackTrace
()
throw
result
}
}
val
Throwable
.
readableMessage
get
()
=
localizedMessage
?:
javaClass
.
name
val
Throwable
.
readableMessage
get
()
=
localizedMessage
?:
javaClass
.
name
private
val
parseNumericAddress
by
lazy
@SuppressLint
(
"DiscouragedPrivateApi"
)
{
private
val
parseNumericAddress
by
lazy
@SuppressLint
(
"DiscouragedPrivateApi"
)
{
...
...
mobile/src/main/java/com/github/shadowsocks/ScannerActivity.kt
View file @
06df4227
...
@@ -40,9 +40,7 @@ import androidx.core.util.forEach
...
@@ -40,9 +40,7 @@ import androidx.core.util.forEach
import
com.crashlytics.android.Crashlytics
import
com.crashlytics.android.Crashlytics
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.database.ProfileManager
import
com.github.shadowsocks.database.ProfileManager
import
com.github.shadowsocks.utils.datas
import
com.github.shadowsocks.utils.*
import
com.github.shadowsocks.utils.openBitmap
import
com.github.shadowsocks.utils.printLog
import
com.google.android.gms.common.GoogleApiAvailability
import
com.google.android.gms.common.GoogleApiAvailability
import
com.google.android.gms.samples.vision.barcodereader.BarcodeCapture
import
com.google.android.gms.samples.vision.barcodereader.BarcodeCapture
import
com.google.android.gms.samples.vision.barcodereader.BarcodeGraphic
import
com.google.android.gms.samples.vision.barcodereader.BarcodeGraphic
...
@@ -142,8 +140,9 @@ class ScannerActivity : AppCompatActivity(), BarcodeRetriever {
...
@@ -142,8 +140,9 @@ class ScannerActivity : AppCompatActivity(), BarcodeRetriever {
when
(
requestCode
)
{
when
(
requestCode
)
{
REQUEST_IMPORT
,
REQUEST_IMPORT_OR_FINISH
->
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
REQUEST_IMPORT
,
REQUEST_IMPORT_OR_FINISH
->
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
val
feature
=
Core
.
currentProfile
?.
first
val
feature
=
Core
.
currentProfile
?.
first
try
{
var
success
=
false
var
success
=
false
for
(
uri
in
data
!!
.
datas
)
try
{
data
!!
.
datas
.
forEachTry
{
uri
->
detector
.
detect
(
Frame
.
Builder
().
setBitmap
(
contentResolver
.
openBitmap
(
uri
)).
build
())
detector
.
detect
(
Frame
.
Builder
().
setBitmap
(
contentResolver
.
openBitmap
(
uri
)).
build
())
.
forEach
{
_
,
barcode
->
.
forEach
{
_
,
barcode
->
Profile
.
findAllUrls
(
barcode
.
rawValue
,
feature
).
forEach
{
Profile
.
findAllUrls
(
barcode
.
rawValue
,
feature
).
forEach
{
...
@@ -151,11 +150,12 @@ class ScannerActivity : AppCompatActivity(), BarcodeRetriever {
...
@@ -151,11 +150,12 @@ class ScannerActivity : AppCompatActivity(), BarcodeRetriever {
success
=
true
success
=
true
}
}
}
}
}
catch
(
e
:
Exception
)
{
printLog
(
e
)
}
}
Toast
.
makeText
(
this
,
if
(
success
)
R
.
string
.
action_import_msg
else
R
.
string
.
action_import_err
,
Toast
.
makeText
(
this
,
if
(
success
)
R
.
string
.
action_import_msg
else
R
.
string
.
action_import_err
,
Toast
.
LENGTH_SHORT
).
show
()
Toast
.
LENGTH_SHORT
).
show
()
}
catch
(
e
:
Exception
)
{
Toast
.
makeText
(
this
,
e
.
readableMessage
,
Toast
.
LENGTH_LONG
).
show
()
}
onSupportNavigateUp
()
onSupportNavigateUp
()
}
else
if
(
requestCode
==
REQUEST_IMPORT_OR_FINISH
)
onSupportNavigateUp
()
}
else
if
(
requestCode
==
REQUEST_IMPORT_OR_FINISH
)
onSupportNavigateUp
()
else
->
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
)
else
->
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
)
...
...
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