Commit 8598e5a1 authored by Max Lv's avatar Max Lv

fix UI on tablet

parent 9bcf54aa
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
<string name="loading">Loading…</string> <string name="loading">Loading…</string>
<string name="yes">Yes</string> <string name="yes">Yes</string>
<string name="no">No</string> <string name="no">No</string>
<string name="remove_profile">Remove this profile?</string> <string name="remove_profile">Remove this profile: %s ?</string>
<!-- menu category --> <!-- menu category -->
<string name="recovery">Reset</string> <string name="recovery">Reset</string>
......
...@@ -529,6 +529,7 @@ class Shadowsocks ...@@ -529,6 +529,7 @@ class Shadowsocks
if (!status.getBoolean(getVersionName, false)) { if (!status.getBoolean(getVersionName, false)) {
status.edit.putBoolean(getVersionName, true).apply() status.edit.putBoolean(getVersionName, true).apply()
reset() reset()
Shadowsocks.currentProfile = profileManager.create()
} }
handler.sendEmptyMessage(MSG_INITIAL_FINISH) handler.sendEmptyMessage(MSG_INITIAL_FINISH)
} }
...@@ -567,14 +568,20 @@ class Shadowsocks ...@@ -567,14 +568,20 @@ class Shadowsocks
handler.postDelayed(new Runnable { handler.postDelayed(new Runnable {
def run() { def run() {
Shadowsocks.currentProfile = profileManager.reload(id) Shadowsocks.currentProfile = profileManager.reload(id)
updatePreferenceScreen()
profileManager.save() profileManager.save()
menuAdapter.updateList(getMenuList, Shadowsocks.currentProfile.id) menuAdapter.updateList(getMenuList, Shadowsocks.currentProfile.id)
if (!isSinglePane) {
sendBroadcast(new Intent(Action.UPDATE_FRAGMENT))
} else {
updatePreferenceScreen()
}
h.sendEmptyMessage(0) h.sendEmptyMessage(0)
} }
}, 600) }, 600)
if (!isSinglePane) sendBroadcast(new Intent(Action.UPDATE_FRAGMENT))
} }
def updateProfile(id: Int) { def updateProfile(id: Int) {
...@@ -585,21 +592,30 @@ class Shadowsocks ...@@ -585,21 +592,30 @@ class Shadowsocks
handler.postDelayed(new Runnable { handler.postDelayed(new Runnable {
def run() { def run() {
Shadowsocks.currentProfile = profileManager.reload(id) Shadowsocks.currentProfile = profileManager.reload(id)
updatePreferenceScreen()
menuAdapter.setActiveId(id) menuAdapter.setActiveId(id)
menuAdapter.notifyDataSetChanged() menuAdapter.notifyDataSetChanged()
if (!isSinglePane) {
sendBroadcast(new Intent(Action.UPDATE_FRAGMENT))
} else {
updatePreferenceScreen()
}
h.sendEmptyMessage(0) h.sendEmptyMessage(0)
} }
}, 600) }, 600)
if (!isSinglePane) sendBroadcast(new Intent(Action.UPDATE_FRAGMENT))
} }
def delProfile(id: Int): Boolean = { def delProfile(id: Int): Boolean = {
drawer.closeMenu(true) drawer.closeMenu(true)
val profile = profileManager.getProfile(id)
if (!profile.isDefined) return false
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setMessage(R.string.remove_profile) .setMessage(String.format(getString(R.string.remove_profile), profile.get.name))
.setCancelable(false) .setCancelable(false)
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
override def onClick(dialog: DialogInterface, i: Int) = dialog.cancel() override def onClick(dialog: DialogInterface, i: Int) = dialog.cancel()
...@@ -612,14 +628,18 @@ class Shadowsocks ...@@ -612,14 +628,18 @@ class Shadowsocks
if (profiles.isEmpty) -1 else profiles(0).id if (profiles.isEmpty) -1 else profiles(0).id
} }
Shadowsocks.currentProfile = profileManager.load(profileId) Shadowsocks.currentProfile = profileManager.load(profileId)
updatePreferenceScreen()
menuAdapter.updateList(getMenuList, Shadowsocks.currentProfile.id) menuAdapter.updateList(getMenuList, Shadowsocks.currentProfile.id)
if (!isSinglePane) {
sendBroadcast(new Intent(Action.UPDATE_FRAGMENT))
} else {
updatePreferenceScreen()
}
dialog.dismiss() dialog.dismiss()
} }
}).create().show() }).create().show()
if (!isSinglePane) sendBroadcast(new Intent(Action.UPDATE_FRAGMENT))
true true
} }
...@@ -636,7 +656,7 @@ class Shadowsocks ...@@ -636,7 +656,7 @@ class Shadowsocks
buf ++= getProfileList buf ++= getProfileList
buf += new Item(-1, getString(R.string.add_profile), android.R.drawable.ic_menu_add, addProfile) buf += new Item(-400, getString(R.string.add_profile), android.R.drawable.ic_menu_add, addProfile)
buf += new Category("Settings") buf += new Category("Settings")
......
...@@ -73,10 +73,10 @@ class Profile { ...@@ -73,10 +73,10 @@ class Profile {
var download: Int = 0 var download: Int = 0
@DatabaseField @DatabaseField
var chnroute: Boolean = false var chnroute: Boolean = true
@DatabaseField @DatabaseField
var global: Boolean = false var global: Boolean = true
@DatabaseField @DatabaseField
var bypass: Boolean = false var bypass: Boolean = false
......
...@@ -133,7 +133,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) { ...@@ -133,7 +133,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
profile profile
} }
def save(): Profile = { private def loadFromPreferences: Profile = {
val profile = new Profile() val profile = new Profile()
profile.id = settings.getInt(Key.profileId, -1) profile.id = settings.getInt(Key.profileId, -1)
...@@ -162,8 +162,18 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) { ...@@ -162,8 +162,18 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
} }
profile.individual = settings.getString(Key.proxied, "") profile.individual = settings.getString(Key.proxied, "")
profile
}
def save(): Profile = {
val profile = loadFromPreferences
updateProfile(profile) updateProfile(profile)
profile
}
def create(): Profile = {
val profile = loadFromPreferences
createOrUpdateProfile(profile)
profile profile
} }
} }
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