Copy feature settings from the current profile to the new profile.
And fix #432.
This commit is contained in:
@@ -61,7 +61,7 @@ class ParserActivity extends Activity {
|
||||
.setTitle(R.string.add_profile_dialog)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(android.R.string.yes, ((dialog: DialogInterface, id: Int) => {
|
||||
ShadowsocksApplication.profileManager.createOrUpdateProfile(profile.get)
|
||||
ShadowsocksApplication.profileManager.createProfile(profile.get)
|
||||
dialog.dismiss()
|
||||
}): DialogInterface.OnClickListener)
|
||||
.setNegativeButton(android.R.string.no, ((dialog: DialogInterface, id: Int) => {
|
||||
|
||||
@@ -153,7 +153,7 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
|
||||
val scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
|
||||
if (scanResult != null) Parser.parse(scanResult.getContents) match {
|
||||
case Some(profile) => ShadowsocksApplication.profileManager.createOrUpdateProfile(profile)
|
||||
case Some(profile) => ShadowsocksApplication.profileManager.createProfile(profile)
|
||||
case _ => // ignore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,15 +49,27 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
|
||||
var profileAddedListener: Profile => Any = _
|
||||
def setProfileAddedListener(listener: Profile => Any) = this.profileAddedListener = listener
|
||||
|
||||
def createOrUpdateProfile(profile: Profile): Boolean = {
|
||||
def createProfile(p: Profile = null): Profile = {
|
||||
try {
|
||||
val profile = if (p == null) new Profile else p
|
||||
profile.id = 0
|
||||
ShadowsocksApplication.currentProfile match {
|
||||
case Some(oldProfile) =>
|
||||
// Copy Feature Settings from old profile
|
||||
profile.route = oldProfile.route
|
||||
profile.ipv6 = oldProfile.ipv6
|
||||
profile.proxyApps = oldProfile.proxyApps
|
||||
profile.individual = oldProfile.individual
|
||||
profile.udpdns = oldProfile.udpdns
|
||||
case _ =>
|
||||
}
|
||||
dbHelper.profileDao.createOrUpdate(profile)
|
||||
if (profileAddedListener != null) profileAddedListener(profile)
|
||||
true
|
||||
profile
|
||||
} catch {
|
||||
case ex: Exception =>
|
||||
Log.e(Shadowsocks.TAG, "addProfile", ex)
|
||||
false
|
||||
p
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,11 +126,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
|
||||
|
||||
def load(id: Int): Profile = {
|
||||
|
||||
val profile = getProfile(id) getOrElse {
|
||||
val p = new Profile()
|
||||
createOrUpdateProfile(p)
|
||||
p
|
||||
}
|
||||
val profile = getProfile(id) getOrElse createProfile()
|
||||
|
||||
val edit = settings.edit()
|
||||
edit.putBoolean(Key.isProxyApps, profile.proxyApps)
|
||||
@@ -175,7 +183,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
|
||||
remotePort = 443
|
||||
password = "u1rRWTssNv0p"
|
||||
}
|
||||
createOrUpdateProfile(profile)
|
||||
createProfile(profile)
|
||||
profile
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ object TrafficMonitor {
|
||||
var txTotal: Long = 0
|
||||
var rxTotal: Long = 0
|
||||
|
||||
def getTraffic(): Traffic = {
|
||||
def getTraffic: Traffic = {
|
||||
new Traffic(Math.max(TrafficStats.getTotalTxBytes - TrafficStats.getUidTxBytes(uid), 0),
|
||||
Math.max(TrafficStats.getTotalRxBytes - TrafficStats.getUidRxBytes(uid), 0), System.currentTimeMillis())
|
||||
}
|
||||
@@ -84,4 +84,3 @@ object TrafficMonitor {
|
||||
}
|
||||
}
|
||||
|
||||
class TrafficMonitor ()
|
||||
|
||||
Reference in New Issue
Block a user