Commit 93d468c5 authored by Mygod's avatar Mygod

Refine no selected profile case again

parent 2be75d0b
......@@ -107,7 +107,7 @@ trait BaseService extends Service {
}
}
override def use(profileId: Int): Unit = synchronized {
override def use(profileId: Int): Unit = synchronized(if (profileId < 0) stopRunner(stopService = true) else {
val profile = app.profileManager.getProfile(profileId).orNull
if (profile == null) stopRunner(stopService = true, "Please select a profile.") else state match { // TODO: localize
case State.STOPPED => if (checkProfile(profile)) startRunner(profile)
......@@ -117,7 +117,7 @@ trait BaseService extends Service {
}
case _ => Log.w(BaseService.this.getClass.getSimpleName, "Illegal state when invoking use: " + state)
}
}
})
override def useSync(profileId: Int): Unit = use(profileId)
}
......
......@@ -181,10 +181,8 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
profiles.insert(index, item)
notifyItemInserted(index)
}
def commit(actions: Iterator[(Int, Profile)]): Unit = for ((_, item) <- actions) {
app.profileManager.delProfile(item.id)
if (item.id == app.profileId) app.profileId(-1)
}
def commit(actions: Iterator[(Int, Profile)]): Unit =
for ((_, item) <- actions) app.profileManager.delProfile(item.id)
def refreshId(id: Int) {
val index = profiles.indexWhere(_.id == id)
......@@ -197,6 +195,7 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
val index = profiles.indexWhere(_.id == id)
profiles.remove(index)
notifyItemRemoved(index)
if (id == app.profileId) app.profileId(0)
}
}
......
......@@ -83,7 +83,7 @@ class ShadowsocksApplication extends Application {
.setFatal(false)
.build())
def profileId: Int = settings.getInt(Key.id, -1)
def profileId: Int = settings.getInt(Key.id, 0)
def profileId(i: Int): Unit = editor.putInt(Key.id, i).apply()
def currentProfile: Option[Profile] = profileManager.getProfile(profileId)
......
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