Commit 14414c64 authored by Mygod's avatar Mygod

Copy feature settings from the current profile to the new profile.

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