Skip to content

Commit

Permalink
Fix server order
Browse files Browse the repository at this point in the history
  • Loading branch information
HMBSbige committed Nov 7, 2019
1 parent 5722a36 commit adc1502
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 98 deletions.
5 changes: 1 addition & 4 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-keep class com.github.shadowsocks.System { *; }
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-keep class okio.** { *; }
-keep interface okio.** { *; }
-dontwarn okio.**
-dontwarn com.google.android.gms.internal.**
-dontwarn com.j256.ormlite.**
-dontwarn org.xbill.**
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault
-dontwarn org.xbill.**
12 changes: 10 additions & 2 deletions app/src/main/java/com/github/shadowsocks/ProfileManagerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,17 @@ class ProfileManagerActivity : AppCompatActivity(), View.OnClickListener, Toolba
val first = profiles[from]
var previousOrder = profiles[from].userOrder
var i = from
while (i < to)
while (true)
{
if (step > 0 && i >= to)
{
break
}
else if (step < 0 && i <= to)
{
break
}

val next = profiles[i + step]
val order = next.userOrder
next.userOrder = previousOrder
Expand All @@ -1143,7 +1152,6 @@ class ProfileManagerActivity : AppCompatActivity(), View.OnClickListener, Toolba
val remove = profiles.removeAt(pos)
ShadowsocksApplication.app.profileManager.delProfile(remove.id)
notifyItemRemoved(pos)

}

fun undo(actions: SparseArray<Profile>)
Expand Down
30 changes: 15 additions & 15 deletions app/src/main/java/com/github/shadowsocks/database/ProfileManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ProfileManager(private val dbHelper: DBHelper)
{
return try
{
dbHelper.profileDao.query(dbHelper.profileDao.queryBuilder().orderBy("url_group", true).orderBy("name", true).prepare())
dbHelper.profileDao.query(dbHelper.profileDao.queryBuilder().orderBy("userOrder", true).prepare())
}
catch (e: Exception)
{
Expand Down Expand Up @@ -101,7 +101,7 @@ class ProfileManager(private val dbHelper: DBHelper)

init
{
this.mProfileAddedListeners = ArrayList(20)
mProfileAddedListeners = ArrayList(20)
}

/**
Expand Down Expand Up @@ -176,7 +176,7 @@ class ProfileManager(private val dbHelper: DBHelper)
profile.userOrder = (Integer.parseInt(last[0]) + 1).toLong()
}

val last_exist = dbHelper.profileDao.queryBuilder()
val lastExist = dbHelper.profileDao.queryBuilder()
.where()
.eq("name", profile.name)
.and()
Expand All @@ -198,7 +198,7 @@ class ProfileManager(private val dbHelper: DBHelper)
.and()
.eq("method", profile.method)
.queryForFirst()
if (last_exist == null)
if (lastExist == null)
{
dbHelper.profileDao.createOrUpdate(profile)
invokeProfileAdded(profile)
Expand Down Expand Up @@ -245,7 +245,7 @@ class ProfileManager(private val dbHelper: DBHelper)
profile.userOrder = (Integer.parseInt(last[0]) + 1).toLong()
}

val last_exist = dbHelper.profileDao.queryBuilder()
val lastExist = dbHelper.profileDao.queryBuilder()
.where()
.eq("name", profile.name)
.and()
Expand All @@ -267,14 +267,14 @@ class ProfileManager(private val dbHelper: DBHelper)
.and()
.eq("method", profile.method)
.queryForFirst()
return if (last_exist == null)
return if (lastExist == null)
{
dbHelper.profileDao.createOrUpdate(profile)
0
}
else
{
last_exist.id
lastExist.id
}
}
catch (e: SQLException)
Expand Down Expand Up @@ -408,7 +408,7 @@ class ProfileManager(private val dbHelper: DBHelper)
{
return try
{
dbHelper.profileDao.query(dbHelper.profileDao.queryBuilder().orderBy("name", true).where().like("url_group", "$group%").prepare())
dbHelper.profileDao.query(dbHelper.profileDao.queryBuilder().orderBy("userOrder", true).where().like("url_group", "$group%").prepare())
}
catch (e: Exception)
{
Expand Down Expand Up @@ -447,13 +447,13 @@ class ProfileManager(private val dbHelper: DBHelper)
{
val profile = Profile()
profile.name = "ShadowsocksR"
profile.host = "1.1.1.1"
profile.remotePort = 80
profile.password = "androidssr"
profile.protocol = "auth_chain_a"
profile.obfs = "http_simple"
profile.method = "none"
profile.url_group = "ShadowsocksR"
profile.host = Constants.DefaultHostName
profile.remotePort = 8388
profile.password = ""
profile.protocol = "origin"
profile.obfs = "plain"
profile.method = "aes-256-cfb"
profile.url_group = "Default Group"
return createProfile(profile)
}

Expand Down
80 changes: 4 additions & 76 deletions app/src/main/java/com/github/shadowsocks/database/SSRSubManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,6 @@ class SSRSubManager(private val dbHelper: DBHelper)
{
private val mSSRSubAddedListeners: MutableList<SSRSubAddedListener>?

val firstSSRSub: SSRSub?
get()
{
try
{
val result = dbHelper.ssrsubDao.query(dbHelper.ssrsubDao.queryBuilder().limit(1L).prepare())
return if (result != null && result.isNotEmpty())
{
result[0]
}
else
{
null
}
}
catch (e: Exception)
{
VayLog.e(TAG, "getAllSSRSubs", e)
ShadowsocksApplication.app.track(e)
return null
}

}

val allSSRSubs: List<SSRSub>
get()
{
Expand All @@ -54,15 +30,7 @@ class SSRSubManager(private val dbHelper: DBHelper)

fun createSSRSub(p: SSRSub?): SSRSub
{
val ssrsub: SSRSub
if (p == null)
{
ssrsub = SSRSub()
}
else
{
ssrsub = p
}
val ssrsub: SSRSub = p ?: SSRSub()
ssrsub.id = 0

try
Expand All @@ -79,59 +47,19 @@ class SSRSubManager(private val dbHelper: DBHelper)
return ssrsub
}

fun updateSSRSub(ssrsub: SSRSub): Boolean
{
try
{
dbHelper.ssrsubDao.update(ssrsub)
return true
}
catch (e: Exception)
{
VayLog.e(TAG, "updateSSRSub", e)
ShadowsocksApplication.app.track(e)
return false
}

}

fun getSSRSub(id: Int): SSRSub?
{
try
{
return dbHelper.ssrsubDao.queryForId(id)
}
catch (e: Exception)
{
VayLog.e(TAG, "getSSRSub", e)
ShadowsocksApplication.app.track(e)
return null
}

}

fun delSSRSub(id: Int): Boolean
{
try
return try
{
dbHelper.ssrsubDao.deleteById(id)
return true
true
}
catch (e: Exception)
{
VayLog.e(TAG, "delSSRSub", e)
ShadowsocksApplication.app.track(e)
return false
false
}

}

fun createDefault(): SSRSub
{
val ssrSub = SSRSub()
ssrSub.url = "https://raw.githubusercontent.com/HMBSbige/Text_Translation/master/ShadowsocksR/freenodeplain.txt"
ssrSub.url_group = "ShadowsocksR"
return createSSRSub(ssrSub)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ class SubUpdateHelper private constructor()
.toMutableList()
val responseString = Base64.decodeUrlSafe(response)
val profiles = Parser.findAllSsr(responseString)
profiles.shuffle()

for (profile in profiles)
{
Expand Down

0 comments on commit adc1502

Please sign in to comment.