update UI
This commit is contained in:
@@ -40,18 +40,20 @@
|
||||
package com.github.shadowsocks.database
|
||||
|
||||
import android.util.Log
|
||||
import com.github.shadowsocks.Shadowsocks
|
||||
import com.github.shadowsocks._
|
||||
import android.content.{SharedPreferences, Context}
|
||||
|
||||
class ProfileManager(dbHelper: DBHelper) {
|
||||
def addProfile(profile: Profile): Boolean = {
|
||||
class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
|
||||
|
||||
def createOrUpdateProfile(profile: Profile): Boolean = {
|
||||
try {
|
||||
dbHelper.profileDao.createOrUpdate(profile)
|
||||
true
|
||||
} catch {
|
||||
case ex: Exception =>
|
||||
Log.e(Shadowsocks.TAG, "addProfile", ex)
|
||||
return false
|
||||
false
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
def getProfile(id: Int): Option[Profile] = {
|
||||
@@ -70,12 +72,12 @@ class ProfileManager(dbHelper: DBHelper) {
|
||||
def delProfile(id: Int): Boolean = {
|
||||
try {
|
||||
dbHelper.profileDao.deleteById(id)
|
||||
true
|
||||
} catch {
|
||||
case ex: Exception =>
|
||||
Log.e(Shadowsocks.TAG, "delProfile", ex)
|
||||
return false
|
||||
false
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
def getAllProfiles: Option[List[Profile]] = {
|
||||
@@ -88,4 +90,70 @@ class ProfileManager(dbHelper: DBHelper) {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
def load(id: Int): Profile = {
|
||||
|
||||
Log.d(Shadowsocks.TAG, id + " ")
|
||||
|
||||
save()
|
||||
|
||||
val profile = getProfile(id) getOrElse {
|
||||
val p = new Profile()
|
||||
createOrUpdateProfile(p)
|
||||
p
|
||||
}
|
||||
|
||||
Log.d(Shadowsocks.TAG, "load " + profile.id + " " + profile.name)
|
||||
|
||||
val edit = settings.edit()
|
||||
edit.putBoolean(Key.isGlobalProxy, profile.global)
|
||||
edit.putBoolean(Key.isGFWList, profile.chnroute)
|
||||
edit.putBoolean(Key.isBypassApps, profile.bypass)
|
||||
edit.putBoolean(Key.isTrafficStat, profile.traffic)
|
||||
edit.putString(Key.profileName, profile.name)
|
||||
edit.putString(Key.proxy, profile.host)
|
||||
edit.putString(Key.sitekey, profile.password)
|
||||
edit.putString(Key.encMethod, profile.method)
|
||||
edit.putString(Key.remotePort, profile.remotePort.toString)
|
||||
edit.putString(Key.localPort, profile.localPort.toString)
|
||||
edit.putString(Key.proxied, profile.individual)
|
||||
edit.putInt(Key.profileId, profile.id)
|
||||
edit.commit()
|
||||
|
||||
profile
|
||||
}
|
||||
|
||||
def save() {
|
||||
val profile = new Profile()
|
||||
|
||||
profile.global = settings.getBoolean(Key.isGlobalProxy, false)
|
||||
profile.chnroute = settings.getBoolean(Key.isGFWList, false)
|
||||
profile.bypass = settings.getBoolean(Key.isBypassApps, false)
|
||||
profile.traffic = settings.getBoolean(Key.isTrafficStat, false)
|
||||
profile.name = settings.getString(Key.profileName, "default")
|
||||
profile.host = settings.getString(Key.proxy, "127.0.0.1")
|
||||
profile.password = settings.getString(Key.sitekey, "default")
|
||||
profile.method = settings.getString(Key.encMethod, "table")
|
||||
profile.remotePort = try {
|
||||
Integer.valueOf(settings.getString(Key.remotePort, "1984"))
|
||||
} catch {
|
||||
case ex: NumberFormatException => {
|
||||
1984
|
||||
}
|
||||
}
|
||||
profile.localPort = try {
|
||||
Integer.valueOf(settings.getString(Key.localPort, "1984"))
|
||||
} catch {
|
||||
case ex: NumberFormatException => {
|
||||
1984
|
||||
}
|
||||
}
|
||||
profile.individual = settings.getString(Key.proxied, "")
|
||||
|
||||
profile.id = settings.getInt(Key.profileId, -1)
|
||||
|
||||
Log.d(Shadowsocks.TAG, "save " + profile.id + " " + profile.name)
|
||||
|
||||
createOrUpdateProfile(profile)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user